Re: Is only one JSContext allowed per thread in JS 76?
Jan de Mooij <[email protected]> Fri, 26 Jun 2020 14:34:23 +0200
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <CABTC+Je_7pW+fQ_TqSzExPtuZRFK_c+mjyQ6nSoy6Z+ekojyvQ@mail.gmail.com> |
On Fri, Jun 26, 2020 at 2:20 PM Miles <[email protected]> wrote: > As a follow up/supplemental question, if you can only have one JSContext > on a thread, can a context have multiple global objects? From my > understanding all the standard classes etc are made using a global object. > Does that mean that if I have two scripts that I want to keep completely > separate I can create two different global objects in one context, > initialise the standard classes for each global object and then compile and > execute the scripts separately in the different globals? > Are the variables, classes etc completely separate and independent? > Yes you can create multiple global objects with JS_NewGlobalObject, switch between them with JSAutoRealm, and compile/execute code in each realm/global separately. Hope this helps. Jan