Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Unified Diff: test/mjsunit/es6/regexp-constructor.js

Issue 1448933002: Introduce a BuiltinsConstructStub that sets up new.target and does a [[call]] per ES6 9.3.2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/es6/classes-subclass-builtins.js ('k') | test/mjsunit/mjsunit.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/regexp-constructor.js
diff --git a/test/mjsunit/es6/regexp-constructor.js b/test/mjsunit/es6/regexp-constructor.js
new file mode 100644
index 0000000000000000000000000000000000000000..e3b7efa0e7a382390fe7f1971422ace491552ead
--- /dev/null
+++ b/test/mjsunit/es6/regexp-constructor.js
@@ -0,0 +1,99 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-regexp-subclass
+
+"use strict";
+
+function should_not_be_called() {
+ throw new Error("should not be called");
+}
+
+(function() {
+ var r = new RegExp("biep");
+ assertTrue(r === RegExp(r));
+ assertFalse(r === new RegExp(r));
+ r[Symbol.match] = false;
+ Object.defineProperty(r, "source", {get: should_not_be_called});
+ Object.defineProperty(r, "flags", {get: should_not_be_called});
+ assertFalse(r === RegExp(r));
+})();
+
+(function() {
+ class A extends RegExp {
+ get source() { throw new Error("should not be called") }
+ get flags() { throw new Error("should not be called") }
+ }
+
+ var r = new A("biep");
+ var r2 = RegExp(r);
+
+ assertFalse(r === r2);
+ assertEquals(r, r2);
+ assertTrue(A.prototype === r.__proto__);
+ assertTrue(RegExp.prototype === r2.__proto__);
+
+ var r3 = RegExp(r);
+ assertFalse(r3 === r);
+ assertEquals(r3, r);
+
+ var r4 = new A(r2);
+ assertFalse(r4 === r2);
+ assertEquals(r4, r2);
+ assertTrue(A.prototype === r4.__proto__);
+
+ r[Symbol.match] = false;
+ var r5 = new A(r);
+ assertFalse(r5 === r);
+ assertEquals(r5, r);
+ assertTrue(A.prototype === r5.__proto__);
+})();
+
+(function() {
+ var log = [];
+ var match = {
+ get source() { log.push("source"); return "biep"; },
+ get flags() { log.push("flags"); return "i"; }
+ };
+ Object.defineProperty(match, Symbol.match,
+ {get() { log.push("match"); return true; }});
+ var r = RegExp(match);
+ assertEquals(["match", "source", "flags"], log);
+ assertFalse(r === match);
+ assertEquals(/biep/i, r);
+})();
+
+(function() {
+ var log = [];
+ var match = {
+ get source() { log.push("source"); return "biep"; },
+ get flags() { log.push("flags"); return "i"; }
+ };
+ Object.defineProperty(match, Symbol.match,
+ {get() { log.push("match"); return true; }});
+ match.constructor = RegExp;
+ var r = RegExp(match);
+ assertEquals(["match"], log);
+ assertTrue(r === match);
+})();
+
+(function() {
+ var r = RegExp("biep", "i");
+ r[Symbol.match] = false;
+ var r2 = RegExp(r, "g");
+ assertFalse(r === r2);
+ assertEquals(/biep/i, r);
+ assertEquals(/biep/g, r2);
+})();
+
+(function() {
+ class A extends RegExp {
+ get ["constructor"]() { log.push("constructor"); return RegExp; }
+ }
+ var r = new A("biep");
+ var log = [];
+ var r2 = RegExp(r);
+ assertEquals(["constructor"], log);
+ assertTrue(r === r2);
+})();
« no previous file with comments | « test/mjsunit/es6/classes-subclass-builtins.js ('k') | test/mjsunit/mjsunit.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698