| 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 12652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12663 v8::V8::ContextDisposedNotification(); | 12663 v8::V8::ContextDisposedNotification(); |
| 12664 CheckSurvivingGlobalObjectsCount(0); | 12664 CheckSurvivingGlobalObjectsCount(0); |
| 12665 } | 12665 } |
| 12666 } | 12666 } |
| 12667 | 12667 |
| 12668 template<class T> | 12668 template<class T> |
| 12669 struct CopyablePersistentTraits { | 12669 struct CopyablePersistentTraits { |
| 12670 typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent; | 12670 typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent; |
| 12671 static const bool kResetInDestructor = true; | 12671 static const bool kResetInDestructor = true; |
| 12672 template<class S, class M> | 12672 template<class S, class M> |
| 12673 V8_INLINE(static void Copy(const Persistent<S, M>& source, | 12673 static V8_INLINE void Copy(const Persistent<S, M>& source, |
| 12674 CopyablePersistent* dest)) { | 12674 CopyablePersistent* dest) { |
| 12675 // do nothing, just allow copy | 12675 // do nothing, just allow copy |
| 12676 } | 12676 } |
| 12677 }; | 12677 }; |
| 12678 | 12678 |
| 12679 | 12679 |
| 12680 TEST(CopyablePersistent) { | 12680 TEST(CopyablePersistent) { |
| 12681 LocalContext context; | 12681 LocalContext context; |
| 12682 v8::Isolate* isolate = context->GetIsolate(); | 12682 v8::Isolate* isolate = context->GetIsolate(); |
| 12683 i::GlobalHandles* globals = | 12683 i::GlobalHandles* globals = |
| 12684 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); | 12684 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); |
| 12685 int initial_handles = globals->global_handles_count(); | 12685 int initial_handles = globals->global_handles_count(); |
| 12686 { | 12686 { |
| 12687 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle1; | 12687 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle1; |
| 12688 { | 12688 { |
| 12689 v8::HandleScope scope(isolate); | 12689 v8::HandleScope scope(isolate); |
| 12690 handle1.Reset(isolate, v8::Object::New()); | 12690 handle1.Reset(isolate, v8::Object::New()); |
| 12691 } | 12691 } |
| 12692 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); | 12692 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); |
| 12693 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle2; | 12693 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle2; |
| 12694 handle2 = handle1; | 12694 handle2 = handle1; |
| 12695 CHECK(handle1 == handle2); | 12695 CHECK(handle1 == handle2); |
| 12696 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); | 12696 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); |
| 12697 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > | 12697 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > |
| 12698 handle3(handle2); | 12698 handle3(handle2); |
| 12699 CHECK(handle1 == handle3); | 12699 CHECK(handle1 == handle3); |
| 12700 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); | 12700 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); |
| 12701 } | 12701 } |
| 12702 // Verify autodispose | 12702 // Verify autodispose |
| 12703 // CHECK_EQ(initial_handles, globals->global_handles_count()); | 12703 CHECK_EQ(initial_handles, globals->global_handles_count()); |
| 12704 } | 12704 } |
| 12705 | 12705 |
| 12706 | 12706 |
| 12707 static void WeakApiCallback( | 12707 static void WeakApiCallback( |
| 12708 const v8::WeakCallbackData<v8::Object, Persistent<v8::Object> >& data) { | 12708 const v8::WeakCallbackData<v8::Object, Persistent<v8::Object> >& data) { |
| 12709 Local<Value> value = data.GetValue()->Get(v8_str("key")); | 12709 Local<Value> value = data.GetValue()->Get(v8_str("key")); |
| 12710 CHECK_EQ(231, static_cast<int32_t>(Local<v8::Integer>::Cast(value)->Value())); | 12710 CHECK_EQ(231, static_cast<int32_t>(Local<v8::Integer>::Cast(value)->Value())); |
| 12711 data.GetParameter()->Reset(); | 12711 data.GetParameter()->Reset(); |
| 12712 delete data.GetParameter(); | 12712 delete data.GetParameter(); |
| 12713 } | 12713 } |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13394 SimulateFullSpace(HEAP->code_space()); | 13394 SimulateFullSpace(HEAP->code_space()); |
| 13395 CompileRun(script); | 13395 CompileRun(script); |
| 13396 | 13396 |
| 13397 // Keep a strong reference to the code object in the handle scope. | 13397 // Keep a strong reference to the code object in the handle scope. |
| 13398 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( | 13398 i::Handle<i::Code> bar_code(i::Handle<i::JSFunction>::cast( |
| 13399 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); | 13399 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))))->code()); |
| 13400 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( | 13400 i::Handle<i::Code> foo_code(i::Handle<i::JSFunction>::cast( |
| 13401 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); | 13401 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))))->code()); |
| 13402 | 13402 |
| 13403 // Clear the compilation cache to get more wastage. | 13403 // Clear the compilation cache to get more wastage. |
| 13404 ISOLATE->compilation_cache()->Clear(); | 13404 reinterpret_cast<i::Isolate*>(isolate)->compilation_cache()->Clear(); |
| 13405 } | 13405 } |
| 13406 | 13406 |
| 13407 // Force code movement. | 13407 // Force code movement. |
| 13408 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); | 13408 HEAP->CollectAllAvailableGarbage("TestSetJitCodeEventHandler"); |
| 13409 | 13409 |
| 13410 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 13410 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); |
| 13411 | 13411 |
| 13412 CHECK_LE(kIterations, saw_bar); | 13412 CHECK_LE(kIterations, saw_bar); |
| 13413 CHECK_LT(0, move_events); | 13413 CHECK_LT(0, move_events); |
| 13414 | 13414 |
| (...skipping 6313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19728 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value); | 19728 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value); |
| 19729 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value); | 19729 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value); |
| 19730 i::Handle<i::Object> false_value = factory->false_value(); | 19730 i::Handle<i::Object> false_value = factory->false_value(); |
| 19731 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value); | 19731 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value); |
| 19732 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value); | 19732 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value); |
| 19733 } | 19733 } |
| 19734 | 19734 |
| 19735 | 19735 |
| 19736 TEST(IsolateEmbedderData) { | 19736 TEST(IsolateEmbedderData) { |
| 19737 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 19737 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 19738 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 19738 CHECK_EQ(NULL, isolate->GetData()); | 19739 CHECK_EQ(NULL, isolate->GetData()); |
| 19739 CHECK_EQ(NULL, ISOLATE->GetData()); | 19740 CHECK_EQ(NULL, i_isolate->GetData()); |
| 19740 static void* data1 = reinterpret_cast<void*>(0xacce55ed); | 19741 static void* data1 = reinterpret_cast<void*>(0xacce55ed); |
| 19741 isolate->SetData(data1); | 19742 isolate->SetData(data1); |
| 19742 CHECK_EQ(data1, isolate->GetData()); | 19743 CHECK_EQ(data1, isolate->GetData()); |
| 19743 CHECK_EQ(data1, ISOLATE->GetData()); | 19744 CHECK_EQ(data1, i_isolate->GetData()); |
| 19744 static void* data2 = reinterpret_cast<void*>(0xdecea5ed); | 19745 static void* data2 = reinterpret_cast<void*>(0xdecea5ed); |
| 19745 ISOLATE->SetData(data2); | 19746 i_isolate->SetData(data2); |
| 19746 CHECK_EQ(data2, isolate->GetData()); | 19747 CHECK_EQ(data2, isolate->GetData()); |
| 19747 CHECK_EQ(data2, ISOLATE->GetData()); | 19748 CHECK_EQ(data2, i_isolate->GetData()); |
| 19748 ISOLATE->TearDown(); | 19749 i_isolate->TearDown(); |
| 19749 CHECK_EQ(data2, isolate->GetData()); | 19750 CHECK_EQ(data2, isolate->GetData()); |
| 19750 CHECK_EQ(data2, ISOLATE->GetData()); | 19751 CHECK_EQ(data2, i_isolate->GetData()); |
| 19751 } | 19752 } |
| 19752 | 19753 |
| 19753 | 19754 |
| 19754 TEST(StringEmpty) { | 19755 TEST(StringEmpty) { |
| 19755 LocalContext context; | 19756 LocalContext context; |
| 19756 i::Factory* factory = i::Isolate::Current()->factory(); | 19757 i::Factory* factory = i::Isolate::Current()->factory(); |
| 19757 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 19758 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 19758 v8::HandleScope scope(isolate); | 19759 v8::HandleScope scope(isolate); |
| 19759 i::Handle<i::Object> empty_string = factory->empty_string(); | 19760 i::Handle<i::Object> empty_string = factory->empty_string(); |
| 19760 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); | 19761 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20579 // Verify function not cached | 20580 // Verify function not cached |
| 20580 int serial_number = | 20581 int serial_number = |
| 20581 i::Smi::cast(v8::Utils::OpenHandle(*func) | 20582 i::Smi::cast(v8::Utils::OpenHandle(*func) |
| 20582 ->shared()->get_api_func_data()->serial_number())->value(); | 20583 ->shared()->get_api_func_data()->serial_number())->value(); |
| 20583 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 20584 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 20584 i::Object* elm = i_isolate->native_context()->function_cache() | 20585 i::Object* elm = i_isolate->native_context()->function_cache() |
| 20585 ->GetElementNoExceptionThrown(i_isolate, serial_number); | 20586 ->GetElementNoExceptionThrown(i_isolate, serial_number); |
| 20586 CHECK(elm->IsNull()); | 20587 CHECK(elm->IsNull()); |
| 20587 } | 20588 } |
| 20588 | 20589 |
| OLD | NEW |