| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
| (...skipping 10266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10277 return result; | 10277 return result; |
| 10278 } | 10278 } |
| 10279 | 10279 |
| 10280 | 10280 |
| 10281 // Wrappers for scripts are kept alive and cached in weak global | 10281 // Wrappers for scripts are kept alive and cached in weak global |
| 10282 // handles referred from foreign objects held by the scripts as long as | 10282 // handles referred from foreign objects held by the scripts as long as |
| 10283 // they are used. When they are not used anymore, the garbage | 10283 // they are used. When they are not used anymore, the garbage |
| 10284 // collector will call the weak callback on the global handle | 10284 // collector will call the weak callback on the global handle |
| 10285 // associated with the wrapper and get rid of both the wrapper and the | 10285 // associated with the wrapper and get rid of both the wrapper and the |
| 10286 // handle. | 10286 // handle. |
| 10287 static void ClearWrapperCache( | 10287 static void ClearWrapperCacheWeakCallback( |
| 10288 const v8::WeakCallbackData<v8::Value, void>& data) { | 10288 const v8::WeakCallbackData<v8::Value, void>& data) { |
| 10289 Object** location = reinterpret_cast<Object**>(data.GetParameter()); | 10289 Object** location = reinterpret_cast<Object**>(data.GetParameter()); |
| 10290 JSValue* wrapper = JSValue::cast(*location); | 10290 JSValue* wrapper = JSValue::cast(*location); |
| 10291 Foreign* foreign = Script::cast(wrapper->value())->wrapper(); | 10291 Script::cast(wrapper->value())->ClearWrapperCache(); |
| 10292 } |
| 10293 |
| 10294 |
| 10295 void Script::ClearWrapperCache() { |
| 10296 Foreign* foreign = wrapper(); |
| 10297 Object** location = reinterpret_cast<Object**>(foreign->foreign_address()); |
| 10292 ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location)); | 10298 ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location)); |
| 10293 foreign->set_foreign_address(0); | 10299 foreign->set_foreign_address(0); |
| 10294 GlobalHandles::Destroy(location); | 10300 GlobalHandles::Destroy(location); |
| 10295 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); | 10301 GetIsolate()->counters()->script_wrappers()->Decrement(); |
| 10296 isolate->counters()->script_wrappers()->Decrement(); | |
| 10297 } | 10302 } |
| 10298 | 10303 |
| 10299 | 10304 |
| 10300 Handle<JSObject> Script::GetWrapper(Handle<Script> script) { | 10305 Handle<JSObject> Script::GetWrapper(Handle<Script> script) { |
| 10301 if (script->wrapper()->foreign_address() != NULL) { | 10306 if (script->wrapper()->foreign_address() != NULL) { |
| 10302 // Return a handle for the existing script wrapper from the cache. | 10307 // Return a handle for the existing script wrapper from the cache. |
| 10303 return Handle<JSValue>( | 10308 return Handle<JSValue>( |
| 10304 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); | 10309 *reinterpret_cast<JSValue**>(script->wrapper()->foreign_address())); |
| 10305 } | 10310 } |
| 10306 Isolate* isolate = script->GetIsolate(); | 10311 Isolate* isolate = script->GetIsolate(); |
| 10307 // Construct a new script wrapper. | 10312 // Construct a new script wrapper. |
| 10308 isolate->counters()->script_wrappers()->Increment(); | 10313 isolate->counters()->script_wrappers()->Increment(); |
| 10309 Handle<JSFunction> constructor = isolate->script_function(); | 10314 Handle<JSFunction> constructor = isolate->script_function(); |
| 10310 Handle<JSValue> result = | 10315 Handle<JSValue> result = |
| 10311 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); | 10316 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
| 10312 | 10317 |
| 10313 result->set_value(*script); | 10318 result->set_value(*script); |
| 10314 | 10319 |
| 10315 // Create a new weak global handle and use it to cache the wrapper | 10320 // Create a new weak global handle and use it to cache the wrapper |
| 10316 // for future use. The cache will automatically be cleared by the | 10321 // for future use. The cache will automatically be cleared by the |
| 10317 // garbage collector when it is not used anymore. | 10322 // garbage collector when it is not used anymore. |
| 10318 Handle<Object> handle = isolate->global_handles()->Create(*result); | 10323 Handle<Object> handle = isolate->global_handles()->Create(*result); |
| 10319 GlobalHandles::MakeWeak(handle.location(), | 10324 GlobalHandles::MakeWeak(handle.location(), |
| 10320 reinterpret_cast<void*>(handle.location()), | 10325 reinterpret_cast<void*>(handle.location()), |
| 10321 &ClearWrapperCache); | 10326 &ClearWrapperCacheWeakCallback); |
| 10322 script->wrapper()->set_foreign_address( | 10327 script->wrapper()->set_foreign_address( |
| 10323 reinterpret_cast<Address>(handle.location())); | 10328 reinterpret_cast<Address>(handle.location())); |
| 10324 return result; | 10329 return result; |
| 10325 } | 10330 } |
| 10326 | 10331 |
| 10327 | 10332 |
| 10328 String* SharedFunctionInfo::DebugName() { | 10333 String* SharedFunctionInfo::DebugName() { |
| 10329 Object* n = name(); | 10334 Object* n = name(); |
| 10330 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); | 10335 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); |
| 10331 return String::cast(n); | 10336 return String::cast(n); |
| (...skipping 6608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16940 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16945 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16941 static const char* error_messages_[] = { | 16946 static const char* error_messages_[] = { |
| 16942 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16947 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16943 }; | 16948 }; |
| 16944 #undef ERROR_MESSAGES_TEXTS | 16949 #undef ERROR_MESSAGES_TEXTS |
| 16945 return error_messages_[reason]; | 16950 return error_messages_[reason]; |
| 16946 } | 16951 } |
| 16947 | 16952 |
| 16948 | 16953 |
| 16949 } } // namespace v8::internal | 16954 } } // namespace v8::internal |
| OLD | NEW |