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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 CHECK(value->IsNumber()); | 484 CHECK(value->IsNumber()); |
485 CHECK_EQ(7, value->Int32Value()); | 485 CHECK_EQ(7, value->Int32Value()); |
486 v8::internal::Heap::CollectAllGarbage(); | 486 v8::internal::Heap::CollectAllGarbage(); |
487 CHECK_EQ(0, TestAsciiResource::dispose_count); | 487 CHECK_EQ(0, TestAsciiResource::dispose_count); |
488 } | 488 } |
489 v8::internal::Heap::CollectAllGarbage(); | 489 v8::internal::Heap::CollectAllGarbage(); |
490 CHECK_EQ(1, TestAsciiResource::dispose_count); | 490 CHECK_EQ(1, TestAsciiResource::dispose_count); |
491 } | 491 } |
492 | 492 |
493 | 493 |
| 494 THREADED_TEST(ScriptMakingExternalString) { |
| 495 TestResource::dispose_count = 0; |
| 496 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
| 497 { |
| 498 v8::HandleScope scope; |
| 499 LocalContext env; |
| 500 Local<String> source = String::New(two_byte_source); |
| 501 bool success = source->MakeExternal(new TestResource(two_byte_source)); |
| 502 CHECK(success); |
| 503 Local<Script> script = Script::Compile(source); |
| 504 Local<Value> value = script->Run(); |
| 505 CHECK(value->IsNumber()); |
| 506 CHECK_EQ(7, value->Int32Value()); |
| 507 v8::internal::Heap::CollectAllGarbage(); |
| 508 CHECK_EQ(0, TestResource::dispose_count); |
| 509 } |
| 510 v8::internal::Heap::CollectAllGarbage(); |
| 511 CHECK_EQ(1, TestResource::dispose_count); |
| 512 } |
| 513 |
| 514 |
| 515 THREADED_TEST(ScriptMakingExternalAsciiString) { |
| 516 TestAsciiResource::dispose_count = 0; |
| 517 const char* c_source = "1 + 2 * 3"; |
| 518 { |
| 519 v8::HandleScope scope; |
| 520 LocalContext env; |
| 521 Local<String> source = v8_str(c_source); |
| 522 bool success = source->MakeExternal( |
| 523 new TestAsciiResource(i::StrDup(c_source))); |
| 524 CHECK(success); |
| 525 Local<Script> script = Script::Compile(source); |
| 526 Local<Value> value = script->Run(); |
| 527 CHECK(value->IsNumber()); |
| 528 CHECK_EQ(7, value->Int32Value()); |
| 529 v8::internal::Heap::CollectAllGarbage(); |
| 530 CHECK_EQ(0, TestAsciiResource::dispose_count); |
| 531 } |
| 532 v8::internal::Heap::CollectAllGarbage(); |
| 533 CHECK_EQ(1, TestAsciiResource::dispose_count); |
| 534 } |
| 535 |
| 536 |
| 537 THREADED_TEST(UsingExternalString) { |
| 538 v8::HandleScope scope; |
| 539 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
| 540 Local<String> string = String::NewExternal(new TestResource(two_byte_string)); |
| 541 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
| 542 // Trigger GCs so that the newly allocated string moves to old gen. |
| 543 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
| 544 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
| 545 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); |
| 546 CHECK(isymbol->IsSymbol()); |
| 547 } |
| 548 |
| 549 |
| 550 THREADED_TEST(UsingExternalAsciiString) { |
| 551 v8::HandleScope scope; |
| 552 const char* one_byte_string = "test string"; |
| 553 Local<String> string = String::NewExternal( |
| 554 new TestAsciiResource(i::StrDup(one_byte_string))); |
| 555 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
| 556 // Trigger GCs so that the newly allocated string moves to old gen. |
| 557 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
| 558 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
| 559 i::Handle<i::String> isymbol = i::Factory::SymbolFromString(istring); |
| 560 CHECK(isymbol->IsSymbol()); |
| 561 } |
| 562 |
| 563 |
494 THREADED_TEST(GlobalProperties) { | 564 THREADED_TEST(GlobalProperties) { |
495 v8::HandleScope scope; | 565 v8::HandleScope scope; |
496 LocalContext env; | 566 LocalContext env; |
497 v8::Handle<v8::Object> global = env->Global(); | 567 v8::Handle<v8::Object> global = env->Global(); |
498 global->Set(v8_str("pi"), v8_num(3.1415926)); | 568 global->Set(v8_str("pi"), v8_num(3.1415926)); |
499 Local<Value> pi = global->Get(v8_str("pi")); | 569 Local<Value> pi = global->Get(v8_str("pi")); |
500 CHECK_EQ(3.1415926, pi->NumberValue()); | 570 CHECK_EQ(3.1415926, pi->NumberValue()); |
501 } | 571 } |
502 | 572 |
503 | 573 |
(...skipping 5129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5633 context1->Global()->Set(v8_str("other"), context0->Global()); | 5703 context1->Global()->Set(v8_str("other"), context0->Global()); |
5634 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); | 5704 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); |
5635 CHECK(value->IsInt32()); | 5705 CHECK(value->IsInt32()); |
5636 CHECK_EQ(42, value->Int32Value()); | 5706 CHECK_EQ(42, value->Int32Value()); |
5637 context1->Exit(); | 5707 context1->Exit(); |
5638 | 5708 |
5639 // Dispose the contexts to allow them to be garbage collected. | 5709 // Dispose the contexts to allow them to be garbage collected. |
5640 context0.Dispose(); | 5710 context0.Dispose(); |
5641 context1.Dispose(); | 5711 context1.Dispose(); |
5642 } | 5712 } |
OLD | NEW |