OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --allow-natives-syntax --function-context-specialization | |
Benedikt Meurer
2015/10/27 11:24:42
Can we have a test that does not require --functio
Michael Starzinger
2015/10/27 11:35:55
Done.
| |
6 | |
7 // This test suite checks that the receiver value (i.e. the 'this' binding) is | |
8 // correctly converted even when the callee function is inlined. This behavior | |
9 // is specified by ES6, section 9.2.1.2 "OrdinaryCallBindThis". | |
10 | |
11 var global = this; | |
12 function test(outer, inner, check) { | |
13 check(outer()); | |
14 check(outer()); | |
15 %OptimizeFunctionOnNextCall(outer); | |
16 check(outer()); | |
17 } | |
18 | |
19 | |
20 // ----------------------------------------------------------------------------- | |
21 // Test undefined in sloppy mode. | |
22 (function UndefinedSloppy() { | |
23 function check(x) { | |
24 assertEquals("object", typeof x); | |
25 assertSame(global, x); | |
26 } | |
27 function inner(x) { | |
28 return this; | |
29 } | |
30 function outer() { | |
31 return inner(); | |
32 } | |
33 test(outer, inner, check); | |
34 })(); | |
35 | |
36 | |
37 // ----------------------------------------------------------------------------- | |
38 // Test undefined in sloppy mode. | |
39 (function UndefinedSloppy() { | |
40 function check(x) { | |
41 assertEquals("undefined", typeof x); | |
42 assertSame(undefined, x); | |
43 } | |
44 function inner(x) { | |
45 "use strict"; | |
46 return this; | |
47 } | |
48 function outer() { | |
49 return inner(); | |
50 } | |
51 test(outer, inner, check); | |
52 })(); | |
53 | |
54 | |
55 // ----------------------------------------------------------------------------- | |
56 // Test primitive number in sloppy mode. | |
57 (function NumberSloppy() { | |
58 function check(x) { | |
59 assertEquals("object", typeof x); | |
60 assertInstanceof(x, Number); | |
61 } | |
62 function inner(x) { | |
63 return this; | |
64 } | |
65 function outer() { | |
66 return (0).sloppy(); | |
67 } | |
68 Number.prototype.sloppy = inner; | |
69 test(outer, inner, check); | |
70 })(); | |
71 | |
72 | |
73 // ----------------------------------------------------------------------------- | |
74 // Test primitive number in strict mode. | |
75 (function NumberStrict() { | |
76 function check(x) { | |
77 assertEquals("number", typeof x); | |
78 assertSame(0, x); | |
79 } | |
80 function inner(x) { | |
81 "use strict"; | |
82 return this; | |
83 } | |
84 function outer() { | |
85 return (0).strict(); | |
86 } | |
87 Number.prototype.strict = inner; | |
88 test(outer, inner, check); | |
89 })(); | |
90 | |
91 | |
92 // ----------------------------------------------------------------------------- | |
93 // Test primitive string in sloppy mode. | |
94 (function StringSloppy() { | |
95 function check(x) { | |
96 assertEquals("object", typeof x); | |
97 assertInstanceof(x, String); | |
98 } | |
99 function inner(x) { | |
100 return this; | |
101 } | |
102 function outer() { | |
103 return ("s").sloppy(); | |
104 } | |
105 String.prototype.sloppy = inner; | |
106 test(outer, inner, check); | |
107 })(); | |
108 | |
109 | |
110 // ----------------------------------------------------------------------------- | |
111 // Test primitive string in strict mode. | |
112 (function StringStrict() { | |
113 function check(x) { | |
114 assertEquals("string", typeof x); | |
115 assertSame("s", x); | |
116 } | |
117 function inner(x) { | |
118 "use strict"; | |
119 return this; | |
120 } | |
121 function outer() { | |
122 return ("s").strict(); | |
123 } | |
124 String.prototype.strict = inner; | |
125 test(outer, inner, check); | |
126 })(); | |
OLD | NEW |