Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: test/mjsunit/strict-mode-implicit-receiver.js

Issue 7039036: Fix calls of strict mode function with an implicit receiver. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix presubmit Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/v8globals.h ('K') | « src/v8globals.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Flags: --allow-natives-syntax
29
30 var y = 3;
31
32 function get_y() { return this.y; }
33 function strict_get_y() { "use strict"; return this.y; }
34
35 // Test calls to strict mode function with explicit receivers.
36 for (var i = 0; i < 10; i++) assertEquals(3, strict_get_y.call(this));
37 var o = { y: 42 };
38 for (var i = 0; i < 10; i++) assertEquals(42, strict_get_y.call(o));
39
40 // Test calls to strict mode function with implicit receiver.
41 function g() {
42 var exception = false;
43 try { strict_get_y(); } catch(e) { exception = true; }
44 assertTrue(exception);
45 }
46 for (var i = 0; i < 3; i++) g();
47
48 // Test calls to local strict mode function with implicit receiver.
49 function local_function_test() {
50 function get_y() { return this.y; }
51 function strict_get_y() { "use strict"; return this.y; }
52 assertEquals(3, get_y());
53 assertEquals(3, get_y(23));
54 strict_get_y();
55 }
56
57 // TODO(ager): Rewrite this test once strict mode detection works.
58 var exception = false;
59 for (var i = 0; i < 10; i++) {
60 try {
61 local_function_test();
62 } catch(e) {
63 exception = true;
64 }
65 assertTrue(exception);
66 }
67
68 // Test call to catch variable strict-mode function. Implicit
69 // receiver.
70 var exception = false;
71 try {
72 throw strict_get_y;
73 } catch(f) {
74 try {
75 f();
76 } catch(e) {
77 exception = true;
78 }
79 assertTrue(exception);
80 }
81
82
83 // Test calls to strict-mode function with the object from a with
84 // statement as the explicit receiver.
85 with(this) {
86 assertEquals(3, strict_get_y());
87 assertEquals(3, strict_get_y(32));
88 }
89
90 var o = { y: 27 };
91 o.f = strict_get_y;
92 with(o) {
93 assertEquals(27, f());
94 assertEquals(27, f(23));
95 }
96
97
98 // Check calls to eval within a function with 'undefined' as receiver.
99 function implicit_receiver_eval() {
100 "use strict";
101 return eval("this");
102 }
103
104 assertEquals(void 0, implicit_receiver_eval());
105 assertEquals(void 0, implicit_receiver_eval(32));
106
107
108 // Strict mode function to get inlined.
109 function strict_return_receiver() {
110 "use strict";
111 return this;
112 }
113
114 // Inline with implicit receiver.
115 function g() {
116 return strict_return_receiver();
117 }
118
119 for (var i = 0; i < 5; i++) {
120 assertEquals(void 0, g());
121 assertEquals(void 0, g(42));
122 }
123 %OptimizeFunctionOnNextCall(g);
124 assertEquals(void 0, g(42));
125 assertEquals(void 0, g());
126
127 // Inline with explicit receiver.
128 function g2() {
129 var o = {};
130 o.f = strict_return_receiver;
131 return o.f();
132 }
133
134 for (var i = 0; i < 5; i++) {
135 assertTrue(typeof g2() == "object");
136 assertTrue(typeof g2(42) == "object");
137 }
138 %OptimizeFunctionOnNextCall(g2);
139 assertTrue(typeof g2() == "object");
140 assertTrue(typeof g2(42) == "object");
141
142 // Implicit receiver to strict mode function overwriting eval.
143 // TODO(ager): Rewrite when strict mode detection has been fixed.
144 function call_result_eval() { return function() { "use strict"; return this; } }
145 var eval = call_result_eval();
146 assertEquals(void 0, eval());
OLDNEW
« src/v8globals.h ('K') | « src/v8globals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698