After another day of staring at the code and trying silly things, I figured 
out the problem. As it turns out, the error wasn't in the prototype 
creation and object setup, but in my implementation of the named 
intercepter callback functions, which were not properly returning 'empty' 
to forward the property evaluation back to the internal v8::Object map. 

For reference, this is how I got the prototypes of the global objects to 
operate properly: 

void JS_Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
            {
                v8::HandleScope scope(info.GetIsolate());               
                
info.This()->SetPrototype(v8::Local<v8::Object>::Cast(info.Data()));
            }

v8::HandleScope scope(isolate);
                v8::Local<v8::FunctionTemplate> global_constructor
                        = 
v8::FunctionTemplate::New(JS_Constructor,transformer.loadArithmetic()/*Object 
from another context*/);

                v8::Local<v8::ObjectTemplate> global = 
global_constructor->InstanceTemplate();

                global->SetNamedPropertyHandler(&GetPropertyValue, 
&SetPropertyValue, &GetPropertyAttributes, 0, &EnumerateProperties);
                global->SetInternalFieldCount(1);

                v8::Local<v8::Context> context = 
v8::Context::New(isolate,NULL,global);
                context->Enter();
                
                v8::Local<v8::Object> globalobj = 
v8::Local<v8::Object>::Cast(context->Global()->GetPrototype());
                
globalobj->SetInternalField(0,v8::External::New((void*)this));

On Thursday, October 17, 2013 9:35:12 AM UTC-4, Jeremy Turpin wrote:
>
> Sorry for resurrecting this post after such a long time, but I'm having 
> the same (or very similar) problem as MikeM, in trying to add additional 
> javascript objects (which may themselves be the global object of another 
> context) to the prototype chain of the global object of a v8 context. It 
> seems like this should be possible, but I can't find the one way that makes 
> everything work. MikeM, were you able to solve your problem?
>
> Application: my global object has a property interceptor assigned to catch 
> all variable accesses (properties) at global scope and delegate those calls 
> to the embedding application. However, if a variable name doesn't exist in 
> the embedding application, I want to delegate to the prototype chain of the 
> Global object, as usual. At the root of my application, I have a javascript 
> object defined in a js file that I load and compile into JS; This object 
> should be in the prototype chain of every context in the application. I 
> have a series of v8::contexts that correspond to a data model hierarchy in 
> my application, where the global object of a child node context should have 
> the global object of the parent node context as its prototype. I haven't 
> found a reason why this shouldn't be possible, but neither have I gotten it 
> to work. 
>
> I have tried: 
> Create the ObjectTemplate, create the Context (with the template), get the 
> global object reference (accounting for the proxy global), and 
> SetPrototype(my_parent_object)
> Create the ObjectTemplate, create the Context (with the template), get the 
> global object reference (accounting for the proxy global), continue to 
> traverse using GetPrototype until GetPrototype returns null, then use 
> SetPrototype(my_parent_object) on that root prototype object. 
> Create a FunctionTemplate to treat as a constructor, write a c++ function 
> (js constructor) that assigns the prototype to the newly-created object, 
> and create the Context with the InstanceTemplate of the FunctionTemplate.
>
> All of these techniques (after a fair bit of fiddling) will compile and 
> execute without segfaults, but none successfully configures the prototype 
> chain, since I cannot access the properties of the intended parent class. 
>
> Is what I am trying to accomplish possible? Is there a better approach? 
> Thanks - 
>
> Jeremy Turpin
>

-- 
-- 
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/groups/opt_out.

Reply via email to