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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 script->set_source(CcTest::heap()->undefined_value()); | 324 script->set_source(CcTest::heap()->undefined_value()); |
325 CHECK_EQ(-1, GetScriptLineNumber(script, 0)); | 325 CHECK_EQ(-1, GetScriptLineNumber(script, 0)); |
326 CHECK_EQ(-1, GetScriptLineNumber(script, 100)); | 326 CHECK_EQ(-1, GetScriptLineNumber(script, 100)); |
327 CHECK_EQ(-1, GetScriptLineNumber(script, -1)); | 327 CHECK_EQ(-1, GetScriptLineNumber(script, -1)); |
328 } | 328 } |
329 | 329 |
330 | 330 |
331 TEST(GetScriptLineNumber) { | 331 TEST(GetScriptLineNumber) { |
332 LocalContext context; | 332 LocalContext context; |
333 v8::HandleScope scope(CcTest::isolate()); | 333 v8::HandleScope scope(CcTest::isolate()); |
334 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); | 334 v8::ScriptOrigin origin = |
| 335 v8::ScriptOrigin(v8::String::NewFromUtf8(CcTest::isolate(), "test")); |
335 const char function_f[] = "function f() {}"; | 336 const char function_f[] = "function f() {}"; |
336 const int max_rows = 1000; | 337 const int max_rows = 1000; |
337 const int buffer_size = max_rows + sizeof(function_f); | 338 const int buffer_size = max_rows + sizeof(function_f); |
338 ScopedVector<char> buffer(buffer_size); | 339 ScopedVector<char> buffer(buffer_size); |
339 memset(buffer.start(), '\n', buffer_size - 1); | 340 memset(buffer.start(), '\n', buffer_size - 1); |
340 buffer[buffer_size - 1] = '\0'; | 341 buffer[buffer_size - 1] = '\0'; |
341 | 342 |
342 for (int i = 0; i < max_rows; ++i) { | 343 for (int i = 0; i < max_rows; ++i) { |
343 if (i > 0) | 344 if (i > 0) |
344 buffer[i - 1] = '\n'; | 345 buffer[i - 1] = '\n'; |
345 OS::MemCopy(&buffer[i], function_f, sizeof(function_f) - 1); | 346 OS::MemCopy(&buffer[i], function_f, sizeof(function_f) - 1); |
346 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); | 347 v8::Handle<v8::String> script_body = |
| 348 v8::String::NewFromUtf8(CcTest::isolate(), buffer.start()); |
347 v8::Script::Compile(script_body, &origin)->Run(); | 349 v8::Script::Compile(script_body, &origin)->Run(); |
348 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 350 v8::Local<v8::Function> f = |
349 context->Global()->Get(v8::String::New("f"))); | 351 v8::Local<v8::Function>::Cast(context->Global()->Get( |
| 352 v8::String::NewFromUtf8(CcTest::isolate(), "f"))); |
350 CHECK_EQ(i, f->GetScriptLineNumber()); | 353 CHECK_EQ(i, f->GetScriptLineNumber()); |
351 } | 354 } |
352 } | 355 } |
353 | 356 |
354 | 357 |
355 // Test that optimized code for different closures is actually shared | 358 // Test that optimized code for different closures is actually shared |
356 // immediately by the FastNewClosureStub when run in the same context. | 359 // immediately by the FastNewClosureStub when run in the same context. |
357 TEST(OptimizedCodeSharing) { | 360 TEST(OptimizedCodeSharing) { |
358 // Skip test if --cache-optimized-code is not activated by default because | 361 // Skip test if --cache-optimized-code is not activated by default because |
359 // FastNewClosureStub that is baked into the snapshot is incorrect. | 362 // FastNewClosureStub that is baked into the snapshot is incorrect. |
360 if (!FLAG_cache_optimized_code) return; | 363 if (!FLAG_cache_optimized_code) return; |
361 FLAG_stress_compaction = false; | 364 FLAG_stress_compaction = false; |
362 FLAG_allow_natives_syntax = true; | 365 FLAG_allow_natives_syntax = true; |
363 CcTest::InitializeVM(); | 366 CcTest::InitializeVM(); |
364 v8::HandleScope scope(CcTest::isolate()); | 367 v8::HandleScope scope(CcTest::isolate()); |
365 for (int i = 0; i < 10; i++) { | 368 for (int i = 0; i < 10; i++) { |
366 LocalContext env; | 369 LocalContext env; |
367 env->Global()->Set(v8::String::New("x"), v8::Integer::New(i)); | 370 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"), |
| 371 v8::Integer::New(i)); |
368 CompileRun("function MakeClosure() {" | 372 CompileRun("function MakeClosure() {" |
369 " return function() { return x; };" | 373 " return function() { return x; };" |
370 "}" | 374 "}" |
371 "var closure0 = MakeClosure();" | 375 "var closure0 = MakeClosure();" |
372 "%DebugPrint(closure0());" | 376 "%DebugPrint(closure0());" |
373 "%OptimizeFunctionOnNextCall(closure0);" | 377 "%OptimizeFunctionOnNextCall(closure0);" |
374 "%DebugPrint(closure0());" | 378 "%DebugPrint(closure0());" |
375 "var closure1 = MakeClosure();" | 379 "var closure1 = MakeClosure();" |
376 "var closure2 = MakeClosure();"); | 380 "var closure2 = MakeClosure();"); |
377 Handle<JSFunction> fun1 = v8::Utils::OpenHandle( | 381 Handle<JSFunction> fun1 = v8::Utils::OpenHandle( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 CompileRun("function f() { a = 12345678 }; f();"); | 436 CompileRun("function f() { a = 12345678 }; f();"); |
433 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 437 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
434 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 438 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
435 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 439 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
436 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 440 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
437 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 441 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
438 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 442 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
439 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 443 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
440 } | 444 } |
441 #endif | 445 #endif |
OLD | NEW |