diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 54cc8187139..ff7528bff30 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1593,14 +1593,16 @@ TraceMallocOpenLogFile(JSContext *cx, unsigned argc, JS::Value *vp) static bool TraceMallocChangeLogFD(JSContext *cx, unsigned argc, JS::Value *vp) { + JS::CallArgs args = CallArgsFromVp(argc, vp); + if (!CheckUniversalXPConnectForTraceMalloc(cx)) return false; int32_t fd, oldfd; - if (argc == 0) { + if (args.length() == 0) { oldfd = -1; } else { - if (!JS_ValueToECMAInt32(cx, JS_ARGV(cx, vp)[0], &fd)) + if (!JS::ToInt32(cx, args[0], &fd)) return false; oldfd = NS_TraceMallocChangeLogFD(fd); if (oldfd == -2) { @@ -1608,23 +1610,27 @@ TraceMallocChangeLogFD(JSContext *cx, unsigned argc, JS::Value *vp) return false; } } - JS_SET_RVAL(cx, vp, INT_TO_JSVAL(oldfd)); + args.rval().setInt32(oldfd); return true; } static bool TraceMallocCloseLogFD(JSContext *cx, unsigned argc, JS::Value *vp) { + JS::CallArgs args = CallArgsFromVp(argc, vp); + if (!CheckUniversalXPConnectForTraceMalloc(cx)) return false; int32_t fd; - JS_SET_RVAL(cx, vp, JSVAL_VOID); - if (argc == 0) + if (args.length() == 0) { + args.rval().setUndefined(); return true; - if (!JS_ValueToECMAInt32(cx, JS_ARGV(cx, vp)[0], &fd)) + } + if (!JS::ToInt32(cx, args[0], &fd)) return false; NS_TraceMallocCloseLogFD((int) fd); + args.rval().setInt32(fd); return true; } diff --git a/dom/base/nsJSTimeoutHandler.cpp b/dom/base/nsJSTimeoutHandler.cpp index 14184775456..ad23ac605ff 100644 --- a/dom/base/nsJSTimeoutHandler.cpp +++ b/dom/base/nsJSTimeoutHandler.cpp @@ -191,11 +191,15 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval, } int32_t interval = 0; - if (argc > 1 && !::JS_ValueToECMAInt32(cx, argv[1], &interval)) { - ::JS_ReportError(cx, - "Second argument to %s must be a millisecond interval", - aIsInterval ? kSetIntervalStr : kSetTimeoutStr); - return NS_ERROR_DOM_TYPE_ERR; + if (argc > 1) { + JS::Rooted arg(cx, argv[1]); + + if (!JS::ToInt32(cx, arg, &interval)) { + ::JS_ReportError(cx, + "Second argument to %s must be a millisecond interval", + aIsInterval ? kSetIntervalStr : kSetTimeoutStr); + return NS_ERROR_DOM_TYPE_ERR; + } } if (argc == 1) { diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 7f9b69e5cce..e9c25e73717 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -271,6 +271,7 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, const char *for } break; } + RootedValue arg(cx, *sp); switch (c) { case 'b': *va_arg(ap, bool *) = ToBoolean(*sp); @@ -280,7 +281,7 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, const char *for return false; break; case 'i': - if (!JS_ValueToECMAInt32(cx, *sp, va_arg(ap, int32_t *))) + if (!ToInt32(cx, arg, va_arg(ap, int32_t *))) return false; break; case 'u': @@ -474,12 +475,6 @@ JS_DoubleToUint32(double d) return ToUint32(d); } -JS_PUBLIC_API(bool) -JS_ValueToECMAInt32(JSContext *cx, jsval valueArg, int32_t *ip) -{ - RootedValue value(cx, valueArg); - return JS::ToInt32(cx, value, ip); -} JS_PUBLIC_API(bool) JS_ValueToECMAUint32(JSContext *cx, jsval valueArg, uint32_t *ip) diff --git a/js/xpconnect/src/dictionary_helper_gen.py b/js/xpconnect/src/dictionary_helper_gen.py index 50d85bab678..7f69b1472e9 100644 --- a/js/xpconnect/src/dictionary_helper_gen.py +++ b/js/xpconnect/src/dictionary_helper_gen.py @@ -293,12 +293,12 @@ def write_getter(a, iface, fd): fd.write(" aDict.%s = u;\n" % a.name) elif realtype.count("int16_t"): fd.write(" int32_t i;\n") - fd.write(" NS_ENSURE_STATE(JS_ValueToECMAInt32(aCx, v, &i));\n") + fd.write(" NS_ENSURE_STATE(JS::ToInt32(aCx, v, &i));\n") fd.write(" aDict.%s = i;\n" % a.name) elif realtype.count("uint32_t"): fd.write(" NS_ENSURE_STATE(JS_ValueToECMAUint32(aCx, v, &aDict.%s));\n" % a.name) elif realtype.count("int32_t"): - fd.write(" NS_ENSURE_STATE(JS_ValueToECMAInt32(aCx, v, &aDict.%s));\n" % a.name) + fd.write(" NS_ENSURE_STATE(JS::ToInt32(aCx, v, &aDict.%s));\n" % a.name) elif realtype.count("uint64_t"): fd.write(" NS_ENSURE_STATE(JS::ToUint64(aCx, v, &aDict.%s));\n" % a.name) elif realtype.count("int64_t"): diff --git a/js/xpconnect/src/qsgen.py b/js/xpconnect/src/qsgen.py index d219a71bafd..8706dc013b6 100644 --- a/js/xpconnect/src/qsgen.py +++ b/js/xpconnect/src/qsgen.py @@ -391,7 +391,7 @@ argumentUnboxingTemplates = { 'short': " int32_t ${name}_i32;\n" - " if (!JS_ValueToECMAInt32(cx, ${argVal}, &${name}_i32))\n" + " if (!JS::ToInt32(cx, ${argVal}, &${name}_i32))\n" " return false;\n" " int16_t ${name} = (int16_t) ${name}_i32;\n", @@ -403,7 +403,7 @@ argumentUnboxingTemplates = { 'long': " int32_t ${name};\n" - " if (!JS_ValueToECMAInt32(cx, ${argVal}, &${name}))\n" + " if (!JS::ToInt32(cx, ${argVal}, &${name}))\n" " return false;\n", 'unsigned long': diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index bcdd09ccf34..0073caa8339 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -622,20 +622,19 @@ IsEmpty(const Histogram *h) bool JSHistogram_Add(JSContext *cx, unsigned argc, JS::Value *vp) { - if (!argc) { + JS::CallArgs args = CallArgsFromVp(argc, vp); + if (!args.length()) { JS_ReportError(cx, "Expected one argument"); return false; } - JS::Value v = JS_ARGV(cx, vp)[0]; - - if (!(JSVAL_IS_NUMBER(v) || JSVAL_IS_BOOLEAN(v))) { + if (!(args[0].isNumber() || args[0].isBoolean())) { JS_ReportError(cx, "Not a number"); return false; } int32_t value; - if (!JS_ValueToECMAInt32(cx, v, &value)) { + if (!JS::ToInt32(cx, args[0], &value)) { return false; }