Bug 1192038 - Update RegExp Xray code. r=bholley,arai
authorTom Schuster <evilpies@gmail.com>
Sat, 26 Nov 2016 19:17:39 +0100
changeset 324354 8f0356af174c3f132eb3ef6bd2b4ad84e145e1bb
parent 324353 3f955c5e71668a73cd034d1404c8482a53bd223f
child 324355 00c4f6b6f300527750b306d5e28ab3f4f4244292
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersbholley, arai
bugs1192038
milestone53.0a1
Bug 1192038 - Update RegExp Xray code. r=bholley,arai
js/xpconnect/tests/chrome/test_xrayToJS.xul
js/xpconnect/tests/unit/test_xray_regexp.js
js/xpconnect/tests/unit/xpcshell.ini
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xul
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul
@@ -234,18 +234,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   gPrototypeProperties['Function'] =
     ["constructor", "toSource", "toString", "apply", "call", "bind",
      "isGenerator", "length", "name", "arguments", "caller", Symbol.hasInstance];
   gConstructorProperties['Function'] = constructorProps([])
 
   gPrototypeProperties['RegExp'] =
     ["constructor", "toSource", "toString", "compile", "exec", "test",
      Symbol.match, Symbol.replace, Symbol.search, Symbol.split,
-     "flags", "global", "ignoreCase", "multiline", "source", "sticky", "unicode",
-     "lastIndex"];
+     "flags", "global", "ignoreCase", "multiline", "source", "sticky", "unicode"];
   gConstructorProperties['RegExp'] =
     constructorProps(["input", "lastMatch", "lastParen",
                       "leftContext", "rightContext", "$1", "$2", "$3", "$4",
                       "$5", "$6", "$7", "$8", "$9", "$_", "$&", "$+",
                       "$`", "$'", Symbol.species])
 
   gPrototypeProperties['Promise'] =
     ["constructor", "catch", "then", Symbol.toStringTag];
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_xray_regexp.js
@@ -0,0 +1,9 @@
+const Cu = Components.utils;
+
+function run_test() {
+    var sandbox = Cu.Sandbox('http://www.example.com');
+    var regexp = Cu.evalInSandbox("/test/i", sandbox);
+    equal(RegExp.prototype.toString.call(regexp), "/test/i");
+    var prototype = Cu.evalInSandbox("RegExp.prototype", sandbox);
+    equal(typeof prototype.lastIndex, "undefined");
+}
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -122,9 +122,10 @@ head = head_watchdog.js
 [test_watchdog_hibernate.js]
 head = head_watchdog.js
 [test_weak_keys.js]
 [test_writeToGlobalPrototype.js]
 [test_xpcwn_tamperproof.js]
 [test_xrayed_iterator.js]
 [test_xray_SavedFrame.js]
 [test_xray_SavedFrame-02.js]
+[test_xray_regexp.js]
 [test_resolve_dead_promise.js]
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -633,20 +633,16 @@ JSXrayTraits::resolveOwnProperty(JSConte
         desc.object().set(wrapper);
         desc.setAttributes(0);
         desc.setGetter(nullptr);
         desc.setSetter(nullptr);
         desc.value().setObject(*constructor);
         return true;
     }
 
-    // Handle the 'lastIndex' property for RegExp prototypes.
-    if (key == JSProto_RegExp && id == GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX))
-        return getOwnPropertyFromWrapperIfSafe(cx, wrapper, id, desc);
-
     // Grab the JSClass. We require all Xrayable classes to have a ClassSpec.
     const js::Class* clasp = js::GetObjectClass(target);
     MOZ_ASSERT(clasp->specDefined());
 
     // Indexed array properties are handled above, so we can just work with the
     // class spec here.
     if (!TryResolvePropertyFromSpecs(cx, id, holder,
                                      clasp->specPrototypeFunctions(),
@@ -878,20 +874,16 @@ JSXrayTraits::enumerateNames(JSContext* 
         // The rest of this function applies only to prototypes.
         return true;
     }
 
     // Add the 'constructor' property.
     if (!props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_CONSTRUCTOR)))
         return false;
 
-    // For RegExp protoypes, add the 'lastIndex' property.
-    if (key == JSProto_RegExp && !props.append(GetJSIDByIndex(cx, XPCJSContext::IDX_LASTINDEX)))
-        return false;
-
     // Grab the JSClass. We require all Xrayable classes to have a ClassSpec.
     const js::Class* clasp = js::GetObjectClass(target);
     MOZ_ASSERT(clasp->specDefined());
 
     return AppendNamesFromFunctionAndPropertySpecs(
         cx, clasp->specPrototypeFunctions(),
         clasp->specPrototypeProperties(), flags, props);
 }