mirror of https://github.com/tc39/test262.git
Update tests for String.prototype.matchAll
As per spec changes (https://github.com/tc39/proposal-string-matchall/pull/35), removed tests related to the removed IsRegExp call. To prevent older implementations (not observing spec change) from passing, added a new test to verify the reduced number of observable calls to IsRegExp. Also fix a misreference in `features` frontmatter.
This commit is contained in:
parent
11f476cdbb
commit
bbad9482e6
|
@ -1,33 +0,0 @@
|
|||
// Copyright (C) 2018 Peter Wong. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: pending
|
||||
description: |
|
||||
Throws TypeError when internally created RegExp's lastIndex is not 0
|
||||
info: |
|
||||
RegExp.prototype [ @@matchAll ] ( string )
|
||||
[...]
|
||||
3. Return ? MatchAllIterator(R, string).
|
||||
|
||||
MatchAllIterator ( R, O )
|
||||
[...]
|
||||
2. If ? IsRegExp(R) is true, then
|
||||
[...]
|
||||
3. Else,
|
||||
a. Let matcher be RegExpCreate(R, "g").
|
||||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception.
|
||||
[...]
|
||||
3. If Get(matcher, "lastIndex") is not 0, throw a TypeError exception.
|
||||
features: [Symbol.match, Symbol.matchAll]
|
||||
---*/
|
||||
|
||||
Object.defineProperty(RegExp.prototype, Symbol.match, {
|
||||
get() {
|
||||
this.lastIndex = 1;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.matchAll].call({}, '');
|
||||
});
|
|
@ -2,7 +2,7 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: pending
|
||||
description: Throws TypeError when internally created RegExp's @@match is false
|
||||
description: IsRegExp should only be called once
|
||||
info: |
|
||||
RegExp.prototype [ @@matchAll ] ( string )
|
||||
[...]
|
||||
|
@ -13,17 +13,28 @@ info: |
|
|||
2. If ? IsRegExp(R) is true, then
|
||||
[...]
|
||||
3. Else,
|
||||
a. Let matcher be RegExpCreate(R, "g").
|
||||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception.
|
||||
a. Let flags be "g".
|
||||
b. Let matcher be ? RegExpCreate(R, flags).
|
||||
features: [Symbol.match, Symbol.matchAll]
|
||||
---*/
|
||||
|
||||
var internalCount = 0;
|
||||
Object.defineProperty(RegExp.prototype, Symbol.match, {
|
||||
get() {
|
||||
return false;
|
||||
get: function() {
|
||||
++internalCount;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.matchAll].call({}, '');
|
||||
});
|
||||
var count = 0;
|
||||
var o = {
|
||||
get [Symbol.match]() {
|
||||
++count;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
RegExp.prototype[Symbol.matchAll].call(o, '1');
|
||||
|
||||
assert.sameValue(0, internalCount);
|
||||
assert.sameValue(1, count);
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (C) 2018 Peter Wong. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: pending
|
||||
description: Re-throws errors thrown while accessing @@match property
|
||||
info: |
|
||||
RegExp.prototype [ @@matchAll ] ( string )
|
||||
[...]
|
||||
3. Return ? MatchAllIterator(R, string).
|
||||
|
||||
MatchAllIterator ( R, O )
|
||||
[...]
|
||||
2. If ? IsRegExp(R) is true, then
|
||||
[...]
|
||||
3. Else,
|
||||
a. Let matcher be RegExpCreate(R, "g").
|
||||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception.
|
||||
features: [Symbol.match, Symbol.matchAll]
|
||||
---*/
|
||||
|
||||
Object.defineProperty(RegExp.prototype, Symbol.match, {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp.prototype[Symbol.matchAll].call({}, '');
|
||||
});
|
|
@ -13,7 +13,8 @@ info: |
|
|||
2. If ? IsRegExp(R) is true, then
|
||||
[...]
|
||||
3. Else,
|
||||
a. Let R be RegExpCreate(R, "g").
|
||||
a. Let flags be "g".
|
||||
b. Let matcher be ? RegExpCreate(R, flags).
|
||||
features: [Symbol.matchAll]
|
||||
---*/
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ info: |
|
|||
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
|
||||
false, [[Configurable]]: false }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Symbol.match]
|
||||
features: [Symbol.matchAll]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Symbol.matchAll, 'symbol');
|
||||
|
|
Loading…
Reference in New Issue