mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 899367 - Add an API to opt out of default compartment objects. r=luke
We need this explicit API because otherwise the default compartment object will get set implicitly during the first call to InitClasses.
This commit is contained in:
parent
9ed5f11e8d
commit
7ea705498c
@ -1526,7 +1526,11 @@ JS_StringToVersion(const char *string);
|
||||
|
||||
/* JS_BIT(10) is currently unused. */
|
||||
|
||||
/* JS_BIT(11) is currently unused. */
|
||||
#define JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT JS_BIT(11) /* This JSContext does not use a
|
||||
default compartment object. Such
|
||||
an object will not be set implicitly,
|
||||
and attempts to get or set it will
|
||||
assert. */
|
||||
|
||||
#define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12) /* A promise to the compiler
|
||||
that a null rval out-param
|
||||
|
@ -449,7 +449,10 @@ struct JSContext : public js::ExclusiveContext,
|
||||
public:
|
||||
inline void setDefaultCompartmentObject(JSObject *obj);
|
||||
inline void setDefaultCompartmentObjectIfUnset(JSObject *obj);
|
||||
JSObject *maybeDefaultCompartmentObject() const { return defaultCompartmentObject_; }
|
||||
JSObject *maybeDefaultCompartmentObject() const {
|
||||
JS_ASSERT(!hasOption(JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT));
|
||||
return defaultCompartmentObject_;
|
||||
}
|
||||
|
||||
/* Wrap cx->exception for the current compartment. */
|
||||
void wrapPendingException();
|
||||
|
@ -438,14 +438,18 @@ JSContext::setPendingException(js::Value v) {
|
||||
inline void
|
||||
JSContext::setDefaultCompartmentObject(JSObject *obj)
|
||||
{
|
||||
JS_ASSERT(!hasOption(JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT));
|
||||
defaultCompartmentObject_ = obj;
|
||||
}
|
||||
|
||||
inline void
|
||||
JSContext::setDefaultCompartmentObjectIfUnset(JSObject *obj)
|
||||
{
|
||||
if (!defaultCompartmentObject_)
|
||||
if (!hasOption(JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT) &&
|
||||
!defaultCompartmentObject_)
|
||||
{
|
||||
setDefaultCompartmentObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
|
@ -682,11 +682,16 @@ bool
|
||||
JSRuntime::initSelfHosting(JSContext *cx)
|
||||
{
|
||||
JS_ASSERT(!selfHostingGlobal_);
|
||||
RootedObject savedGlobal(cx, js::DefaultObjectForContextOrNull(cx));
|
||||
|
||||
bool receivesDefaultObject = !cx->hasOption(JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT);
|
||||
RootedObject savedGlobal(cx, receivesDefaultObject
|
||||
? js::DefaultObjectForContextOrNull(cx)
|
||||
: NULL);
|
||||
if (!(selfHostingGlobal_ = JS_NewGlobalObject(cx, &self_hosting_global_class,
|
||||
NULL, JS::DontFireOnNewGlobalHook)))
|
||||
return false;
|
||||
JSAutoCompartment ac(cx, selfHostingGlobal_);
|
||||
if (receivesDefaultObject)
|
||||
js::SetDefaultObjectForContext(cx, selfHostingGlobal_);
|
||||
Rooted<GlobalObject*> shg(cx, &selfHostingGlobal_->as<GlobalObject>());
|
||||
/*
|
||||
@ -756,6 +761,7 @@ JSRuntime::initSelfHosting(JSContext *cx)
|
||||
ok = Evaluate(cx, shg, options, src, srcLen, &rv);
|
||||
}
|
||||
JS_SetErrorReporter(cx, oldReporter);
|
||||
if (receivesDefaultObject)
|
||||
js::SetDefaultObjectForContext(cx, savedGlobal);
|
||||
return ok;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user