Bug 1746651 - Move nukeCCW helper to make it available in xpcshell tests r=sfink
authorMatthew Gaudet <mgaudet@mozilla.com>
Fri, 14 Jan 2022 21:09:22 +0000
changeset 604609 6695c09a3d12df1d71fb38e2dab67f6eff987e77
parent 604608 1a1f7c796b8f82b85ef186d723b243bf1bae4888
child 604610 32d9429008ec32f65f3990cc7e6c8854932ff582
push id39152
push userabutkovits@mozilla.com
push dateSat, 15 Jan 2022 09:45:36 +0000
treeherdermozilla-central@60998033086a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1746651
milestone98.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1746651 - Move nukeCCW helper to make it available in xpcshell tests r=sfink Differential Revision: https://phabricator.services.mozilla.com/D135288
js/public/friend/ErrorNumbers.msg
js/src/builtin/TestingFunctions.cpp
js/src/shell/js.cpp
--- a/js/public/friend/ErrorNumbers.msg
+++ b/js/public/friend/ErrorNumbers.msg
@@ -580,16 +580,17 @@ MSG_DEF(JSMSG_DEBUG_CENSUS_BREAKDOWN,  1
 MSG_DEF(JSMSG_DEBUG_PROMISE_NOT_RESOLVED, 0, JSEXN_TYPEERR, "Promise hasn't been resolved")
 MSG_DEF(JSMSG_DEBUG_PROMISE_NOT_FULFILLED, 0, JSEXN_TYPEERR, "Promise hasn't been fulfilled")
 MSG_DEF(JSMSG_DEBUG_PROMISE_NOT_REJECTED, 0, JSEXN_TYPEERR, "Promise hasn't been rejected")
 MSG_DEF(JSMSG_DEBUG_NO_BINARY_SOURCE,  0, JSEXN_ERR, "WebAssembly binary source is not available")
 MSG_DEF(JSMSG_DEBUG_NO_PRIVATE_METHOD, 0, JSEXN_ERR, "private method calls aren't available in this context")
 
 // Testing functions
 MSG_DEF(JSMSG_TESTING_SCRIPTS_ONLY, 0, JSEXN_TYPEERR, "only works on scripts")
+MSG_DEF(JSMSG_INVALID_ARGS,         1, JSEXN_ERR, "{0}: invalid arguments")
 
 // Tracelogger
 MSG_DEF(JSMSG_TRACELOGGER_ENABLE_FAIL, 1, JSEXN_ERR, "enabling tracelogger failed: {0}")
 
 // Intl
 MSG_DEF(JSMSG_DATE_NOT_FINITE,         2, JSEXN_RANGEERR, "date value is not finite in {0}.{1}()")
 MSG_DEF(JSMSG_DUPLICATE_VARIANT_SUBTAG, 0, JSEXN_RANGEERR, "duplicate variant subtag")
 MSG_DEF(JSMSG_INTERNAL_INTL_ERROR,     0, JSEXN_ERR, "internal error while computing Intl data")
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -7832,16 +7832,31 @@ static bool PCCountProfiling_ScriptConte
   if (!str) {
     return false;
   }
 
   args.rval().setString(str);
   return true;
 }
 
+static bool NukeCCW(JSContext* cx, unsigned argc, Value* vp) {
+  CallArgs args = CallArgsFromVp(argc, vp);
+
+  if (args.length() != 1 || !args[0].isObject() ||
+      !IsCrossCompartmentWrapper(&args[0].toObject())) {
+    JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INVALID_ARGS,
+                              "nukeCCW");
+    return false;
+  }
+
+  NukeCrossCompartmentWrapper(cx, &args[0].toObject());
+  args.rval().setUndefined();
+  return true;
+}
+
 // clang-format off
 static const JSFunctionSpecWithHelp TestingFunctions[] = {
     JS_FN_HELP("gc", ::GC, 0, 0,
 "gc([obj] | 'zone' [, ('shrinking' | 'last-ditch') ])",
 "  Run the garbage collector.\n"
 "  The first parameter describes which zones to collect: if an object is\n"
 "  given, GC only its zone. If 'zone' is given, GC any zones that were\n"
 "  scheduled via schedulegc.\n"
@@ -8830,16 +8845,20 @@ JS_FN_HELP("isSmallFunction", IsSmallFun
 "  Reads the given stencil XDR object, and evaluates the top-level script it"
 "  defines."),
 
     JS_FN_HELP("getExceptionInfo", GetExceptionInfo, 1, 0,
 "getExceptionInfo(fun)",
 "  Calls the given function and returns information about the exception it"
 "  throws. Returns null if the function didn't throw an exception."),
 
+    JS_FN_HELP("nukeCCW", NukeCCW, 1, 0,
+"nukeCCW(wrapper)",
+"  Nuke a CrossCompartmentWrapper, which turns it into a DeadProxyObject."),
+
     JS_FS_HELP_END
 };
 // clang-format on
 
 // clang-format off
 static const JSFunctionSpecWithHelp FuzzingUnsafeTestingFunctions[] = {
     JS_FN_HELP("getErrorNotes", GetErrorNotes, 1, 0,
 "getErrorNotes(error)",
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -7095,31 +7095,16 @@ static bool NewGlobal(JSContext* cx, uns
   if (!JS_WrapObject(cx, &wrapped)) {
     return false;
   }
 
   args.rval().setObject(*wrapped);
   return true;
 }
 
-static bool NukeCCW(JSContext* cx, unsigned argc, Value* vp) {
-  CallArgs args = CallArgsFromVp(argc, vp);
-
-  if (args.length() != 1 || !args[0].isObject() ||
-      !IsCrossCompartmentWrapper(&args[0].toObject())) {
-    JS_ReportErrorNumberASCII(cx, my_GetErrorMessage, nullptr,
-                              JSSMSG_INVALID_ARGS, "nukeCCW");
-    return false;
-  }
-
-  NukeCrossCompartmentWrapper(cx, &args[0].toObject());
-  args.rval().setUndefined();
-  return true;
-}
-
 static bool NukeAllCCWs(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
 
   if (args.length() != 0) {
     JS_ReportErrorNumberASCII(cx, my_GetErrorMessage, nullptr,
                               JSSMSG_INVALID_ARGS, "nukeAllCCWs");
     return false;
   }
@@ -9567,20 +9552,16 @@ static const JSFunctionSpecWithHelp shel
 "         shell principal subsumes another if its set bits are a superset of\n"
 "         the other's. Thus, a principal of 0 subsumes nothing, while a\n"
 "         principals of ~0 subsumes all other principals. The absence of a\n"
 "         principal is treated as if its bits were 0xffff, for subsumption\n"
 "         purposes. If this property is omitted, supply no principal.\n"
 "      systemPrincipal: If true, use the shell's trusted principals for the\n"
 "         new realm. This creates a realm that's marked as a 'system' realm."),
 
-    JS_FN_HELP("nukeCCW", NukeCCW, 1, 0,
-"nukeCCW(wrapper)",
-"  Nuke a CrossCompartmentWrapper, which turns it into a DeadProxyObject."),
-
     JS_FN_HELP("nukeAllCCWs", NukeAllCCWs, 0, 0,
 "nukeAllCCWs()",
 "  Like nukeCCW, but for all CrossCompartmentWrappers targeting the current realm."),
 
     JS_FN_HELP("recomputeWrappers", RecomputeWrappers, 2, 0,
 "recomputeWrappers([src, [target]])",
 "  Recompute all cross-compartment wrappers. src and target are both optional\n"
 "  and can be used to filter source or target compartments: the unwrapped\n"