Chromium Code Reviews

Side by Side Diff: src/objects.cc

Issue 1183733006: Keep a canonical list of shared function infos. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: serializer tweak Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 10403 matching lines...)
10414 Handle<JSFunction> constructor = isolate->script_function(); 10414 Handle<JSFunction> constructor = isolate->script_function();
10415 Handle<JSValue> result = 10415 Handle<JSValue> result =
10416 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); 10416 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
10417 result->set_value(*script); 10417 result->set_value(*script);
10418 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); 10418 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result);
10419 script->set_wrapper(*cell); 10419 script->set_wrapper(*cell);
10420 return result; 10420 return result;
10421 } 10421 }
10422 10422
10423 10423
10424 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo(
10425 FunctionLiteral* fun) {
10426 if (shared_function_infos()->IsWeakFixedArray()) {
10427 WeakFixedArray* array = WeakFixedArray::cast(shared_function_infos());
10428 for (int i = 0; i < array->Length(); i++) {
10429 Object* obj = array->Get(i);
10430 if (!obj->IsSharedFunctionInfo()) continue;
10431 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
10432 if (fun->function_token_position() == shared->function_token_position() &&
10433 fun->start_position() == shared->start_position() &&
10434 fun->end_position() == shared->end_position()) {
10435 return Handle<SharedFunctionInfo>(shared);
10436 }
10437 }
10438 }
10439 return MaybeHandle<SharedFunctionInfo>();
10440 }
10441
10442
10443 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
10444 Handle<Object> script_object) {
10445 if (shared->script() == *script_object) return;
10446 // Remove shared function info from old script's list.
10447 if (shared->script()->IsScript()) {
10448 Script* old_script = Script::cast(shared->script());
10449 if (old_script->shared_function_infos()->IsWeakFixedArray()) {
10450 WeakFixedArray* list =
10451 WeakFixedArray::cast(old_script->shared_function_infos());
10452 list->Remove(shared);
10453 }
10454 }
10455 // Add shared function info to new script's list.
10456 if (script_object->IsScript()) {
10457 Handle<Script> script = Handle<Script>::cast(script_object);
10458 bool found = false;
10459 Handle<Object> list(script->shared_function_infos(), shared->GetIsolate());
10460 list = WeakFixedArray::Add(list, shared, WeakFixedArray::kAddIfNotFound,
10461 &found);
10462 CHECK(!found);
10463 script->set_shared_function_infos(*list);
10464 }
10465 // Finally set new script.
10466 shared->set_script(*script_object);
10467 }
10468
10469
10424 String* SharedFunctionInfo::DebugName() { 10470 String* SharedFunctionInfo::DebugName() {
10425 Object* n = name(); 10471 Object* n = name();
10426 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name(); 10472 if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name();
10427 return String::cast(n); 10473 return String::cast(n);
10428 } 10474 }
10429 10475
10430 10476
10431 bool SharedFunctionInfo::HasSourceCode() const { 10477 bool SharedFunctionInfo::HasSourceCode() const {
10432 return !script()->IsUndefined() && 10478 return !script()->IsUndefined() &&
10433 !reinterpret_cast<Script*>(script())->source()->IsUndefined(); 10479 !reinterpret_cast<Script*>(script())->source()->IsUndefined();
(...skipping 6219 matching lines...)
16653 Handle<Object> new_value) { 16699 Handle<Object> new_value) {
16654 if (cell->value() != *new_value) { 16700 if (cell->value() != *new_value) {
16655 cell->set_value(*new_value); 16701 cell->set_value(*new_value);
16656 Isolate* isolate = cell->GetIsolate(); 16702 Isolate* isolate = cell->GetIsolate();
16657 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16703 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16658 isolate, DependentCode::kPropertyCellChangedGroup); 16704 isolate, DependentCode::kPropertyCellChangedGroup);
16659 } 16705 }
16660 } 16706 }
16661 } // namespace internal 16707 } // namespace internal
16662 } // namespace v8 16708 } // namespace v8
OLDNEW

Powered by Google App Engine