summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore.js
blob: 393d02a14e9416270688581e957d0f0f94510e93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
es6id: 21.2.5.9
description: The `lastIndex` value is restored following match execution
info: |
    [...]
    8. If SameValue(currentLastIndex, previousLastIndex) is false, then
       a. Perform ? Set(rx, "lastIndex", previousLastIndex, true).
    [...]
features: [Symbol.search]
---*/

var latestValue = 86;
var callCount = 0;
var fakeRe = {
  get lastIndex() {
    return latestValue;
  },
  set lastIndex(_) {
    latestValue = _;
  },
  exec: function() {
    callCount++;
    latestValue = null;
    return null;
  }
};

RegExp.prototype[Symbol.search].call(fakeRe);

assert.sameValue(callCount, 1);
assert.sameValue(latestValue, 86);

reportCompare(0, 0);