Bug 959787 - Handlify several JSAPI interfaces that can GC, Part 1; r=sfink,Ms2ger

--HG--
extra : rebase_source : 0e0e75028f12db9cc4cf612a9205525669b70267
This commit is contained in:
Terrence Cole 2014-01-14 12:41:22 -08:00
parent 0ed9fa84e9
commit 422649470f
7 changed files with 22 additions and 28 deletions

View File

@ -2324,7 +2324,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
// so all expandos and such defined on the outer window should go away. Force
// all Xray wrappers to be recomputed.
JS::ExposeObjectToActiveJS(mJSObject);
if (!JS_RefreshCrossCompartmentWrappers(cx, mJSObject)) {
JS::Rooted<JSObject*> rootedObject(cx, mJSObject);
if (!JS_RefreshCrossCompartmentWrappers(cx, rootedObject)) {
return NS_ERROR_FAILURE;
}

View File

@ -2003,8 +2003,9 @@ NPObjectMember_Convert(JSContext *cx, JS::Handle<JSObject*> obj, JSType type, JS
case JSTYPE_STRING:
case JSTYPE_NUMBER:
vp.set(memberPrivate->fieldValue);
if (!JSVAL_IS_PRIMITIVE(vp)) {
return JS_DefaultValue(cx, JSVAL_TO_OBJECT(vp), type, vp.address());
if (vp.isObject()) {
JS::Rooted<JSObject*> objVal(cx, &vp.toObject());
return JS_DefaultValue(cx, objVal, type, vp);
}
return true;
case JSTYPE_BOOLEAN:

View File

@ -126,7 +126,7 @@ _newJSDContext(JSRuntime* jsrt,
{
JSAutoCompartment ac(cx, jsdc->glob);
ok = JS_AddNamedObjectRoot(cx, &jsdc->glob, "JSD context global") &&
JS_InitStandardClasses(cx, jsdc->glob);
JS_InitStandardClasses(cx, JS::HandleObject::fromMarkedLocation(&jsdc->glob));
}
if( ! ok )
goto label_newJSDContext_failure;

View File

@ -896,7 +896,7 @@ CanonicalizeNaN(double d)
* !JSVAL_IS_PRIMITIVE(v) === v.isObject()
*
* Also, to help prevent mistakenly boxing a nullable JSObject* as an object,
* Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a
* Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a
* JSObject&.) A convenience member Value::setObjectOrNull is provided.
*
* - JSVAL_VOID is the same as the singleton value of the Undefined type.

View File

@ -1129,16 +1129,14 @@ JS_TransplantObject(JSContext *cx, HandleObject origobj, HandleObject target)
* the inner window and global object.
*/
JS_PUBLIC_API(bool)
JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *objArg)
JS_RefreshCrossCompartmentWrappers(JSContext *cx, HandleObject obj)
{
RootedObject obj(cx, objArg);
return RemapAllWrappersForObject(cx, obj, obj);
}
JS_PUBLIC_API(bool)
JS_InitStandardClasses(JSContext *cx, JSObject *objArg)
JS_InitStandardClasses(JSContext *cx, HandleObject obj)
{
RootedObject obj(cx, objArg);
JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
@ -2275,20 +2273,13 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp)
}
JS_PUBLIC_API(bool)
JS_DefaultValue(JSContext *cx, JSObject *objArg, JSType hint, jsval *vp)
JS_DefaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp)
{
RootedObject obj(cx, objArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
JS_ASSERT(obj != nullptr);
JS_ASSERT(hint == JSTYPE_VOID || hint == JSTYPE_STRING || hint == JSTYPE_NUMBER);
RootedValue value(cx);
if (!JSObject::defaultValue(cx, obj, hint, &value))
return false;
*vp = value;
return true;
return JSObject::defaultValue(cx, obj, hint, vp);
}
JS_PUBLIC_API(bool)

View File

@ -1670,7 +1670,7 @@ extern JS_PUBLIC_API(JSObject *)
JS_TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject target);
extern JS_PUBLIC_API(bool)
JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob);
JS_RefreshCrossCompartmentWrappers(JSContext *cx, JS::Handle<JSObject*> obj);
/*
* At any time, a JSContext has a current (possibly-nullptr) compartment.
@ -1743,7 +1743,7 @@ JS_IterateCompartments(JSRuntime *rt, void *data,
* NB: This sets cx's global object to obj if it was null.
*/
extern JS_PUBLIC_API(bool)
JS_InitStandardClasses(JSContext *cx, JSObject *obj);
JS_InitStandardClasses(JSContext *cx, JS::Handle<JSObject*> obj);
/*
* Resolve id, which must contain either a string or an int, to a standard
@ -2328,7 +2328,8 @@ JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
* success the resulting value is stored in *vp.
*/
extern JS_PUBLIC_API(bool)
JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
JS_DefaultValue(JSContext *cx, JS::Handle<JSObject*> obj, JSType hint,
JS::MutableHandle<JS::Value> vp);
extern JS_PUBLIC_API(bool)
JS_PropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id,

View File

@ -540,7 +540,7 @@ private:
/*
* Not setting this will cause JS_CHECK_RECURSION to report false
* positives
*/
*/
JS_SetNativeStackQuota(mRuntime, 128 * sizeof(size_t) * 1024);
mContext = JS_NewContext(mRuntime, 0);
@ -554,18 +554,18 @@ private:
mGlobal = JS_NewGlobalObject(mContext, &sGlobalClass, nullptr,
JS::DontFireOnNewGlobalHook, options);
NS_ENSURE_TRUE(mGlobal, NS_ERROR_OUT_OF_MEMORY);
JS::Rooted<JSObject*> global(mContext, mGlobal);
JSAutoCompartment ac(mContext, mGlobal);
js::SetDefaultObjectForContext(mContext, mGlobal);
JS_InitStandardClasses(mContext, mGlobal);
JSAutoCompartment ac(mContext, global);
js::SetDefaultObjectForContext(mContext, global);
JS_InitStandardClasses(mContext, global);
JS_SetErrorReporter(mContext, PACErrorReporter);
if (!JS_DefineFunctions(mContext, mGlobal, PACGlobalFunctions))
if (!JS_DefineFunctions(mContext, global, PACGlobalFunctions))
return NS_ERROR_FAILURE;
JS::Rooted<JSObject*> rootedGlobal(mContext, mGlobal);
JS_FireOnNewGlobalObject(mContext, rootedGlobal);
JS_FireOnNewGlobalObject(mContext, global);
return NS_OK;
}