Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index d0e40b94859e2fe81f0ec3d05bcffadd3431581b..2a9e62ee40ac07c24a4f67ef2f8af60cbb54b3ef 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -13643,52 +13643,58 @@ Handle<JSObject> Script::GetWrapper(Handle<Script> script) { |
| MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( |
| FunctionLiteral* fun) { |
| - WeakFixedArray::Iterator iterator(shared_function_infos()); |
| - SharedFunctionInfo* shared; |
| - while ((shared = iterator.Next<SharedFunctionInfo>())) { |
| - if (fun->function_token_position() == shared->function_token_position() && |
| - fun->start_position() == shared->start_position() && |
| - fun->end_position() == shared->end_position()) { |
| - DCHECK_EQ(fun->function_literal_id(), shared->function_literal_id()); |
| - return Handle<SharedFunctionInfo>(shared); |
| - } |
| - DCHECK_NE(fun->function_literal_id(), shared->function_literal_id()); |
| + if (fun->function_literal_id() == FunctionLiteral::kIdTypeInvalid || |
|
Toon Verwaest
2016/12/06 21:10:14
Mmh. DCHECK_NE(id, Invalid); DCHECK_LT(id, length)
jochen (gone - plz use gerrit)
2016/12/07 15:57:00
done
|
| + fun->function_literal_id() >= shared_function_infos()->length()) { |
| + UNREACHABLE(); |
| + return MaybeHandle<SharedFunctionInfo>(); |
| } |
| - return MaybeHandle<SharedFunctionInfo>(); |
| + Object* shared = shared_function_infos()->get(fun->function_literal_id()); |
| + if (shared->IsSmi() || WeakCell::cast(shared)->cleared()) { |
| + return MaybeHandle<SharedFunctionInfo>(); |
| + } |
| + return handle(SharedFunctionInfo::cast(WeakCell::cast(shared)->value())); |
| } |
| - |
| Script::Iterator::Iterator(Isolate* isolate) |
| : iterator_(isolate->heap()->script_list()) {} |
| Script* Script::Iterator::Next() { return iterator_.Next<Script>(); } |
| - |
| SharedFunctionInfo::Iterator::Iterator(Isolate* isolate) |
| : script_iterator_(isolate), |
| - sfi_iterator_(isolate->heap()->noscript_shared_function_infos()) {} |
| - |
| - |
| -bool SharedFunctionInfo::Iterator::NextScript() { |
| - Script* script = script_iterator_.Next(); |
| - if (script == NULL) return false; |
| - sfi_iterator_.Reset(script->shared_function_infos()); |
| - return true; |
| + sfi_iterator_(isolate->heap()->noscript_shared_function_infos()), |
| + current_script_(nullptr), |
| + index_(-1) { |
| + NextScript(); |
| } |
| +void SharedFunctionInfo::Iterator::NextScript() { |
| + current_script_ = script_iterator_.Next(); |
| + if (current_script_ == nullptr) return; |
| + index_ = 0; |
| +} |
| SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() { |
| - do { |
| - SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>(); |
| - if (next != NULL) return next; |
| - } while (NextScript()); |
| - return NULL; |
| + SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>(); |
| + if (next != nullptr) return next; |
| + while (current_script_ != nullptr) { |
| + FixedArray* infos = current_script_->shared_function_infos(); |
| + while (index_ < infos->length()) { |
| + Object* info = infos->get(index_++); |
| + if (!(info->IsSmi() || WeakCell::cast(info)->cleared())) { |
| + return SharedFunctionInfo::cast(WeakCell::cast(info)->value()); |
| + } |
| + } |
| + NextScript(); |
| + } |
| + return nullptr; |
| } |
| void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, |
| Handle<Object> script_object) { |
| + DCHECK(shared->function_literal_id() != FunctionLiteral::kIdTypeInvalid); |
|
Toon Verwaest
2016/12/06 21:10:14
DCHECK_NE
jochen (gone - plz use gerrit)
2016/12/07 15:57:00
done
|
| if (shared->script() == *script_object) return; |
| Isolate* isolate = shared->GetIsolate(); |
| @@ -13696,39 +13702,52 @@ void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, |
| // the shared function info may be temporarily in two lists. |
| // This is okay because the gc-time processing of these lists can tolerate |
| // duplicates. |
| - Handle<Object> list; |
| if (script_object->IsScript()) { |
| Handle<Script> script = Handle<Script>::cast(script_object); |
| - list = handle(script->shared_function_infos(), isolate); |
| + Handle<FixedArray> list = handle(script->shared_function_infos(), isolate); |
| +#ifdef DEBUG |
| + DCHECK_LT(shared->function_literal_id(), list->length()); |
| + if (list->get(shared->function_literal_id())->IsWeakCell() && |
| + !WeakCell::cast(list->get(shared->function_literal_id()))->cleared()) { |
| + DCHECK( |
| + WeakCell::cast(list->get(shared->function_literal_id()))->value() == |
| + *shared); |
| + } |
| +#endif |
| + Handle<WeakCell> cell = isolate->factory()->NewWeakCell(shared); |
| + list->set(shared->function_literal_id(), *cell); |
| } else { |
| - list = isolate->factory()->noscript_shared_function_infos(); |
| - } |
| + Handle<Object> list = isolate->factory()->noscript_shared_function_infos(); |
| #ifdef DEBUG |
| - if (FLAG_enable_slow_asserts) { |
| - WeakFixedArray::Iterator iterator(*list); |
| - SharedFunctionInfo* next; |
| - while ((next = iterator.Next<SharedFunctionInfo>())) { |
| - DCHECK_NE(next, *shared); |
| + if (FLAG_enable_slow_asserts) { |
| + WeakFixedArray::Iterator iterator(*list); |
| + SharedFunctionInfo* next; |
| + while ((next = iterator.Next<SharedFunctionInfo>())) { |
| + DCHECK_NE(next, *shared); |
| + } |
| } |
| - } |
| #endif // DEBUG |
| - list = WeakFixedArray::Add(list, shared); |
| - if (script_object->IsScript()) { |
| - Handle<Script> script = Handle<Script>::cast(script_object); |
| - script->set_shared_function_infos(*list); |
| - } else { |
| + list = WeakFixedArray::Add(list, shared); |
| + |
| isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); |
| } |
| - // Remove shared function info from old script's list. |
| if (shared->script()->IsScript()) { |
| + // Remove shared function info from old script's list. |
| 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); |
| + |
| + // Due to liveedit, it might happen that the old_script doesn't know |
| + // about the SharedFunctionInfo, so we have to guard against that. |
| + Handle<FixedArray> infos(old_script->shared_function_infos(), isolate); |
| + if (shared->function_literal_id() < infos->length()) { |
| + Object* raw = old_script->shared_function_infos()->get( |
| + shared->function_literal_id()); |
| + if (!raw->IsWeakCell() || WeakCell::cast(raw)->value() == *shared) { |
| + old_script->shared_function_infos()->set(shared->function_literal_id(), |
| + Smi::kZero); |
| + } |
| } |
| } else { |
| // Remove shared function info from root array. |
| @@ -13993,7 +14012,6 @@ void SharedFunctionInfo::InitFromFunctionLiteral( |
| shared_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
| shared_info->set_is_function(lit->is_function()); |
| - shared_info->set_never_compiled(true); |
| shared_info->set_kind(lit->kind()); |
| if (!IsConstructable(lit->kind(), lit->language_mode())) { |
| shared_info->SetConstructStub( |