| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include <map> | 30 #include <map> |
| 31 #include <string> | 31 #include <string> |
| 32 | 32 |
| 33 #include "v8.h" | 33 #include "v8.h" |
| 34 | 34 |
| 35 #include "api.h" | 35 #include "api.h" |
| 36 #include "compilation-cache.h" |
| 36 #include "snapshot.h" | 37 #include "snapshot.h" |
| 37 #include "platform.h" | 38 #include "platform.h" |
| 38 #include "top.h" | 39 #include "top.h" |
| 39 #include "cctest.h" | 40 #include "cctest.h" |
| 40 | 41 |
| 41 static bool IsNaN(double x) { | 42 static bool IsNaN(double x) { |
| 42 #ifdef WIN32 | 43 #ifdef WIN32 |
| 43 return _isnan(x); | 44 return _isnan(x); |
| 44 #else | 45 #else |
| 45 return isnan(x); | 46 return isnan(x); |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 Local<Script> script = Script::Compile(source); | 461 Local<Script> script = Script::Compile(source); |
| 461 Local<Value> value = script->Run(); | 462 Local<Value> value = script->Run(); |
| 462 CHECK(value->IsNumber()); | 463 CHECK(value->IsNumber()); |
| 463 CHECK_EQ(7, value->Int32Value()); | 464 CHECK_EQ(7, value->Int32Value()); |
| 464 CHECK(source->IsExternal()); | 465 CHECK(source->IsExternal()); |
| 465 CHECK_EQ(resource, | 466 CHECK_EQ(resource, |
| 466 static_cast<TestResource*>(source->GetExternalStringResource())); | 467 static_cast<TestResource*>(source->GetExternalStringResource())); |
| 467 v8::internal::Heap::CollectAllGarbage(); | 468 v8::internal::Heap::CollectAllGarbage(); |
| 468 CHECK_EQ(0, TestResource::dispose_count); | 469 CHECK_EQ(0, TestResource::dispose_count); |
| 469 } | 470 } |
| 471 v8::internal::CompilationCache::Clear(); |
| 470 v8::internal::Heap::CollectAllGarbage(); | 472 v8::internal::Heap::CollectAllGarbage(); |
| 471 CHECK_EQ(1, TestResource::dispose_count); | 473 CHECK_EQ(1, TestResource::dispose_count); |
| 472 } | 474 } |
| 473 | 475 |
| 474 | 476 |
| 475 THREADED_TEST(ScriptUsingAsciiStringResource) { | 477 THREADED_TEST(ScriptUsingAsciiStringResource) { |
| 476 TestAsciiResource::dispose_count = 0; | 478 TestAsciiResource::dispose_count = 0; |
| 477 const char* c_source = "1 + 2 * 3"; | 479 const char* c_source = "1 + 2 * 3"; |
| 478 { | 480 { |
| 479 v8::HandleScope scope; | 481 v8::HandleScope scope; |
| 480 LocalContext env; | 482 LocalContext env; |
| 481 Local<String> source = | 483 Local<String> source = |
| 482 String::NewExternal(new TestAsciiResource(i::StrDup(c_source))); | 484 String::NewExternal(new TestAsciiResource(i::StrDup(c_source))); |
| 483 Local<Script> script = Script::Compile(source); | 485 Local<Script> script = Script::Compile(source); |
| 484 Local<Value> value = script->Run(); | 486 Local<Value> value = script->Run(); |
| 485 CHECK(value->IsNumber()); | 487 CHECK(value->IsNumber()); |
| 486 CHECK_EQ(7, value->Int32Value()); | 488 CHECK_EQ(7, value->Int32Value()); |
| 487 v8::internal::Heap::CollectAllGarbage(); | 489 v8::internal::Heap::CollectAllGarbage(); |
| 488 CHECK_EQ(0, TestAsciiResource::dispose_count); | 490 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 489 } | 491 } |
| 492 v8::internal::CompilationCache::Clear(); |
| 490 v8::internal::Heap::CollectAllGarbage(); | 493 v8::internal::Heap::CollectAllGarbage(); |
| 491 CHECK_EQ(1, TestAsciiResource::dispose_count); | 494 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 492 } | 495 } |
| 493 | 496 |
| 494 | 497 |
| 495 THREADED_TEST(ScriptMakingExternalString) { | 498 THREADED_TEST(ScriptMakingExternalString) { |
| 496 TestResource::dispose_count = 0; | 499 TestResource::dispose_count = 0; |
| 497 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); | 500 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
| 498 { | 501 { |
| 499 v8::HandleScope scope; | 502 v8::HandleScope scope; |
| 500 LocalContext env; | 503 LocalContext env; |
| 501 Local<String> source = String::New(two_byte_source); | 504 Local<String> source = String::New(two_byte_source); |
| 502 bool success = source->MakeExternal(new TestResource(two_byte_source)); | 505 bool success = source->MakeExternal(new TestResource(two_byte_source)); |
| 503 CHECK(success); | 506 CHECK(success); |
| 504 Local<Script> script = Script::Compile(source); | 507 Local<Script> script = Script::Compile(source); |
| 505 Local<Value> value = script->Run(); | 508 Local<Value> value = script->Run(); |
| 506 CHECK(value->IsNumber()); | 509 CHECK(value->IsNumber()); |
| 507 CHECK_EQ(7, value->Int32Value()); | 510 CHECK_EQ(7, value->Int32Value()); |
| 508 v8::internal::Heap::CollectAllGarbage(); | 511 v8::internal::Heap::CollectAllGarbage(); |
| 509 CHECK_EQ(0, TestResource::dispose_count); | 512 CHECK_EQ(0, TestResource::dispose_count); |
| 510 } | 513 } |
| 514 v8::internal::CompilationCache::Clear(); |
| 511 v8::internal::Heap::CollectAllGarbage(); | 515 v8::internal::Heap::CollectAllGarbage(); |
| 512 CHECK_EQ(1, TestResource::dispose_count); | 516 CHECK_EQ(1, TestResource::dispose_count); |
| 513 } | 517 } |
| 514 | 518 |
| 515 | 519 |
| 516 THREADED_TEST(ScriptMakingExternalAsciiString) { | 520 THREADED_TEST(ScriptMakingExternalAsciiString) { |
| 517 TestAsciiResource::dispose_count = 0; | 521 TestAsciiResource::dispose_count = 0; |
| 518 const char* c_source = "1 + 2 * 3"; | 522 const char* c_source = "1 + 2 * 3"; |
| 519 { | 523 { |
| 520 v8::HandleScope scope; | 524 v8::HandleScope scope; |
| 521 LocalContext env; | 525 LocalContext env; |
| 522 Local<String> source = v8_str(c_source); | 526 Local<String> source = v8_str(c_source); |
| 523 bool success = source->MakeExternal( | 527 bool success = source->MakeExternal( |
| 524 new TestAsciiResource(i::StrDup(c_source))); | 528 new TestAsciiResource(i::StrDup(c_source))); |
| 525 CHECK(success); | 529 CHECK(success); |
| 526 Local<Script> script = Script::Compile(source); | 530 Local<Script> script = Script::Compile(source); |
| 527 Local<Value> value = script->Run(); | 531 Local<Value> value = script->Run(); |
| 528 CHECK(value->IsNumber()); | 532 CHECK(value->IsNumber()); |
| 529 CHECK_EQ(7, value->Int32Value()); | 533 CHECK_EQ(7, value->Int32Value()); |
| 530 v8::internal::Heap::CollectAllGarbage(); | 534 v8::internal::Heap::CollectAllGarbage(); |
| 531 CHECK_EQ(0, TestAsciiResource::dispose_count); | 535 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 532 } | 536 } |
| 537 v8::internal::CompilationCache::Clear(); |
| 533 v8::internal::Heap::CollectAllGarbage(); | 538 v8::internal::Heap::CollectAllGarbage(); |
| 534 CHECK_EQ(1, TestAsciiResource::dispose_count); | 539 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 535 } | 540 } |
| 536 | 541 |
| 537 | 542 |
| 538 THREADED_TEST(UsingExternalString) { | 543 THREADED_TEST(UsingExternalString) { |
| 539 v8::HandleScope scope; | 544 v8::HandleScope scope; |
| 540 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 545 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
| 541 Local<String> string = String::NewExternal(new TestResource(two_byte_string)); | 546 Local<String> string = String::NewExternal(new TestResource(two_byte_string)); |
| 542 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 547 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
| (...skipping 5632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6175 // Check without 'eval' or 'with'. | 6180 // Check without 'eval' or 'with'. |
| 6176 v8::Handle<v8::Value> res = | 6181 v8::Handle<v8::Value> res = |
| 6177 CompileRun("function f() { x = 42; return x; }; f()"); | 6182 CompileRun("function f() { x = 42; return x; }; f()"); |
| 6178 // Check with 'eval'. | 6183 // Check with 'eval'. |
| 6179 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); | 6184 res = CompileRun("function f() { eval('1'); y = 42; return y; }; f()"); |
| 6180 CHECK_EQ(v8::Integer::New(42), res); | 6185 CHECK_EQ(v8::Integer::New(42), res); |
| 6181 // Check with 'with'. | 6186 // Check with 'with'. |
| 6182 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); | 6187 res = CompileRun("function f() { with (this) { y = 42 }; return y; }; f()"); |
| 6183 CHECK_EQ(v8::Integer::New(42), res); | 6188 CHECK_EQ(v8::Integer::New(42), res); |
| 6184 } | 6189 } |
| OLD | NEW |