Regarding the code sample that Ben kindly provided here -
I checked it out, and I'm afraid it should be written with 
GetPropertyNames(), not GetOwnPropertyNames() ...

On Monday, March 24, 2014 at 9:03:23 AM UTC+2, Michael Klimontov wrote:
>
> Hello guys. I need your help for solve this question.
>
> I am want loading cfg.js in context.
> In any action we will loading and working with scr_1.js. In scr_1 changing 
> vals from cfg.js. After will need working with scr_2 where have clear vars 
> from cfg.js, but they changed in prev work with scr_1.
> How are correct work with context and copy they?
>
> Thanks for your.
>
> ___ cfg.js ___
>
> var a = { a : 22522, b : '123' };
> // Define common functions ....
>
> ___ scr_1.js ___
>
> function test_function(test_arg1,test_arg2)
> {
>     log("Src 1");
>     log(a.a)
>     a.a = 9999;
>     log("Src 1 -> new a = " a.a)
>     return 0;
> }
>
> ___ scr_2.js ___
>
> function test_function(test_arg1,test_arg2)
> {
>     log(a.a)
>     return 0;
> }
>
> ___ main.cpp ___
>
> int main(int argc, char* argv[]) 
> {
>     v8::V8::InitializeICU();
>
>     Isolate* isolate = Isolate::GetCurrent();
>     HandleScope handle_scope(isolate);
>
>
>     Handle<ObjectTemplate> global_cfg = ObjectTemplate::New(isolate);
>     global_cfg->Set(String::NewFromUtf8(isolate, "log"), 
> FunctionTemplate::New(isolate, LogCallback));
>     Persistent<Context> persistent_context;
>
>     {
>         v8::Handle<v8::Context> context_global = Context::New(isolate, 
> NULL, global_cfg);
>         persistent_context.Reset(isolate, context_global);
>
>         v8::Local<v8::Context> context_tmp = 
> v8::Local<v8::Context>::New(isolate, persistent_context);
>         Context::Scope context_scope_tmp(context_tmp);
>         Handle<String> source2 = ReadFile(isolate, "cfg.js");
>         v8::Handle<v8::Script> script2 = Script::Compile(source2);
>         script2->Run();
>     }
>
>
>     // Run test 1. Need copy context with out change.
>     // After run test_function a = new value
>     {
>         HandleScope handle_scope(isolate);
>         v8::Local<v8::Context> context_tmp = 
> v8::Local<v8::Context>::New(isolate, persistent_context);
>         context_tmp->Enter();
>
>         Context::Scope context_scope_tmp(context_tmp);
>         HandleScope handle_scope(isolate);
>
>         Handle<String> source = ReadFile(isolate, "scr_1.js");
>         v8::Handle<v8::Script> script = Script::Compile(source);
>         // ! run function test_function
>         script->Run();
>         context_tmp->Exit();
>     }
>
>     // Run test 2. Need copy context without change.
>     {
>         HandleScope handle_scope(isolate);
>         v8::Local<v8::Context> context_tmp = 
> v8::Local<v8::Context>::New(isolate, persistent_context);
>         context_tmp->Enter();
>
>         Context::Scope context_scope_tmp(context_tmp);
>         HandleScope handle_scope(isolate);
>
>         Handle<String> source = ReadFile(isolate, "scr_1.js");
>         v8::Handle<v8::Script> script = Script::Compile(source);
>         // This val must equal var a = { a : 22522, b : '123' }, but test1 
> changes it.
>         script->Run();
>
>         
>         context_tmp->Exit();
>     }
> }
>
>

-- 
-- 
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.

Reply via email to