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

Side by Side Diff: test/mjsunit/regress/regress-5434.js

Issue 2440413002: [regexp] Add regression test for v8:5434 (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Ensure that we have the correct number of accesses to exec in split, and
6 // that exec is called at the correct point in time.
7
8 var lastIndexHasBeenSet = false;
9 var countOfExecGets = 0;
10
11 // Force the slow path and make sure the created splitter object has our
12 // overwritten exec method (@@split does not call exec on the original regexp
13 // but on a newly-created splitter which is guaranteed to be sticky).
14 class ObservableExecRegExp extends RegExp {
15 constructor(pattern, flags) {
16 super(pattern, flags);
17 this.lastIndex = 42;
18
19 const re = this;
20 Object.defineProperty(this, "exec", {
21 get: function() {
22 // Ensure exec is first accessed after lastIndex has been reset to
23 // satisfy the spec.
24 assertTrue(re.lastIndex != 42);
25 countOfExecGets++;
26 return RegExp.prototype.exec;
27 }
28 });
29 }
30 }
31
32
33
34 var re = new ObservableExecRegExp(/x/);
35
36 assertEquals(42, re.lastIndex);
37 assertEquals(0, countOfExecGets);
38
39 var result = "axbxc".split(re);
40
41 assertEquals(5, countOfExecGets);
42 assertEquals(["a", "b", "c"], result);
OLDNEW
« 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