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
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: String.prototype.indexOf type coercion for searchString parameter
esid: sec-string.prototype.indexof
info: |
String.prototype.indexOf ( searchString [ , position ] )
3. Let searchStr be ? ToString(searchString).
features: [Symbol.toPrimitive, computed-property-names]
---*/
assert.sameValue("__foo__".indexOf(Object("foo")), 2,
"ToPrimitive: unbox object with internal slot");
assert.sameValue("__foo__".indexOf({
[Symbol.toPrimitive]: function() {
return "foo";
}
}), 2, "ToPrimitive: @@toPrimitive");
assert.sameValue("__foo__".indexOf({
valueOf: function() {
return "foo";
},
toString: null
}), 2, "ToPrimitive: valueOf");
assert.sameValue("__foo__".indexOf({
toString: function() {
return "foo";
}
}), 2, "ToPrimitive: toString");
assert.sameValue("__undefined__".indexOf({
[Symbol.toPrimitive]: function() {
return undefined;
}
}), 2, 'ToString: @@toPrimitive => undefined => "undefined"');
assert.sameValue("__undefined__".indexOf({
valueOf: function() {
return undefined;
},
toString: null
}), 2, 'ToString: valueOf => undefined => "undefined"');
assert.sameValue("__undefined__".indexOf({
toString: function() {
return undefined;
}
}), 2, 'ToString: toString => undefined => "undefined"');
assert.sameValue("__null__".indexOf({
[Symbol.toPrimitive]: function() {
return null;
}
}), 2, 'ToString: @@toPrimitive => null => "null"');
assert.sameValue("__null__".indexOf({
valueOf: function() {
return null;
},
toString: null
}), 2, 'ToString: valueOf => null => "null"');
assert.sameValue("__null__".indexOf({
toString: function() {
return null;
}
}), 2, 'ToString: toString => null => "null"');
assert.sameValue("__false__".indexOf(Object(false)), 2,
'ToString: unbox object with internal slot => false => "false"');
assert.sameValue("__false__".indexOf({
[Symbol.toPrimitive]: function() {
return false;
}
}), 2, 'ToString: @@toPrimitive => false => "false"');
assert.sameValue("__false__".indexOf({
valueOf: function() {
return false;
},
toString: null
}), 2, 'ToString: valueOf => false => "false"');
assert.sameValue("__false__".indexOf({
toString: function() {
return false;
}
}), 2, 'ToString: toString => false => "false"');
assert.sameValue("__0__".indexOf(Object(0)), 2,
"ToString: unbox object with internal slot => Number to String");
assert.sameValue("__0__".indexOf({
[Symbol.toPrimitive]: function() {
return 0;
}
}), 2, "ToString: @@toPrimitive => Number to String");
assert.sameValue("__0__".indexOf({
valueOf: function() {
return 0;
},
toString: null
}), 2, "ToString: valueOf => Number to String");
assert.sameValue("__0__".indexOf({
toString: function() {
return 0;
}
}), 2, "ToString: toString => Number to String");
reportCompare(0, 0);
|