| Index: src/objects.cc
|
| diff --git a/src/objects.cc b/src/objects.cc
|
| index 11114f9c04d007dc7c4309a23b43230135fbfedd..df1fe6a7c268edd386da9532d8226d451018f43e 100644
|
| --- a/src/objects.cc
|
| +++ b/src/objects.cc
|
| @@ -13645,47 +13645,52 @@ 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 ||
|
| + 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;
|
| }
|
|
|
|
|
| @@ -13698,39 +13703,43 @@ 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);
|
| + 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.
|
| @@ -13995,7 +14004,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(
|
|
|