String.prototype.matchAll: add tests for stage 3

`RegExp.prototype[Symbol.matchAll]`: Add basic tests.
This commit is contained in:
Jordan Harband 2018-01-25 23:45:12 -08:00
parent 5b3914a37b
commit e15be1853b
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
7 changed files with 174 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Copyright (C) 2018 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: String coercion of string parameter
info: |
RegExp.prototype [ @@matchAll ] ( string )
[...]
2. Let S be ? ToString(O).
[...]
features: [Symbol.match, Symbol.matchAll]
---*/
var obj = {
valueOf: function() {
$ERROR('This method should not be invoked.');
},
toString: function() {
throw new Test262Error('toString invoked');
}
};
obj[Symbol.match] = true;
assert.throws(Test262Error, function () {
/toString value/[Symbol.matchAll](obj);
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Behavior when error is thrown during retrieval of `Symbol.species` property
info: |
3. Let C be ? SpeciesConstructor(R, %RegExp%).
features: [Symbol.match, Symbol.matchAll, Symbol.species]
---*/
var obj = {};
Object.defineProperty(obj, Symbol.species, {
get: function () {
throw new Test262Error();
}
});
obj[Symbol.match] = true;
assert.throws(Test262Error, function() {
RegExp.prototype[Symbol.matchAll].call(obj);
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2018 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: RegExp.prototype[Symbol.matchAll] `length` property
info: |
ES6 Section 17:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this value
is equal to the largest number of named arguments shown in the subclause
headings for the function description, including optional parameters.
[...]
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Symbol.matchAll]
---*/
assert.sameValue(RegExp.prototype[Symbol.matchAll].length, 1);
verifyNotEnumerable(RegExp.prototype[Symbol.matchAll], 'length');
verifyNotWritable(RegExp.prototype[Symbol.matchAll], 'length');
verifyConfigurable(RegExp.prototype[Symbol.matchAll], 'length');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2018 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: RegExp.prototype[Symbol.matchAll] `name` property
info: |
The value of the name property of this function is "[Symbol.matchAll]".
ES6 Section 17:
[...]
Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Symbol.matchAll]
---*/
assert.sameValue(RegExp.prototype[Symbol.matchAll].name, '[Symbol.matchAll]');
verifyNotEnumerable(RegExp.prototype[Symbol.matchAll], 'name');
verifyNotWritable(RegExp.prototype[Symbol.matchAll], 'name');
verifyConfigurable(RegExp.prototype[Symbol.matchAll], 'name');

View File

@ -0,0 +1,19 @@
// Copyright (C) 2018 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: RegExp.prototype[Symbol.matchAll] property descriptor
info: |
ES6 Section 17
Every other data property described in clauses 18 through 26 and in Annex
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
features: [Symbol.matchAll]
---*/
assert.sameValue(typeof RegExp.prototype[Symbol.matchAll], 'function');
verifyNotEnumerable(RegExp.prototype, Symbol.matchAll);
verifyWritable(RegExp.prototype, Symbol.matchAll);
verifyConfigurable(RegExp.prototype, Symbol.matchAll);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2018 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The `this` value must be an object
info: |
1. Let R be the this value.
2. Return ? MatchAllIterator(R, string).
[...]
1. If ? IsRegExp(R) is not true, throw a TypeError exception.
features: [Symbol.matchAll]
---*/
assert.throws(TypeError, function() {
RegExp.prototype[Symbol.matchAll].call(undefined);
});
assert.throws(TypeError, function() {
RegExp.prototype[Symbol.matchAll].call(null);
});
assert.throws(TypeError, function() {
RegExp.prototype[Symbol.matchAll].call(true);
});
assert.throws(TypeError, function() {
RegExp.prototype[Symbol.matchAll].call('string');
});
assert.throws(TypeError, function() {
RegExp.prototype[Symbol.matchAll].call(Symbol.matchAll);
});
assert.throws(TypeError, function() {
RegExp.prototype[Symbol.matchAll].call(86);
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2018 Jordan Harband. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The `this` value must be a regular expression (has Symbol.match)
info: |
1. Let R be the this value.
2. Return ? MatchAllIterator(R, string).
[...]
1. If ? IsRegExp(R) is not true, throw a TypeError exception.
features: [Symbol.match, Symbol.matchAll]
---*/
var regexObj = {};
regexObj[Symbol.match] = true;
var obj = {};
RegExp.prototype[Symbol.matchAll].call(regexObj);
assert.throws(TypeError, function() {
RegExp.prototype[Symbol.matchAll].call(obj);
});