V8 Unable to access properties from script compiled in new context

I created a simple "require" mechanism ( https://gist.github.com/1031869 ), into which the new context is compiled and run the included script. However, when I call the function in the included script and pass it in this, the included script does not see any properties in it.

//required.js - compiled and run in new context
exports.logThis = function(what){
    for (key in what) log(key + ' : ' + what[key]);
}

//main.js
logger = require('required');
this.someProp = {some: 'prop'}
logger.logThis({one: 'two'});   //works, prints 'one : two'
logger.logThis(this); //doesn't work, prints nothing. expected 'some : prop'
logger.logThis(this.someProp); //works, prints 'some : prop'
+3
source share
1 answer

The problem was that V8 does not allow the context to access the global variables of another Context. Therefore, logger.logThis (this) did not print anything.

This was resolved by setting the security token in a new context:

moduleContext->SetSecurityToken(context->GetSecurityToken());

"" , moduleContext - , script.

+4

All Articles