In J2V8 (our Java bindings for V8 [1]) we provide access to objects defined 
in the global scope.

[1] https://github.com/eclipsesource/j2v8

In Java you can write:

v8.executeScript("var foo = [1,2,3]");

V8Array array = (V8Array) v8.get("foo");


v8 in this case is the the isolate, and when we create the isolate we 
provide a Persistent<Object>

that matches the global scope:


    Handle<Context> context = Context::New(runtime->isolate, NULL, 
globalObject);

    runtime->context_.Reset(runtime->isolate, context);

    runtime->globalObject = new Persistent<Object>;

    runtime->globalObject->Reset(runtime->isolate, context->Global());


We can then access the objects using:

  Handle<Object> object = Local<Object>::New(isolate, 
*reinterpret_cast<Persistent<Object>*>(objectHandle));

  Local<String> v8Key = createV8String(env, isolate, key);

  MaybeLocal<Value> result = object->Get(context, v8Key);


Where v8Key is the identifier ("foo" in this case), and object is the 
globalObject.


If we change the JavaScript to:

"let foo = [1,2,3]" (notice let instead of var) this code returns 
Undefined. I'm not a JS expert 

(I just write bindings), but I guess this is because let defines a block 
scoped variable, whereas

var is not. Can we access these blocked scoped (ES6) variables using the V8 
API? I would like

to expose this to users of the J2V8 bindings.


Thanks,

Ian

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