Merge pull request #1587 from peterwmwong/update-matchall

Update tests for String.prototype.matchAll
This commit is contained in:
Rick Waldron 2018-06-07 23:15:50 -04:00 committed by GitHub
commit f90a52b396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 72 deletions

View File

@ -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({}, '');
});

View File

@ -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);

View File

@ -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({}, '');
});

View File

@ -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]
---*/

View File

@ -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');