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 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 "v8.h" | 30 #include "v8.h" |
31 | 31 |
32 #include "api.h" | 32 #include "api.h" |
| 33 #include "compilation-cache.h" |
33 #include "snapshot.h" | 34 #include "snapshot.h" |
34 #include "platform.h" | 35 #include "platform.h" |
35 #include "top.h" | 36 #include "top.h" |
36 #include "cctest.h" | 37 #include "cctest.h" |
37 | 38 |
38 static bool IsNaN(double x) { | 39 static bool IsNaN(double x) { |
39 #ifdef WIN32 | 40 #ifdef WIN32 |
40 return _isnan(x); | 41 return _isnan(x); |
41 #else | 42 #else |
42 return isnan(x); | 43 return isnan(x); |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 Local<Script> script = Script::Compile(source); | 458 Local<Script> script = Script::Compile(source); |
458 Local<Value> value = script->Run(); | 459 Local<Value> value = script->Run(); |
459 CHECK(value->IsNumber()); | 460 CHECK(value->IsNumber()); |
460 CHECK_EQ(7, value->Int32Value()); | 461 CHECK_EQ(7, value->Int32Value()); |
461 CHECK(source->IsExternal()); | 462 CHECK(source->IsExternal()); |
462 CHECK_EQ(resource, | 463 CHECK_EQ(resource, |
463 static_cast<TestResource*>(source->GetExternalStringResource())); | 464 static_cast<TestResource*>(source->GetExternalStringResource())); |
464 v8::internal::Heap::CollectAllGarbage(); | 465 v8::internal::Heap::CollectAllGarbage(); |
465 CHECK_EQ(0, TestResource::dispose_count); | 466 CHECK_EQ(0, TestResource::dispose_count); |
466 } | 467 } |
| 468 v8::internal::CompilationCache::Clear(); |
467 v8::internal::Heap::CollectAllGarbage(); | 469 v8::internal::Heap::CollectAllGarbage(); |
468 CHECK_EQ(1, TestResource::dispose_count); | 470 CHECK_EQ(1, TestResource::dispose_count); |
469 } | 471 } |
470 | 472 |
471 | 473 |
472 THREADED_TEST(ScriptUsingAsciiStringResource) { | 474 THREADED_TEST(ScriptUsingAsciiStringResource) { |
473 TestAsciiResource::dispose_count = 0; | 475 TestAsciiResource::dispose_count = 0; |
474 const char* c_source = "1 + 2 * 3"; | 476 const char* c_source = "1 + 2 * 3"; |
475 { | 477 { |
476 v8::HandleScope scope; | 478 v8::HandleScope scope; |
477 LocalContext env; | 479 LocalContext env; |
478 Local<String> source = | 480 Local<String> source = |
479 String::NewExternal(new TestAsciiResource(i::StrDup(c_source))); | 481 String::NewExternal(new TestAsciiResource(i::StrDup(c_source))); |
480 Local<Script> script = Script::Compile(source); | 482 Local<Script> script = Script::Compile(source); |
481 Local<Value> value = script->Run(); | 483 Local<Value> value = script->Run(); |
482 CHECK(value->IsNumber()); | 484 CHECK(value->IsNumber()); |
483 CHECK_EQ(7, value->Int32Value()); | 485 CHECK_EQ(7, value->Int32Value()); |
484 v8::internal::Heap::CollectAllGarbage(); | 486 v8::internal::Heap::CollectAllGarbage(); |
485 CHECK_EQ(0, TestAsciiResource::dispose_count); | 487 CHECK_EQ(0, TestAsciiResource::dispose_count); |
486 } | 488 } |
| 489 v8::internal::CompilationCache::Clear(); |
487 v8::internal::Heap::CollectAllGarbage(); | 490 v8::internal::Heap::CollectAllGarbage(); |
488 CHECK_EQ(1, TestAsciiResource::dispose_count); | 491 CHECK_EQ(1, TestAsciiResource::dispose_count); |
489 } | 492 } |
490 | 493 |
491 | 494 |
492 THREADED_TEST(ScriptMakingExternalString) { | 495 THREADED_TEST(ScriptMakingExternalString) { |
493 TestResource::dispose_count = 0; | 496 TestResource::dispose_count = 0; |
494 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); | 497 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
495 { | 498 { |
496 v8::HandleScope scope; | 499 v8::HandleScope scope; |
497 LocalContext env; | 500 LocalContext env; |
498 Local<String> source = String::New(two_byte_source); | 501 Local<String> source = String::New(two_byte_source); |
499 bool success = source->MakeExternal(new TestResource(two_byte_source)); | 502 bool success = source->MakeExternal(new TestResource(two_byte_source)); |
500 CHECK(success); | 503 CHECK(success); |
501 Local<Script> script = Script::Compile(source); | 504 Local<Script> script = Script::Compile(source); |
502 Local<Value> value = script->Run(); | 505 Local<Value> value = script->Run(); |
503 CHECK(value->IsNumber()); | 506 CHECK(value->IsNumber()); |
504 CHECK_EQ(7, value->Int32Value()); | 507 CHECK_EQ(7, value->Int32Value()); |
505 v8::internal::Heap::CollectAllGarbage(); | 508 v8::internal::Heap::CollectAllGarbage(); |
506 CHECK_EQ(0, TestResource::dispose_count); | 509 CHECK_EQ(0, TestResource::dispose_count); |
507 } | 510 } |
| 511 v8::internal::CompilationCache::Clear(); |
508 v8::internal::Heap::CollectAllGarbage(); | 512 v8::internal::Heap::CollectAllGarbage(); |
509 CHECK_EQ(1, TestResource::dispose_count); | 513 CHECK_EQ(1, TestResource::dispose_count); |
510 } | 514 } |
511 | 515 |
512 | 516 |
513 THREADED_TEST(ScriptMakingExternalAsciiString) { | 517 THREADED_TEST(ScriptMakingExternalAsciiString) { |
514 TestAsciiResource::dispose_count = 0; | 518 TestAsciiResource::dispose_count = 0; |
515 const char* c_source = "1 + 2 * 3"; | 519 const char* c_source = "1 + 2 * 3"; |
516 { | 520 { |
517 v8::HandleScope scope; | 521 v8::HandleScope scope; |
518 LocalContext env; | 522 LocalContext env; |
519 Local<String> source = v8_str(c_source); | 523 Local<String> source = v8_str(c_source); |
520 bool success = source->MakeExternal( | 524 bool success = source->MakeExternal( |
521 new TestAsciiResource(i::StrDup(c_source))); | 525 new TestAsciiResource(i::StrDup(c_source))); |
522 CHECK(success); | 526 CHECK(success); |
523 Local<Script> script = Script::Compile(source); | 527 Local<Script> script = Script::Compile(source); |
524 Local<Value> value = script->Run(); | 528 Local<Value> value = script->Run(); |
525 CHECK(value->IsNumber()); | 529 CHECK(value->IsNumber()); |
526 CHECK_EQ(7, value->Int32Value()); | 530 CHECK_EQ(7, value->Int32Value()); |
527 v8::internal::Heap::CollectAllGarbage(); | 531 v8::internal::Heap::CollectAllGarbage(); |
528 CHECK_EQ(0, TestAsciiResource::dispose_count); | 532 CHECK_EQ(0, TestAsciiResource::dispose_count); |
529 } | 533 } |
| 534 v8::internal::CompilationCache::Clear(); |
530 v8::internal::Heap::CollectAllGarbage(); | 535 v8::internal::Heap::CollectAllGarbage(); |
531 CHECK_EQ(1, TestAsciiResource::dispose_count); | 536 CHECK_EQ(1, TestAsciiResource::dispose_count); |
532 } | 537 } |
533 | 538 |
534 | 539 |
535 THREADED_TEST(UsingExternalString) { | 540 THREADED_TEST(UsingExternalString) { |
536 v8::HandleScope scope; | 541 v8::HandleScope scope; |
537 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 542 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
538 Local<String> string = String::NewExternal(new TestResource(two_byte_string)); | 543 Local<String> string = String::NewExternal(new TestResource(two_byte_string)); |
539 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 544 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
(...skipping 6056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6596 // the property | 6601 // the property |
6597 pass_on_get = false; | 6602 pass_on_get = false; |
6598 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 6603 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
6599 CHECK_EQ(1, force_set_set_count); | 6604 CHECK_EQ(1, force_set_set_count); |
6600 CHECK_EQ(5, force_set_get_count); | 6605 CHECK_EQ(5, force_set_get_count); |
6601 // The interceptor should also work for other properties | 6606 // The interceptor should also work for other properties |
6602 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); | 6607 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); |
6603 CHECK_EQ(1, force_set_set_count); | 6608 CHECK_EQ(1, force_set_set_count); |
6604 CHECK_EQ(6, force_set_get_count); | 6609 CHECK_EQ(6, force_set_get_count); |
6605 } | 6610 } |
OLD | NEW |