This may be brain-dead obvious to those who understand what's going on underneath, but I was hoping to run javascript that assigns a function to a variable in one context and use that function in another context (in the same isolate). The goal behind this was to make sure to not allow the user to directly pollute the "real" global object while creating the function.
When I try to do this, I get unexpected results, however, as the new context's global isn't picked up and the receiver information seems to be ignored. Full reproduction code here: https://gist.github.com/xaxxon/ad74e6a9c8ab76e3faf7 Interesting bits: auto s = v8::Script::Compile(c, v8::String::NewFromUtf8(i,"a=function(){return b;}")).ToLocalChecked(); (void)s->Run(c); } // THIS OF COURSE WORKS //(void)c->Global()->Set(c,String::NewFromUtf8(i,"b"), String::NewFromUtf8(i,"HELLO")); //auto a_val = c->Global()->Get(c, String::NewFromUtf8(i,"a")).ToLocalChecked(); //auto a_func = Local<Function>::Cast(a_val); //auto result = a_func->Call(c, c->Global(), 0, nullptr); //printf("result: %s\n", *String::Utf8Value(result.ToLocalChecked())); auto c2 = v8::Context::New(i, nullptr, got); { Context::Scope cs2(c2); (void)c2->Global()->Set(c2,String::NewFromUtf8(i,"b"), String::NewFromUtf8(i,"HELLO")); auto a_val2 = c2->Global()->Get(c, String::NewFromUtf8(i,"a")).ToLocalChecked(); auto a_func2 = Local<Function>::Cast(a_val2); auto result2 = a_func2->Call(c2, c2->Global(), 0, nullptr); printf("result: %s\n", *String::Utf8Value(result2.ToLocalChecked())); } Output: <unknown>:20: Uncaught ReferenceError: b is not defined -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
