Add "lastIndex" restore test

This commit is contained in:
Alexey Shvayka 2020-03-20 20:34:39 +02:00 committed by Rick Waldron
parent fe2dfe9525
commit dc21d6b0a4
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-regexp.prototype-@@search
description: >
`currentLastIndex` value is compared using SameValue.
info: |
RegExp.prototype [ @@search ] ( string )
[...]
6. Let result be ? RegExpExec(rx, S).
7. Let currentLastIndex be ? Get(rx, "lastIndex").
8. If SameValue(currentLastIndex, previousLastIndex) is false, then
a. Perform ? Set(rx, "lastIndex", previousLastIndex, true).
[...]
features: [Symbol.search]
---*/
var re = /(?:)/;
re.exec = function() {
re.lastIndex = -0;
return null;
};
assert.sameValue(re[Symbol.search](""), -1);
assert.sameValue(re.lastIndex, 0);