638
edits
(→Plans) |
|||
Line 142: | Line 142: | ||
--> | --> | ||
=== Compartments and wrappers - | === Compartments and wrappers - implementation details === | ||
Each runtime has a ''default compartment'' which contains interned strings (and, in non-compartment-aware embeddings, everything else). | |||
A consequence of this is that the API function <code>JS_SetProperty(cx, obj, name, vp)</code> must put cx into obj's compartment before calling <code>js_Atomize</code>. | Each context has a ''current compartment'', initially the default compartment, and normally the compartment of JS_GetScopeChain(cx). So, for example, <code>js_Atomize(cx, name, strlen(name), 0)</code> allocates the new string from <code>cx->currentCompartment()</code>. | ||
A tricky consequence of this is that the API function <code>JS_SetProperty(cx, obj, name, vp)</code> must put cx into obj's compartment before calling <code>js_Atomize</code>. Otherwise obj might end up with property ids in other compartments, a bad scene. | |||
When does a context's current compartment change? At API entry points and when a function is called across compartment boundaries (which always happens via a wrapper). So it will be rare and will not ordinarily happen on trace. |
edits