Skip to content
Snippets Groups Projects
Unverified Commit e15be185 authored by Jordan Harband's avatar Jordan Harband
Browse files

String.prototype.matchAll: add tests for stage 3

`RegExp.prototype[Symbol.matchAll]`: Add basic tests.
parent 5b3914a3
No related branches found
No related tags found
No related merge requests found
// 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);
});
// 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);
});
// 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');
// 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');
// 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);
// 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);
});
// 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);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment