Bug 563099 - Compartments and wrappers API. r=gal.

This commit is contained in:
Jason Orendorff
2010-06-23 16:35:10 -05:00
parent d4c5ccb2b1
commit dccd1beb86
20 changed files with 1122 additions and 523 deletions

View File

@@ -86,6 +86,7 @@
#include "prmjtime.h"
#include "jsstaticcheck.h"
#include "jsvector.h"
#include "jswrapper.h"
#include "jstypedarray.h"
#include "jsatominlines.h"
@@ -566,8 +567,10 @@ JSRuntime::JSRuntime()
bool
JSRuntime::init(uint32 maxbytes)
{
if (!(defaultCompartment = new JSCompartment(this)))
if (!(defaultCompartment = new JSCompartment(this)) ||
!defaultCompartment->init()) {
return false;
}
if (!js_InitGC(this, maxbytes) || !js_InitAtomState(this))
return false;
@@ -1089,6 +1092,30 @@ JS_GetImplementationVersion(void)
return "JavaScript-C 1.8.0 pre-release 1 2007-10-03";
}
JS_PUBLIC_API(JSCrossCompartmentCall *)
JS_EnterCrossCompartmentCall(JSContext *cx, JSObject *target)
{
CHECK_REQUEST(cx);
AutoCompartment *call = new AutoCompartment(cx, target);
if (!call)
return NULL;
if (!call->enter()) {
delete call;
return NULL;
}
return reinterpret_cast<JSCrossCompartmentCall *>(call);
}
JS_PUBLIC_API(void)
JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call)
{
AutoCompartment *realcall = reinterpret_cast<AutoCompartment *>(call);
CHECK_REQUEST(realcall->context);
realcall->leave();
delete realcall;
}
JS_PUBLIC_API(JSObject *)
JS_GetGlobalObject(JSContext *cx)
{
@@ -2886,6 +2913,22 @@ JS_NewGlobalObject(JSContext *cx, JSClass *clasp)
return obj;
}
JS_PUBLIC_API(JSObject *)
JS_NewCompartmentAndGlobalObject(JSContext *cx, JSClass *clasp)
{
CHECK_REQUEST(cx);
JSCompartment *compartment = NewCompartment(cx);
if (!compartment)
return NULL;
JSCompartment *saved = cx->compartment;
cx->compartment = compartment;
JSObject *obj = JS_NewGlobalObject(cx, clasp);
cx->compartment = saved;
return obj;
}
JS_PUBLIC_API(JSObject *)
JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent)
{
@@ -4869,11 +4912,12 @@ JS_IsRunning(JSContext *cx)
#ifdef JS_TRACER
JS_ASSERT_IF(JS_TRACE_MONITOR(cx).tracecx == cx, cx->fp);
#endif
return cx->fp != NULL;
JSStackFrame *fp = cx->fp;
while (fp && fp->isDummyFrame())
fp = fp->down;
return fp != NULL;
}
JS_PUBLIC_API(JSBool)
JS_IsConstructing(JSContext *cx)
{