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 <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 15758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15769 os << " (" << PrivateSymbolToName() << ")"; | 15769 os << " (" << PrivateSymbolToName() << ")"; |
15770 } | 15770 } |
15771 os << ">"; | 15771 os << ">"; |
15772 } | 15772 } |
15773 | 15773 |
15774 | 15774 |
15775 // StringSharedKeys are used as keys in the eval cache. | 15775 // StringSharedKeys are used as keys in the eval cache. |
15776 class StringSharedKey : public HashTableKey { | 15776 class StringSharedKey : public HashTableKey { |
15777 public: | 15777 public: |
15778 StringSharedKey(Handle<String> source, Handle<SharedFunctionInfo> shared, | 15778 StringSharedKey(Handle<String> source, Handle<SharedFunctionInfo> shared, |
15779 LanguageMode language_mode, int scope_position) | 15779 LanguageMode language_mode, bool is_module, |
| 15780 int scope_position) |
15780 : source_(source), | 15781 : source_(source), |
15781 shared_(shared), | 15782 shared_(shared), |
15782 language_mode_(language_mode), | 15783 language_mode_(language_mode), |
| 15784 is_module_(is_module), |
15783 scope_position_(scope_position) {} | 15785 scope_position_(scope_position) {} |
15784 | 15786 |
15785 bool IsMatch(Object* other) override { | 15787 bool IsMatch(Object* other) override { |
15786 DisallowHeapAllocation no_allocation; | 15788 DisallowHeapAllocation no_allocation; |
15787 if (!other->IsFixedArray()) { | 15789 if (!other->IsFixedArray()) { |
15788 if (!other->IsNumber()) return false; | 15790 if (!other->IsNumber()) return false; |
15789 uint32_t other_hash = static_cast<uint32_t>(other->Number()); | 15791 uint32_t other_hash = static_cast<uint32_t>(other->Number()); |
15790 return Hash() == other_hash; | 15792 return Hash() == other_hash; |
15791 } | 15793 } |
15792 FixedArray* other_array = FixedArray::cast(other); | 15794 FixedArray* other_array = FixedArray::cast(other); |
15793 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); | 15795 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); |
15794 if (shared != *shared_) return false; | 15796 if (shared != *shared_) return false; |
15795 int language_unchecked = Smi::cast(other_array->get(2))->value(); | 15797 int language_unchecked = Smi::cast(other_array->get(2))->value(); |
15796 DCHECK(is_valid_language_mode(language_unchecked)); | 15798 DCHECK(is_valid_language_mode(language_unchecked)); |
15797 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); | 15799 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); |
15798 if (language_mode != language_mode_) return false; | 15800 if (language_mode != language_mode_) return false; |
15799 int scope_position = Smi::cast(other_array->get(3))->value(); | 15801 bool is_module = Smi::cast(other_array->get(3))->value() == 1; |
| 15802 if (is_module != is_module_) return false; |
| 15803 int scope_position = Smi::cast(other_array->get(4))->value(); |
15800 if (scope_position != scope_position_) return false; | 15804 if (scope_position != scope_position_) return false; |
15801 String* source = String::cast(other_array->get(1)); | 15805 String* source = String::cast(other_array->get(1)); |
15802 return source->Equals(*source_); | 15806 return source->Equals(*source_); |
15803 } | 15807 } |
15804 | 15808 |
15805 static uint32_t StringSharedHashHelper(String* source, | 15809 static uint32_t StringSharedHashHelper(String* source, |
15806 SharedFunctionInfo* shared, | 15810 SharedFunctionInfo* shared, |
15807 LanguageMode language_mode, | 15811 LanguageMode language_mode, |
15808 int scope_position) { | 15812 bool is_module, int scope_position) { |
15809 uint32_t hash = source->Hash(); | 15813 uint32_t hash = source->Hash(); |
15810 if (shared->HasSourceCode()) { | 15814 if (shared->HasSourceCode()) { |
15811 // Instead of using the SharedFunctionInfo pointer in the hash | 15815 // Instead of using the SharedFunctionInfo pointer in the hash |
15812 // code computation, we use a combination of the hash of the | 15816 // code computation, we use a combination of the hash of the |
15813 // script source code and the start position of the calling scope. | 15817 // script source code and the start position of the calling scope. |
15814 // We do this to ensure that the cache entries can survive garbage | 15818 // We do this to ensure that the cache entries can survive garbage |
15815 // collection. | 15819 // collection. |
15816 Script* script(Script::cast(shared->script())); | 15820 Script* script(Script::cast(shared->script())); |
15817 hash ^= String::cast(script->source())->Hash(); | 15821 hash ^= String::cast(script->source())->Hash(); |
15818 STATIC_ASSERT(LANGUAGE_END == 3); | 15822 STATIC_ASSERT(LANGUAGE_END == 3); |
15819 if (is_strict(language_mode)) hash ^= 0x8000; | 15823 if (is_strict(language_mode)) hash ^= 0x8000; |
| 15824 if (is_module) hash ^= 0x4000; |
15820 hash += scope_position; | 15825 hash += scope_position; |
15821 } | 15826 } |
15822 return hash; | 15827 return hash; |
15823 } | 15828 } |
15824 | 15829 |
15825 uint32_t Hash() override { | 15830 uint32_t Hash() override { |
15826 return StringSharedHashHelper(*source_, *shared_, language_mode_, | 15831 return StringSharedHashHelper(*source_, *shared_, language_mode_, |
15827 scope_position_); | 15832 is_module_, scope_position_); |
15828 } | 15833 } |
15829 | 15834 |
15830 uint32_t HashForObject(Object* obj) override { | 15835 uint32_t HashForObject(Object* obj) override { |
15831 DisallowHeapAllocation no_allocation; | 15836 DisallowHeapAllocation no_allocation; |
15832 if (obj->IsNumber()) { | 15837 if (obj->IsNumber()) { |
15833 return static_cast<uint32_t>(obj->Number()); | 15838 return static_cast<uint32_t>(obj->Number()); |
15834 } | 15839 } |
15835 FixedArray* other_array = FixedArray::cast(obj); | 15840 FixedArray* other_array = FixedArray::cast(obj); |
15836 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); | 15841 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); |
15837 String* source = String::cast(other_array->get(1)); | 15842 String* source = String::cast(other_array->get(1)); |
15838 int language_unchecked = Smi::cast(other_array->get(2))->value(); | 15843 int language_unchecked = Smi::cast(other_array->get(2))->value(); |
15839 DCHECK(is_valid_language_mode(language_unchecked)); | 15844 DCHECK(is_valid_language_mode(language_unchecked)); |
15840 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); | 15845 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); |
15841 int scope_position = Smi::cast(other_array->get(3))->value(); | 15846 bool is_module = Smi::cast(other_array->get(3))->value() == 1; |
15842 return StringSharedHashHelper(source, shared, language_mode, | 15847 int scope_position = Smi::cast(other_array->get(4))->value(); |
| 15848 return StringSharedHashHelper(source, shared, language_mode, is_module, |
15843 scope_position); | 15849 scope_position); |
15844 } | 15850 } |
15845 | 15851 |
15846 | 15852 |
15847 Handle<Object> AsHandle(Isolate* isolate) override { | 15853 Handle<Object> AsHandle(Isolate* isolate) override { |
15848 Handle<FixedArray> array = isolate->factory()->NewFixedArray(4); | 15854 Handle<FixedArray> array = isolate->factory()->NewFixedArray(5); |
15849 array->set(0, *shared_); | 15855 array->set(0, *shared_); |
15850 array->set(1, *source_); | 15856 array->set(1, *source_); |
15851 array->set(2, Smi::FromInt(language_mode_)); | 15857 array->set(2, Smi::FromInt(language_mode_)); |
15852 array->set(3, Smi::FromInt(scope_position_)); | 15858 array->set(3, Smi::FromInt(is_module_ ? 1 : 0)); |
| 15859 array->set(4, Smi::FromInt(scope_position_)); |
15853 return array; | 15860 return array; |
15854 } | 15861 } |
15855 | 15862 |
15856 private: | 15863 private: |
15857 Handle<String> source_; | 15864 Handle<String> source_; |
15858 Handle<SharedFunctionInfo> shared_; | 15865 Handle<SharedFunctionInfo> shared_; |
15859 LanguageMode language_mode_; | 15866 LanguageMode language_mode_; |
| 15867 bool is_module_; |
15860 int scope_position_; | 15868 int scope_position_; |
15861 }; | 15869 }; |
15862 | 15870 |
15863 | 15871 |
15864 namespace { | 15872 namespace { |
15865 | 15873 |
15866 JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, bool* success) { | 15874 JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, bool* success) { |
15867 JSRegExp::Flags value = JSRegExp::kNone; | 15875 JSRegExp::Flags value = JSRegExp::kNone; |
15868 int length = flags->length(); | 15876 int length = flags->length(); |
15869 // A longer flags string cannot be valid. | 15877 // A longer flags string cannot be valid. |
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17097 set = EnsureCapacity(set, 1, key); | 17105 set = EnsureCapacity(set, 1, key); |
17098 int entry = set->FindInsertionEntry(hash); | 17106 int entry = set->FindInsertionEntry(hash); |
17099 set->set(EntryToIndex(entry), *key); | 17107 set->set(EntryToIndex(entry), *key); |
17100 set->ElementAdded(); | 17108 set->ElementAdded(); |
17101 } | 17109 } |
17102 return set; | 17110 return set; |
17103 } | 17111 } |
17104 | 17112 |
17105 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, | 17113 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, |
17106 Handle<Context> context, | 17114 Handle<Context> context, |
17107 LanguageMode language_mode) { | 17115 LanguageMode language_mode, |
| 17116 bool is_module) { |
17108 Isolate* isolate = GetIsolate(); | 17117 Isolate* isolate = GetIsolate(); |
17109 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 17118 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
17110 StringSharedKey key(src, shared, language_mode, kNoSourcePosition); | 17119 StringSharedKey key(src, shared, language_mode, is_module, kNoSourcePosition); |
17111 int entry = FindEntry(&key); | 17120 int entry = FindEntry(&key); |
17112 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17121 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17113 int index = EntryToIndex(entry); | 17122 int index = EntryToIndex(entry); |
17114 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); | 17123 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); |
17115 return Handle<Object>(get(index + 1), isolate); | 17124 return Handle<Object>(get(index + 1), isolate); |
17116 } | 17125 } |
17117 | 17126 |
17118 | 17127 |
17119 Handle<Object> CompilationCacheTable::LookupEval( | 17128 Handle<Object> CompilationCacheTable::LookupEval( |
17120 Handle<String> src, Handle<SharedFunctionInfo> outer_info, | 17129 Handle<String> src, Handle<SharedFunctionInfo> outer_info, |
17121 LanguageMode language_mode, int scope_position) { | 17130 LanguageMode language_mode, int scope_position) { |
17122 Isolate* isolate = GetIsolate(); | 17131 Isolate* isolate = GetIsolate(); |
17123 // Cache key is the tuple (source, outer shared function info, scope position) | 17132 // Cache key is the tuple (source, outer shared function info, scope position) |
17124 // to unambiguously identify the context chain the cached eval code assumes. | 17133 // to unambiguously identify the context chain the cached eval code assumes. |
17125 StringSharedKey key(src, outer_info, language_mode, scope_position); | 17134 StringSharedKey key(src, outer_info, language_mode, false, scope_position); |
17126 int entry = FindEntry(&key); | 17135 int entry = FindEntry(&key); |
17127 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17136 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17128 int index = EntryToIndex(entry); | 17137 int index = EntryToIndex(entry); |
17129 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); | 17138 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); |
17130 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); | 17139 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); |
17131 } | 17140 } |
17132 | 17141 |
17133 | 17142 |
17134 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, | 17143 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, |
17135 JSRegExp::Flags flags) { | 17144 JSRegExp::Flags flags) { |
17136 Isolate* isolate = GetIsolate(); | 17145 Isolate* isolate = GetIsolate(); |
17137 DisallowHeapAllocation no_allocation; | 17146 DisallowHeapAllocation no_allocation; |
17138 RegExpKey key(src, flags); | 17147 RegExpKey key(src, flags); |
17139 int entry = FindEntry(&key); | 17148 int entry = FindEntry(&key); |
17140 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17149 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17141 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); | 17150 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); |
17142 } | 17151 } |
17143 | 17152 |
17144 | |
17145 Handle<CompilationCacheTable> CompilationCacheTable::Put( | 17153 Handle<CompilationCacheTable> CompilationCacheTable::Put( |
17146 Handle<CompilationCacheTable> cache, Handle<String> src, | 17154 Handle<CompilationCacheTable> cache, Handle<String> src, |
17147 Handle<Context> context, LanguageMode language_mode, Handle<Object> value) { | 17155 Handle<Context> context, LanguageMode language_mode, bool is_module, |
| 17156 Handle<Object> value) { |
17148 Isolate* isolate = cache->GetIsolate(); | 17157 Isolate* isolate = cache->GetIsolate(); |
17149 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 17158 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
17150 StringSharedKey key(src, shared, language_mode, kNoSourcePosition); | 17159 StringSharedKey key(src, shared, language_mode, is_module, kNoSourcePosition); |
17151 Handle<Object> k = key.AsHandle(isolate); | 17160 Handle<Object> k = key.AsHandle(isolate); |
17152 cache = EnsureCapacity(cache, 1, &key); | 17161 cache = EnsureCapacity(cache, 1, &key); |
17153 int entry = cache->FindInsertionEntry(key.Hash()); | 17162 int entry = cache->FindInsertionEntry(key.Hash()); |
17154 cache->set(EntryToIndex(entry), *k); | 17163 cache->set(EntryToIndex(entry), *k); |
17155 cache->set(EntryToIndex(entry) + 1, *value); | 17164 cache->set(EntryToIndex(entry) + 1, *value); |
17156 cache->ElementAdded(); | 17165 cache->ElementAdded(); |
17157 return cache; | 17166 return cache; |
17158 } | 17167 } |
17159 | 17168 |
17160 | 17169 |
17161 Handle<CompilationCacheTable> CompilationCacheTable::PutEval( | 17170 Handle<CompilationCacheTable> CompilationCacheTable::PutEval( |
17162 Handle<CompilationCacheTable> cache, Handle<String> src, | 17171 Handle<CompilationCacheTable> cache, Handle<String> src, |
17163 Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value, | 17172 Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value, |
17164 int scope_position) { | 17173 int scope_position) { |
17165 Isolate* isolate = cache->GetIsolate(); | 17174 Isolate* isolate = cache->GetIsolate(); |
17166 StringSharedKey key(src, outer_info, value->language_mode(), scope_position); | 17175 StringSharedKey key(src, outer_info, value->language_mode(), false, |
| 17176 scope_position); |
17167 { | 17177 { |
17168 Handle<Object> k = key.AsHandle(isolate); | 17178 Handle<Object> k = key.AsHandle(isolate); |
17169 DisallowHeapAllocation no_allocation_scope; | 17179 DisallowHeapAllocation no_allocation_scope; |
17170 int entry = cache->FindEntry(&key); | 17180 int entry = cache->FindEntry(&key); |
17171 if (entry != kNotFound) { | 17181 if (entry != kNotFound) { |
17172 cache->set(EntryToIndex(entry), *k); | 17182 cache->set(EntryToIndex(entry), *k); |
17173 cache->set(EntryToIndex(entry) + 1, *value); | 17183 cache->set(EntryToIndex(entry) + 1, *value); |
17174 return cache; | 17184 return cache; |
17175 } | 17185 } |
17176 } | 17186 } |
(...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18978 | 18988 |
18979 Object* data_obj = | 18989 Object* data_obj = |
18980 constructor->shared()->get_api_func_data()->access_check_info(); | 18990 constructor->shared()->get_api_func_data()->access_check_info(); |
18981 if (data_obj->IsUndefined(isolate)) return nullptr; | 18991 if (data_obj->IsUndefined(isolate)) return nullptr; |
18982 | 18992 |
18983 return AccessCheckInfo::cast(data_obj); | 18993 return AccessCheckInfo::cast(data_obj); |
18984 } | 18994 } |
18985 | 18995 |
18986 } // namespace internal | 18996 } // namespace internal |
18987 } // namespace v8 | 18997 } // namespace v8 |
OLD | NEW |