| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // Return the script wrapper directly from the cache. | 368 // Return the script wrapper directly from the cache. |
| 369 return Handle<JSValue>( | 369 return Handle<JSValue>( |
| 370 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); | 370 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); |
| 371 } | 371 } |
| 372 Isolate* isolate = Isolate::Current(); | 372 Isolate* isolate = Isolate::Current(); |
| 373 // Construct a new script wrapper. | 373 // Construct a new script wrapper. |
| 374 isolate->counters()->script_wrappers()->Increment(); | 374 isolate->counters()->script_wrappers()->Increment(); |
| 375 Handle<JSFunction> constructor = isolate->script_function(); | 375 Handle<JSFunction> constructor = isolate->script_function(); |
| 376 Handle<JSValue> result = | 376 Handle<JSValue> result = |
| 377 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); | 377 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
| 378 | |
| 379 // The allocation might have triggered a GC, which could have called this | |
| 380 // function recursively, and a wrapper has already been created and cached. | |
| 381 // In that case, simply return the cached wrapper. | |
| 382 if (script->wrapper()->foreign_address() != NULL) { | |
| 383 return Handle<JSValue>( | |
| 384 reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); | |
| 385 } | |
| 386 | |
| 387 result->set_value(*script); | 378 result->set_value(*script); |
| 388 | 379 |
| 389 // Create a new weak global handle and use it to cache the wrapper | 380 // Create a new weak global handle and use it to cache the wrapper |
| 390 // for future use. The cache will automatically be cleared by the | 381 // for future use. The cache will automatically be cleared by the |
| 391 // garbage collector when it is not used anymore. | 382 // garbage collector when it is not used anymore. |
| 392 Handle<Object> handle = isolate->global_handles()->Create(*result); | 383 Handle<Object> handle = isolate->global_handles()->Create(*result); |
| 393 isolate->global_handles()->MakeWeak(handle.location(), NULL, | 384 isolate->global_handles()->MakeWeak(handle.location(), NULL, |
| 394 &ClearWrapperCache); | 385 &ClearWrapperCache); |
| 395 script->wrapper()->set_foreign_address( | 386 script->wrapper()->set_foreign_address( |
| 396 reinterpret_cast<Address>(handle.location())); | 387 reinterpret_cast<Address>(handle.location())); |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 data->next = prev_next_; | 919 data->next = prev_next_; |
| 929 data->limit = prev_limit_; | 920 data->limit = prev_limit_; |
| 930 #ifdef DEBUG | 921 #ifdef DEBUG |
| 931 handles_detached_ = true; | 922 handles_detached_ = true; |
| 932 #endif | 923 #endif |
| 933 return deferred; | 924 return deferred; |
| 934 } | 925 } |
| 935 | 926 |
| 936 | 927 |
| 937 } } // namespace v8::internal | 928 } } // namespace v8::internal |
| OLD | NEW |