| 1 |
// Copyright (C) 2015 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Initialization from a RegExp-like object (with flag overrides) |
| 6 |
es6id: 21.2.3.1 |
| 7 |
info: | |
| 8 |
1. Let patternIsRegExp be IsRegExp(pattern). |
| 9 |
[...] |
| 10 |
6. Else if patternIsRegExp is true, then |
| 11 |
a. Let P be Get(pattern, "source"). |
| 12 |
b. ReturnIfAbrupt(P). |
| 13 |
c. If flags is undefined, then |
| 14 |
[...] |
| 15 |
d. Else, let F be flags. |
| 16 |
[...] |
| 17 |
10. Return RegExpInitialize(O, P, F). |
| 18 |
features: [Symbol, Symbol.match] |
| 19 |
---*/ |
| 20 |
|
| 21 |
var obj = { |
| 22 |
source: 'source text' |
| 23 |
}; |
| 24 |
var result; |
| 25 |
|
| 26 |
Object.defineProperty(obj, 'flags', { |
| 27 |
get: function() { |
| 28 |
$ERROR('The `flags` property value should not be referenced.'); |
| 29 |
} |
| 30 |
}); |
| 31 |
|
| 32 |
obj[Symbol.match] = true; |
| 33 |
result = new RegExp(obj, 'g'); |
| 34 |
assert.sameValue( |
| 35 |
result.source, 'source text', '@@match specified as a primitive boolean' |
| 36 |
); |
| 37 |
assert.sameValue( |
| 38 |
result.flags, 'g', '@@match specified as a primitive boolean' |
| 39 |
); |
| 40 |
|
| 41 |
obj[Symbol.match] = 'string'; |
| 42 |
result = new RegExp(obj, 'g'); |
| 43 |
assert.sameValue( |
| 44 |
result.source, 'source text', '@@match specified as a primitive string' |
| 45 |
); |
| 46 |
assert.sameValue(result.flags, 'g', '@@match specified as a primitive string'); |
| 47 |
|
| 48 |
obj[Symbol.match] = []; |
| 49 |
result = new RegExp(obj, 'g'); |
| 50 |
assert.sameValue( |
| 51 |
result.source, 'source text', '@@match specified as an array' |
| 52 |
); |
| 53 |
assert.sameValue(result.flags, 'g', '@@match specified as an array'); |
| 54 |
|
| 55 |
obj[Symbol.match] = Symbol(); |
| 56 |
result = new RegExp(obj, 'g'); |
| 57 |
assert.sameValue( |
| 58 |
result.source, 'source text', '@@match specified as a Symbol' |
| 59 |
); |
| 60 |
assert.sameValue(result.flags, 'g', '@@match specified as a Symbol'); |
| 61 |
|
| 62 |
obj[Symbol.match] = 86; |
| 63 |
result = new RegExp(obj, 'g'); |
| 64 |
assert.sameValue( |
| 65 |
result.source, 'source text', '@@match specified as a primitive number' |
| 66 |
); |
| 67 |
assert.sameValue(result.flags, 'g', '@@match specified as a primitive number'); |