From c3759c40ff205678f05d398eb038e33fdfd0f634 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Tue, 11 Feb 2014 10:59:16 +0000 Subject: [PATCH] Bug 965830 - Convert use of JS_CallFunction and related APIs uses to HandleValueArray r=terrence r=smaug --- content/base/src/nsFrameMessageManager.cpp | 4 +-- content/base/src/nsObjectLoadingContent.cpp | 3 +- dom/base/nsDOMClassInfo.cpp | 8 ++--- dom/bindings/BindingUtils.cpp | 2 +- dom/bindings/Codegen.py | 8 ++--- dom/plugins/base/nsJSNPRuntime.cpp | 5 ++- dom/src/json/nsJSON.cpp | 2 +- dom/workers/Console.cpp | 15 +++------ dom/workers/WorkerPrivate.cpp | 8 ++--- dom/xbl/nsXBLProtoImplMethod.cpp | 2 +- ipc/nfc/Nfc.cpp | 8 ++--- ipc/ril/Ril.cpp | 8 ++--- ipc/testshell/TestShellParent.cpp | 3 +- js/ipc/JavaScriptChild.cpp | 3 +- js/src/ctypes/CTypes.cpp | 3 +- js/src/jsapi-tests/testBindCallable.cpp | 2 +- .../testCallNonGenericMethodOnProxy.cpp | 6 ++-- js/src/jsapi-tests/testChromeBuffer.cpp | 8 ++--- js/src/jsapi-tests/testClassGetter.cpp | 2 +- js/src/jsapi-tests/testCloneScript.cpp | 4 +-- js/src/jsapi-tests/testDebugger.cpp | 5 ++- js/src/jsapi-tests/testErrorCopying.cpp | 2 +- js/src/jsapi-tests/testException.cpp | 2 +- js/src/jsapi-tests/testOps.cpp | 2 +- js/src/jsapi-tests/testProfileStrings.cpp | 26 ++++++++-------- js/src/jsapi.cpp | 26 ++++++++-------- js/src/jsapi.h | 31 ++++++++++--------- js/src/jscntxtinlines.h | 10 ++++++ js/src/jsobj.h | 4 +-- js/src/shell/js.cpp | 7 ++--- js/src/vm/Interpreter.cpp | 2 +- js/src/vm/Interpreter.h | 2 +- js/xpconnect/loader/mozJSComponentLoader.cpp | 2 +- js/xpconnect/loader/mozJSSubScriptLoader.cpp | 2 +- js/xpconnect/src/Sandbox.cpp | 8 ++--- js/xpconnect/src/XPCComponents.cpp | 12 +++---- js/xpconnect/src/XPCShellImpl.cpp | 2 +- js/xpconnect/src/XPCWrappedJSClass.cpp | 9 ++---- netwerk/base/src/ProxyAutoConfig.cpp | 9 +++--- .../directory/nsDirectoryViewer.cpp | 6 ++-- 40 files changed, 130 insertions(+), 143 deletions(-) diff --git a/content/base/src/nsFrameMessageManager.cpp b/content/base/src/nsFrameMessageManager.cpp index b29af9e5a2d9..4ab5bfd0f94e 100644 --- a/content/base/src/nsFrameMessageManager.cpp +++ b/content/base/src/nsFrameMessageManager.cpp @@ -1031,7 +1031,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, } if (!JS_CallFunctionValue(cx, thisObject, - funval, 1, argv.address(), rval.address())) { + funval, argv, rval.address())) { nsJSUtils::ReportPendingException(cx); continue; } @@ -1419,7 +1419,7 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL, JS::Rooted rval(cx); JS::Rooted methodVal(cx, JS::ObjectValue(*method)); ok = JS_CallFunctionValue(cx, global, methodVal, - 0, nullptr, rval.address()); + JS::EmptyValueArray, rval.address()); } else if (script) { ok = JS_ExecuteScript(cx, global, script, nullptr); } diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index 5d1fe2a130c8..9100dd1ce187 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -3225,8 +3225,7 @@ nsObjectLoadingContent::LegacyCall(JSContext* aCx, } JS::Rooted retval(aCx); - bool ok = JS::Call(aCx, thisVal, pi_obj, args.length(), args.begin(), - &retval); + bool ok = JS::Call(aCx, thisVal, pi_obj, args, &retval); if (!ok) { aRv.Throw(NS_ERROR_FAILURE); return JS::UndefinedValue(); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 4a3655eeb7ac..65edac3f9287 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -2043,7 +2043,9 @@ BaseStubConstructor(nsIWeakReference* aWeakOwner, // we also pass in the calling window as the first argument unsigned argc = args.length() + 1; JS::AutoValueVector argv(cx); - argv.resize(argc); + if (!argv.resize(argc)) { + return NS_ERROR_OUT_OF_MEMORY; + } nsCOMPtr currentWin(do_GetInterface(currentInner)); rv = WrapNative(cx, obj, currentWin, &NS_GET_IID(nsIDOMWindow), @@ -2058,9 +2060,7 @@ BaseStubConstructor(nsIWeakReference* aWeakOwner, } JS::Rooted frval(cx); - bool ret = JS_CallFunctionValue(cx, thisObject, funval, - argc, argv.begin(), - frval.address()); + bool ret = JS_CallFunctionValue(cx, thisObject, funval, argv, frval.address()); if (!ret) { return NS_ERROR_FAILURE; diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 9e240aa718b8..273fa72d9806 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -1608,7 +1608,7 @@ NativeToString(JSContext* cx, JS::Handle wrapper, } MOZ_ASSERT(JS_ObjectIsCallable(cx, &toString.toObject())); JS::Rooted toStringResult(cx); - if (JS_CallFunctionValue(cx, obj, toString, 0, nullptr, + if (JS_CallFunctionValue(cx, obj, toString, JS::EmptyValueArray, toStringResult.address())) { str = toStringResult.toString(); } else { diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 278d5118a98e..c49038449d66 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -11294,14 +11294,12 @@ class CallbackMethod(CallbackMember): "callGuard": self.getCallGuard() } if self.argCount > 0: - replacements["argv"] = "argv.begin()" - replacements["argc"] = "argc" + replacements["args"] = "JS::HandleValueArray::subarray(argv, 0, argc)" else: - replacements["argv"] = "nullptr" - replacements["argc"] = "0" + replacements["args"] = "JS::EmptyValueArray" return string.Template("${getCallable}" "if (${callGuard}!JS::Call(cx, ${thisVal}, callable,\n" - " ${argc}, ${argv}, &rval)) {\n" + " ${args}, &rval)) {\n" " aRv.Throw(NS_ERROR_UNEXPECTED);\n" " return${errorReturn};\n" "}\n").substitute(replacements) diff --git a/dom/plugins/base/nsJSNPRuntime.cpp b/dom/plugins/base/nsJSNPRuntime.cpp index b628b5066461..fbd298d2d43b 100644 --- a/dom/plugins/base/nsJSNPRuntime.cpp +++ b/dom/plugins/base/nsJSNPRuntime.cpp @@ -659,8 +659,7 @@ doInvoke(NPObject *npobj, NPIdentifier method, const NPVariant *args, ok = true; } } else { - ok = ::JS_CallFunctionValue(cx, npjsobj->mJSObj, fv, jsargs.length(), - jsargs.begin(), v.address()); + ok = ::JS_CallFunctionValue(cx, npjsobj->mJSObj, fv, jsargs, v.address()); } if (ok) @@ -1606,7 +1605,7 @@ NPObjWrapper_Convert(JSContext *cx, JS::Handle obj, JSType hint, JS:: if (!JS_GetProperty(cx, obj, "toString", &v)) return false; if (!JSVAL_IS_PRIMITIVE(v) && JS_ObjectIsCallable(cx, JSVAL_TO_OBJECT(v))) { - if (!JS_CallFunctionValue(cx, obj, v, 0, nullptr, vp.address())) + if (!JS_CallFunctionValue(cx, obj, v, JS::EmptyValueArray, vp.address())) return false; if (JSVAL_IS_PRIMITIVE(vp)) return true; diff --git a/dom/src/json/nsJSON.cpp b/dom/src/json/nsJSON.cpp index 0a0ac7915b06..3cdbd48107ad 100644 --- a/dom/src/json/nsJSON.cpp +++ b/dom/src/json/nsJSON.cpp @@ -220,7 +220,7 @@ nsJSON::EncodeInternal(JSContext* cx, const JS::Value& aValue, toJSON.isObject() && JS_ObjectIsCallable(cx, &toJSON.toObject())) { // If toJSON is implemented, it must not throw - if (!JS_CallFunctionValue(cx, obj, toJSON, 0, nullptr, val.address())) { + if (!JS_CallFunctionValue(cx, obj, toJSON, JS::EmptyValueArray, val.address())) { if (JS_IsExceptionPending(cx)) // passing NS_OK will throw the pending exception return NS_OK; diff --git a/dom/workers/Console.cpp b/dom/workers/Console.cpp index 11c7c3a1488b..d1265d834696 100644 --- a/dom/workers/Console.cpp +++ b/dom/workers/Console.cpp @@ -321,18 +321,13 @@ private: stackValue = JS::ObjectValue(*stackObj); } - JS::AutoValueVector argv(cx); - if (!argv.resize(3)) { - return; - } - - argv[0] = methodValue; - argv[1] = argumentsValue; - argv[2] = stackValue; + JS::AutoValueArray<3> args(cx); + args[0].set(methodValue); + args[1].set(argumentsValue); + args[2].set(stackValue); JS::Rooted ret(cx); - JS_CallFunctionName(cx, consoleObj, "queueCall", argv.length(), - argv.begin(), ret.address()); + JS_CallFunctionName(cx, consoleObj, "queueCall", args, ret.address()); } WorkerConsole* mConsole; diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 49acaee38e6a..b1f5508aabf5 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -5388,10 +5388,10 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx) * unsafeGet() is needed below because the argument is a not a const * pointer, even though values are not modified. */ - if (!JS_CallFunctionValue(aCx, global, info->mTimeoutCallable, - info->mExtraArgVals.Length(), - info->mExtraArgVals.Elements()->unsafeGet(), - rval.address()) && + JS::HandleValueArray args = + JS::HandleValueArray::fromMarkedLocation(info->mExtraArgVals.Length(), + info->mExtraArgVals.Elements()->unsafeGet()); + if (!JS_CallFunctionValue(aCx, global, info->mTimeoutCallable, args, rval.address()) && !JS_ReportPendingException(aCx)) { retval = false; break; diff --git a/dom/xbl/nsXBLProtoImplMethod.cpp b/dom/xbl/nsXBLProtoImplMethod.cpp index 00d39a7acc2c..73e0245c6352 100644 --- a/dom/xbl/nsXBLProtoImplMethod.cpp +++ b/dom/xbl/nsXBLProtoImplMethod.cpp @@ -335,7 +335,7 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement) if (scriptAllowed) { JS::Rooted retval(cx); ok = ::JS_CallFunctionValue(cx, thisObject, OBJECT_TO_JSVAL(method), - 0 /* argc */, nullptr /* argv */, retval.address()); + JS::EmptyValueArray, retval.address()); } if (!ok) { diff --git a/ipc/nfc/Nfc.cpp b/ipc/nfc/Nfc.cpp index 72c9275cfe19..13c6578ec9d4 100644 --- a/ipc/nfc/Nfc.cpp +++ b/ipc/nfc/Nfc.cpp @@ -157,17 +157,17 @@ private: bool DispatchNFCEvent::RunTask(JSContext* aCx) { - JSObject* obj = JS::CurrentGlobalOrNull(aCx); + JS::Rooted obj(aCx, JS::CurrentGlobalOrNull(aCx)); JSObject* array = JS_NewUint8Array(aCx, mMessage->mSize); if (!array) { return false; } + JS::Rooted arrayVal(aCx, JS::ObjectValue(*array)); memcpy(JS_GetArrayBufferViewData(array), mMessage->mData, mMessage->mSize); - JS::Value argv[] = { OBJECT_TO_JSVAL(array) }; - return JS_CallFunctionName(aCx, obj, "onNfcMessage", - mozilla::ArrayLength(argv), argv, argv); + JS::Rooted rval(aCx); + return JS_CallFunctionName(aCx, obj, "onNfcMessage", arrayVal, rval.address()); } class NfcConnector : public mozilla::ipc::UnixSocketConnector diff --git a/ipc/ril/Ril.cpp b/ipc/ril/Ril.cpp index 062effde6b79..9fad35ec5410 100644 --- a/ipc/ril/Ril.cpp +++ b/ipc/ril/Ril.cpp @@ -164,17 +164,17 @@ private: bool DispatchRILEvent::RunTask(JSContext *aCx) { - JSObject *obj = JS::CurrentGlobalOrNull(aCx); + JS::Rooted obj(aCx, JS::CurrentGlobalOrNull(aCx)); JSObject *array = JS_NewUint8Array(aCx, mMessage->mSize); if (!array) { return false; } + JS::Rooted arrayVal(aCx, JS::ObjectValue(*array)); memcpy(JS_GetArrayBufferViewData(array), mMessage->mData, mMessage->mSize); - JS::Value argv[] = { OBJECT_TO_JSVAL(array) }; - return JS_CallFunctionName(aCx, obj, "onRILMessage", - mozilla::ArrayLength(argv), argv, argv); + JS::Rooted rval(aCx); + return JS_CallFunctionName(aCx, obj, "onRILMessage", arrayVal, rval.address()); } class RilConnector : public mozilla::ipc::UnixSocketConnector diff --git a/ipc/testshell/TestShellParent.cpp b/ipc/testshell/TestShellParent.cpp index 1641320ed4b3..29e4b8a568a9 100644 --- a/ipc/testshell/TestShellParent.cpp +++ b/ipc/testshell/TestShellParent.cpp @@ -73,8 +73,7 @@ TestShellCommandParent::RunCallback(const nsString& aResponse) JS::Rooted strVal(mCx, JS::StringValue(str)); JS::Rooted rval(mCx); - bool ok = JS_CallFunctionValue(mCx, global, mCallback, 1, strVal.address(), - rval.address()); + bool ok = JS_CallFunctionValue(mCx, global, mCallback, strVal, rval.address()); NS_ENSURE_TRUE(ok, false); return true; diff --git a/js/ipc/JavaScriptChild.cpp b/js/ipc/JavaScriptChild.cpp index e034489a4e2e..134e47b0d7b6 100644 --- a/js/ipc/JavaScriptChild.cpp +++ b/js/ipc/JavaScriptChild.cpp @@ -501,7 +501,8 @@ JavaScriptChild::AnswerCall(const ObjectId &objId, const nsTArray &argv AutoSaveContextOptions asco(cx); ContextOptionsRef(cx).setDontReportUncaught(true); - bool success = JS::Call(cx, vals[1], vals[0], vals.length() - 2, vals.begin() + 2, &rval); + HandleValueArray args = HandleValueArray::subarray(vals, 2, vals.length() - 2); + bool success = JS::Call(cx, vals[1], vals[0], args, &rval); if (!success) return fail(cx, rs); } diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index c40ecbf81127..edcdd7e14d7c 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -6185,8 +6185,7 @@ CClosure::ClosureStub(ffi_cif* cif, void* result, void** args, void* userData) // Call the JS function. 'thisObj' may be nullptr, in which case the JS // engine will find an appropriate object to use. RootedValue rval(cx); - bool success = JS_CallFunctionValue(cx, thisObj, OBJECT_TO_JSVAL(jsfnObj), - cif->nargs, argv.begin(), rval.address()); + bool success = JS_CallFunctionValue(cx, thisObj, OBJECT_TO_JSVAL(jsfnObj), argv, rval.address()); // Convert the result. Note that we pass 'isArgument = false', such that // ImplicitConvert will *not* autoconvert a JS string into a pointer-to-char diff --git a/js/src/jsapi-tests/testBindCallable.cpp b/js/src/jsapi-tests/testBindCallable.cpp index b8ded16fd593..3651ba8c409e 100644 --- a/js/src/jsapi-tests/testBindCallable.cpp +++ b/js/src/jsapi-tests/testBindCallable.cpp @@ -20,7 +20,7 @@ BEGIN_TEST(test_BindCallable) CHECK(newCallable); JS::RootedValue retval(cx); - bool called = JS_CallFunctionValue(cx, nullptr, OBJECT_TO_JSVAL(newCallable), 0, nullptr, + bool called = JS_CallFunctionValue(cx, nullptr, OBJECT_TO_JSVAL(newCallable), JS::EmptyValueArray, retval.address()); CHECK(called); diff --git a/js/src/jsapi-tests/testCallNonGenericMethodOnProxy.cpp b/js/src/jsapi-tests/testCallNonGenericMethodOnProxy.cpp index 408ee53c4769..65792b20e5ee 100644 --- a/js/src/jsapi-tests/testCallNonGenericMethodOnProxy.cpp +++ b/js/src/jsapi-tests/testCallNonGenericMethodOnProxy.cpp @@ -55,7 +55,7 @@ BEGIN_TEST(test_CallNonGenericMethodOnProxy) CHECK(customMethodA); JS::RootedValue rval(cx); - CHECK(JS_CallFunction(cx, customA, customMethodA, 0, nullptr, rval.address())); + CHECK(JS_CallFunction(cx, customA, customMethodA, JS::EmptyValueArray, rval.address())); CHECK_SAME(rval, Int32Value(17)); // Now create the second global object and compartment... @@ -73,14 +73,14 @@ BEGIN_TEST(test_CallNonGenericMethodOnProxy) CHECK(customMethodB); JS::RootedValue rval(cx); - CHECK(JS_CallFunction(cx, customB, customMethodB, 0, nullptr, rval.address())); + CHECK(JS_CallFunction(cx, customB, customMethodB, JS::EmptyValueArray, rval.address())); CHECK_SAME(rval, Int32Value(42)); JS::RootedObject wrappedCustomA(cx, customA); CHECK(JS_WrapObject(cx, &wrappedCustomA)); JS::RootedValue rval2(cx); - CHECK(JS_CallFunction(cx, wrappedCustomA, customMethodB, 0, nullptr, rval2.address())); + CHECK(JS_CallFunction(cx, wrappedCustomA, customMethodB, JS::EmptyValueArray, rval2.address())); CHECK_SAME(rval, Int32Value(42)); } diff --git a/js/src/jsapi-tests/testChromeBuffer.cpp b/js/src/jsapi-tests/testChromeBuffer.cpp index 301a63300349..337fcbd8187c 100644 --- a/js/src/jsapi-tests/testChromeBuffer.cpp +++ b/js/src/jsapi-tests/testChromeBuffer.cpp @@ -33,7 +33,7 @@ CallTrusted(JSContext *cx, unsigned argc, jsval *vp) { JSAutoCompartment ac(cx, trusted_glob); ok = JS_CallFunctionValue(cx, nullptr, JS::ObjectValue(*trusted_fun), - 0, nullptr, vp); + JS::EmptyValueArray, vp); } JS_RestoreFrameChain(cx); return ok; @@ -91,7 +91,7 @@ BEGIN_TEST(testChromeBuffer) bytes, strlen(bytes), options)); JS::RootedValue rval(cx); - CHECK(JS_CallFunction(cx, nullptr, fun, 1, v.address(), rval.address())); + CHECK(JS_CallFunction(cx, nullptr, fun, v, rval.address())); CHECK(JSVAL_TO_INT(rval) == 100); } @@ -132,7 +132,7 @@ BEGIN_TEST(testChromeBuffer) bytes, strlen(bytes), options)); JS::RootedValue rval(cx); - CHECK(JS_CallFunction(cx, nullptr, fun, 1, v.address(), rval.address())); + CHECK(JS_CallFunction(cx, nullptr, fun, v, rval.address())); bool match; CHECK(JS_StringEqualsAscii(cx, JSVAL_TO_STRING(rval), "From trusted: InternalError: too much recursion", &match)); CHECK(match); @@ -171,7 +171,7 @@ BEGIN_TEST(testChromeBuffer) JS::RootedValue arg(cx, JS::ObjectValue(*callTrusted)); JS::RootedValue rval(cx); - CHECK(JS_CallFunction(cx, nullptr, fun, 1, arg.address(), rval.address())); + CHECK(JS_CallFunction(cx, nullptr, fun, arg, rval.address())); CHECK(JSVAL_TO_INT(rval) == 42); } diff --git a/js/src/jsapi-tests/testClassGetter.cpp b/js/src/jsapi-tests/testClassGetter.cpp index b4e1af43edf1..17b5e04ea288 100644 --- a/js/src/jsapi-tests/testClassGetter.cpp +++ b/js/src/jsapi-tests/testClassGetter.cpp @@ -63,7 +63,7 @@ BEGIN_TEST(testClassGetter_isCalled) for (int i = 1; i < 9; i++) { JS::RootedValue rval(cx); - CHECK(JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK_SAME(INT_TO_JSVAL(called_test_fn), INT_TO_JSVAL(i)); CHECK_SAME(INT_TO_JSVAL(called_test_prop_get), INT_TO_JSVAL(4 * i)); } diff --git a/js/src/jsapi-tests/testCloneScript.cpp b/js/src/jsapi-tests/testCloneScript.cpp index e332629efd1f..7d21df0f8602 100644 --- a/js/src/jsapi-tests/testCloneScript.cpp +++ b/js/src/jsapi-tests/testCloneScript.cpp @@ -137,8 +137,8 @@ BEGIN_TEST(test_cloneScriptWithPrincipals) CHECK(JS_GetScriptPrincipals(script) == principalsB); JS::RootedValue v(cx); - JS::Value args[] = { JS::Int32Value(1) }; - CHECK(JS_CallFunctionValue(cx, B, JS::ObjectValue(*cloned), 1, args, v.address())); + JS::RootedValue arg(cx, JS::Int32Value(1)); + CHECK(JS_CallFunctionValue(cx, B, JS::ObjectValue(*cloned), arg, v.address())); CHECK(v.isObject()); JSObject *funobj = &v.toObject(); diff --git a/js/src/jsapi-tests/testDebugger.cpp b/js/src/jsapi-tests/testDebugger.cpp index d01e08077cf2..f86863fec4db 100644 --- a/js/src/jsapi-tests/testDebugger.cpp +++ b/js/src/jsapi-tests/testDebugger.cpp @@ -224,10 +224,9 @@ bool testIndirectEval(JS::HandleObject scope, const char *code) JSAutoCompartment ae(cx, scope); JSString *codestr = JS_NewStringCopyZ(cx, code); CHECK(codestr); - JS::AutoValueArray<1> args(cx); - args[1].setString(codestr); + JS::RootedValue arg(cx, JS::StringValue(codestr)); JS::RootedValue v(cx); - CHECK(JS_CallFunctionName(cx, scope, "eval", 1, args.begin(), v.address())); + CHECK(JS_CallFunctionName(cx, scope, "eval", arg, v.address())); } JS::RootedValue hitsv(cx); diff --git a/js/src/jsapi-tests/testErrorCopying.cpp b/js/src/jsapi-tests/testErrorCopying.cpp index eb36a7454cac..d060524d0476 100644 --- a/js/src/jsapi-tests/testErrorCopying.cpp +++ b/js/src/jsapi-tests/testErrorCopying.cpp @@ -20,7 +20,7 @@ BEGIN_TEST(testErrorCopying_columnCopied) JS::RootedValue rval(cx); JS_SetErrorReporter(cx, my_ErrorReporter); - CHECK(!JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(!JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK(column == 27); return true; } diff --git a/js/src/jsapi-tests/testException.cpp b/js/src/jsapi-tests/testException.cpp index 846a6b7c6016..1e88563c83e0 100644 --- a/js/src/jsapi-tests/testException.cpp +++ b/js/src/jsapi-tests/testException.cpp @@ -15,7 +15,7 @@ BEGIN_TEST(testException_bug860435) CHECK(fun.isObject()); JS::RootedValue v(cx); - JS_CallFunctionValue(cx, global, fun, 0, v.address(), v.address()); + JS_CallFunctionValue(cx, global, fun, JS::EmptyValueArray, v.address()); CHECK(v.isObject()); JS::RootedObject obj(cx, &v.toObject()); diff --git a/js/src/jsapi-tests/testOps.cpp b/js/src/jsapi-tests/testOps.cpp index d4e7daffef63..c24379fdd8a3 100644 --- a/js/src/jsapi-tests/testOps.cpp +++ b/js/src/jsapi-tests/testOps.cpp @@ -55,7 +55,7 @@ BEGIN_TEST(testOps_bug559006) for (int i = 0; i < 9; i++) { JS::RootedValue rval(cx); - CHECK(JS_CallFunctionName(cx, global, "main", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "main", JS::EmptyValueArray, rval.address())); CHECK_SAME(rval, INT_TO_JSVAL(123)); } return true; diff --git a/js/src/jsapi-tests/testProfileStrings.cpp b/js/src/jsapi-tests/testProfileStrings.cpp index 49547c22ae91..1048aeb024ca 100644 --- a/js/src/jsapi-tests/testProfileStrings.cpp +++ b/js/src/jsapi-tests/testProfileStrings.cpp @@ -42,7 +42,7 @@ test_fn2(JSContext *cx, unsigned argc, jsval *vp) { JS::RootedValue r(cx); JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx)); - return JS_CallFunctionName(cx, global, "d", 0, nullptr, r.address()); + return JS_CallFunctionName(cx, global, "d", JS::EmptyValueArray, r.address()); } static bool @@ -104,13 +104,13 @@ BEGIN_TEST(testProfileStrings_isCalledWithInterpreter) { JS::RootedValue rval(cx); /* Make sure the stack resets and we have an entry for each stack */ - CHECK(JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK(psize == 0); CHECK(max_stack >= 8); CHECK(cx->runtime()->spsProfiler.stringsCount() == 8); /* Make sure the stack resets and we added no new entries */ max_stack = 0; - CHECK(JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK(psize == 0); CHECK(max_stack >= 8); CHECK(cx->runtime()->spsProfiler.stringsCount() == 8); @@ -118,7 +118,7 @@ BEGIN_TEST(testProfileStrings_isCalledWithInterpreter) reset(cx); { JS::RootedValue rval(cx); - CHECK(JS_CallFunctionName(cx, global, "check2", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check2", JS::EmptyValueArray, rval.address())); CHECK(cx->runtime()->spsProfiler.stringsCount() == 5); CHECK(max_stack >= 6); CHECK(psize == 0); @@ -129,7 +129,7 @@ BEGIN_TEST(testProfileStrings_isCalledWithInterpreter) { JS::RootedValue rval(cx); pstack[3].setLabel((char*) 1234); - CHECK(JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK((size_t) pstack[3].label() == 1234); CHECK(max_stack >= 8); CHECK(psize == 0); @@ -158,14 +158,14 @@ BEGIN_TEST(testProfileStrings_isCalledWithJIT) { JS::RootedValue rval(cx); /* Make sure the stack resets and we have an entry for each stack */ - CHECK(JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK(psize == 0); CHECK(max_stack >= 8); /* Make sure the stack resets and we added no new entries */ uint32_t cnt = cx->runtime()->spsProfiler.stringsCount(); max_stack = 0; - CHECK(JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK(psize == 0); CHECK(cx->runtime()->spsProfiler.stringsCount() == cnt); CHECK(max_stack >= 8); @@ -178,7 +178,7 @@ BEGIN_TEST(testProfileStrings_isCalledWithJIT) /* Limit the size of the stack and make sure we don't overflow */ JS::RootedValue rval(cx); pstack[3].setLabel((char*) 1234); - CHECK(JS_CallFunctionName(cx, global, "check", 0, nullptr, rval.address())); + CHECK(JS_CallFunctionName(cx, global, "check", JS::EmptyValueArray, rval.address())); CHECK(psize == 0); CHECK(max_stack >= 8); CHECK((size_t) pstack[3].label() == 1234); @@ -200,7 +200,7 @@ BEGIN_TEST(testProfileStrings_isCalledWhenError) { JS::RootedValue rval(cx); /* Make sure the stack resets and we have an entry for each stack */ - bool ok = JS_CallFunctionName(cx, global, "check2", 0, nullptr, rval.address()); + bool ok = JS_CallFunctionName(cx, global, "check2", JS::EmptyValueArray, rval.address()); CHECK(!ok); CHECK(psize == 0); CHECK(cx->runtime()->spsProfiler.stringsCount() == 1); @@ -224,7 +224,7 @@ BEGIN_TEST(testProfileStrings_worksWhenEnabledOnTheFly) { /* enable it in the middle of JS and make sure things check out */ JS::RootedValue rval(cx); - JS_CallFunctionName(cx, global, "a", 0, nullptr, rval.address()); + JS_CallFunctionName(cx, global, "a", JS::EmptyValueArray, rval.address()); CHECK(psize == 0); CHECK(max_stack >= 1); CHECK(cx->runtime()->spsProfiler.stringsCount() == 1); @@ -236,7 +236,7 @@ BEGIN_TEST(testProfileStrings_worksWhenEnabledOnTheFly) { /* now disable in the middle of js */ JS::RootedValue rval(cx); - JS_CallFunctionName(cx, global, "c", 0, nullptr, rval.address()); + JS_CallFunctionName(cx, global, "c", JS::EmptyValueArray, rval.address()); CHECK(psize == 0); } @@ -245,7 +245,7 @@ BEGIN_TEST(testProfileStrings_worksWhenEnabledOnTheFly) { /* now disable in the middle of js, but re-enable before final exit */ JS::RootedValue rval(cx); - JS_CallFunctionName(cx, global, "e", 0, nullptr, rval.address()); + JS_CallFunctionName(cx, global, "e", JS::EmptyValueArray, rval.address()); CHECK(psize == 0); CHECK(max_stack >= 3); } @@ -259,7 +259,7 @@ BEGIN_TEST(testProfileStrings_worksWhenEnabledOnTheFly) JS::RootedValue rval(cx); /* disable, and make sure that if we try to re-enter the JIT the pop * will still happen */ - JS_CallFunctionName(cx, global, "f", 0, nullptr, rval.address()); + JS_CallFunctionName(cx, global, "f", JS::EmptyValueArray, rval.address()); CHECK(psize == 0); } return true; diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 7fde8dc670a5..90fdccc6b925 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -4957,32 +4957,32 @@ JS_EvaluateScript(JSContext *cx, JSObject *objArg, const char *bytes, unsigned n } JS_PUBLIC_API(bool) -JS_CallFunction(JSContext *cx, JSObject *objArg, JSFunction *fun, unsigned argc, jsval *argv, +JS_CallFunction(JSContext *cx, JSObject *objArg, JSFunction *fun, const JS::HandleValueArray& args, jsval *rval) { RootedObject obj(cx, objArg); JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); - assertSameCompartment(cx, obj, fun, JSValueArray(argv, argc)); + assertSameCompartment(cx, obj, fun, args); AutoLastFrameCheck lfc(cx); RootedValue rv(cx); - if (!Invoke(cx, ObjectOrNullValue(obj), ObjectValue(*fun), argc, argv, &rv)) + if (!Invoke(cx, ObjectOrNullValue(obj), ObjectValue(*fun), args.length(), args.begin(), &rv)) return false; *rval = rv; return true; } JS_PUBLIC_API(bool) -JS_CallFunctionName(JSContext *cx, JSObject *objArg, const char *name, unsigned argc, jsval *argv, - jsval *rval) +JS_CallFunctionName(JSContext *cx, JSObject *objArg, const char *name, + const JS::HandleValueArray& args, jsval *rval) { RootedObject obj(cx, objArg); JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); - assertSameCompartment(cx, obj, JSValueArray(argv, argc)); + assertSameCompartment(cx, obj, args); AutoLastFrameCheck lfc(cx); JSAtom *atom = Atomize(cx, name, strlen(name)); @@ -4995,40 +4995,40 @@ JS_CallFunctionName(JSContext *cx, JSObject *objArg, const char *name, unsigned return false; RootedValue rv(cx); - if (!Invoke(cx, ObjectOrNullValue(obj), v, argc, argv, &rv)) + if (!Invoke(cx, ObjectOrNullValue(obj), v, args.length(), args.begin(), &rv)) return false; *rval = rv; return true; } JS_PUBLIC_API(bool) -JS_CallFunctionValue(JSContext *cx, JSObject *objArg, jsval fval, unsigned argc, jsval *argv, +JS_CallFunctionValue(JSContext *cx, JSObject *objArg, jsval fval, const JS::HandleValueArray& args, jsval *rval) { RootedObject obj(cx, objArg); JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); - assertSameCompartment(cx, obj, fval, JSValueArray(argv, argc)); + assertSameCompartment(cx, obj, fval, args); AutoLastFrameCheck lfc(cx); RootedValue rv(cx); - if (!Invoke(cx, ObjectOrNullValue(obj), fval, argc, argv, &rv)) + if (!Invoke(cx, ObjectOrNullValue(obj), fval, args.length(), args.begin(), &rv)) return false; *rval = rv; return true; } JS_PUBLIC_API(bool) -JS::Call(JSContext *cx, jsval thisv, jsval fval, unsigned argc, jsval *argv, +JS::Call(JSContext *cx, jsval thisv, jsval fval, const JS::HandleValueArray& args, MutableHandleValue rval) { AssertHeapIsIdle(cx); CHECK_REQUEST(cx); - assertSameCompartment(cx, thisv, fval, JSValueArray(argv, argc)); + assertSameCompartment(cx, thisv, fval, args); AutoLastFrameCheck lfc(cx); - return Invoke(cx, thisv, fval, argc, argv, rval); + return Invoke(cx, thisv, fval, args.length(), args.begin(), rval); } JS_PUBLIC_API(JSObject *) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index a1d31fd198e6..2e548be84e81 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3911,48 +3911,49 @@ Evaluate(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &opti } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, const JS::HandleValueArray& args, + jsval *rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, const JS::HandleValueArray& args, + jsval *rval); extern JS_PUBLIC_API(bool) -JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc, - jsval *argv, jsval *rval); +JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, const JS::HandleValueArray& args, + jsval *rval); namespace JS { static inline bool -Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, +Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, const JS::HandleValueArray &args, MutableHandleValue rval) { - return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunction(cx, thisObj, fun, args, rval.address()); } static inline bool -Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, +Call(JSContext *cx, JSObject *thisObj, const char *name, const JS::HandleValueArray& args, MutableHandleValue rval) { - return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval.address()); + return !!JS_CallFunctionName(cx, thisObj, name, args, rval.address()); } static inline bool -Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, +Call(JSContext *cx, JSObject *thisObj, jsval fun, const JS::HandleValueArray& args, MutableHandleValue rval) { - return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval.address()); + return !!JS_CallFunctionValue(cx, thisObj, fun, args, rval.address()); } extern JS_PUBLIC_API(bool) -Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, MutableHandleValue rval); +Call(JSContext *cx, jsval thisv, jsval fun, const JS::HandleValueArray& args, + MutableHandleValue rval); static inline bool -Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, +Call(JSContext *cx, jsval thisv, JSObject *funObj, const JS::HandleValueArray& args, MutableHandleValue rval) { - return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval); + return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), args, rval); } } /* namespace JS */ diff --git a/js/src/jscntxtinlines.h b/js/src/jscntxtinlines.h index 2b8fa446d3a3..bac370043cde 100644 --- a/js/src/jscntxtinlines.h +++ b/js/src/jscntxtinlines.h @@ -72,6 +72,11 @@ class CompartmentChecker check(obj->compartment()); } + template + void check(const Rooted& rooted) { + check(rooted.get()); + } + template void check(Handle handle) { check(handle.get()); @@ -99,6 +104,11 @@ class CompartmentChecker check(arr.array[i]); } + void check(const JS::HandleValueArray &arr) { + for (size_t i = 0; i < arr.length(); i++) + check(arr[i]); + } + void check(const CallArgs &args) { for (Value *p = args.base(); p != args.end(); ++p) check(*p); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 0c67297202f8..7a4d8ef336c9 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -1257,10 +1257,10 @@ GetOuterObject(JSContext *cx, js::HandleObject obj) class JSValueArray { public: - jsval *array; + const jsval *array; size_t length; - JSValueArray(jsval *v, size_t c) : array(v), length(c) {} + JSValueArray(const jsval *v, size_t c) : array(v), length(c) {} }; class ValueArray { diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 85dc39bf2627..5b3f96b3df75 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -323,7 +323,7 @@ ShellOperationCallback(JSContext *cx) if (!gTimeoutFunc.isNull()) { JSAutoCompartment ac(cx, &gTimeoutFunc.toObject()); RootedValue returnedValue(cx); - if (!JS_CallFunctionValue(cx, nullptr, gTimeoutFunc, 0, nullptr, returnedValue.address())) + if (!JS_CallFunctionValue(cx, nullptr, gTimeoutFunc, JS::EmptyValueArray, returnedValue.address())) return false; if (returnedValue.isBoolean()) result = returnedValue.toBoolean(); @@ -3944,8 +3944,7 @@ class ShellSourceHook: public SourceHook { RootedValue filenameValue(cx, StringValue(str)); RootedValue result(cx); - if (!Call(cx, UndefinedValue(), &fun->as(), - 1, filenameValue.address(), &result)) + if (!Call(cx, UndefinedValue(), &fun->as(), filenameValue, &result)) return false; str = JS::ToString(cx, result); @@ -3991,7 +3990,7 @@ WithSourceHook(JSContext *cx, unsigned argc, jsval *vp) SourceHook *savedHook = js::ForgetSourceHook(cx->runtime()); js::SetSourceHook(cx->runtime(), hook); - bool result = Call(cx, UndefinedValue(), &args[1].toObject(), 0, nullptr, args.rval()); + bool result = Call(cx, UndefinedValue(), &args[1].toObject(), JS::EmptyValueArray, args.rval()); js::SetSourceHook(cx->runtime(), savedHook); return result; } diff --git a/js/src/vm/Interpreter.cpp b/js/src/vm/Interpreter.cpp index ab9038255df8..abb323e54fbe 100644 --- a/js/src/vm/Interpreter.cpp +++ b/js/src/vm/Interpreter.cpp @@ -499,7 +499,7 @@ js::Invoke(JSContext *cx, CallArgs args, MaybeConstruct construct) } bool -js::Invoke(JSContext *cx, const Value &thisv, const Value &fval, unsigned argc, Value *argv, +js::Invoke(JSContext *cx, const Value &thisv, const Value &fval, unsigned argc, const Value *argv, MutableHandleValue rval) { InvokeArgs args(cx); diff --git a/js/src/vm/Interpreter.h b/js/src/vm/Interpreter.h index 66c5ab06bcf1..673d883c6bc4 100644 --- a/js/src/vm/Interpreter.h +++ b/js/src/vm/Interpreter.h @@ -129,7 +129,7 @@ Invoke(JSContext *cx, CallArgs args, MaybeConstruct construct = NO_CONSTRUCT); * arguments onto the stack. */ extern bool -Invoke(JSContext *cx, const Value &thisv, const Value &fval, unsigned argc, Value *argv, +Invoke(JSContext *cx, const Value &thisv, const Value &fval, unsigned argc, const Value *argv, MutableHandleValue rval); /* diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 9e21a89c4913..5df8ad7f4f93 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -999,7 +999,7 @@ mozJSComponentLoader::ObjectForLocation(nsIFile *aComponentFile, ok = JS_ExecuteScriptVersion(cx, obj, script, nullptr, JSVERSION_LATEST); } else { RootedValue rval(cx); - ok = JS_CallFunction(cx, obj, function, 0, nullptr, rval.address()); + ok = JS_CallFunction(cx, obj, function, JS::EmptyValueArray, rval.address()); } } diff --git a/js/xpconnect/loader/mozJSSubScriptLoader.cpp b/js/xpconnect/loader/mozJSSubScriptLoader.cpp index ef2b496e3551..a53d4296128a 100644 --- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp +++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp @@ -349,7 +349,7 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString &url, bool ok = false; if (function) { - ok = JS_CallFunction(cx, targetObj, function, 0, nullptr, retval.address()); + ok = JS_CallFunction(cx, targetObj, function, JS::EmptyValueArray, retval.address()); } else { ok = JS_ExecuteScriptVersion(cx, targetObj, script, retval.address(), version); } diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index 7ae4da47fa01..1db4c9962dab 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -766,8 +766,7 @@ xpc::SandboxCallableProxyHandler::call(JSContext *cx, JS::Handle prox thisVal = ObjectValue(*js::GetProxyTargetObject(sandboxProxy)); } - return JS::Call(cx, thisVal, js::GetProxyPrivate(proxy), args.length(), args.array(), - args.rval()); + return JS::Call(cx, thisVal, js::GetProxyPrivate(proxy), args, args.rval()); } xpc::SandboxCallableProxyHandler xpc::sandboxCallableProxyHandler; @@ -1748,7 +1747,7 @@ NonCloningFunctionForwarder(JSContext *cx, unsigned argc, Value *vp) if (!obj) { return false; } - return JS_CallFunctionValue(cx, obj, v, args.length(), args.array(), vp); + return JS_CallFunctionValue(cx, obj, v, args, vp); } /* @@ -1778,8 +1777,7 @@ CloningFunctionForwarder(JSContext *cx, unsigned argc, Value *vp) RootedValue functionVal(cx); functionVal.setObject(*origFunObj); - if (!JS_CallFunctionValue(cx, nullptr, functionVal, args.length(), args.array(), - args.rval().address())) + if (!JS_CallFunctionValue(cx, nullptr, functionVal, args, args.rval().address())) return false; } diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 7f01959a372a..045d206a0a35 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -2155,13 +2155,9 @@ nsXPCConstructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,JSContext * return ThrowAndFail(NS_ERROR_XPC_CANT_CREATE_WN, cx, _retval); } - JS::AutoValueVector argv(cx); - MOZ_ALWAYS_TRUE(argv.resize(1)); - argv[0].setObject(*iidObj); - + JS::Rooted arg(cx, ObjectValue(*iidObj)); RootedValue rval(cx); - if (!JS_CallFunctionName(cx, cidObj, "createInstance", 1, argv.begin(), - rval.address()) || + if (!JS_CallFunctionName(cx, cidObj, "createInstance", arg, rval.address()) || rval.isPrimitive()) { // createInstance will have thrown an exception *_retval = false; @@ -2181,7 +2177,7 @@ nsXPCConstructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,JSContext * } RootedValue dummy(cx); - if (!JS_CallFunctionValue(cx, newObj, fun, args.length(), args.array(), dummy.address())) { + if (!JS_CallFunctionValue(cx, newObj, fun, args, dummy.address())) { // function should have thrown an exception *_retval = false; return NS_OK; @@ -3386,7 +3382,7 @@ nsXPCComponents_Utils::GetIncumbentGlobal(HandleValue aCallback, // Invoke the callback, if passed. if (aCallback.isObject()) { RootedValue ignored(aCx); - if (!JS_CallFunctionValue(aCx, nullptr, aCallback, 1, globalVal.address(), ignored.address())) + if (!JS_CallFunctionValue(aCx, nullptr, aCallback, globalVal, ignored.address())) return NS_ERROR_FAILURE; } diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 0a04fa901e1e..839921b23920 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -652,7 +652,7 @@ XPCShellOperationCallback(JSContext *cx) JSAutoCompartment ac(cx, &sScriptedOperationCallback.toObject()); RootedValue rv(cx); if (!JS_CallFunctionValue(cx, nullptr, sScriptedOperationCallback, - 0, nullptr, rv.address()) || !rv.isBoolean()) + JS::EmptyValueArray, rv.address()) || !rv.isBoolean()) { NS_WARNING("Scripted operation callback failed! Terminating script."); JS_ClearPendingException(cx); diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 9c097aeef9b1..511050bde196 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -233,11 +233,8 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx, { AutoSaveContextOptions asco(cx); ContextOptionsRef(cx).setDontReportUncaught(true); - JS::AutoValueVector argv(cx); - MOZ_ALWAYS_TRUE(argv.resize(1)); - argv[0].setObject(*id); - success = JS_CallFunctionValue(cx, jsobj, fun, 1, argv.begin(), - retval.address()); + RootedValue arg(cx, JS::ObjectValue(*id)); + success = JS_CallFunctionValue(cx, jsobj, fun, arg, retval.address()); } if (!success && JS_IsExceptionPending(cx)) { @@ -1287,7 +1284,7 @@ pre_call_clean_up: AutoSaveContextOptions asco(cx); ContextOptionsRef(cx).setDontReportUncaught(true); - success = JS_CallFunctionValue(cx, thisObj, fval, argc, argv, rval.address()); + success = JS_CallFunctionValue(cx, thisObj, fval, args, rval.address()); } else { // The property was not an object so can't be a function. // Let's build and 'throw' an exception. diff --git a/netwerk/base/src/ProxyAutoConfig.cpp b/netwerk/base/src/ProxyAutoConfig.cpp index ded02866572b..fb1612ac6153 100644 --- a/netwerk/base/src/ProxyAutoConfig.cpp +++ b/netwerk/base/src/ProxyAutoConfig.cpp @@ -685,14 +685,13 @@ ProxyAutoConfig::GetProxyForURI(const nsCString &aTestURI, JS::RootedString hostString(cx, JS_NewStringCopyZ(cx, aTestHost.get())); if (uriString && hostString) { - JS::AutoValueVector argv(cx); - MOZ_ALWAYS_TRUE(argv.resize(2)); - argv[0].setString(uriString); - argv[1].setString(hostString); + JS::AutoValueArray<2> args(cx); + args[0].setString(uriString); + args[1].setString(hostString); JS::Rooted rval(cx); bool ok = JS_CallFunctionName(cx, mJSRuntime->Global(), - "FindProxyForURL", 2, argv.begin(), rval.address()); + "FindProxyForURL", args, rval.address()); if (ok && rval.isString()) { nsDependentJSString pacString; diff --git a/xpfe/components/directory/nsDirectoryViewer.cpp b/xpfe/components/directory/nsDirectoryViewer.cpp index e3c6678c0a1e..99439edcf2f1 100644 --- a/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/xpfe/components/directory/nsDirectoryViewer.cpp @@ -169,8 +169,7 @@ nsHTTPIndex::OnFTPControlLog(bool server, const char *msg) JSString* jsMsgStr = JS_NewUCStringCopyZ(cx, unicodeMsg.get()); NS_ENSURE_TRUE(jsMsgStr, NS_ERROR_OUT_OF_MEMORY); - JS::AutoValueVector params(cx); - MOZ_ALWAYS_TRUE(params.resize(2)); + JS::AutoValueArray<2> params(cx); params[0].setBoolean(server); params[1].setString(jsMsgStr); @@ -178,8 +177,7 @@ nsHTTPIndex::OnFTPControlLog(bool server, const char *msg) JS_CallFunctionName(cx, global, "OnFTPControlLog", - 2, - params.begin(), + params, val.address()); return NS_OK; }