What is shared/discrete between multiple contexts in a single isolate?

79 views
Skip to first unread message

Zac Hansen

unread,
Jun 24, 2016, 1:34:35 AM6/24/16
to v8-users
If I create two contexts both within a single isolate, what types of things can I share between them and what is only available in the specific context?

I know this is a broad question, so I'm happy to get broad answers or links to documentation.   

An example that I find confusing is:  v8::Object is created with only a isolate but to call .set on it requires a context.  http://v8.paulfryzel.com/docs/master/classv8_1_1_object.html

Is the object somehow shared across contexts, but the attributes aren't?   

Any insight would be great.   I've also got an open question on this on stack overflow and I'll put anything I learn on this thread into that.  http://stackoverflow.com/questions/37981291/what-is-shared-discrete-across-multiple-v8-context-objects-belonging-to-a-single

Thanks.

--Zac

Ben Noordhuis

unread,
Jun 24, 2016, 4:42:15 AM6/24/16
to v8-users
It depends on the security policy. By default, everything is shared.

You can turn on access checks with
v8::ObjectTemplate::SetAccessCheckCallback() to block access on a
per-property basis or disallow sharing altogether by changing the
security token with v8::Context::SetSecurityToken().

Aside: I believe the reason you need to pass a context to
v8::Object::Set() is to disambiguate the overloaded function. C++
doesn't allow overloading on just the return type.

It's also slightly faster. The non-context version of Set() looks up
the current context and calls the contextified Set().

Zac Hansen

unread,
Jun 24, 2016, 6:43:59 AM6/24/16
to v8-u...@googlegroups.com
Define "everything"?   Could I take any javascript program and take each line and run it in a different context (on the same isolate) and it would work?   At least theoretically,  with no fundamental changes to the program?





--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/SVISaM3bR8k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Noordhuis

unread,
Jun 24, 2016, 9:45:30 AM6/24/16
to v8-users
On Fri, Jun 24, 2016 at 12:43 PM, Zac Hansen <xax...@gmail.com> wrote:
> Define "everything"? Could I take any javascript program and take each
> line and run it in a different context (on the same isolate) and it would
> work? At least theoretically, with no fundamental changes to the program?

Not quite. The fundamental unit of execution in V8 is the function.
Functions belong to the context they're compiled in.

Zac Hansen

unread,
Jun 24, 2016, 10:43:30 AM6/24/16
to v8-u...@googlegroups.com
Ok, the bit about functions belonging to the context they're compiled in is what had bitten me in the past that I couldn't quite remember.   Thank you.

Reply all
Reply to author
Forward
0 new messages