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