OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 | 196 |
197 TEST(Sum) { | 197 TEST(Sum) { |
198 CcTest::InitializeVM(); | 198 CcTest::InitializeVM(); |
199 v8::HandleScope scope(CcTest::isolate()); | 199 v8::HandleScope scope(CcTest::isolate()); |
200 CHECK_EQ(5050.0, Sum(CcTest::i_isolate(), 100)); | 200 CHECK_EQ(5050.0, Sum(CcTest::i_isolate(), 100)); |
201 } | 201 } |
202 | 202 |
203 | 203 |
204 TEST(Print) { | 204 TEST(Print) { |
205 CcTest::InitializeVM(PRINT_EXTENSION); | |
206 v8::HandleScope scope(CcTest::isolate()); | 205 v8::HandleScope scope(CcTest::isolate()); |
| 206 v8::Local<v8::Context> context = CcTest::NewContext(PRINT_EXTENSION); |
| 207 v8::Context::Scope context_scope(context); |
207 const char* source = "for (n = 0; n < 100; ++n) print(n, 1, 2);"; | 208 const char* source = "for (n = 0; n < 100; ++n) print(n, 1, 2);"; |
208 Handle<JSFunction> fun = Compile(source); | 209 Handle<JSFunction> fun = Compile(source); |
209 if (fun.is_null()) return; | 210 if (fun.is_null()) return; |
210 bool has_pending_exception; | 211 bool has_pending_exception; |
211 Handle<JSObject> global(CcTest::i_isolate()->context()->global_object()); | 212 Handle<JSObject> global(CcTest::i_isolate()->context()->global_object()); |
212 Execution::Call( | 213 Execution::Call( |
213 CcTest::i_isolate(), fun, global, 0, NULL, &has_pending_exception); | 214 CcTest::i_isolate(), fun, global, 0, NULL, &has_pending_exception); |
214 CHECK(!has_pending_exception); | 215 CHECK(!has_pending_exception); |
215 } | 216 } |
216 | 217 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 267 } |
267 | 268 |
268 | 269 |
269 // Tests calling a builtin function from C/C++ code, and the builtin function | 270 // Tests calling a builtin function from C/C++ code, and the builtin function |
270 // performs GC. It creates a stack frame looks like following: | 271 // performs GC. It creates a stack frame looks like following: |
271 // | C (PerformGC) | | 272 // | C (PerformGC) | |
272 // | JS-to-C | | 273 // | JS-to-C | |
273 // | JS | | 274 // | JS | |
274 // | C-to-JS | | 275 // | C-to-JS | |
275 TEST(C2JSFrames) { | 276 TEST(C2JSFrames) { |
276 CcTest::InitializeVM(PRINT_EXTENSION | GC_EXTENSION); | |
277 v8::HandleScope scope(CcTest::isolate()); | 277 v8::HandleScope scope(CcTest::isolate()); |
| 278 v8::Local<v8::Context> context = |
| 279 CcTest::NewContext(PRINT_EXTENSION | GC_EXTENSION); |
| 280 v8::Context::Scope context_scope(context); |
278 | 281 |
279 const char* source = "function foo(a) { gc(), print(a); }"; | 282 const char* source = "function foo(a) { gc(), print(a); }"; |
280 | 283 |
281 Handle<JSFunction> fun0 = Compile(source); | 284 Handle<JSFunction> fun0 = Compile(source); |
282 CHECK(!fun0.is_null()); | 285 CHECK(!fun0.is_null()); |
283 Isolate* isolate = fun0->GetIsolate(); | 286 Isolate* isolate = fun0->GetIsolate(); |
284 | 287 |
285 // Run the generated code to populate the global object with 'foo'. | 288 // Run the generated code to populate the global object with 'foo'. |
286 bool has_pending_exception; | 289 bool has_pending_exception; |
287 Handle<JSObject> global(isolate->context()->global_object()); | 290 Handle<JSObject> global(isolate->context()->global_object()); |
(...skipping 30 matching lines...) Expand all Loading... |
318 | 321 |
319 Handle<Script> script = factory->NewScript(factory->empty_string()); | 322 Handle<Script> script = factory->NewScript(factory->empty_string()); |
320 script->set_source(CcTest::heap()->undefined_value()); | 323 script->set_source(CcTest::heap()->undefined_value()); |
321 CHECK_EQ(-1, GetScriptLineNumber(script, 0)); | 324 CHECK_EQ(-1, GetScriptLineNumber(script, 0)); |
322 CHECK_EQ(-1, GetScriptLineNumber(script, 100)); | 325 CHECK_EQ(-1, GetScriptLineNumber(script, 100)); |
323 CHECK_EQ(-1, GetScriptLineNumber(script, -1)); | 326 CHECK_EQ(-1, GetScriptLineNumber(script, -1)); |
324 } | 327 } |
325 | 328 |
326 | 329 |
327 TEST(GetScriptLineNumber) { | 330 TEST(GetScriptLineNumber) { |
328 CcTest::InitializeVM(); | 331 LocalContext context; |
329 v8::HandleScope scope(CcTest::isolate()); | 332 v8::HandleScope scope(CcTest::isolate()); |
330 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); | 333 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
331 const char function_f[] = "function f() {}"; | 334 const char function_f[] = "function f() {}"; |
332 const int max_rows = 1000; | 335 const int max_rows = 1000; |
333 const int buffer_size = max_rows + sizeof(function_f); | 336 const int buffer_size = max_rows + sizeof(function_f); |
334 ScopedVector<char> buffer(buffer_size); | 337 ScopedVector<char> buffer(buffer_size); |
335 memset(buffer.start(), '\n', buffer_size - 1); | 338 memset(buffer.start(), '\n', buffer_size - 1); |
336 buffer[buffer_size - 1] = '\0'; | 339 buffer[buffer_size - 1] = '\0'; |
337 | 340 |
338 for (int i = 0; i < max_rows; ++i) { | 341 for (int i = 0; i < max_rows; ++i) { |
339 if (i > 0) | 342 if (i > 0) |
340 buffer[i - 1] = '\n'; | 343 buffer[i - 1] = '\n'; |
341 OS::MemCopy(&buffer[i], function_f, sizeof(function_f) - 1); | 344 OS::MemCopy(&buffer[i], function_f, sizeof(function_f) - 1); |
342 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); | 345 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); |
343 v8::Script::Compile(script_body, &origin)->Run(); | 346 v8::Script::Compile(script_body, &origin)->Run(); |
344 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 347 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
345 CcTest::env()->Global()->Get(v8::String::New("f"))); | 348 context->Global()->Get(v8::String::New("f"))); |
346 CHECK_EQ(i, f->GetScriptLineNumber()); | 349 CHECK_EQ(i, f->GetScriptLineNumber()); |
347 } | 350 } |
348 } | 351 } |
349 | 352 |
350 | 353 |
351 // Test that optimized code for different closures is actually shared | 354 // Test that optimized code for different closures is actually shared |
352 // immediately by the FastNewClosureStub when run in the same context. | 355 // immediately by the FastNewClosureStub when run in the same context. |
353 TEST(OptimizedCodeSharing) { | 356 TEST(OptimizedCodeSharing) { |
354 // Skip test if --cache-optimized-code is not activated by default because | 357 // Skip test if --cache-optimized-code is not activated by default because |
355 // FastNewClosureStub that is baked into the snapshot is incorrect. | 358 // FastNewClosureStub that is baked into the snapshot is incorrect. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } else { | 416 } else { |
414 pc += d.InstructionDecode(decode_buffer, pc); | 417 pc += d.InstructionDecode(decode_buffer, pc); |
415 CHECK(strstr(decode_buffer.start(), smi_hex_buffer.start()) == NULL); | 418 CHECK(strstr(decode_buffer.start(), smi_hex_buffer.start()) == NULL); |
416 } | 419 } |
417 } | 420 } |
418 } | 421 } |
419 } | 422 } |
420 | 423 |
421 | 424 |
422 TEST(SplitConstantsInFullCompiler) { | 425 TEST(SplitConstantsInFullCompiler) { |
423 CcTest::InitializeVM(); | 426 LocalContext context; |
424 v8::HandleScope scope(CcTest::isolate()); | 427 v8::HandleScope scope(CcTest::isolate()); |
425 | 428 |
426 CompileRun("function f() { a = 12345678 }; f();"); | 429 CompileRun("function f() { a = 12345678 }; f();"); |
427 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 430 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
428 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 431 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
429 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 432 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
430 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 433 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
431 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 434 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
432 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 435 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
433 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 436 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
434 } | 437 } |
435 #endif | 438 #endif |
OLD | NEW |