Bug 900979 - Change JS_DeleteProperty APIs to use a boolean out param rather than a value r=waldo r=bz

This commit is contained in:
Jon Coppeard 2013-08-05 14:01:53 +01:00
parent 32e23e5b1f
commit 694e4a5be0
9 changed files with 29 additions and 60 deletions

View File

@ -303,7 +303,7 @@ nsXBLProtoImpl::UndefineFields(JSContext *cx, JS::Handle<JSObject*> obj) const
JSBool hasProp;
if (::JS_AlreadyHasOwnUCProperty(cx, obj, s, name.Length(), &hasProp) &&
hasProp) {
JS::Rooted<JS::Value> dummy(cx);
bool dummy;
::JS_DeleteUCProperty2(cx, obj, s, name.Length(), &dummy);
}
}

View File

@ -211,18 +211,12 @@ bool
DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id, bool* bp)
{
JSBool b = true;
JS::Rooted<JSObject*> expando(cx);
if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
JS::Rooted<Value> v(cx);
if (!JS_DeletePropertyById2(cx, expando, id, &v) ||
!JS_ValueToBoolean(cx, v, &b)) {
return false;
}
return JS_DeletePropertyById2(cx, expando, id, bp);
}
*bp = !!b;
*bp = true;
return true;
}

View File

@ -204,16 +204,14 @@ GetJSValFromKeyPathString(JSContext* aCx,
if (targetObject) {
// If this fails, we lose, and the web page sees a magical property
// appear on the object :-(
JS::Rooted<JS::Value> succeeded(aCx);
bool succeeded;
if (!JS_DeleteUCProperty2(aCx, targetObject,
targetObjectPropName.get(),
targetObjectPropName.Length(),
&succeeded)) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
NS_ASSERTION(JSVAL_IS_BOOLEAN(succeeded), "Wtf?");
NS_ENSURE_TRUE(JSVAL_TO_BOOLEAN(succeeded),
NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
NS_ENSURE_TRUE(succeeded, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -818,13 +818,13 @@ nsJSObjWrapper::NP_RemoveProperty(NPObject *npobj, NPIdentifier id)
nsCxPusher pusher;
pusher.Push(cx);
AutoJSExceptionReporter reporter(cx);
JS::Rooted<JS::Value> deleted(cx, JSVAL_FALSE);
bool deleted = false;
JSAutoCompartment ac(cx, npjsobj->mJSObj);
NS_ASSERTION(NPIdentifierIsInt(id) || NPIdentifierIsString(id),
"id must be either string or int!\n");
ok = ::JS_DeletePropertyById2(cx, npjsobj->mJSObj, NPIdentifierToJSId(id), &deleted);
if (ok && deleted == JSVAL_TRUE) {
if (ok && deleted) {
// FIXME: See bug 425823, we shouldn't need to do this, and once
// that bug is fixed we can remove this code.
@ -835,13 +835,11 @@ nsJSObjWrapper::NP_RemoveProperty(NPObject *npobj, NPIdentifier id)
// The property might have been deleted, but it got
// re-resolved, so no, it's not really deleted.
deleted = JSVAL_FALSE;
deleted = false;
}
}
// return ok == JS_TRUE to quiet down compiler warning, even if
// return ok is what we really want.
return ok == JS_TRUE && deleted == JSVAL_TRUE;
return ok && deleted;
}
//static

View File

@ -284,15 +284,9 @@ JavaScriptChild::AnswerDelete(const ObjectId &objId, const nsString &id, ReturnS
if (!convertGeckoStringToId(cx, id, &internedId))
return fail(cx, rs);
RootedValue v(cx);
if (!JS_DeletePropertyById2(cx, obj, internedId, &v))
if (!JS_DeletePropertyById2(cx, obj, internedId, success))
return fail(cx, rs);
JSBool b;
if (!JS_ValueToBoolean(cx, v, &b))
return fail(cx, rs);
*success = !!b;
return ok(rs);
}

View File

@ -3932,7 +3932,7 @@ JS_SetUCProperty(JSContext *cx, JSObject *objArg, const jschar *name, size_t nam
}
JS_PUBLIC_API(JSBool)
JS_DeletePropertyById2(JSContext *cx, JSObject *objArg, jsid id, MutableHandleValue rval)
JS_DeletePropertyById2(JSContext *cx, JSObject *objArg, jsid id, bool *result)
{
RootedObject obj(cx, objArg);
AssertHeapIsIdle(cx);
@ -3952,12 +3952,12 @@ JS_DeletePropertyById2(JSContext *cx, JSObject *objArg, jsid id, MutableHandleVa
return false;
}
rval.setBoolean(succeeded);
*result = !!succeeded;
return true;
}
JS_PUBLIC_API(JSBool)
JS_DeleteElement2(JSContext *cx, JSObject *objArg, uint32_t index, jsval *rval)
JS_DeleteElement2(JSContext *cx, JSObject *objArg, uint32_t index, bool *result)
{
RootedObject obj(cx, objArg);
AssertHeapIsIdle(cx);
@ -3969,12 +3969,12 @@ JS_DeleteElement2(JSContext *cx, JSObject *objArg, uint32_t index, jsval *rval)
if (!JSObject::deleteElement(cx, obj, index, &succeeded))
return false;
*rval = BooleanValue(succeeded);
*result = !!succeeded;
return true;
}
JS_PUBLIC_API(JSBool)
JS_DeleteProperty2(JSContext *cx, JSObject *objArg, const char *name, MutableHandleValue rval)
JS_DeleteProperty2(JSContext *cx, JSObject *objArg, const char *name, bool *result)
{
RootedObject obj(cx, objArg);
CHECK_REQUEST(cx);
@ -3989,13 +3989,13 @@ JS_DeleteProperty2(JSContext *cx, JSObject *objArg, const char *name, MutableHan
if (!JSObject::deleteByValue(cx, obj, StringValue(atom), &succeeded))
return false;
rval.setBoolean(succeeded);
*result = !!succeeded;
return true;
}
JS_PUBLIC_API(JSBool)
JS_DeleteUCProperty2(JSContext *cx, JSObject *objArg, const jschar *name, size_t namelen,
MutableHandleValue rval)
bool *result)
{
RootedObject obj(cx, objArg);
CHECK_REQUEST(cx);
@ -4010,28 +4010,28 @@ JS_DeleteUCProperty2(JSContext *cx, JSObject *objArg, const jschar *name, size_t
if (!JSObject::deleteByValue(cx, obj, StringValue(atom), &succeeded))
return false;
rval.setBoolean(succeeded);
*result = !!succeeded;
return true;
}
JS_PUBLIC_API(JSBool)
JS_DeletePropertyById(JSContext *cx, JSObject *objArg, jsid idArg)
{
RootedValue junk(cx);
bool junk;
return JS_DeletePropertyById2(cx, objArg, idArg, &junk);
}
JS_PUBLIC_API(JSBool)
JS_DeleteElement(JSContext *cx, JSObject *objArg, uint32_t index)
{
jsval junk;
bool junk;
return JS_DeleteElement2(cx, objArg, index, &junk);
}
JS_PUBLIC_API(JSBool)
JS_DeleteProperty(JSContext *cx, JSObject *objArg, const char *name)
{
RootedValue junk(cx);
bool junk;
return JS_DeleteProperty2(cx, objArg, name, &junk);
}

View File

@ -3560,14 +3560,13 @@ extern JS_PUBLIC_API(JSBool)
JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
extern JS_PUBLIC_API(JSBool)
JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
JS::MutableHandle<JS::Value> rval);
JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, bool *succeeded);
extern JS_PUBLIC_API(JSBool)
JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id);
extern JS_PUBLIC_API(JSBool)
JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle<JS::Value> rval);
JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, bool *succeeded);
extern JS_PUBLIC_API(JSBool)
JS_DefineUCProperty(JSContext *cx, JSObject *obj,
@ -3642,9 +3641,8 @@ JS_SetUCProperty(JSContext *cx, JSObject *obj,
JS::Handle<JS::Value> v);
extern JS_PUBLIC_API(JSBool)
JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
const jschar *name, size_t namelen,
JS::MutableHandle<JS::Value> rval);
JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen,
bool *succeeded);
extern JS_PUBLIC_API(JSObject *)
JS_NewArrayObject(JSContext *cx, int length, jsval *vector);
@ -3694,7 +3692,7 @@ extern JS_PUBLIC_API(JSBool)
JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index);
extern JS_PUBLIC_API(JSBool)
JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, jsval *rval);
JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, bool *succeeded);
/*
* Remove all configurable properties from the given (non-global) object and

View File

@ -423,14 +423,7 @@ DirectProxyHandler::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool
{
assertEnteredPolicy(cx, proxy, id);
RootedObject target(cx, proxy->as<ProxyObject>().target());
RootedValue v(cx);
if (!JS_DeletePropertyById2(cx, target, id, &v))
return false;
JSBool b;
if (!JS_ValueToBoolean(cx, v, &b))
return false;
*bp = !!b;
return true;
return JS_DeletePropertyById2(cx, target, id, bp);
}
bool

View File

@ -1625,17 +1625,11 @@ XrayWrapper<Base, Traits>::delete_(JSContext *cx, HandleObject wrapper,
// Check the expando object.
RootedObject target(cx, Traits::getTargetObject(wrapper));
RootedObject expando(cx, Traits::singleton.getExpandoObject(cx, target, wrapper));
JSBool b = true;
if (expando) {
JSAutoCompartment ac(cx, expando);
RootedValue v(cx);
if (!JS_DeletePropertyById2(cx, expando, id, &v) ||
!JS_ValueToBoolean(cx, v, &b))
{
return false;
}
return JS_DeletePropertyById2(cx, expando, id, bp);
}
*bp = !!b;
*bp = true;
return true;
}