Dear All
I'm new of V8 and would like to know how to implement scope chain with V8 , I was ever with Spider monkey which having object scope to calling with API
or if you don't understand please kindly see this JAVA Script code below
var global_scope = this;
var some_value = 'hello';
global_scope.some_value ; // 'hello'
function (){
var function_scope = this;
var some_value = 'hi';
function_scope.some_value ; // 'hi'
}
global_scope.some_value ; // 'hello'
function_scope.some_value = 'hi'; // error : function_scope is not defined; because scope chain (function_scope) was terminated;
============================
but when implementing with V8 , I have done something like this code below
Handle<Context> contextA = Context::New(isolate);
Handle<Context> contextB = Context::New(isolate);
Context::Scope context_scope1(contextA);
Handle<String> source = String::NewFromUtf8(isolate, “var scope1 = this ; some_value=‘hello’;");
Handle<Script> script = Script::Compile(source);
Handle<Value> result = script->Run(); //
{
Context::Scope context_scope2(contextB);
Handle<String> source = String::NewFromUtf8(isolate, “scope1.some_value");
Handle<Script> script = Script::Compile(source);
Handle<Value> result = script->Run(); // Error scope1 is not defined !!! result should be as 'hello' as above executing
String::Utf8Value utf8(result);
}
==================================================
Please kindly advise and I do thank you very much for all that read my email.
Best Regards
Puwanat S.