| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 return Handle<JSValue>( | 168 return Handle<JSValue>( |
| 169 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); | 169 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); |
| 170 } | 170 } |
| 171 Isolate* isolate = script->GetIsolate(); | 171 Isolate* isolate = script->GetIsolate(); |
| 172 // Construct a new script wrapper. | 172 // Construct a new script wrapper. |
| 173 isolate->counters()->script_wrappers()->Increment(); | 173 isolate->counters()->script_wrappers()->Increment(); |
| 174 Handle<JSFunction> constructor = isolate->script_function(); | 174 Handle<JSFunction> constructor = isolate->script_function(); |
| 175 Handle<JSValue> result = | 175 Handle<JSValue> result = |
| 176 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); | 176 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
| 177 | 177 |
| 178 // The allocation might have triggered a GC, which could have called this | |
| 179 // function recursively, and a wrapper has already been created and cached. | |
| 180 // In that case, simply return a handle for the cached wrapper. | |
| 181 if (script->wrapper()->foreign_address() != NULL) { | |
| 182 return Handle<JSValue>( | |
| 183 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); | |
| 184 } | |
| 185 | |
| 186 result->set_value(*script); | 178 result->set_value(*script); |
| 187 | 179 |
| 188 // Create a new weak global handle and use it to cache the wrapper | 180 // Create a new weak global handle and use it to cache the wrapper |
| 189 // for future use. The cache will automatically be cleared by the | 181 // for future use. The cache will automatically be cleared by the |
| 190 // garbage collector when it is not used anymore. | 182 // garbage collector when it is not used anymore. |
| 191 Handle<Object> handle = isolate->global_handles()->Create(*result); | 183 Handle<Object> handle = isolate->global_handles()->Create(*result); |
| 192 GlobalHandles::MakeWeak(handle.location(), | 184 GlobalHandles::MakeWeak(handle.location(), |
| 193 reinterpret_cast<void*>(handle.location()), | 185 reinterpret_cast<void*>(handle.location()), |
| 194 &ClearWrapperCache); | 186 &ClearWrapperCache); |
| 195 script->wrapper()->set_foreign_address( | 187 script->wrapper()->set_foreign_address( |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 Handle<Code> code) { | 706 Handle<Code> code) { |
| 715 heap->EnsureWeakObjectToCodeTable(); | 707 heap->EnsureWeakObjectToCodeTable(); |
| 716 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); | 708 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); |
| 717 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); | 709 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); |
| 718 CALL_HEAP_FUNCTION_VOID(heap->isolate(), | 710 CALL_HEAP_FUNCTION_VOID(heap->isolate(), |
| 719 heap->AddWeakObjectToCodeDependency(*object, *dep)); | 711 heap->AddWeakObjectToCodeDependency(*object, *dep)); |
| 720 } | 712 } |
| 721 | 713 |
| 722 | 714 |
| 723 } } // namespace v8::internal | 715 } } // namespace v8::internal |
| OLD | NEW |