638
edits
Line 142: | Line 142: | ||
--> | --> | ||
=== Compartments and wrappers - | === Compartments and wrappers - API === | ||
Each runtime has a ''default compartment'' which contains interned strings, the empty string, +Inf, -Inf, NaN—and, in non-compartment-aware embeddings, everything else. | Each runtime has a ''default compartment'' which contains interned strings, the empty string, +Inf, -Inf, NaN—and, in non-compartment-aware embeddings, everything else. | ||
Line 153: | Line 153: | ||
JSCompartment * | JSCompartment * | ||
JS_GetDefaultCompartment(JSRuntime *rt); | |||
JSCompartment * | JSCompartment * | ||
JS_GetCurrentCompartment(cx); | JS_NewCompartment(JSRuntime *rt, JSPrincipals *principals); | ||
JSCompartment * | |||
JS_GetCurrentCompartment(JSContext *cx); | |||
void | void | ||
JS_SetCurrentCompartment(cx, compartment); | JS_SetCurrentCompartment(JSContext *cx, JSCompartment *compartment); | ||
All existing APIs could just assert that cx->currentCompartment() agrees with all the arguments that happen to be gc-things. The precise rule is: each gc-thing passed in must either be in <code>cx->currentCompartment()</code> or be a string or double in <code>cx->runtime->defaultCompartment</code>. | All existing APIs could just assert that cx->currentCompartment() agrees with all the arguments that happen to be gc-things. The precise rule is: each gc-thing passed in must either be in <code>cx->currentCompartment()</code> or be a string or double in <code>cx->runtime->defaultCompartment</code>. | ||
'''GC roots''' will be per-compartment. This means <code>JS_AddGCRootRT</code> will add a root to the default compartment. This behavior is a bit unexpected. To help embeddings get this right, GC should assert that each gc thing pointed to by a root is in the expected compartment. | |||
'''Walking the GC heap.''' <code>JS_TraceChildren</code> and friends will have to have a mode for walking the entire heap and a separate mode for walking just one compartment. TBD. | |||
'''Wrapper API.''' Since the cross-compartment reference from a wrapper to the wrappee is so special, we will need API for it. TBD. |
edits