| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 13622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13633 isolate->counters()->script_wrappers()->Increment(); | 13633 isolate->counters()->script_wrappers()->Increment(); |
| 13634 Handle<JSFunction> constructor = isolate->script_function(); | 13634 Handle<JSFunction> constructor = isolate->script_function(); |
| 13635 Handle<JSValue> result = | 13635 Handle<JSValue> result = |
| 13636 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); | 13636 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); |
| 13637 result->set_value(*script); | 13637 result->set_value(*script); |
| 13638 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); | 13638 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); |
| 13639 script->set_wrapper(*cell); | 13639 script->set_wrapper(*cell); |
| 13640 return result; | 13640 return result; |
| 13641 } | 13641 } |
| 13642 | 13642 |
| 13643 | |
| 13644 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( | 13643 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( |
| 13645 FunctionLiteral* fun) { | 13644 Isolate* isolate, FunctionLiteral* fun) { |
| 13646 WeakFixedArray::Iterator iterator(shared_function_infos()); | 13645 DCHECK_NE(fun->function_literal_id(), FunctionLiteral::kIdTypeInvalid); |
| 13647 SharedFunctionInfo* shared; | 13646 DCHECK_LT(fun->function_literal_id(), shared_function_infos()->length()); |
| 13648 while ((shared = iterator.Next<SharedFunctionInfo>())) { | 13647 Object* shared = shared_function_infos()->get(fun->function_literal_id()); |
| 13649 if (fun->function_token_position() == shared->function_token_position() && | 13648 if (shared->IsUndefined(isolate) || WeakCell::cast(shared)->cleared()) { |
| 13650 fun->start_position() == shared->start_position() && | 13649 return MaybeHandle<SharedFunctionInfo>(); |
| 13651 fun->end_position() == shared->end_position()) { | |
| 13652 DCHECK_EQ(fun->function_literal_id(), shared->function_literal_id()); | |
| 13653 return Handle<SharedFunctionInfo>(shared); | |
| 13654 } | |
| 13655 DCHECK_NE(fun->function_literal_id(), shared->function_literal_id()); | |
| 13656 } | 13650 } |
| 13657 return MaybeHandle<SharedFunctionInfo>(); | 13651 return handle(SharedFunctionInfo::cast(WeakCell::cast(shared)->value())); |
| 13658 } | 13652 } |
| 13659 | 13653 |
| 13660 | |
| 13661 Script::Iterator::Iterator(Isolate* isolate) | 13654 Script::Iterator::Iterator(Isolate* isolate) |
| 13662 : iterator_(isolate->heap()->script_list()) {} | 13655 : iterator_(isolate->heap()->script_list()) {} |
| 13663 | 13656 |
| 13664 | 13657 |
| 13665 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); } | 13658 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); } |
| 13666 | 13659 |
| 13660 SharedFunctionInfo::ScriptIterator::ScriptIterator(Handle<Script> script) |
| 13661 : ScriptIterator(script->GetIsolate(), |
| 13662 handle(script->shared_function_infos())) {} |
| 13667 | 13663 |
| 13668 SharedFunctionInfo::Iterator::Iterator(Isolate* isolate) | 13664 SharedFunctionInfo::ScriptIterator::ScriptIterator( |
| 13669 : script_iterator_(isolate), | 13665 Isolate* isolate, Handle<FixedArray> shared_function_infos) |
| 13670 sfi_iterator_(isolate->heap()->noscript_shared_function_infos()) {} | 13666 : isolate_(isolate), |
| 13667 shared_function_infos_(shared_function_infos), |
| 13668 index_(0) {} |
| 13671 | 13669 |
| 13672 | 13670 SharedFunctionInfo* SharedFunctionInfo::ScriptIterator::Next() { |
| 13673 bool SharedFunctionInfo::Iterator::NextScript() { | 13671 while (index_ < shared_function_infos_->length()) { |
| 13674 Script* script = script_iterator_.Next(); | 13672 Object* raw = shared_function_infos_->get(index_++); |
| 13675 if (script == NULL) return false; | 13673 if (raw->IsUndefined(isolate_) || WeakCell::cast(raw)->cleared()) continue; |
| 13676 sfi_iterator_.Reset(script->shared_function_infos()); | 13674 return SharedFunctionInfo::cast(WeakCell::cast(raw)->value()); |
| 13677 return true; | 13675 } |
| 13676 return nullptr; |
| 13678 } | 13677 } |
| 13679 | 13678 |
| 13679 void SharedFunctionInfo::ScriptIterator::Reset(Handle<Script> script) { |
| 13680 shared_function_infos_ = handle(script->shared_function_infos()); |
| 13681 index_ = 0; |
| 13682 } |
| 13680 | 13683 |
| 13681 SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() { | 13684 SharedFunctionInfo::GlobalIterator::GlobalIterator(Isolate* isolate) |
| 13682 do { | 13685 : script_iterator_(isolate), |
| 13683 SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>(); | 13686 noscript_sfi_iterator_(isolate->heap()->noscript_shared_function_infos()), |
| 13684 if (next != NULL) return next; | 13687 sfi_iterator_(handle(script_iterator_.Next(), isolate)) {} |
| 13685 } while (NextScript()); | 13688 |
| 13686 return NULL; | 13689 SharedFunctionInfo* SharedFunctionInfo::GlobalIterator::Next() { |
| 13690 SharedFunctionInfo* next = noscript_sfi_iterator_.Next<SharedFunctionInfo>(); |
| 13691 if (next != nullptr) return next; |
| 13692 for (;;) { |
| 13693 next = sfi_iterator_.Next(); |
| 13694 if (next != nullptr) return next; |
| 13695 Script* next_script = script_iterator_.Next(); |
| 13696 if (next_script == nullptr) return nullptr; |
| 13697 sfi_iterator_.Reset(handle(next_script)); |
| 13698 } |
| 13687 } | 13699 } |
| 13688 | 13700 |
| 13689 | 13701 |
| 13690 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, | 13702 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, |
| 13691 Handle<Object> script_object) { | 13703 Handle<Object> script_object) { |
| 13704 DCHECK_NE(shared->function_literal_id(), FunctionLiteral::kIdTypeInvalid); |
| 13692 if (shared->script() == *script_object) return; | 13705 if (shared->script() == *script_object) return; |
| 13693 Isolate* isolate = shared->GetIsolate(); | 13706 Isolate* isolate = shared->GetIsolate(); |
| 13694 | 13707 |
| 13695 // Add shared function info to new script's list. If a collection occurs, | 13708 // Add shared function info to new script's list. If a collection occurs, |
| 13696 // the shared function info may be temporarily in two lists. | 13709 // the shared function info may be temporarily in two lists. |
| 13697 // This is okay because the gc-time processing of these lists can tolerate | 13710 // This is okay because the gc-time processing of these lists can tolerate |
| 13698 // duplicates. | 13711 // duplicates. |
| 13699 Handle<Object> list; | |
| 13700 if (script_object->IsScript()) { | 13712 if (script_object->IsScript()) { |
| 13701 Handle<Script> script = Handle<Script>::cast(script_object); | 13713 Handle<Script> script = Handle<Script>::cast(script_object); |
| 13702 list = handle(script->shared_function_infos(), isolate); | 13714 Handle<FixedArray> list = handle(script->shared_function_infos(), isolate); |
| 13715 #ifdef DEBUG |
| 13716 DCHECK_LT(shared->function_literal_id(), list->length()); |
| 13717 if (list->get(shared->function_literal_id())->IsWeakCell() && |
| 13718 !WeakCell::cast(list->get(shared->function_literal_id()))->cleared()) { |
| 13719 DCHECK( |
| 13720 WeakCell::cast(list->get(shared->function_literal_id()))->value() == |
| 13721 *shared); |
| 13722 } |
| 13723 #endif |
| 13724 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(shared); |
| 13725 list->set(shared->function_literal_id(), *cell); |
| 13703 } else { | 13726 } else { |
| 13704 list = isolate->factory()->noscript_shared_function_infos(); | 13727 Handle<Object> list = isolate->factory()->noscript_shared_function_infos(); |
| 13705 } | |
| 13706 | 13728 |
| 13707 #ifdef DEBUG | 13729 #ifdef DEBUG |
| 13708 if (FLAG_enable_slow_asserts) { | 13730 if (FLAG_enable_slow_asserts) { |
| 13709 WeakFixedArray::Iterator iterator(*list); | 13731 WeakFixedArray::Iterator iterator(*list); |
| 13710 SharedFunctionInfo* next; | 13732 SharedFunctionInfo* next; |
| 13711 while ((next = iterator.Next<SharedFunctionInfo>())) { | 13733 while ((next = iterator.Next<SharedFunctionInfo>())) { |
| 13712 DCHECK_NE(next, *shared); | 13734 DCHECK_NE(next, *shared); |
| 13735 } |
| 13713 } | 13736 } |
| 13714 } | |
| 13715 #endif // DEBUG | 13737 #endif // DEBUG |
| 13716 list = WeakFixedArray::Add(list, shared); | |
| 13717 | 13738 |
| 13718 if (script_object->IsScript()) { | 13739 list = WeakFixedArray::Add(list, shared); |
| 13719 Handle<Script> script = Handle<Script>::cast(script_object); | 13740 |
| 13720 script->set_shared_function_infos(*list); | |
| 13721 } else { | |
| 13722 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); | 13741 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); |
| 13723 } | 13742 } |
| 13724 | 13743 |
| 13725 // Remove shared function info from old script's list. | |
| 13726 if (shared->script()->IsScript()) { | 13744 if (shared->script()->IsScript()) { |
| 13745 // Remove shared function info from old script's list. |
| 13727 Script* old_script = Script::cast(shared->script()); | 13746 Script* old_script = Script::cast(shared->script()); |
| 13728 if (old_script->shared_function_infos()->IsWeakFixedArray()) { | 13747 |
| 13729 WeakFixedArray* list = | 13748 // Due to liveedit, it might happen that the old_script doesn't know |
| 13730 WeakFixedArray::cast(old_script->shared_function_infos()); | 13749 // about the SharedFunctionInfo, so we have to guard against that. |
| 13731 list->Remove(shared); | 13750 Handle<FixedArray> infos(old_script->shared_function_infos(), isolate); |
| 13751 if (shared->function_literal_id() < infos->length()) { |
| 13752 Object* raw = old_script->shared_function_infos()->get( |
| 13753 shared->function_literal_id()); |
| 13754 if (!raw->IsWeakCell() || WeakCell::cast(raw)->value() == *shared) { |
| 13755 old_script->shared_function_infos()->set( |
| 13756 shared->function_literal_id(), isolate->heap()->undefined_value()); |
| 13757 } |
| 13732 } | 13758 } |
| 13733 } else { | 13759 } else { |
| 13734 // Remove shared function info from root array. | 13760 // Remove shared function info from root array. |
| 13735 Object* list = isolate->heap()->noscript_shared_function_infos(); | 13761 Object* list = isolate->heap()->noscript_shared_function_infos(); |
| 13736 CHECK(WeakFixedArray::cast(list)->Remove(shared)); | 13762 CHECK(WeakFixedArray::cast(list)->Remove(shared)); |
| 13737 } | 13763 } |
| 13738 | 13764 |
| 13739 // Finally set new script. | 13765 // Finally set new script. |
| 13740 shared->set_script(*script_object); | 13766 shared->set_script(*script_object); |
| 13741 } | 13767 } |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13986 shared_info->set_end_position(lit->end_position()); | 14012 shared_info->set_end_position(lit->end_position()); |
| 13987 shared_info->set_is_declaration(lit->is_declaration()); | 14013 shared_info->set_is_declaration(lit->is_declaration()); |
| 13988 shared_info->set_is_named_expression(lit->is_named_expression()); | 14014 shared_info->set_is_named_expression(lit->is_named_expression()); |
| 13989 shared_info->set_is_anonymous_expression(lit->is_anonymous_expression()); | 14015 shared_info->set_is_anonymous_expression(lit->is_anonymous_expression()); |
| 13990 shared_info->set_inferred_name(*lit->inferred_name()); | 14016 shared_info->set_inferred_name(*lit->inferred_name()); |
| 13991 shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 14017 shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
| 13992 shared_info->set_language_mode(lit->language_mode()); | 14018 shared_info->set_language_mode(lit->language_mode()); |
| 13993 shared_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 14019 shared_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| 13994 shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 14020 shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
| 13995 shared_info->set_is_function(lit->is_function()); | 14021 shared_info->set_is_function(lit->is_function()); |
| 13996 shared_info->set_never_compiled(true); | |
| 13997 shared_info->set_kind(lit->kind()); | 14022 shared_info->set_kind(lit->kind()); |
| 13998 if (!IsConstructable(lit->kind(), lit->language_mode())) { | 14023 if (!IsConstructable(lit->kind(), lit->language_mode())) { |
| 13999 shared_info->SetConstructStub( | 14024 shared_info->SetConstructStub( |
| 14000 *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable()); | 14025 *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable()); |
| 14001 } | 14026 } |
| 14002 shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject()); | 14027 shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject()); |
| 14003 shared_info->set_asm_function(lit->scope()->asm_function()); | 14028 shared_info->set_asm_function(lit->scope()->asm_function()); |
| 14004 shared_info->set_requires_class_field_init(lit->requires_class_field_init()); | 14029 shared_info->set_requires_class_field_init(lit->requires_class_field_init()); |
| 14005 shared_info->set_is_class_field_initializer( | 14030 shared_info->set_is_class_field_initializer( |
| 14006 lit->is_class_field_initializer()); | 14031 lit->is_class_field_initializer()); |
| (...skipping 6404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20411 // depend on this. | 20436 // depend on this. |
| 20412 return DICTIONARY_ELEMENTS; | 20437 return DICTIONARY_ELEMENTS; |
| 20413 } | 20438 } |
| 20414 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20439 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
| 20415 return kind; | 20440 return kind; |
| 20416 } | 20441 } |
| 20417 } | 20442 } |
| 20418 | 20443 |
| 20419 } // namespace internal | 20444 } // namespace internal |
| 20420 } // namespace v8 | 20445 } // namespace v8 |
| OLD | NEW |