Looks like the __proto__ trick works similarly to wrapping the script
in a "with" block. However, it looks better than wrapping, thanks for
the hint. One thing that bothers me is that it's not standard. Can I
be sure it won't disappear or change behavior in future revisions of
v8?

On 22 янв, 17:08, Flier Lu <[email protected]> wrote:
> As I know, v8 doesn't provide any public API to change the global
> object of context, but we could do it with javascript way, just set
> the __proto__ property of global object to our global object.
>
> http://code.google.com/p/pyv8/source/browse/trunk/src/Context.cpp#79
>
> m_context->Global()->Set(v8::String::NewSymbol("__proto__"),
> CPythonObject::Wrap(global));
>
> you could check __proto__ for more detail <https://
> developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/
> Object/Proto>
>
> On 1月22日, 下午9时56分, Andrey Semashev <[email protected]> wrote:
>
>
>
> > > v8 provide the global object with Context::Global method, you should
> > > wrap the document object first, and add it to the global object in the
> > > entered context.
>
> > That's right. I added the root scope in my hierarchy (which is
> > session) to this object. So I have this:
>
> >   [global object] =
> >   {
> >     session :
> >     {
> >       application :
> >       {
> >         document :
> >         {
> >           dialog : {}
> >         }
> >       }
> >     }
> >   };
>
> > The problem is, I can't find any methods in the context to make
> > another object global (such as document in my example).
>
> > > to wrap the document object, you must implement the named, indexed
> > > property and call as function handler, and create the object with
> > > ObjectTemplate
>
> > >   v8::HandleScope handle_scope;
>
> > >   v8::Handle<v8::ObjectTemplate> clazz = v8::ObjectTemplate::New();
>
> > >   clazz->SetNamedPropertyHandler(NamedGetter, NamedSetter, NamedQuery,
> > > NamedDeleter, NamedEnumerator);
> > >   clazz->SetIndexedPropertyHandler(IndexedGetter, IndexedSetter,
> > > IndexedQuery, IndexedDeleter, IndexedEnumerator);
> > >   clazz->SetCallAsFunctionHandler(Caller);
>
> > >   return v8::Persistent<v8::ObjectTemplate>::New(clazz);
>
> > I don't understand. All scope objects are pure JS objects, they are
> > not native. Why do I need an ObjectTemplate? Or do you mean that I
> > have to create an artifical native object that would reroute all its
> > property access calls to the appropriate scope object of my hierarchy?

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to