From a48ae1d629f4c7939f3421db969f43db6bab8e11 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 11 Sep 2013 09:14:33 +0200 Subject: Fix rare crash when calling SetExternalResource This is a patch on top of the original patch that adds support for external resources to v8::Object. When the provided external resource pointer cannot be encoded in SMI, then we need to allocate an object on the heap to hold it. That in turn may trigger a garbage collection, which in turn may end up collecting the object itself. Similarly to other methods dealing with the allocation of i::Foreign, the insertion of a HandleScope is required. Done-with: Lars Task-Number: QTBUG-29127 Change-Id: I9a99998e2fbfcb8a4c1e31595344680123072c6b Reviewed-by: Andy Shaw Reviewed-by: Lars Knoll --- src/3rdparty/v8/src/api.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/3rdparty/v8/src/api.cc b/src/3rdparty/v8/src/api.cc index cbb3a04..baa5b0a 100644 --- a/src/3rdparty/v8/src/api.cc +++ b/src/3rdparty/v8/src/api.cc @@ -4421,11 +4421,13 @@ void v8::Object::SetPointerInInternalField(int index, void* value) { void v8::Object::SetExternalResource(v8::Object::ExternalResource *resource) { i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); ENTER_V8(isolate); + HandleScope scope; i::Handle obj = Utils::OpenHandle(this); if (CanBeEncodedAsSmi(resource)) { obj->SetExternalResourceObject(EncodeAsSmi(resource)); } else { - obj->SetExternalResourceObject(*isolate->factory()->NewForeign(static_cast((void *)resource))); + i::Handle foreign = isolate->factory()->NewForeign(static_cast((void *)resource)); + obj->SetExternalResourceObject(*foreign); } if (!obj->IsSymbol()) { isolate->heap()->external_string_table()->AddObject(*obj); -- cgit v1.2.1