| 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 13627 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  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  | 
|  13646 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( |  13646 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( | 
|  13647     FunctionLiteral* fun) { |  13647     FunctionLiteral* fun) { | 
|  13648   WeakFixedArray::Iterator iterator(shared_function_infos()); |  13648   if (fun->function_literal_id() == FunctionLiteral::kIdTypeInvalid || | 
|  13649   SharedFunctionInfo* shared; |  13649       fun->function_literal_id() >= shared_function_infos()->length()) { | 
|  13650   while ((shared = iterator.Next<SharedFunctionInfo>())) { |  13650     UNREACHABLE(); | 
|  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()); |  | 
|  13658   } |  13652   } | 
|  13659   return MaybeHandle<SharedFunctionInfo>(); |  13653   Object* shared = shared_function_infos()->get(fun->function_literal_id()); | 
 |  13654   if (shared->IsSmi() || WeakCell::cast(shared)->cleared()) { | 
 |  13655     return MaybeHandle<SharedFunctionInfo>(); | 
 |  13656   } | 
 |  13657   return handle(SharedFunctionInfo::cast(WeakCell::cast(shared)->value())); | 
|  13660 } |  13658 } | 
|  13661  |  13659  | 
|  13662  |  | 
|  13663 Script::Iterator::Iterator(Isolate* isolate) |  13660 Script::Iterator::Iterator(Isolate* isolate) | 
|  13664     : iterator_(isolate->heap()->script_list()) {} |  13661     : iterator_(isolate->heap()->script_list()) {} | 
|  13665  |  13662  | 
|  13666  |  13663  | 
|  13667 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); } |  13664 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); } | 
|  13668  |  13665  | 
|  13669  |  | 
|  13670 SharedFunctionInfo::Iterator::Iterator(Isolate* isolate) |  13666 SharedFunctionInfo::Iterator::Iterator(Isolate* isolate) | 
|  13671     : script_iterator_(isolate), |  13667     : script_iterator_(isolate), | 
|  13672       sfi_iterator_(isolate->heap()->noscript_shared_function_infos()) {} |  13668       sfi_iterator_(isolate->heap()->noscript_shared_function_infos()), | 
 |  13669       current_script_(nullptr), | 
 |  13670       index_(-1) { | 
 |  13671   NextScript(); | 
 |  13672 } | 
|  13673  |  13673  | 
 |  13674 void SharedFunctionInfo::Iterator::NextScript() { | 
 |  13675   current_script_ = script_iterator_.Next(); | 
 |  13676   if (current_script_ == nullptr) return; | 
 |  13677   index_ = 0; | 
 |  13678 } | 
|  13674  |  13679  | 
|  13675 bool SharedFunctionInfo::Iterator::NextScript() { |  13680 SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() { | 
|  13676   Script* script = script_iterator_.Next(); |  13681   SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>(); | 
|  13677   if (script == NULL) return false; |  13682   if (next != nullptr) return next; | 
|  13678   sfi_iterator_.Reset(script->shared_function_infos()); |  13683   while (current_script_ != nullptr) { | 
|  13679   return true; |  13684     FixedArray* infos = current_script_->shared_function_infos(); | 
 |  13685     while (index_ < infos->length()) { | 
 |  13686       Object* info = infos->get(index_++); | 
 |  13687       if (!(info->IsSmi() || WeakCell::cast(info)->cleared())) { | 
 |  13688         return SharedFunctionInfo::cast(WeakCell::cast(info)->value()); | 
 |  13689       } | 
 |  13690     } | 
 |  13691     NextScript(); | 
 |  13692   } | 
 |  13693   return nullptr; | 
|  13680 } |  13694 } | 
|  13681  |  13695  | 
|  13682  |  13696  | 
|  13683 SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() { |  | 
|  13684   do { |  | 
|  13685     SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>(); |  | 
|  13686     if (next != NULL) return next; |  | 
|  13687   } while (NextScript()); |  | 
|  13688   return NULL; |  | 
|  13689 } |  | 
|  13690  |  | 
|  13691  |  | 
|  13692 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, |  13697 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, | 
|  13693                                    Handle<Object> script_object) { |  13698                                    Handle<Object> script_object) { | 
|  13694   if (shared->script() == *script_object) return; |  13699   if (shared->script() == *script_object) return; | 
|  13695   Isolate* isolate = shared->GetIsolate(); |  13700   Isolate* isolate = shared->GetIsolate(); | 
|  13696  |  13701  | 
|  13697   // Add shared function info to new script's list. If a collection occurs, |  13702   // Add shared function info to new script's list. If a collection occurs, | 
|  13698   // the shared function info may be temporarily in two lists. |  13703   // the shared function info may be temporarily in two lists. | 
|  13699   // This is okay because the gc-time processing of these lists can tolerate |  13704   // This is okay because the gc-time processing of these lists can tolerate | 
|  13700   // duplicates. |  13705   // duplicates. | 
|  13701   Handle<Object> list; |  | 
|  13702   if (script_object->IsScript()) { |  13706   if (script_object->IsScript()) { | 
|  13703     Handle<Script> script = Handle<Script>::cast(script_object); |  13707     Handle<Script> script = Handle<Script>::cast(script_object); | 
|  13704     list = handle(script->shared_function_infos(), isolate); |  13708     Handle<FixedArray> list = handle(script->shared_function_infos(), isolate); | 
 |  13709     Handle<WeakCell> cell = isolate->factory()->NewWeakCell(shared); | 
 |  13710     list->set(shared->function_literal_id(), *cell); | 
|  13705   } else { |  13711   } else { | 
|  13706     list = isolate->factory()->noscript_shared_function_infos(); |  13712     Handle<Object> list = isolate->factory()->noscript_shared_function_infos(); | 
|  13707   } |  | 
|  13708  |  13713  | 
|  13709 #ifdef DEBUG |  13714 #ifdef DEBUG | 
|  13710   if (FLAG_enable_slow_asserts) { |  13715     if (FLAG_enable_slow_asserts) { | 
|  13711     WeakFixedArray::Iterator iterator(*list); |  13716       WeakFixedArray::Iterator iterator(*list); | 
|  13712     SharedFunctionInfo* next; |  13717       SharedFunctionInfo* next; | 
|  13713     while ((next = iterator.Next<SharedFunctionInfo>())) { |  13718       while ((next = iterator.Next<SharedFunctionInfo>())) { | 
|  13714       DCHECK_NE(next, *shared); |  13719         DCHECK_NE(next, *shared); | 
 |  13720       } | 
|  13715     } |  13721     } | 
|  13716   } |  | 
|  13717 #endif  // DEBUG |  13722 #endif  // DEBUG | 
|  13718   list = WeakFixedArray::Add(list, shared); |  | 
|  13719  |  13723  | 
|  13720   if (script_object->IsScript()) { |  13724     list = WeakFixedArray::Add(list, shared); | 
|  13721     Handle<Script> script = Handle<Script>::cast(script_object); |  13725  | 
|  13722     script->set_shared_function_infos(*list); |  | 
|  13723   } else { |  | 
|  13724     isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); |  13726     isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); | 
|  13725   } |  13727   } | 
|  13726  |  13728  | 
|  13727   // Remove shared function info from old script's list. |  | 
|  13728   if (shared->script()->IsScript()) { |  13729   if (shared->script()->IsScript()) { | 
 |  13730     // Remove shared function info from old script's list. | 
|  13729     Script* old_script = Script::cast(shared->script()); |  13731     Script* old_script = Script::cast(shared->script()); | 
|  13730     if (old_script->shared_function_infos()->IsWeakFixedArray()) { |  13732  | 
|  13731       WeakFixedArray* list = |  13733     // Due to liveedit, it might happen that the old_script doesn't know | 
|  13732           WeakFixedArray::cast(old_script->shared_function_infos()); |  13734     // about the SharedFunctionInfo, so we have to guard against that. | 
|  13733       list->Remove(shared); |  13735     Handle<FixedArray> infos(old_script->shared_function_infos(), isolate); | 
 |  13736     if (shared->function_literal_id() < infos->length()) { | 
 |  13737       Object* raw = old_script->shared_function_infos()->get( | 
 |  13738           shared->function_literal_id()); | 
 |  13739       if (!raw->IsWeakCell() || WeakCell::cast(raw)->value() == *shared) { | 
 |  13740         old_script->shared_function_infos()->set(shared->function_literal_id(), | 
 |  13741                                                  Smi::kZero); | 
 |  13742       } | 
|  13734     } |  13743     } | 
|  13735   } else { |  13744   } else { | 
|  13736     // Remove shared function info from root array. |  13745     // Remove shared function info from root array. | 
|  13737     Object* list = isolate->heap()->noscript_shared_function_infos(); |  13746     Object* list = isolate->heap()->noscript_shared_function_infos(); | 
|  13738     CHECK(WeakFixedArray::cast(list)->Remove(shared)); |  13747     CHECK(WeakFixedArray::cast(list)->Remove(shared)); | 
|  13739   } |  13748   } | 
|  13740  |  13749  | 
|  13741   // Finally set new script. |  13750   // Finally set new script. | 
|  13742   shared->set_script(*script_object); |  13751   shared->set_script(*script_object); | 
|  13743 } |  13752 } | 
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  13988   shared_info->set_end_position(lit->end_position()); |  13997   shared_info->set_end_position(lit->end_position()); | 
|  13989   shared_info->set_is_declaration(lit->is_declaration()); |  13998   shared_info->set_is_declaration(lit->is_declaration()); | 
|  13990   shared_info->set_is_named_expression(lit->is_named_expression()); |  13999   shared_info->set_is_named_expression(lit->is_named_expression()); | 
|  13991   shared_info->set_is_anonymous_expression(lit->is_anonymous_expression()); |  14000   shared_info->set_is_anonymous_expression(lit->is_anonymous_expression()); | 
|  13992   shared_info->set_inferred_name(*lit->inferred_name()); |  14001   shared_info->set_inferred_name(*lit->inferred_name()); | 
|  13993   shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |  14002   shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 
|  13994   shared_info->set_language_mode(lit->language_mode()); |  14003   shared_info->set_language_mode(lit->language_mode()); | 
|  13995   shared_info->set_uses_arguments(lit->scope()->arguments() != NULL); |  14004   shared_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 
|  13996   shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |  14005   shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 
|  13997   shared_info->set_is_function(lit->is_function()); |  14006   shared_info->set_is_function(lit->is_function()); | 
|  13998   shared_info->set_never_compiled(true); |  | 
|  13999   shared_info->set_kind(lit->kind()); |  14007   shared_info->set_kind(lit->kind()); | 
|  14000   if (!IsConstructable(lit->kind(), lit->language_mode())) { |  14008   if (!IsConstructable(lit->kind(), lit->language_mode())) { | 
|  14001     shared_info->SetConstructStub( |  14009     shared_info->SetConstructStub( | 
|  14002         *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable()); |  14010         *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable()); | 
|  14003   } |  14011   } | 
|  14004   shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject()); |  14012   shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject()); | 
|  14005   shared_info->set_asm_function(lit->scope()->asm_function()); |  14013   shared_info->set_asm_function(lit->scope()->asm_function()); | 
|  14006   shared_info->set_requires_class_field_init(lit->requires_class_field_init()); |  14014   shared_info->set_requires_class_field_init(lit->requires_class_field_init()); | 
|  14007   shared_info->set_is_class_field_initializer( |  14015   shared_info->set_is_class_field_initializer( | 
|  14008       lit->is_class_field_initializer()); |  14016       lit->is_class_field_initializer()); | 
| (...skipping 6507 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  20516       // depend on this. |  20524       // depend on this. | 
|  20517       return DICTIONARY_ELEMENTS; |  20525       return DICTIONARY_ELEMENTS; | 
|  20518     } |  20526     } | 
|  20519     DCHECK_LE(kind, LAST_ELEMENTS_KIND); |  20527     DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 
|  20520     return kind; |  20528     return kind; | 
|  20521   } |  20529   } | 
|  20522 } |  20530 } | 
|  20523  |  20531  | 
|  20524 }  // namespace internal |  20532 }  // namespace internal | 
|  20525 }  // namespace v8 |  20533 }  // namespace v8 | 
| OLD | NEW |