Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: src/objects.cc

Issue 1211453002: Reland "Keep a canonical list of shared function infos." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix alwaysopt Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698