Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 377164e254d9be7cc2f5b1aa7d6a8b73d97f8443..be38302a57fc7a78ad6036422c6de9a3960111b5 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -10404,6 +10404,55 @@ Handle<JSObject> Script::GetWrapper(Handle<Script> script) { |
} |
+MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( |
+ FunctionLiteral* fun) { |
+ if (shared_function_infos()->IsWeakFixedArray()) { |
+ WeakFixedArray* array = WeakFixedArray::cast(shared_function_infos()); |
+ for (int i = 0; i < array->Length(); i++) { |
+ Object* obj = array->Get(i); |
+ if (!obj->IsSharedFunctionInfo()) continue; |
+ SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); |
+ if (fun->function_token_position() == shared->function_token_position() && |
+ fun->start_position() == shared->start_position()) { |
+ return Handle<SharedFunctionInfo>(shared); |
+ } |
+ } |
+ } |
+ return MaybeHandle<SharedFunctionInfo>(); |
+} |
+ |
+ |
+void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, |
+ Handle<Object> script_object) { |
+ if (shared->script() == *script_object) return; |
+ // Remove shared function info from old script's list. |
+ if (shared->script()->IsScript()) { |
+ Script* old_script = Script::cast(shared->script()); |
+ if (old_script->shared_function_infos()->IsWeakFixedArray()) { |
+ WeakFixedArray* list = |
+ WeakFixedArray::cast(old_script->shared_function_infos()); |
+ list->Remove(shared); |
+ } |
+ } |
+ // Add shared function info to new script's list. |
+ if (script_object->IsScript()) { |
+ Handle<Script> script = Handle<Script>::cast(script_object); |
+ Handle<Object> list(script->shared_function_infos(), shared->GetIsolate()); |
+#ifdef DEBUG |
+ bool found = false; |
+ list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAddIfNotFound, |
+ &found); |
+ CHECK(!found); |
+#else |
+ list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAlwaysAdd); |
+#endif // DEBUG |
+ script->set_shared_function_infos(*list); |
+ } |
+ // Finally set new script. |
+ shared->set_script(*script_object); |
+} |
+ |
+ |
String* SharedFunctionInfo::DebugName() { |
Object* n = name(); |
if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); |