From 52d10a68cbd428f90e91e3dd91fa5c06acceac5b Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Fri, 25 Jan 2013 08:31:46 +0000 Subject: [PATCH] Add Isolate parameter to Persistent class. BUG=v8:2487 Review URL: https://codereview.chromium.org/12033011 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13501 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 225 +++++++++------ samples/lineprocessor.cc | 5 +- samples/process.cc | 18 +- samples/shell.cc | 2 +- src/api.cc | 85 +----- src/d8.cc | 31 ++- src/d8.h | 4 +- src/debug.cc | 28 +- src/debug.h | 8 +- src/deoptimizer.cc | 7 +- src/deoptimizer.h | 5 +- src/global-handles.cc | 61 +++-- src/global-handles.h | 3 +- src/handles.cc | 10 +- src/mksnapshot.cc | 2 +- src/profile-generator.cc | 9 +- src/profile-generator.h | 3 +- test/cctest/cctest.h | 5 +- test/cctest/test-api.cc | 485 ++++++++++++++++++--------------- test/cctest/test-debug.cc | 6 +- test/cctest/test-decls.cc | 4 +- test/cctest/test-heap-profiler.cc | 39 +-- test/cctest/test-heap.cc | 26 +- test/cctest/test-lockers.cc | 4 +- test/cctest/test-log.cc | 10 +- test/cctest/test-mark-compact.cc | 15 +- test/cctest/test-regexp.cc | 2 +- test/cctest/test-serialize.cc | 6 +- test/cctest/test-thread-termination.cc | 12 +- test/cctest/test-weakmaps.cc | 7 +- 30 files changed, 624 insertions(+), 503 deletions(-) diff --git a/include/v8.h b/include/v8.h index 5f3e2ed..bf3beff 100644 --- a/include/v8.h +++ b/include/v8.h @@ -157,6 +157,10 @@ class Isolate; typedef void (*WeakReferenceCallback)(Persistent object, void* parameter); +// TODO(svenpanne) Temporary definition until Chrome is in sync. +typedef void (*NearDeathCallback)(Isolate* isolate, + Persistent object, + void* parameter); // --- Handles --- @@ -389,11 +393,16 @@ template class Persistent : public Handle { return Persistent::Cast(*this); } + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(static Persistent New(Handle that)); + /** - * Creates a new persistent handle for an existing local or - * persistent handle. + * Creates a new persistent handle for an existing local or persistent handle. */ - V8_INLINE(static Persistent New(Handle that)); + V8_INLINE(static Persistent New(Isolate* isolate, Handle that)); + + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(void Dispose()); /** * Releases the storage cell referenced by this persistent handle. @@ -401,66 +410,87 @@ template class Persistent : public Handle { * This handle's reference, and any other references to the storage * cell remain and IsEmpty will still return false. */ - V8_INLINE(void Dispose()); V8_INLINE(void Dispose(Isolate* isolate)); + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(void MakeWeak(void* parameters, + WeakReferenceCallback callback)); + /** * Make the reference to this object weak. When only weak handles * refer to the object, the garbage collector will perform a - * callback to the given V8::WeakReferenceCallback function, passing + * callback to the given V8::NearDeathCallback function, passing * it the object reference and the given parameters. */ - V8_INLINE(void MakeWeak(void* parameters, WeakReferenceCallback callback)); V8_INLINE(void MakeWeak(Isolate* isolate, void* parameters, - WeakReferenceCallback callback)); + NearDeathCallback callback)); + + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(void ClearWeak()); /** Clears the weak reference to this object. */ - V8_INLINE(void ClearWeak()); + V8_INLINE(void ClearWeak(Isolate* isolate)); + + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(void MarkIndependent()); /** - * Marks the reference to this object independent. Garbage collector - * is free to ignore any object groups containing this object. - * Weak callback for an independent handle should not - * assume that it will be preceded by a global GC prologue callback - * or followed by a global GC epilogue callback. + * Marks the reference to this object independent. Garbage collector is free + * to ignore any object groups containing this object. Weak callback for an + * independent handle should not assume that it will be preceded by a global + * GC prologue callback or followed by a global GC epilogue callback. */ - V8_INLINE(void MarkIndependent()); V8_INLINE(void MarkIndependent(Isolate* isolate)); + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(void MarkPartiallyDependent()); + /** - * Marks the reference to this object partially dependent. Partially - * dependent handles only depend on other partially dependent handles and - * these dependencies are provided through object groups. It provides a way - * to build smaller object groups for young objects that represent only a - * subset of all external dependencies. This mark is automatically cleared - * after each garbage collection. + * Marks the reference to this object partially dependent. Partially dependent + * handles only depend on other partially dependent handles and these + * dependencies are provided through object groups. It provides a way to build + * smaller object groups for young objects that represent only a subset of all + * external dependencies. This mark is automatically cleared after each + * garbage collection. */ - V8_INLINE(void MarkPartiallyDependent()); V8_INLINE(void MarkPartiallyDependent(Isolate* isolate)); + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(bool IsIndependent() const); + /** Returns true if this handle was previously marked as independent. */ - V8_INLINE(bool IsIndependent() const); V8_INLINE(bool IsIndependent(Isolate* isolate) const); + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(bool IsNearDeath() const); + /** Checks if the handle holds the only reference to an object. */ - V8_INLINE(bool IsNearDeath() const); + V8_INLINE(bool IsNearDeath(Isolate* isolate) const); + + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(bool IsWeak() const); /** Returns true if the handle's reference is weak. */ - V8_INLINE(bool IsWeak() const); V8_INLINE(bool IsWeak(Isolate* isolate) const); + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(void SetWrapperClassId(uint16_t class_id)); + /** - * Assigns a wrapper class ID to the handle. See RetainedObjectInfo - * interface description in v8-profiler.h for details. + * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface + * description in v8-profiler.h for details. */ - V8_INLINE(void SetWrapperClassId(uint16_t class_id)); + V8_INLINE(void SetWrapperClassId(Isolate* isolate, uint16_t class_id)); + + /** Deprecated. Use Isolate version instead. */ + V8_DEPRECATED(uint16_t WrapperClassId() const); /** - * Returns the class ID previously assigned to this handle or 0 if no class - * ID was previously assigned. + * Returns the class ID previously assigned to this handle or 0 if no class ID + * was previously assigned. */ - V8_INLINE(uint16_t WrapperClassId() const); + V8_INLINE(uint16_t WrapperClassId(Isolate* isolate) const); private: friend class ImplementationUtilities; @@ -3529,31 +3559,17 @@ class V8EXPORT V8 { private: V8(); - static internal::Object** GlobalizeReference(internal::Object** handle); - static void DisposeGlobal(internal::Object** global_handle); + static internal::Object** GlobalizeReference(internal::Isolate* isolate, + internal::Object** handle); static void DisposeGlobal(internal::Isolate* isolate, internal::Object** global_handle); - static void MakeWeak(internal::Object** global_handle, - void* data, - WeakReferenceCallback); static void MakeWeak(internal::Isolate* isolate, internal::Object** global_handle, void* data, - WeakReferenceCallback); - static void ClearWeak(internal::Object** global_handle); - static void MarkIndependent(internal::Object** global_handle); - static void MarkIndependent(internal::Isolate* isolate, - internal::Object** global_handle); - static void MarkPartiallyDependent(internal::Object** global_handle); - static void MarkPartiallyDependent(internal::Isolate* isolate, - internal::Object** global_handle); - static bool IsGlobalIndependent(internal::Object** global_handle); - static bool IsGlobalIndependent(internal::Isolate* isolate, - internal::Object** global_handle); - static bool IsGlobalNearDeath(internal::Object** global_handle); - static bool IsGlobalWeak(internal::Object** global_handle); - static bool IsGlobalWeak(internal::Isolate* isolate, - internal::Object** global_handle); + WeakReferenceCallback weak_reference_callback, + NearDeathCallback near_death_callback); + static void ClearWeak(internal::Isolate* isolate, + internal::Object** global_handle); template friend class Handle; template friend class Local; @@ -3974,9 +3990,7 @@ class V8EXPORT Unlocker { */ V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } - /** - * Deprecated. Use Isolate version instead. - */ + /** Deprecated. Use Isolate version instead. */ V8_DEPRECATED(Unlocker()); ~Unlocker(); @@ -3994,9 +4008,7 @@ class V8EXPORT Locker { */ V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } - /** - * Deprecated. Use Isolate version instead. - */ + /** Deprecated. Use Isolate version instead. */ V8_DEPRECATED(Locker()); ~Locker(); @@ -4175,14 +4187,17 @@ class Internals { static const int kIsolateStateOffset = 0; static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; static const int kIsolateRootsOffset = 3 * kApiPointerSize; - static const int kNodeClassIdOffset = 1 * kApiPointerSize; - static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; static const int kUndefinedValueRootIndex = 5; static const int kNullValueRootIndex = 7; static const int kTrueValueRootIndex = 8; static const int kFalseValueRootIndex = 9; static const int kEmptySymbolRootIndex = 119; + static const int kNodeClassIdOffset = 1 * kApiPointerSize; + static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; + static const int kNodeStateMask = 0xf; + static const int kNodeStateIsWeakValue = 2; + static const int kNodeStateIsNearDeathValue = 4; static const int kNodeIsIndependentShift = 4; static const int kNodeIsPartiallyDependentShift = 5; @@ -4236,6 +4251,17 @@ class Internals { *addr = (*addr & ~mask) | (value << shift); } + V8_INLINE(static uint8_t GetNodeState(internal::Object** obj)) { + uint8_t* addr = reinterpret_cast(obj) + kNodeFlagsOffset; + return *addr & kNodeStateMask; + } + + V8_INLINE(static void UpdateNodeState(internal::Object** obj, + uint8_t value)) { + uint8_t* addr = reinterpret_cast(obj) + kNodeFlagsOffset; + *addr = (*addr & ~kNodeStateMask) | value; + } + V8_INLINE(static void SetEmbedderData(v8::Isolate* isolate, void* data)) { uint8_t* addr = reinterpret_cast(isolate) + kIsolateEmbedderDataOffset; @@ -4303,7 +4329,7 @@ Local Local::New(Handle that) { template - Local Local::New(Isolate* isolate, Handle that) { +Local Local::New(Isolate* isolate, Handle that) { if (that.IsEmpty()) return Local(); T* that_ptr = *that; internal::Object** p = reinterpret_cast(that_ptr); @@ -4314,16 +4340,23 @@ template template Persistent Persistent::New(Handle that) { + return New(Isolate::GetCurrent(), that); +} + + +template +Persistent Persistent::New(Isolate* isolate, Handle that) { if (that.IsEmpty()) return Persistent(); internal::Object** p = reinterpret_cast(*that); - return Persistent(reinterpret_cast(V8::GlobalizeReference(p))); + return Persistent(reinterpret_cast( + V8::GlobalizeReference(reinterpret_cast(isolate), + p))); } template bool Persistent::IsIndependent() const { - if (this->IsEmpty()) return false; - return V8::IsGlobalIndependent(reinterpret_cast(**this)); + return IsIndependent(Isolate::GetCurrent()); } @@ -4339,30 +4372,39 @@ bool Persistent::IsIndependent(Isolate* isolate) const { template bool Persistent::IsNearDeath() const { + return IsNearDeath(Isolate::GetCurrent()); +} + + +template +bool Persistent::IsNearDeath(Isolate* isolate) const { + typedef internal::Internals I; if (this->IsEmpty()) return false; - return V8::IsGlobalNearDeath(reinterpret_cast(**this)); + if (!I::IsInitialized(isolate)) return false; + return I::GetNodeState(reinterpret_cast(**this)) == + I::kNodeStateIsNearDeathValue; } template bool Persistent::IsWeak() const { - if (this->IsEmpty()) return false; - return V8::IsGlobalWeak(reinterpret_cast(**this)); + return IsWeak(Isolate::GetCurrent()); } template bool Persistent::IsWeak(Isolate* isolate) const { + typedef internal::Internals I; if (this->IsEmpty()) return false; - return V8::IsGlobalWeak(reinterpret_cast(isolate), - reinterpret_cast(**this)); + if (!I::IsInitialized(isolate)) return false; + return I::GetNodeState(reinterpret_cast(**this)) == + I::kNodeStateIsWeakValue; } template void Persistent::Dispose() { - if (this->IsEmpty()) return; - V8::DisposeGlobal(reinterpret_cast(**this)); + Dispose(Isolate::GetCurrent()); } @@ -4379,28 +4421,39 @@ Persistent::Persistent() : Handle() { } template void Persistent::MakeWeak(void* parameters, WeakReferenceCallback callback) { - V8::MakeWeak(reinterpret_cast(**this), + Isolate* isolate = Isolate::GetCurrent(); + V8::MakeWeak(reinterpret_cast(isolate), + reinterpret_cast(**this), parameters, - callback); + callback, + NULL); } template -void Persistent::MakeWeak(Isolate* isolate, void* parameters, - WeakReferenceCallback callback) { +void Persistent::MakeWeak(Isolate* isolate, + void* parameters, + NearDeathCallback callback) { V8::MakeWeak(reinterpret_cast(isolate), reinterpret_cast(**this), parameters, + NULL, callback); } template void Persistent::ClearWeak() { - V8::ClearWeak(reinterpret_cast(**this)); + ClearWeak(Isolate::GetCurrent()); +} + +template +void Persistent::ClearWeak(Isolate* isolate) { + V8::ClearWeak(reinterpret_cast(isolate), + reinterpret_cast(**this)); } template void Persistent::MarkIndependent() { - V8::MarkIndependent(reinterpret_cast(**this)); + MarkIndependent(Isolate::GetCurrent()); } template @@ -4409,12 +4462,13 @@ void Persistent::MarkIndependent(Isolate* isolate) { if (this->IsEmpty()) return; if (!I::IsInitialized(isolate)) return; I::UpdateNodeFlag(reinterpret_cast(**this), - true, I::kNodeIsIndependentShift); + true, + I::kNodeIsIndependentShift); } template void Persistent::MarkPartiallyDependent() { - V8::MarkPartiallyDependent(reinterpret_cast(**this)); + MarkPartiallyDependent(Isolate::GetCurrent()); } template @@ -4423,12 +4477,20 @@ void Persistent::MarkPartiallyDependent(Isolate* isolate) { if (this->IsEmpty()) return; if (!I::IsInitialized(isolate)) return; I::UpdateNodeFlag(reinterpret_cast(**this), - true, I::kNodeIsPartiallyDependentShift); + true, + I::kNodeIsPartiallyDependentShift); } template void Persistent::SetWrapperClassId(uint16_t class_id) { + SetWrapperClassId(Isolate::GetCurrent(), class_id); +} + +template +void Persistent::SetWrapperClassId(Isolate* isolate, uint16_t class_id) { typedef internal::Internals I; + if (this->IsEmpty()) return; + if (!I::IsInitialized(isolate)) return; internal::Object** obj = reinterpret_cast(**this); uint8_t* addr = reinterpret_cast(obj) + I::kNodeClassIdOffset; *reinterpret_cast(addr) = class_id; @@ -4436,7 +4498,14 @@ void Persistent::SetWrapperClassId(uint16_t class_id) { template uint16_t Persistent::WrapperClassId() const { + return WrapperClassId(Isolate::GetCurrent()); +} + +template +uint16_t Persistent::WrapperClassId(Isolate* isolate) const { typedef internal::Internals I; + if (this->IsEmpty()) return 0; + if (!I::IsInitialized(isolate)) return 0; internal::Object** obj = reinterpret_cast(**this); uint8_t* addr = reinterpret_cast(obj) + I::kNodeClassIdOffset; return *reinterpret_cast(addr); diff --git a/samples/lineprocessor.cc b/samples/lineprocessor.cc index 4fc28b7..6549f4c 100644 --- a/samples/lineprocessor.cc +++ b/samples/lineprocessor.cc @@ -212,9 +212,10 @@ int RunMain(int argc, char* argv[]) { v8::Context::Scope context_scope(context); #ifdef ENABLE_DEBUGGER_SUPPORT - debug_message_context = v8::Persistent::New(context); + debug_message_context = + v8::Persistent::New(context->GetIsolate(), context); - v8::Locker locker(v8::Isolate::GetCurrent()); + v8::Locker locker(context->GetIsolate()); if (support_callback) { v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); diff --git a/samples/process.cc b/samples/process.cc index ae6a550..c3d1773 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -116,11 +116,13 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { // Utility methods for wrapping C++ objects as JavaScript objects, // and going back again. - static Handle WrapMap(map* obj); + Handle WrapMap(map* obj); static map* UnwrapMap(Handle obj); - static Handle WrapRequest(HttpRequest* obj); + Handle WrapRequest(HttpRequest* obj); static HttpRequest* UnwrapRequest(Handle obj); + Isolate* GetIsolate() { return context_->GetIsolate(); } + Handle script_; Persistent context_; Persistent process_; @@ -187,7 +189,7 @@ bool JsHttpRequestProcessor::Initialize(map* opts, // Store the function in a Persistent handle, since we also want // that to remain after this call returns - process_ = Persistent::New(process_fun); + process_ = Persistent::New(GetIsolate(), process_fun); // All done; all went well return true; @@ -273,8 +275,9 @@ JsHttpRequestProcessor::~JsHttpRequestProcessor() { // Dispose the persistent handles. When noone else has any // references to the objects stored in the handles they will be // automatically reclaimed. - context_.Dispose(); - process_.Dispose(); + v8::Isolate* isolate = GetIsolate(); + context_.Dispose(isolate); + process_.Dispose(isolate); } @@ -296,7 +299,7 @@ Handle JsHttpRequestProcessor::WrapMap(map* obj) { // It only has to be created once, which we do on demand. if (map_template_.IsEmpty()) { Handle raw_template = MakeMapTemplate(); - map_template_ = Persistent::New(raw_template); + map_template_ = Persistent::New(GetIsolate(), raw_template); } Handle templ = map_template_; @@ -401,7 +404,8 @@ Handle JsHttpRequestProcessor::WrapRequest(HttpRequest* request) { // It only has to be created once, which we do on demand. if (request_template_.IsEmpty()) { Handle raw_template = MakeRequestTemplate(); - request_template_ = Persistent::New(raw_template); + request_template_ = + Persistent::New(GetIsolate(), raw_template); } Handle templ = request_template_; diff --git a/samples/shell.cc b/samples/shell.cc index 62f4045..e9057f9 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -79,7 +79,7 @@ int main(int argc, char* argv[]) { result = RunMain(argc, argv); if (run_shell) RunShell(context); context->Exit(); - context.Dispose(); + context.Dispose(context->GetIsolate()); } v8::V8::Dispose(); return result; diff --git a/src/api.cc b/src/api.cc index 1561f24..d3d472d 100644 --- a/src/api.cc +++ b/src/api.cc @@ -626,95 +626,34 @@ bool SetResourceConstraints(ResourceConstraints* constraints) { } -i::Object** V8::GlobalizeReference(i::Object** obj) { - i::Isolate* isolate = i::Isolate::Current(); +i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL; LOG_API(isolate, "Persistent::New"); - i::Handle result = - isolate->global_handles()->Create(*obj); + i::Handle result = isolate->global_handles()->Create(*obj); return result.location(); } -void V8::MakeWeak(i::Object** object, void* parameters, - WeakReferenceCallback callback) { - i::Isolate* isolate = i::Isolate::Current(); - LOG_API(isolate, "MakeWeak"); - isolate->global_handles()->MakeWeak(object, parameters, - callback); -} - - -void V8::MakeWeak(i::Isolate* isolate, i::Object** object, - void* parameters, WeakReferenceCallback callback) { +void V8::MakeWeak(i::Isolate* isolate, + i::Object** object, + void* parameters, + WeakReferenceCallback weak_reference_callback, + NearDeathCallback near_death_callback) { ASSERT(isolate == i::Isolate::Current()); LOG_API(isolate, "MakeWeak"); - isolate->global_handles()->MakeWeak(object, parameters, - callback); + isolate->global_handles()->MakeWeak(object, + parameters, + weak_reference_callback, + near_death_callback); } -void V8::ClearWeak(i::Object** obj) { - i::Isolate* isolate = i::Isolate::Current(); +void V8::ClearWeak(i::Isolate* isolate, i::Object** obj) { LOG_API(isolate, "ClearWeak"); isolate->global_handles()->ClearWeakness(obj); } -void V8::MarkIndependent(i::Object** object) { - i::Isolate* isolate = i::Isolate::Current(); - LOG_API(isolate, "MarkIndependent"); - isolate->global_handles()->MarkIndependent(object); -} - - -void V8::MarkPartiallyDependent(i::Object** object) { - i::Isolate* isolate = i::Isolate::Current(); - LOG_API(isolate, "MarkPartiallyDependent"); - isolate->global_handles()->MarkPartiallyDependent(object); -} - - -bool V8::IsGlobalIndependent(i::Object** obj) { - i::Isolate* isolate = i::Isolate::Current(); - LOG_API(isolate, "IsGlobalIndependent"); - if (!isolate->IsInitialized()) return false; - return i::GlobalHandles::IsIndependent(obj); -} - - -bool V8::IsGlobalNearDeath(i::Object** obj) { - i::Isolate* isolate = i::Isolate::Current(); - LOG_API(isolate, "IsGlobalNearDeath"); - if (!isolate->IsInitialized()) return false; - return i::GlobalHandles::IsNearDeath(obj); -} - - -bool V8::IsGlobalWeak(i::Object** obj) { - i::Isolate* isolate = i::Isolate::Current(); - LOG_API(isolate, "IsGlobalWeak"); - if (!isolate->IsInitialized()) return false; - return i::GlobalHandles::IsWeak(obj); -} - - -bool V8::IsGlobalWeak(i::Isolate* isolate, i::Object** obj) { - ASSERT(isolate == i::Isolate::Current()); - LOG_API(isolate, "IsGlobalWeak"); - if (!isolate->IsInitialized()) return false; - return i::GlobalHandles::IsWeak(obj); -} - - -void V8::DisposeGlobal(i::Object** obj) { - i::Isolate* isolate = i::Isolate::Current(); - LOG_API(isolate, "DisposeGlobal"); - if (!isolate->IsInitialized()) return; - isolate->global_handles()->Destroy(obj); -} - - void V8::DisposeGlobal(i::Isolate* isolate, i::Object** obj) { ASSERT(isolate == i::Isolate::Current()); LOG_API(isolate, "DisposeGlobal"); diff --git a/src/d8.cc b/src/d8.cc index 407488f..6d63ef1 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -95,14 +95,14 @@ class Symbols { explicit Symbols(Isolate* isolate) : isolate_(isolate) { HandleScope scope; #define INIT_SYMBOL(name, value) \ - name##_ = Persistent::New(String::NewSymbol(value)); + name##_ = Persistent::New(isolate, String::NewSymbol(value)); FOR_EACH_SYMBOL(INIT_SYMBOL) #undef INIT_SYMBOL isolate->SetData(this); } ~Symbols() { -#define DISPOSE_SYMBOL(name, value) name##_.Dispose(); +#define DISPOSE_SYMBOL(name, value) name##_.Dispose(isolate_); FOR_EACH_SYMBOL(DISPOSE_SYMBOL) #undef DISPOSE_SYMBOL isolate_->SetData(NULL); // Not really needed, just to be sure... @@ -399,9 +399,10 @@ Handle Shell::CreateExternalArrayBuffer(Isolate* isolate, memset(data, 0, length); buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); - Persistent persistent_array = Persistent::New(buffer); - persistent_array.MakeWeak(data, ExternalArrayWeakCallback); - persistent_array.MarkIndependent(); + Persistent persistent_array = + Persistent::New(isolate, buffer); + persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback); + persistent_array.MarkIndependent(isolate); V8::AdjustAmountOfExternalAllocatedMemory(length); buffer->SetIndexedPropertiesToExternalArrayData( @@ -826,14 +827,15 @@ Handle Shell::ArraySet(const Arguments& args) { } -void Shell::ExternalArrayWeakCallback(Persistent object, void* data) { +void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate, + Persistent object, + void* data) { HandleScope scope; - Isolate* isolate = Isolate::GetCurrent(); int32_t length = object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value(); V8::AdjustAmountOfExternalAllocatedMemory(-length); delete[] static_cast(data); - object.Dispose(); + object.Dispose(isolate); } @@ -1442,9 +1444,10 @@ Handle Shell::ReadBuffer(const Arguments& args) { Isolate* isolate = args.GetIsolate(); Handle buffer = Object::New(); buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); - Persistent persistent_buffer = Persistent::New(buffer); - persistent_buffer.MakeWeak(data, ExternalArrayWeakCallback); - persistent_buffer.MarkIndependent(); + Persistent persistent_buffer = + Persistent::New(isolate, buffer); + persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback); + persistent_buffer.MarkIndependent(isolate); V8::AdjustAmountOfExternalAllocatedMemory(length); buffer->SetIndexedPropertiesToExternalArrayData( @@ -1565,7 +1568,7 @@ void ShellThread::Run() { Shell::ExecuteString(str, String::New(filename), false, false); } - thread_context.Dispose(); + thread_context.Dispose(thread_context->GetIsolate()); ptr = next_line; } } @@ -1649,7 +1652,7 @@ void SourceGroup::ExecuteInThread() { Context::Scope cscope(context); Execute(isolate); } - context.Dispose(); + context.Dispose(isolate); if (Shell::options.send_idle_notification) { const int kLongIdlePauseInMs = 1000; V8::ContextDisposedNotification(); @@ -1858,7 +1861,7 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) { options.isolate_sources[0].Execute(isolate); } if (!options.last_run) { - context.Dispose(); + context.Dispose(isolate); if (options.send_idle_notification) { const int kLongIdlePauseInMs = 1000; V8::ContextDisposedNotification(); diff --git a/src/d8.h b/src/d8.h index 63efd66..1c3ce0a 100644 --- a/src/d8.h +++ b/src/d8.h @@ -404,7 +404,9 @@ class Shell : public i::AllStatic { static Handle CreateExternalArray(const Arguments& args, ExternalArrayType type, int32_t element_size); - static void ExternalArrayWeakCallback(Persistent object, void* data); + static void ExternalArrayWeakCallback(Isolate* isolate, + Persistent object, + void* data); }; diff --git a/src/debug.cc b/src/debug.cc index 7baed88..866839d 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -617,10 +617,10 @@ void ScriptCache::Add(Handle