Index: src/handles.cc |
diff --git a/src/handles.cc b/src/handles.cc |
index 3bc1f4bea03d831cf802c453eb69c15e6a13f49f..855997ec3fca354ccdd3c027bfc0819e21b95e08 100644 |
--- a/src/handles.cc |
+++ b/src/handles.cc |
@@ -375,6 +375,15 @@ Handle<JSValue> GetScriptWrapper(Handle<Script> script) { |
Handle<JSFunction> constructor = isolate->script_function(); |
Handle<JSValue> result = |
Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
+ |
+ // The allocation might have triggered a GC, which could have called this |
+ // function recursively, and a wrapper has already been created and cached. |
+ // In that case, simply return the cached wrapper. |
+ if (script->wrapper()->foreign_address() != NULL) { |
+ return Handle<JSValue>( |
+ reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); |
+ } |
+ |
result->set_value(*script); |
// Create a new weak global handle and use it to cache the wrapper |