1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright (C) 2018 Peter Wong. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
description: IsRegExp should only be called once
info: |
RegExp.prototype [ @@matchAll ] ( string )
1. Let R be the this value.
[...]
4. Let C be ? SpeciesConstructor(R, %RegExp%).
5. Let flags be ? ToString(? Get(R, "flags")).
6. Let matcher be ? Construct(C, « R, flags »).
21.2.3.1 RegExp ( pattern, flags )
1. Let patternIsRegExp be ? IsRegExp(pattern).
[...]
features: [Symbol.match, Symbol.matchAll]
---*/
var internalCount = 0;
Object.defineProperty(RegExp.prototype, Symbol.match, {
get: function() {
++internalCount;
return true;
}
});
var calls = [];
var o = {
get [Symbol.match]() {
calls.push('get @@match');
return false;
},
get flags() {
calls.push('get flags');
return {
toString() {
calls.push('flags toString');
return "";
}
};
},
};
RegExp.prototype[Symbol.matchAll].call(o, {
toString() {
calls.push('arg toString')
}
});
assert.sameValue(0, internalCount);
assert.sameValue(calls.length, 4);
assert.sameValue(calls[0], 'arg toString');
assert.sameValue(calls[1], 'get flags');
assert.sameValue(calls[2], 'flags toString');
assert.sameValue(calls[3], 'get @@match');
reportCompare(0, 0);
|