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
101
102
103
104
105
106
107
108
109
110
111
|
// 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 position parameter
esid: sec-string.prototype.indexof
info: |
String.prototype.indexOf ( searchString [ , position ] )
4. Let pos be ? ToInteger(position).
features: [Symbol.toPrimitive, computed-property-names]
---*/
assert.sameValue("aaaa".indexOf("aa", Object(0)), 0, "ToPrimitive: unbox object with internal slot");
assert.sameValue("aaaa".indexOf("aa", {
[Symbol.toPrimitive]: function() {
return 0;
}
}), 0, "ToPrimitive: @@toPrimitive");
assert.sameValue("aaaa".indexOf("aa", {
valueOf: function() {
return 0;
}
}), 0, "ToPrimitive: valueOf");
assert.sameValue("aaaa".indexOf("aa", {
toString: function() {
return 0;
}
}), 0, "ToPrimitive: toString");
assert.sameValue("aaaa".indexOf("aa", Object(NaN)), 0,
"ToInteger: unbox object with internal slot => NaN => 0");
assert.sameValue("aaaa".indexOf("aa", {
[Symbol.toPrimitive]: function() {
return NaN;
}
}), 0, "ToInteger: @@toPrimitive => NaN => 0");
assert.sameValue("aaaa".indexOf("aa", {
valueOf: function() {
return NaN;
}
}), 0, "ToInteger: valueOf => NaN => 0");
assert.sameValue("aaaa".indexOf("aa", {
toString: function() {
return NaN;
}
}), 0, "ToInteger: toString => NaN => 0");
assert.sameValue("aaaa".indexOf("aa", {
[Symbol.toPrimitive]: function() {
return undefined;
}
}), 0, "ToInteger: @@toPrimitive => undefined => NaN => 0");
assert.sameValue("aaaa".indexOf("aa", {
valueOf: function() {
return undefined;
}
}), 0, "ToInteger: valueOf => undefined => NaN => 0");
assert.sameValue("aaaa".indexOf("aa", {
toString: function() {
return undefined;
}
}), 0, "ToInteger: toString => undefined => NaN => 0");
assert.sameValue("aaaa".indexOf("aa", {
[Symbol.toPrimitive]: function() {
return null;
}
}), 0, "ToInteger: @@toPrimitive => null => 0");
assert.sameValue("aaaa".indexOf("aa", {
valueOf: function() {
return null;
}
}), 0, "ToInteger: valueOf => null => 0");
assert.sameValue("aaaa".indexOf("aa", {
toString: function() {
return null;
}
}), 0, "ToInteger: toString => null => 0");
assert.sameValue("aaaa".indexOf("aa", Object(true)), 1,
"ToInteger: unbox object with internal slot => true => 1");
assert.sameValue("aaaa".indexOf("aa", {
[Symbol.toPrimitive]: function() {
return true;
}
}), 1, "ToInteger: @@toPrimitive => true => 1");
assert.sameValue("aaaa".indexOf("aa", {
valueOf: function() {
return true;
}
}), 1, "ToInteger: valueOf => true => 1");
assert.sameValue("aaaa".indexOf("aa", {
toString: function() {
return true;
}
}), 1, "ToInteger: toString => true => 1");
assert.sameValue("aaaa".indexOf("aa", Object("1.9")), 1,
"ToInteger: unbox object with internal slot => parse Number => 1.9 => 1");
assert.sameValue("aaaa".indexOf("aa", {
[Symbol.toPrimitive]: function() {
return "1.9";
}
}), 1, "ToInteger: @@toPrimitive => parse Number => 1.9 => 1");
assert.sameValue("aaaa".indexOf("aa", {
valueOf: function() {
return "1.9";
}
}), 1, "ToInteger: valueOf => parse Number => 1.9 => 1");
assert.sameValue("aaaa".indexOf("aa", {
toString: function() {
return "1.9";
}
}), 1, "ToInteger: toString => parse Number => 1.9 => 1");
reportCompare(0, 0);
|