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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Boolean coercion of `global` property
esid: sec-regexp.prototype-@@match
info: |
21.2.5.6 RegExp.prototype [ @@match ] ( string )
[...]
4. Let global be ToBoolean(? Get(rx, "global")).
5. If global is false, then
a. Return ? RegExpExec(rx, S).
6. Else global is true,
a. Let fullUnicode be ToBoolean(? Get(rx, "unicode")).
[...]
features: [Symbol.match]
---*/
var exec = function() {
execCount += 1;
if (execCount === 1) {
return [''];
}
return null;
};
var r, result, execCount;
r = /a/g;
r.exec = exec;
Object.defineProperty(r, 'global', { writable: true });
execCount = 0;
r.global = undefined;
r[Symbol.match]('aa');
assert.sameValue(execCount, 1, 'value: undefined');
execCount = 0;
r.global = null;
r[Symbol.match]('aa');
assert.sameValue(execCount, 1, 'value: null');
execCount = 0;
r.global = false;
r[Symbol.match]('aa');
assert.sameValue(execCount, 1, 'value: false');
execCount = 0;
r.global = NaN;
r[Symbol.match]('aa');
assert.sameValue(execCount, 1, 'value: NaN');
execCount = 0;
r.global = 0;
r[Symbol.match]('aa');
assert.sameValue(execCount, 1, 'value: 0');
execCount = 0;
r.global = '';
r[Symbol.match]('aa');
assert.sameValue(execCount, 1, 'value: ""');
r = /a/;
r.exec = exec;
Object.defineProperty(r, 'global', { writable: true });
r.global = true;
execCount = 0;
r[Symbol.match]('aa');
assert.sameValue(execCount, 2, 'value: true');
r.global = 86;
execCount = 0;
r[Symbol.match]('aa');
assert.sameValue(execCount, 2, 'value: 86');
r.global = Symbol.match;
execCount = 0;
r[Symbol.match]('aa');
assert.sameValue(execCount, 2, 'value: Symbol.match');
r.global = {};
execCount = 0;
r[Symbol.match]('aa');
assert.sameValue(execCount, 2, 'value: {}');
reportCompare(0, 0);
|