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 |
378 result->set_value(*script); | 387 result->set_value(*script); |
379 | 388 |
380 // Create a new weak global handle and use it to cache the wrapper | 389 // Create a new weak global handle and use it to cache the wrapper |
381 // for future use. The cache will automatically be cleared by the | 390 // for future use. The cache will automatically be cleared by the |
382 // garbage collector when it is not used anymore. | 391 // garbage collector when it is not used anymore. |
383 Handle<Object> handle = isolate->global_handles()->Create(*result); | 392 Handle<Object> handle = isolate->global_handles()->Create(*result); |
384 isolate->global_handles()->MakeWeak(handle.location(), NULL, | 393 isolate->global_handles()->MakeWeak(handle.location(), NULL, |
385 &ClearWrapperCache); | 394 &ClearWrapperCache); |
386 script->wrapper()->set_foreign_address( | 395 script->wrapper()->set_foreign_address( |
387 reinterpret_cast<Address>(handle.location())); | 396 reinterpret_cast<Address>(handle.location())); |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 data->next = prev_next_; | 1087 data->next = prev_next_; |
1079 data->limit = prev_limit_; | 1088 data->limit = prev_limit_; |
1080 #ifdef DEBUG | 1089 #ifdef DEBUG |
1081 handles_detached_ = true; | 1090 handles_detached_ = true; |
1082 #endif | 1091 #endif |
1083 return deferred; | 1092 return deferred; |
1084 } | 1093 } |
1085 | 1094 |
1086 | 1095 |
1087 } } // namespace v8::internal | 1096 } } // namespace v8::internal |
OLD | NEW |