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
|
// 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
es6id: 21.2.5.8
info: |
21.2.5.6 RegExp.prototype [ @@replace ] ( string )
[...]
8. Let global be ToBoolean(Get(rx, "global")).
[...]
features: [Symbol.replace]
---*/
Array.print = print;
var r = /a/g;
Object.defineProperty(r, 'global', { writable: true });
r.lastIndex = 0;
r.global = undefined;
assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: undefined');
r.lastIndex = 0;
r.global = null;
assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: null');
r.lastIndex = 0;
r.global = false;
assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: false');
r.lastIndex = 0;
r.global = NaN;
assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: NaN');
r.lastIndex = 0;
r.global = 0;
assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: global');
r.lastIndex = 0;
r.global = '';
assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: ""');
var execCount = 0;
r = /a/;
Object.defineProperty(r, 'global', { writable: true });
r.exec = function() {
execCount += 1;
if (execCount === 1) {
return ['a'];
}
return null;
};
execCount = 0;
r.global = true;
r[Symbol.replace]('aa', 'b');
assert.sameValue(execCount, 2, 'value: true');
execCount = 0;
r.global = 86;
r[Symbol.replace]('aa', 'b');
assert.sameValue(execCount, 2, 'value: 86');
execCount = 0;
r.global = Symbol.replace;
r[Symbol.replace]('aa', 'b');
assert.sameValue(execCount, 2, 'value: Symbol.replace');
execCount = 0;
r.global = {};
r[Symbol.replace]('aa', 'b');
assert.sameValue(execCount, 2, 'value: {}');
reportCompare(0, 0);
|