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