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

Side by Side Diff: test/mjsunit/eval.js

Issue 8343054: Make eval consider anything on the form eval(args...) a potential direct cal (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments. Created 9 years, 1 month 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/regress/regress-221.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 assertTrue(f === eval(f)); 32 assertTrue(f === eval(f));
33 33
34 function g(x, y) { return 4; }; 34 function g(x, y) { return 4; };
35 35
36 count = 0; 36 count = 0;
37 assertEquals(4, eval('2 + 2', count++)); 37 assertEquals(4, eval('2 + 2', count++));
38 assertEquals(1, count); 38 assertEquals(1, count);
39 39
40 try { 40 try {
41 eval('hest 7 &*^*&^'); 41 eval('hest 7 &*^*&^');
42 assertTrue(false, 'Did not throw on syntax error.'); 42 assertUnreachable('Did not throw on syntax error.');
43 } catch (e) { 43 } catch (e) {
44 assertEquals('SyntaxError', e.name); 44 assertEquals('SyntaxError', e.name);
45 } 45 }
46 46
47 47
48 // eval has special evaluation order for consistency with other browsers. 48 // eval has special evaluation order for consistency with other browsers.
49 global_eval = eval; 49 global_eval = eval;
50 assertEquals(void 0, eval(eval("var eval = function f(x) { return 'hest';}"))) 50 assertEquals(void 0, eval(eval("var eval = function f(x) { return 'hest';}")))
51 eval = global_eval; 51 eval = global_eval;
52 52
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 function MyOtherObject() { this.self = e('this'); } 101 function MyOtherObject() { this.self = e('this'); }
102 var o = new MyOtherObject(); 102 var o = new MyOtherObject();
103 assertTrue(this === o.self); 103 assertTrue(this === o.self);
104 104
105 // Try to cheat the 'aliased eval' detection. 105 // Try to cheat the 'aliased eval' detection.
106 var x = this; 106 var x = this;
107 foo = 0; 107 foo = 0;
108 result = 108 result =
109 (function() { 109 (function() {
110 var foo = 2; 110 var foo = 2;
111 // Should be non-direct call.
111 return x.eval('foo'); 112 return x.eval('foo');
112 })(); 113 })();
113 assertEquals(0, result); 114 assertEquals(0, result);
114 115
115 foo = 0; 116 foo = 0;
116 result = 117 result =
117 (function() { 118 (function() {
119 var foo = 2;
120 // Should be non-direct call.
121 return (1,eval)('foo');
122 })();
123 assertEquals(0, result);
124
125 foo = 0;
126 result =
127 (function() {
118 var eval = function(x) { return x; }; 128 var eval = function(x) { return x; };
119 var foo = eval(2); 129 var foo = eval(2);
130 // Should be non-direct call.
120 return e('foo'); 131 return e('foo');
121 })(); 132 })();
122 assertEquals(0, result); 133 assertEquals(0, result);
123 134
135 foo = 0;
136 result =
137 (function() {
138 var foo = 2;
139 // Should be direct call.
140 with ({ eval : e }) {
141 return eval('foo');
142 }
143 })();
144 assertEquals(2, result);
145
124 result = 146 result =
125 (function() { 147 (function() {
126 var eval = function(x) { return 2 * x; }; 148 var eval = function(x) { return 2 * x; };
127 return (function() { return eval(2); })(); 149 return (function() { return eval(2); })();
128 })(); 150 })();
129 assertEquals(4, result); 151 assertEquals(4, result);
130 152
131 result = 153 result =
132 (function() { 154 (function() {
133 eval("var eval = function(s) { return this; }"); 155 eval("var eval = function(s) { return this; }");
134 return eval("42"); // Should return the global object 156 return eval("42"); // Should return the global object
135 })(); 157 })();
136 assertEquals(this, result); 158 assertEquals(this, result);
137 159
138 result = 160 (function() {
139 (function() { 161 var obj = { f: function(eval) { return eval("this"); } };
140 var obj = { f: function(eval) { return eval("this"); } }; 162 result = obj.f(eval);
141 return obj.f(eval); 163 assertEquals(obj, result);
142 })(); 164 })();
143 assertEquals(this, result);
144 165
145 result = 166 (function() {
146 (function() { 167 var obj = { f: function(eval) { arguments; return eval("this"); } };
147 var obj = { f: function(eval) { arguments; return eval("this"); } }; 168 result = obj.f(eval);
148 return obj.f(eval); 169 assertEquals(obj, result);
149 })(); 170 })();
150 assertEquals(this, result);
151 171
152 eval = function(x) { return 2 * x; }; 172 eval = function(x) { return 2 * x; };
153 result = 173 result =
154 (function() { 174 (function() {
155 return (function() { return eval(2); })(); 175 return (function() { return eval(2); })();
156 })(); 176 })();
157 assertEquals(4, result); 177 assertEquals(4, result);
158 178
179
180
181
159 // Regression test: calling a function named eval found in a context that is 182 // Regression test: calling a function named eval found in a context that is
160 // not the global context should get the global object as receiver. 183 // not the global context should get the global object as receiver.
161 result = 184 result =
162 (function () { 185 (function () {
163 var eval = function (x) { return this; }; 186 var eval = function (x) { return this; };
164 with ({}) { return eval('ignore'); } 187 with ({}) { return eval('ignore'); }
165 })(); 188 })();
166 assertEquals(this, result); 189 assertEquals(this, result);
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/regress/regress-221.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698