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

--HG--
extra : rebase_source : e36c89af9c362e781d9ca9aceee42779258328b5
This commit is contained in:
Terrence Cole 2014-01-14 17:19:07 -08:00
parent 422649470f
commit 348c21d424
11 changed files with 58 additions and 64 deletions

View File

@ -1053,8 +1053,8 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget,
#ifdef DEBUG
{
JSAutoCompartment ac(cx, aHandler);
NS_ASSERTION(JS_TypeOfValue(cx,
OBJECT_TO_JSVAL(aHandler)) == JSTYPE_FUNCTION,
JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*aHandler));
NS_ASSERTION(JS_TypeOfValue(cx, val) == JSTYPE_FUNCTION,
"Event handler object not a function");
}
#endif

View File

@ -310,15 +310,15 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval,
*aIsInterval = false;
}
switch (::JS_TypeOfValue(cx, argv[0])) {
JS::Rooted<JS::Value> arg(cx, argv[0]);
switch (::JS_TypeOfValue(cx, arg)) {
case JSTYPE_FUNCTION:
funobj = JSVAL_TO_OBJECT(argv[0]);
funobj = &arg.toObject();
break;
case JSTYPE_STRING:
case JSTYPE_OBJECT:
{
JS::Rooted<JS::Value> arg(cx, argv[0]);
JSString *str = JS::ToString(cx, arg);
if (!str)
return NS_ERROR_OUT_OF_MEMORY;
@ -327,7 +327,7 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval,
if (!expr)
return NS_ERROR_OUT_OF_MEMORY;
argv[0] = STRING_TO_JSVAL(str);
argv[0] = JS::StringValue(str);
}
break;

View File

@ -842,7 +842,7 @@ GetErrorMessage(void* userRef, const char* locale, const unsigned errorNumber)
}
static bool
TypeError(JSContext* cx, const char* expected, jsval actual)
TypeError(JSContext* cx, const char* expected, HandleValue actual)
{
JSString* str = JS_ValueToSource(cx, actual);
JSAutoByteString bytes;
@ -3010,7 +3010,8 @@ BuildDataSource(JSContext* cx,
return false;
// Escape characters, and quote as necessary.
JSString* src = JS_ValueToSource(cx, STRING_TO_JSVAL(str));
RootedValue valStr(cx, StringValue(str));
JSString* src = JS_ValueToSource(cx, valStr);
if (!src)
return false;
@ -6902,7 +6903,7 @@ CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval *vp)
return false;
}
JS::Value valCodePtr = args[1];
JS::HandleValue valCodePtr = args[1];
if (!valCodePtr.isObject()) {
return TypeError(cx, "_a CData object_ of a function pointer type",
valCodePtr);
@ -6918,12 +6919,13 @@ CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval *vp)
valCodePtr);
}
RootedObject objCodePtrType(cx, CData::GetCType(objCodePtr));
RootedValue valCodePtrType(cx, ObjectValue(*objCodePtrType));
MOZ_ASSERT(objCodePtrType);
TypeCode typCodePtr = CType::GetTypeCode(objCodePtrType);
if (typCodePtr != TYPE_pointer) {
return TypeError(cx, "a CData object of a function _pointer_ type",
OBJECT_TO_JSVAL(objCodePtrType));
valCodePtrType);
}
JSObject *objCodeType = PointerType::GetBaseType(objCodePtrType);
@ -6932,12 +6934,12 @@ CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval *vp)
TypeCode typCode = CType::GetTypeCode(objCodeType);
if (typCode != TYPE_function) {
return TypeError(cx, "a CData object of a _function_ pointer type",
OBJECT_TO_JSVAL(objCodePtrType));
valCodePtrType);
}
uintptr_t code = *reinterpret_cast<uintptr_t*>(CData::GetData(objCodePtr));
if (!code) {
return TypeError(cx, "a CData object of a _non-NULL_ function pointer type",
OBJECT_TO_JSVAL(objCodePtrType));
valCodePtrType);
}
FunctionInfo* funInfoFinalizer =
@ -6946,8 +6948,9 @@ CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval *vp)
if ((funInfoFinalizer->mArgTypes.length() != 1)
|| (funInfoFinalizer->mIsVariadic)) {
RootedValue valCodeType(cx, ObjectValue(*objCodeType));
return TypeError(cx, "a function accepting exactly one argument",
OBJECT_TO_JSVAL(objCodeType));
valCodeType);
}
RootedObject objArgType(cx, funInfoFinalizer->mArgTypes[0]);
RootedObject returnType(cx, funInfoFinalizer->mReturnType);
@ -6969,8 +6972,9 @@ CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval *vp)
if (!ImplicitConvert(cx, valData, objArgType, cargs.get(),
false, &freePointer)) {
RootedValue valArgType(cx, ObjectValue(*objArgType));
return TypeError(cx, "(an object that can be converted to the following type)",
OBJECT_TO_JSVAL(objArgType));
valArgType);
}
if (freePointer) {
// Note: We could handle that case, if necessary.
@ -7116,7 +7120,8 @@ CDataFinalizer::Methods::Forget(JSContext* cx, unsigned argc, jsval *vp)
if (!obj)
return false;
if (!CDataFinalizer::IsCDataFinalizer(obj)) {
return TypeError(cx, "a CDataFinalizer", OBJECT_TO_JSVAL(obj));
RootedValue val(cx, ObjectValue(*obj));
return TypeError(cx, "a CDataFinalizer", val);
}
CDataFinalizer::Private *p = (CDataFinalizer::Private *)
@ -7163,7 +7168,8 @@ CDataFinalizer::Methods::Dispose(JSContext* cx, unsigned argc, jsval *vp)
if (!obj)
return false;
if (!CDataFinalizer::IsCDataFinalizer(obj)) {
return TypeError(cx, "a CDataFinalizer", OBJECT_TO_JSVAL(obj));
RootedValue val(cx, ObjectValue(*obj));
return TypeError(cx, "a CDataFinalizer", val);
}
CDataFinalizer::Private *p = (CDataFinalizer::Private *)

View File

@ -98,7 +98,7 @@ class JSAPITest
bool evaluate(const char *bytes, const char *filename, int lineno, jsval *vp);
JSAPITestString jsvalToSource(jsval v) {
JSAPITestString jsvalToSource(JS::HandleValue v) {
JSString *str = JS_ValueToSource(cx, v);
if (str) {
JSAutoByteString bytes(cx, str);
@ -146,7 +146,8 @@ class JSAPITest
}
JSAPITestString toSource(JSAtom *v) {
return jsvalToSource(STRING_TO_JSVAL((JSString*)v));
JS::RootedValue val(cx, JS::StringValue((JSString *)v));
return jsvalToSource(val);
}
JSAPITestString toSource(JSVersion v) {

View File

@ -411,9 +411,8 @@ JS_ValueToConstructor(JSContext *cx, HandleValue value)
}
JS_PUBLIC_API(JSString *)
JS_ValueToSource(JSContext *cx, jsval valueArg)
JS_ValueToSource(JSContext *cx, HandleValue value)
{
RootedValue value(cx, valueArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, value);
@ -439,9 +438,8 @@ JS_DoubleToUint32(double d)
}
JS_PUBLIC_API(JSType)
JS_TypeOfValue(JSContext *cx, jsval valueArg)
JS_TypeOfValue(JSContext *cx, HandleValue value)
{
RootedValue value(cx, valueArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, value);
@ -470,18 +468,13 @@ JS_StrictlyEqual(JSContext *cx, jsval value1, jsval value2, bool *equal)
}
JS_PUBLIC_API(bool)
JS_LooselyEqual(JSContext *cx, jsval value1Arg, jsval value2Arg, bool *equal)
JS_LooselyEqual(JSContext *cx, HandleValue value1, HandleValue value2, bool *equal)
{
RootedValue value1(cx, value1Arg);
RootedValue value2(cx, value2Arg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, value1, value2);
bool eq;
if (!LooselyEqual(cx, value1, value2, &eq))
return false;
*equal = eq;
return true;
JS_ASSERT(equal);
return LooselyEqual(cx, value1, value2, equal);
}
JS_PUBLIC_API(bool)
@ -1369,29 +1362,20 @@ JS_EnumerateStandardClasses(JSContext *cx, HandleObject obj)
}
JS_PUBLIC_API(bool)
JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objpArg)
JS_GetClassObject(JSContext *cx, HandleObject obj, JSProtoKey key, MutableHandleObject objp)
{
RootedObject objp(cx, *objpArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
if (!js_GetClassObject(cx, obj, key, &objp))
return false;
*objpArg = objp;
return true;
return js_GetClassObject(cx, obj, key, objp);
}
JS_PUBLIC_API(bool)
JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp_)
JS_GetClassPrototype(JSContext *cx, JSProtoKey key, MutableHandleObject objp)
{
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
RootedObject objp(cx);
bool result = js_GetClassPrototype(cx, key, &objp);
*objp_ = objp;
return result;
return js_GetClassPrototype(cx, key, objp);
}
JS_PUBLIC_API(JSProtoKey)

View File

@ -1051,7 +1051,7 @@ extern JS_PUBLIC_API(JSFunction *)
JS_ValueToConstructor(JSContext *cx, JS::HandleValue v);
extern JS_PUBLIC_API(JSString *)
JS_ValueToSource(JSContext *cx, jsval v);
JS_ValueToSource(JSContext *cx, JS::Handle<JS::Value> v);
namespace js {
/*
@ -1226,7 +1226,7 @@ ToUint64(JSContext *cx, JS::HandleValue v, uint64_t *out)
} /* namespace JS */
extern JS_PUBLIC_API(JSType)
JS_TypeOfValue(JSContext *cx, jsval v);
JS_TypeOfValue(JSContext *cx, JS::Handle<JS::Value> v);
extern JS_PUBLIC_API(const char *)
JS_GetTypeName(JSContext *cx, JSType type);
@ -1235,7 +1235,7 @@ extern JS_PUBLIC_API(bool)
JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal);
extern JS_PUBLIC_API(bool)
JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, bool *equal);
JS_LooselyEqual(JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool *equal);
extern JS_PUBLIC_API(bool)
JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same);
@ -1766,10 +1766,11 @@ extern JS_PUBLIC_API(bool)
JS_EnumerateStandardClasses(JSContext *cx, JS::HandleObject obj);
extern JS_PUBLIC_API(bool)
JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject **objp);
JS_GetClassObject(JSContext *cx, JS::Handle<JSObject*> obj, JSProtoKey key,
JS::MutableHandle<JSObject*> objp);
extern JS_PUBLIC_API(bool)
JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp);
JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JS::MutableHandle<JSObject*> objp);
extern JS_PUBLIC_API(JSProtoKey)
JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj);

View File

@ -3087,20 +3087,20 @@ Parent(JSContext *cx, unsigned argc, jsval *vp)
static bool
Compile(JSContext *cx, unsigned argc, jsval *vp)
{
if (argc < 1) {
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() < 1) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED,
"compile", "0", "s");
return false;
}
jsval arg0 = JS_ARGV(cx, vp)[0];
if (!JSVAL_IS_STRING(arg0)) {
const char *typeName = JS_GetTypeName(cx, JS_TypeOfValue(cx, arg0));
if (!args[0].isString()) {
const char *typeName = JS_GetTypeName(cx, JS_TypeOfValue(cx, args[0]));
JS_ReportError(cx, "expected string to compile, got %s", typeName);
return false;
}
RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
JSString *scriptContents = JSVAL_TO_STRING(arg0);
JSString *scriptContents = args[0].toString();
JS::AutoSaveContextOptions asco(cx);
JS::ContextOptionsRef(cx).setNoScriptRval(true);
JS::CompileOptions options(cx);
@ -3108,7 +3108,7 @@ Compile(JSContext *cx, unsigned argc, jsval *vp)
.setCompileAndGo(true);
bool ok = JS_CompileUCScript(cx, global, JS_GetStringCharsZ(cx, scriptContents),
JS_GetStringLength(scriptContents), options);
JS_SET_RVAL(cx, vp, UndefinedValue());
args.rval().setUndefined();
return ok;
}

View File

@ -1171,9 +1171,9 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
// a callable object then the JS engine will throw an error and we'll
// pass this along to the caller as an exception/result code.
fval = ObjectValue(*obj);
if (isFunction &&
JS_TypeOfValue(ccx, OBJECT_TO_JSVAL(obj)) == JSTYPE_FUNCTION) {
fval = OBJECT_TO_JSVAL(obj);
JS_TypeOfValue(ccx, fval) == JSTYPE_FUNCTION) {
// We may need to translate the 'this' for the function object.

View File

@ -144,7 +144,7 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx, unsigned argc, jsval *vp)
XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
MOZ_ASSERT(JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION, "bad function");
MOZ_ASSERT(JS_TypeOfValue(cx, args.calleev()) == JSTYPE_FUNCTION, "bad function");
RootedObject realObject(cx, GetDoubleWrappedJSObject(ccx, wrapper));
if (!realObject) {
@ -1278,8 +1278,9 @@ FixUpThisIfBroken(JSObject *obj, JSObject *funobj)
bool
XPC_WN_CallMethod(JSContext *cx, unsigned argc, jsval *vp)
{
MOZ_ASSERT(JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION, "bad function");
RootedObject funobj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
MOZ_ASSERT(JS_TypeOfValue(cx, args.calleev()) == JSTYPE_FUNCTION, "bad function");
RootedObject funobj(cx, &args.callee());
RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
if (!obj)
@ -1303,8 +1304,9 @@ XPC_WN_CallMethod(JSContext *cx, unsigned argc, jsval *vp)
bool
XPC_WN_GetterSetter(JSContext *cx, unsigned argc, jsval *vp)
{
MOZ_ASSERT(JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION, "bad function");
RootedObject funobj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
MOZ_ASSERT(JS_TypeOfValue(cx, args.calleev()) == JSTYPE_FUNCTION, "bad function");
RootedObject funobj(cx, &args.callee());
RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
if (!obj)
@ -1326,7 +1328,7 @@ XPC_WN_GetterSetter(JSContext *cx, unsigned argc, jsval *vp)
ccx.SetCallInfo(iface, member, true);
bool retval = XPCWrappedNative::SetAttribute(ccx);
if (retval)
*vp = JS_ARGV(cx, vp)[0];
args.rval().set(args[0]);
return retval;
}
// else...

View File

@ -178,7 +178,7 @@ WrapperFactory::PrepareForWrapping(JSContext *cx, HandleObject scope,
}
if (key != JSProto_Null) {
RootedObject homeProto(cx);
if (!JS_GetClassPrototype(cx, key, homeProto.address()))
if (!JS_GetClassPrototype(cx, key, &homeProto))
return nullptr;
MOZ_ASSERT(homeProto);
// No need to double-wrap here. We should never have waivers to

View File

@ -823,7 +823,7 @@ XrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper,
if (key != JSProto_Null) {
MOZ_ASSERT(key < JSProto_LIMIT);
RootedObject constructor(cx);
if (!JS_GetClassObject(cx, target, key, constructor.address()))
if (!JS_GetClassObject(cx, target, key, &constructor))
return false;
MOZ_ASSERT(constructor);
desc.value().set(ObjectValue(*constructor));