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

Unified Diff: test/mjsunit/regress/regress-5434.js

Issue 2440413002: [regexp] Add regression test for v8:5434 (Closed)
Patch Set: Created 4 years, 2 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/regress/regress-5434.js
diff --git a/test/mjsunit/regress/regress-5434.js b/test/mjsunit/regress/regress-5434.js
new file mode 100644
index 0000000000000000000000000000000000000000..8c45a9607957f21e935c2ca689b041747303ce57
--- /dev/null
+++ b/test/mjsunit/regress/regress-5434.js
@@ -0,0 +1,42 @@
+// Copyright 2016 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.
+
+// Ensure that we have the correct number of accesses to exec in split, and
+// that exec is called at the correct point in time.
+
+var lastIndexHasBeenSet = false;
+var countOfExecGets = 0;
+
+// Force the slow path and make sure the created splitter object has our
+// overwritten exec method (@@split does not call exec on the original regexp
+// but on a newly-created splitter which is guaranteed to be sticky).
+class ObservableExecRegExp extends RegExp {
+ constructor(pattern, flags) {
+ super(pattern, flags);
+ this.lastIndex = 42;
+
+ const re = this;
+ Object.defineProperty(this, "exec", {
+ get: function() {
+ // Ensure exec is first accessed after lastIndex has been reset to
+ // satisfy the spec.
+ assertTrue(re.lastIndex != 42);
+ countOfExecGets++;
+ return RegExp.prototype.exec;
+ }
+ });
+ }
+}
+
+
+
+var re = new ObservableExecRegExp(/x/);
+
+assertEquals(42, re.lastIndex);
+assertEquals(0, countOfExecGets);
+
+var result = "axbxc".split(re);
+
+assertEquals(5, countOfExecGets);
+assertEquals(["a", "b", "c"], result);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698