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

Side by Side Diff: test/cctest/test-func-name-inference.cc

Issue 13483017: Unify the way cctest initalizes the VM for each test case. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed presubmit errors. Created 7 years, 8 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
« no previous file with comments | « test/cctest/test-disasm-x64.cc ('k') | test/cctest/test-heap.cc » ('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 29 matching lines...) Expand all
40 using ::v8::internal::Isolate; 40 using ::v8::internal::Isolate;
41 using ::v8::internal::JSFunction; 41 using ::v8::internal::JSFunction;
42 using ::v8::internal::Object; 42 using ::v8::internal::Object;
43 using ::v8::internal::Runtime; 43 using ::v8::internal::Runtime;
44 using ::v8::internal::Script; 44 using ::v8::internal::Script;
45 using ::v8::internal::SmartArrayPointer; 45 using ::v8::internal::SmartArrayPointer;
46 using ::v8::internal::SharedFunctionInfo; 46 using ::v8::internal::SharedFunctionInfo;
47 using ::v8::internal::String; 47 using ::v8::internal::String;
48 48
49 49
50 static v8::Persistent<v8::Context> env;
51
52
53 static void InitializeVM() {
54 if (env.IsEmpty()) {
55 env = v8::Context::New();
56 }
57 env->Enter();
58 }
59
60
61 static void CheckFunctionName(v8::Handle<v8::Script> script, 50 static void CheckFunctionName(v8::Handle<v8::Script> script,
62 const char* func_pos_src, 51 const char* func_pos_src,
63 const char* ref_inferred_name) { 52 const char* ref_inferred_name) {
64 // Get script source. 53 // Get script source.
65 Handle<Object> obj = v8::Utils::OpenHandle(*script); 54 Handle<Object> obj = v8::Utils::OpenHandle(*script);
66 Handle<SharedFunctionInfo> shared_function; 55 Handle<SharedFunctionInfo> shared_function;
67 if (obj->IsSharedFunctionInfo()) { 56 if (obj->IsSharedFunctionInfo()) {
68 shared_function = 57 shared_function =
69 Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(*obj)); 58 Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(*obj));
70 } else { 59 } else {
(...skipping 30 matching lines...) Expand all
101 #endif // ENABLE_DEBUGGER_SUPPORT 90 #endif // ENABLE_DEBUGGER_SUPPORT
102 } 91 }
103 92
104 93
105 static v8::Handle<v8::Script> Compile(const char* src) { 94 static v8::Handle<v8::Script> Compile(const char* src) {
106 return v8::Script::Compile(v8::String::New(src)); 95 return v8::Script::Compile(v8::String::New(src));
107 } 96 }
108 97
109 98
110 TEST(GlobalProperty) { 99 TEST(GlobalProperty) {
111 InitializeVM(); 100 CcTest::InitializeVM();
112 v8::HandleScope scope(env->GetIsolate()); 101 v8::HandleScope scope(CcTest::isolate());
113 102
114 v8::Handle<v8::Script> script = Compile( 103 v8::Handle<v8::Script> script = Compile(
115 "fun1 = function() { return 1; }\n" 104 "fun1 = function() { return 1; }\n"
116 "fun2 = function() { return 2; }\n"); 105 "fun2 = function() { return 2; }\n");
117 CheckFunctionName(script, "return 1", "fun1"); 106 CheckFunctionName(script, "return 1", "fun1");
118 CheckFunctionName(script, "return 2", "fun2"); 107 CheckFunctionName(script, "return 2", "fun2");
119 } 108 }
120 109
121 110
122 TEST(GlobalVar) { 111 TEST(GlobalVar) {
123 InitializeVM(); 112 CcTest::InitializeVM();
124 v8::HandleScope scope(env->GetIsolate()); 113 v8::HandleScope scope(CcTest::isolate());
125 114
126 v8::Handle<v8::Script> script = Compile( 115 v8::Handle<v8::Script> script = Compile(
127 "var fun1 = function() { return 1; }\n" 116 "var fun1 = function() { return 1; }\n"
128 "var fun2 = function() { return 2; }\n"); 117 "var fun2 = function() { return 2; }\n");
129 CheckFunctionName(script, "return 1", "fun1"); 118 CheckFunctionName(script, "return 1", "fun1");
130 CheckFunctionName(script, "return 2", "fun2"); 119 CheckFunctionName(script, "return 2", "fun2");
131 } 120 }
132 121
133 122
134 TEST(LocalVar) { 123 TEST(LocalVar) {
135 InitializeVM(); 124 CcTest::InitializeVM();
136 v8::HandleScope scope(env->GetIsolate()); 125 v8::HandleScope scope(CcTest::isolate());
137 126
138 v8::Handle<v8::Script> script = Compile( 127 v8::Handle<v8::Script> script = Compile(
139 "function outer() {\n" 128 "function outer() {\n"
140 " var fun1 = function() { return 1; }\n" 129 " var fun1 = function() { return 1; }\n"
141 " var fun2 = function() { return 2; }\n" 130 " var fun2 = function() { return 2; }\n"
142 "}"); 131 "}");
143 CheckFunctionName(script, "return 1", "fun1"); 132 CheckFunctionName(script, "return 1", "fun1");
144 CheckFunctionName(script, "return 2", "fun2"); 133 CheckFunctionName(script, "return 2", "fun2");
145 } 134 }
146 135
147 136
148 TEST(InConstructor) { 137 TEST(InConstructor) {
149 InitializeVM(); 138 CcTest::InitializeVM();
150 v8::HandleScope scope(env->GetIsolate()); 139 v8::HandleScope scope(CcTest::isolate());
151 140
152 v8::Handle<v8::Script> script = Compile( 141 v8::Handle<v8::Script> script = Compile(
153 "function MyClass() {\n" 142 "function MyClass() {\n"
154 " this.method1 = function() { return 1; }\n" 143 " this.method1 = function() { return 1; }\n"
155 " this.method2 = function() { return 2; }\n" 144 " this.method2 = function() { return 2; }\n"
156 "}"); 145 "}");
157 CheckFunctionName(script, "return 1", "MyClass.method1"); 146 CheckFunctionName(script, "return 1", "MyClass.method1");
158 CheckFunctionName(script, "return 2", "MyClass.method2"); 147 CheckFunctionName(script, "return 2", "MyClass.method2");
159 } 148 }
160 149
161 150
162 TEST(Factory) { 151 TEST(Factory) {
163 InitializeVM(); 152 CcTest::InitializeVM();
164 v8::HandleScope scope(env->GetIsolate()); 153 v8::HandleScope scope(CcTest::isolate());
165 154
166 v8::Handle<v8::Script> script = Compile( 155 v8::Handle<v8::Script> script = Compile(
167 "function createMyObj() {\n" 156 "function createMyObj() {\n"
168 " var obj = {};\n" 157 " var obj = {};\n"
169 " obj.method1 = function() { return 1; }\n" 158 " obj.method1 = function() { return 1; }\n"
170 " obj.method2 = function() { return 2; }\n" 159 " obj.method2 = function() { return 2; }\n"
171 " return obj;\n" 160 " return obj;\n"
172 "}"); 161 "}");
173 CheckFunctionName(script, "return 1", "obj.method1"); 162 CheckFunctionName(script, "return 1", "obj.method1");
174 CheckFunctionName(script, "return 2", "obj.method2"); 163 CheckFunctionName(script, "return 2", "obj.method2");
175 } 164 }
176 165
177 166
178 TEST(Static) { 167 TEST(Static) {
179 InitializeVM(); 168 CcTest::InitializeVM();
180 v8::HandleScope scope(env->GetIsolate()); 169 v8::HandleScope scope(CcTest::isolate());
181 170
182 v8::Handle<v8::Script> script = Compile( 171 v8::Handle<v8::Script> script = Compile(
183 "function MyClass() {}\n" 172 "function MyClass() {}\n"
184 "MyClass.static1 = function() { return 1; }\n" 173 "MyClass.static1 = function() { return 1; }\n"
185 "MyClass.static2 = function() { return 2; }\n" 174 "MyClass.static2 = function() { return 2; }\n"
186 "MyClass.MyInnerClass = {}\n" 175 "MyClass.MyInnerClass = {}\n"
187 "MyClass.MyInnerClass.static3 = function() { return 3; }\n" 176 "MyClass.MyInnerClass.static3 = function() { return 3; }\n"
188 "MyClass.MyInnerClass.static4 = function() { return 4; }"); 177 "MyClass.MyInnerClass.static4 = function() { return 4; }");
189 CheckFunctionName(script, "return 1", "MyClass.static1"); 178 CheckFunctionName(script, "return 1", "MyClass.static1");
190 CheckFunctionName(script, "return 2", "MyClass.static2"); 179 CheckFunctionName(script, "return 2", "MyClass.static2");
191 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.static3"); 180 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.static3");
192 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.static4"); 181 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.static4");
193 } 182 }
194 183
195 184
196 TEST(Prototype) { 185 TEST(Prototype) {
197 InitializeVM(); 186 CcTest::InitializeVM();
198 v8::HandleScope scope(env->GetIsolate()); 187 v8::HandleScope scope(CcTest::isolate());
199 188
200 v8::Handle<v8::Script> script = Compile( 189 v8::Handle<v8::Script> script = Compile(
201 "function MyClass() {}\n" 190 "function MyClass() {}\n"
202 "MyClass.prototype.method1 = function() { return 1; }\n" 191 "MyClass.prototype.method1 = function() { return 1; }\n"
203 "MyClass.prototype.method2 = function() { return 2; }\n" 192 "MyClass.prototype.method2 = function() { return 2; }\n"
204 "MyClass.MyInnerClass = function() {}\n" 193 "MyClass.MyInnerClass = function() {}\n"
205 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n" 194 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n"
206 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }"); 195 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }");
207 CheckFunctionName(script, "return 1", "MyClass.method1"); 196 CheckFunctionName(script, "return 1", "MyClass.method1");
208 CheckFunctionName(script, "return 2", "MyClass.method2"); 197 CheckFunctionName(script, "return 2", "MyClass.method2");
209 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.method3"); 198 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.method3");
210 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.method4"); 199 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.method4");
211 } 200 }
212 201
213 202
214 TEST(ObjectLiteral) { 203 TEST(ObjectLiteral) {
215 InitializeVM(); 204 CcTest::InitializeVM();
216 v8::HandleScope scope(env->GetIsolate()); 205 v8::HandleScope scope(CcTest::isolate());
217 206
218 v8::Handle<v8::Script> script = Compile( 207 v8::Handle<v8::Script> script = Compile(
219 "function MyClass() {}\n" 208 "function MyClass() {}\n"
220 "MyClass.prototype = {\n" 209 "MyClass.prototype = {\n"
221 " method1: function() { return 1; },\n" 210 " method1: function() { return 1; },\n"
222 " method2: function() { return 2; } }"); 211 " method2: function() { return 2; } }");
223 CheckFunctionName(script, "return 1", "MyClass.method1"); 212 CheckFunctionName(script, "return 1", "MyClass.method1");
224 CheckFunctionName(script, "return 2", "MyClass.method2"); 213 CheckFunctionName(script, "return 2", "MyClass.method2");
225 } 214 }
226 215
227 216
228 TEST(AsParameter) { 217 TEST(AsParameter) {
229 InitializeVM(); 218 CcTest::InitializeVM();
230 v8::HandleScope scope(env->GetIsolate()); 219 v8::HandleScope scope(CcTest::isolate());
231 220
232 v8::Handle<v8::Script> script = Compile( 221 v8::Handle<v8::Script> script = Compile(
233 "function f1(a) { return a(); }\n" 222 "function f1(a) { return a(); }\n"
234 "function f2(a, b) { return a() + b(); }\n" 223 "function f2(a, b) { return a() + b(); }\n"
235 "var result1 = f1(function() { return 1; })\n" 224 "var result1 = f1(function() { return 1; })\n"
236 "var result2 = f2(function() { return 2; }, function() { return 3; })"); 225 "var result2 = f2(function() { return 2; }, function() { return 3; })");
237 // Can't infer names here. 226 // Can't infer names here.
238 CheckFunctionName(script, "return 1", ""); 227 CheckFunctionName(script, "return 1", "");
239 CheckFunctionName(script, "return 2", ""); 228 CheckFunctionName(script, "return 2", "");
240 CheckFunctionName(script, "return 3", ""); 229 CheckFunctionName(script, "return 3", "");
241 } 230 }
242 231
243 232
244 TEST(MultipleFuncsConditional) { 233 TEST(MultipleFuncsConditional) {
245 InitializeVM(); 234 CcTest::InitializeVM();
246 v8::HandleScope scope(env->GetIsolate()); 235 v8::HandleScope scope(CcTest::isolate());
247 236
248 v8::Handle<v8::Script> script = Compile( 237 v8::Handle<v8::Script> script = Compile(
249 "fun1 = 0 ?\n" 238 "fun1 = 0 ?\n"
250 " function() { return 1; } :\n" 239 " function() { return 1; } :\n"
251 " function() { return 2; }"); 240 " function() { return 2; }");
252 CheckFunctionName(script, "return 1", "fun1"); 241 CheckFunctionName(script, "return 1", "fun1");
253 CheckFunctionName(script, "return 2", "fun1"); 242 CheckFunctionName(script, "return 2", "fun1");
254 } 243 }
255 244
256 245
257 TEST(MultipleFuncsInLiteral) { 246 TEST(MultipleFuncsInLiteral) {
258 InitializeVM(); 247 CcTest::InitializeVM();
259 v8::HandleScope scope(env->GetIsolate()); 248 v8::HandleScope scope(CcTest::isolate());
260 249
261 v8::Handle<v8::Script> script = Compile( 250 v8::Handle<v8::Script> script = Compile(
262 "function MyClass() {}\n" 251 "function MyClass() {}\n"
263 "MyClass.prototype = {\n" 252 "MyClass.prototype = {\n"
264 " method1: 0 ? function() { return 1; } :\n" 253 " method1: 0 ? function() { return 1; } :\n"
265 " function() { return 2; } }"); 254 " function() { return 2; } }");
266 CheckFunctionName(script, "return 1", "MyClass.method1"); 255 CheckFunctionName(script, "return 1", "MyClass.method1");
267 CheckFunctionName(script, "return 2", "MyClass.method1"); 256 CheckFunctionName(script, "return 2", "MyClass.method1");
268 } 257 }
269 258
270 259
271 // See http://code.google.com/p/v8/issues/detail?id=380 260 // See http://code.google.com/p/v8/issues/detail?id=380
272 TEST(Issue380) { 261 TEST(Issue380) {
273 InitializeVM(); 262 CcTest::InitializeVM();
274 v8::HandleScope scope(env->GetIsolate()); 263 v8::HandleScope scope(CcTest::isolate());
275 264
276 v8::Handle<v8::Script> script = Compile( 265 v8::Handle<v8::Script> script = Compile(
277 "function a() {\n" 266 "function a() {\n"
278 "var result = function(p,a,c,k,e,d)" 267 "var result = function(p,a,c,k,e,d)"
279 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n" 268 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n"
280 "}"); 269 "}");
281 CheckFunctionName(script, "return p", ""); 270 CheckFunctionName(script, "return p", "");
282 } 271 }
283 272
284 273
285 TEST(MultipleAssignments) { 274 TEST(MultipleAssignments) {
286 InitializeVM(); 275 CcTest::InitializeVM();
287 v8::HandleScope scope(env->GetIsolate()); 276 v8::HandleScope scope(CcTest::isolate());
288 277
289 v8::Handle<v8::Script> script = Compile( 278 v8::Handle<v8::Script> script = Compile(
290 "var fun1 = fun2 = function () { return 1; }\n" 279 "var fun1 = fun2 = function () { return 1; }\n"
291 "var bar1 = bar2 = bar3 = function () { return 2; }\n" 280 "var bar1 = bar2 = bar3 = function () { return 2; }\n"
292 "foo1 = foo2 = function () { return 3; }\n" 281 "foo1 = foo2 = function () { return 3; }\n"
293 "baz1 = baz2 = baz3 = function () { return 4; }"); 282 "baz1 = baz2 = baz3 = function () { return 4; }");
294 CheckFunctionName(script, "return 1", "fun2"); 283 CheckFunctionName(script, "return 1", "fun2");
295 CheckFunctionName(script, "return 2", "bar3"); 284 CheckFunctionName(script, "return 2", "bar3");
296 CheckFunctionName(script, "return 3", "foo2"); 285 CheckFunctionName(script, "return 3", "foo2");
297 CheckFunctionName(script, "return 4", "baz3"); 286 CheckFunctionName(script, "return 4", "baz3");
298 } 287 }
299 288
300 289
301 TEST(AsConstructorParameter) { 290 TEST(AsConstructorParameter) {
302 InitializeVM(); 291 CcTest::InitializeVM();
303 v8::HandleScope scope(env->GetIsolate()); 292 v8::HandleScope scope(CcTest::isolate());
304 293
305 v8::Handle<v8::Script> script = Compile( 294 v8::Handle<v8::Script> script = Compile(
306 "function Foo() {}\n" 295 "function Foo() {}\n"
307 "var foo = new Foo(function() { return 1; })\n" 296 "var foo = new Foo(function() { return 1; })\n"
308 "var bar = new Foo(function() { return 2; }, function() { return 3; })"); 297 "var bar = new Foo(function() { return 2; }, function() { return 3; })");
309 CheckFunctionName(script, "return 1", ""); 298 CheckFunctionName(script, "return 1", "");
310 CheckFunctionName(script, "return 2", ""); 299 CheckFunctionName(script, "return 2", "");
311 CheckFunctionName(script, "return 3", ""); 300 CheckFunctionName(script, "return 3", "");
312 } 301 }
313 302
314 303
315 TEST(FactoryHashmap) { 304 TEST(FactoryHashmap) {
316 InitializeVM(); 305 CcTest::InitializeVM();
317 v8::HandleScope scope(env->GetIsolate()); 306 v8::HandleScope scope(CcTest::isolate());
318 307
319 v8::Handle<v8::Script> script = Compile( 308 v8::Handle<v8::Script> script = Compile(
320 "function createMyObj() {\n" 309 "function createMyObj() {\n"
321 " var obj = {};\n" 310 " var obj = {};\n"
322 " obj[\"method1\"] = function() { return 1; }\n" 311 " obj[\"method1\"] = function() { return 1; }\n"
323 " obj[\"method2\"] = function() { return 2; }\n" 312 " obj[\"method2\"] = function() { return 2; }\n"
324 " return obj;\n" 313 " return obj;\n"
325 "}"); 314 "}");
326 CheckFunctionName(script, "return 1", "obj.method1"); 315 CheckFunctionName(script, "return 1", "obj.method1");
327 CheckFunctionName(script, "return 2", "obj.method2"); 316 CheckFunctionName(script, "return 2", "obj.method2");
328 } 317 }
329 318
330 319
331 TEST(FactoryHashmapVariable) { 320 TEST(FactoryHashmapVariable) {
332 InitializeVM(); 321 CcTest::InitializeVM();
333 v8::HandleScope scope(env->GetIsolate()); 322 v8::HandleScope scope(CcTest::isolate());
334 323
335 v8::Handle<v8::Script> script = Compile( 324 v8::Handle<v8::Script> script = Compile(
336 "function createMyObj() {\n" 325 "function createMyObj() {\n"
337 " var obj = {};\n" 326 " var obj = {};\n"
338 " var methodName = \"method1\";\n" 327 " var methodName = \"method1\";\n"
339 " obj[methodName] = function() { return 1; }\n" 328 " obj[methodName] = function() { return 1; }\n"
340 " methodName = \"method2\";\n" 329 " methodName = \"method2\";\n"
341 " obj[methodName] = function() { return 2; }\n" 330 " obj[methodName] = function() { return 2; }\n"
342 " return obj;\n" 331 " return obj;\n"
343 "}"); 332 "}");
344 // Can't infer function names statically. 333 // Can't infer function names statically.
345 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); 334 CheckFunctionName(script, "return 1", "obj.(anonymous function)");
346 CheckFunctionName(script, "return 2", "obj.(anonymous function)"); 335 CheckFunctionName(script, "return 2", "obj.(anonymous function)");
347 } 336 }
348 337
349 338
350 TEST(FactoryHashmapConditional) { 339 TEST(FactoryHashmapConditional) {
351 InitializeVM(); 340 CcTest::InitializeVM();
352 v8::HandleScope scope(env->GetIsolate()); 341 v8::HandleScope scope(CcTest::isolate());
353 342
354 v8::Handle<v8::Script> script = Compile( 343 v8::Handle<v8::Script> script = Compile(
355 "function createMyObj() {\n" 344 "function createMyObj() {\n"
356 " var obj = {};\n" 345 " var obj = {};\n"
357 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n" 346 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n"
358 " return obj;\n" 347 " return obj;\n"
359 "}"); 348 "}");
360 // Can't infer the function name statically. 349 // Can't infer the function name statically.
361 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); 350 CheckFunctionName(script, "return 1", "obj.(anonymous function)");
362 } 351 }
363 352
364 353
365 TEST(GlobalAssignmentAndCall) { 354 TEST(GlobalAssignmentAndCall) {
366 InitializeVM(); 355 CcTest::InitializeVM();
367 v8::HandleScope scope(env->GetIsolate()); 356 v8::HandleScope scope(CcTest::isolate());
368 357
369 v8::Handle<v8::Script> script = Compile( 358 v8::Handle<v8::Script> script = Compile(
370 "var Foo = function() {\n" 359 "var Foo = function() {\n"
371 " return 1;\n" 360 " return 1;\n"
372 "}();\n" 361 "}();\n"
373 "var Baz = Bar = function() {\n" 362 "var Baz = Bar = function() {\n"
374 " return 2;\n" 363 " return 2;\n"
375 "}"); 364 "}");
376 // The inferred name is empty, because this is an assignment of a result. 365 // The inferred name is empty, because this is an assignment of a result.
377 CheckFunctionName(script, "return 1", ""); 366 CheckFunctionName(script, "return 1", "");
378 // See MultipleAssignments test. 367 // See MultipleAssignments test.
379 CheckFunctionName(script, "return 2", "Bar"); 368 CheckFunctionName(script, "return 2", "Bar");
380 } 369 }
381 370
382 371
383 TEST(AssignmentAndCall) { 372 TEST(AssignmentAndCall) {
384 InitializeVM(); 373 CcTest::InitializeVM();
385 v8::HandleScope scope(env->GetIsolate()); 374 v8::HandleScope scope(CcTest::isolate());
386 375
387 v8::Handle<v8::Script> script = Compile( 376 v8::Handle<v8::Script> script = Compile(
388 "(function Enclosing() {\n" 377 "(function Enclosing() {\n"
389 " var Foo;\n" 378 " var Foo;\n"
390 " Foo = function() {\n" 379 " Foo = function() {\n"
391 " return 1;\n" 380 " return 1;\n"
392 " }();\n" 381 " }();\n"
393 " var Baz = Bar = function() {\n" 382 " var Baz = Bar = function() {\n"
394 " return 2;\n" 383 " return 2;\n"
395 " }\n" 384 " }\n"
396 "})();"); 385 "})();");
397 // The inferred name is empty, because this is an assignment of a result. 386 // The inferred name is empty, because this is an assignment of a result.
398 CheckFunctionName(script, "return 1", ""); 387 CheckFunctionName(script, "return 1", "");
399 // See MultipleAssignments test. 388 // See MultipleAssignments test.
400 // TODO(2276): Lazy compiling the enclosing outer closure would yield 389 // TODO(2276): Lazy compiling the enclosing outer closure would yield
401 // in "Enclosing.Bar" being the inferred name here. 390 // in "Enclosing.Bar" being the inferred name here.
402 CheckFunctionName(script, "return 2", "Bar"); 391 CheckFunctionName(script, "return 2", "Bar");
403 } 392 }
404 393
405 394
406 TEST(MethodAssignmentInAnonymousFunctionCall) { 395 TEST(MethodAssignmentInAnonymousFunctionCall) {
407 InitializeVM(); 396 CcTest::InitializeVM();
408 v8::HandleScope scope(env->GetIsolate()); 397 v8::HandleScope scope(CcTest::isolate());
409 398
410 v8::Handle<v8::Script> script = Compile( 399 v8::Handle<v8::Script> script = Compile(
411 "(function () {\n" 400 "(function () {\n"
412 " var EventSource = function () { };\n" 401 " var EventSource = function () { };\n"
413 " EventSource.prototype.addListener = function () {\n" 402 " EventSource.prototype.addListener = function () {\n"
414 " return 2012;\n" 403 " return 2012;\n"
415 " };\n" 404 " };\n"
416 " this.PublicEventSource = EventSource;\n" 405 " this.PublicEventSource = EventSource;\n"
417 "})();"); 406 "})();");
418 CheckFunctionName(script, "return 2012", "EventSource.addListener"); 407 CheckFunctionName(script, "return 2012", "EventSource.addListener");
419 } 408 }
420 409
421 410
422 TEST(ReturnAnonymousFunction) { 411 TEST(ReturnAnonymousFunction) {
423 InitializeVM(); 412 CcTest::InitializeVM();
424 v8::HandleScope scope(env->GetIsolate()); 413 v8::HandleScope scope(CcTest::isolate());
425 414
426 v8::Handle<v8::Script> script = Compile( 415 v8::Handle<v8::Script> script = Compile(
427 "(function() {\n" 416 "(function() {\n"
428 " function wrapCode() {\n" 417 " function wrapCode() {\n"
429 " return function () {\n" 418 " return function () {\n"
430 " return 2012;\n" 419 " return 2012;\n"
431 " };\n" 420 " };\n"
432 " };\n" 421 " };\n"
433 " var foo = 10;\n" 422 " var foo = 10;\n"
434 " function f() {\n" 423 " function f() {\n"
435 " return wrapCode();\n" 424 " return wrapCode();\n"
436 " }\n" 425 " }\n"
437 " this.ref = f;\n" 426 " this.ref = f;\n"
438 "})()"); 427 "})()");
439 script->Run(); 428 script->Run();
440 CheckFunctionName(script, "return 2012", ""); 429 CheckFunctionName(script, "return 2012", "");
441 } 430 }
OLDNEW
« no previous file with comments | « test/cctest/test-disasm-x64.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698