Bug 1192038 - Tests. r=arai
authorTom Schuster <evilpies@gmail.com>
Sat, 26 Nov 2016 19:01:59 +0100
changeset 324352 023c20b89e6a2dabbf80e25fdc4e8ac3beada472
parent 324351 47d405339a6fbf6e8ea0350db40607c73a65c324
child 324353 3f955c5e71668a73cd034d1404c8482a53bd223f
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersarai
bugs1192038
milestone53.0a1
Bug 1192038 - Tests. r=arai
js/src/jit-test/tests/basic/plain-object-prototypes-error.js
js/src/jit-test/tests/basic/plain-object-prototypes.js
js/src/tests/ecma_5/RegExp/instance-property-storage-introspection.js
js/src/tests/ecma_6/RegExp/prototype.js
js/src/tests/js1_8_5/extensions/clone-regexp.js
--- a/js/src/jit-test/tests/basic/plain-object-prototypes-error.js
+++ b/js/src/jit-test/tests/basic/plain-object-prototypes-error.js
@@ -9,8 +9,9 @@ function assertThrowsObjectError(f) {
     }
 }
 
 assertThrowsObjectError(() => Map.prototype.has(0));
 assertThrowsObjectError(() => Set.prototype.has(0));
 assertThrowsObjectError(() => WeakMap.prototype.has({}));
 assertThrowsObjectError(() => WeakSet.prototype.has({}));
 assertThrowsObjectError(() => Date.prototype.getSeconds());
+assertThrowsObjectError(() => RegExp.prototype.compile());
--- a/js/src/jit-test/tests/basic/plain-object-prototypes.js
+++ b/js/src/jit-test/tests/basic/plain-object-prototypes.js
@@ -7,14 +7,15 @@ const prototypes = [
     Error.prototype,
     InternalError.prototype,
     EvalError.prototype,
     RangeError.prototype,
     ReferenceError.prototype,
     SyntaxError.prototype,
     TypeError.prototype,
     URIError.prototype,
+    RegExp.prototype,
 ];
 
 for (const prototype of prototypes) {
     delete prototype[Symbol.toStringTag];
     assertEq(Object.prototype.toString.call(prototype), "[object Object]");
 }
--- a/js/src/tests/ecma_5/RegExp/instance-property-storage-introspection.js
+++ b/js/src/tests/ecma_5/RegExp/instance-property-storage-introspection.js
@@ -35,32 +35,29 @@ function checkDataProperty(obj, p, expec
   assertEq(d.writable, d2.writable, msg + ": writable changed on redefinition of " + p + "?");
   assertEq(d.enumerable, d2.enumerable, msg + ": enumerable changed on redefinition of " + p + "?");
   assertEq(d.configurable, d2.configurable, msg + ": configurable changed on redefinition of " + p + "?");
 }
 
 
 // Check a bunch of "empty" regular expressions first.
 
-var choices = [{ msg: "RegExp.prototype",
-                 get: function() { return RegExp.prototype; } },
-               { msg: "new RegExp()",
+var choices = [{ msg: "new RegExp()",
                  get: function() { return new RegExp(); } },
                { msg: "/(?:)/",
                  get: Function("return /(?:)/;") }];
 
 function checkRegExp(r, msg, lastIndex)
 {
   var expect;
 
   expect = { value: lastIndex, enumerable: false, configurable: false, writable: true };
   checkDataProperty(r, "lastIndex", expect, msg);
 }
 
-checkRegExp(RegExp.prototype, "RegExp.prototype", 0);
 checkRegExp(new RegExp(), "new RegExp()", 0);
 checkRegExp(/(?:)/, "/(?:)/", 0);
 checkRegExp(Function("return /(?:)/;")(), 'Function("return /(?:)/;")()', 0);
 
 for (var i = 0; i < choices.length; i++)
 {
   var choice = choices[i];
   var msg = choice.msg;
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/RegExp/prototype.js
@@ -0,0 +1,31 @@
+const t = RegExp.prototype;
+
+const properties = "toSource,toString,compile,exec,test," +
+                   "flags,global,ignoreCase,multiline,source,sticky,unicode," +
+                   "constructor," +
+                   "Symbol(Symbol.match),Symbol(Symbol.replace),Symbol(Symbol.search),Symbol(Symbol.split)";
+assertEq(Reflect.ownKeys(t).map(String).toString(), properties);
+
+
+// Invoking getters on the prototype should not throw
+function getter(name) {
+    return Object.getOwnPropertyDescriptor(t, name).get.call(t);
+}
+
+assertEq(getter("flags"), "");
+assertEq(getter("global"), undefined);
+assertEq(getter("ignoreCase"), undefined);
+assertEq(getter("multiline"), undefined);
+assertEq(getter("source"), "(?:)");
+assertEq(getter("sticky"), undefined);
+assertEq(getter("unicode"), undefined);
+
+assertEq(t.toString(), "/(?:)/");
+
+// The methods don't work with the prototype
+assertThrowsInstanceOf(() => t.compile("b", "i"), TypeError);
+assertThrowsInstanceOf(() => t.test("x"), TypeError);
+assertThrowsInstanceOf(() => t.exec("x"), TypeError);
+
+if (typeof reportCompare === "function")
+    reportCompare(0, 0);
--- a/js/src/tests/js1_8_5/extensions/clone-regexp.js
+++ b/js/src/tests/js1_8_5/extensions/clone-regexp.js
@@ -17,17 +17,16 @@ function testRegExp(b, c=b) {
     assertEq(a.multiline, c.multiline);
     assertEq(a.sticky, c.sticky);
     assertEq("expando" in a, false);
 }
 
 testRegExp(RegExp(""));
 testRegExp(/(?:)/);
 testRegExp(/^(.*)$/gimy);
-testRegExp(RegExp.prototype);
 
 var re = /\bx\b/gi;
 re.expando = true;
 testRegExp(re);
 // `source` and the flag accessors are defined on RegExp.prototype, so they're
 // not available after re.__proto__ has been changed. We solve that by passing
 // in an additional copy of the same RegExp to compare the
 // serialized-then-deserialized clone with."