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 7918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7929 FieldIndex index) { | 7929 FieldIndex index) { |
7930 Isolate* isolate = object->GetIsolate(); | 7930 Isolate* isolate = object->GetIsolate(); |
7931 if (object->IsUnboxedDoubleField(index)) { | 7931 if (object->IsUnboxedDoubleField(index)) { |
7932 double value = object->RawFastDoublePropertyAt(index); | 7932 double value = object->RawFastDoublePropertyAt(index); |
7933 return isolate->factory()->NewHeapNumber(value); | 7933 return isolate->factory()->NewHeapNumber(value); |
7934 } | 7934 } |
7935 Handle<Object> raw_value(object->RawFastPropertyAt(index), isolate); | 7935 Handle<Object> raw_value(object->RawFastPropertyAt(index), isolate); |
7936 return Object::WrapForRead(isolate, raw_value, representation); | 7936 return Object::WrapForRead(isolate, raw_value, representation); |
7937 } | 7937 } |
7938 | 7938 |
7939 enum class BoilerplateKind { kNormalBoilerplate, kApiBoilerplate }; | 7939 template <class ContextObject> |
7940 | |
7941 template <class ContextObject, BoilerplateKind boilerplate_kind> | |
7942 class JSObjectWalkVisitor { | 7940 class JSObjectWalkVisitor { |
7943 public: | 7941 public: |
7944 JSObjectWalkVisitor(ContextObject* site_context, bool copying, | 7942 JSObjectWalkVisitor(ContextObject* site_context, bool copying, |
7945 JSObject::DeepCopyHints hints) | 7943 JSObject::DeepCopyHints hints) |
7946 : site_context_(site_context), | 7944 : site_context_(site_context), |
7947 copying_(copying), | 7945 copying_(copying), |
7948 hints_(hints) {} | 7946 hints_(hints) {} |
7949 | 7947 |
7950 MUST_USE_RESULT MaybeHandle<JSObject> StructureWalk(Handle<JSObject> object); | 7948 MUST_USE_RESULT MaybeHandle<JSObject> StructureWalk(Handle<JSObject> object); |
7951 | 7949 |
(...skipping 11 matching lines...) Expand all Loading... |
7963 inline Isolate* isolate() { return site_context()->isolate(); } | 7961 inline Isolate* isolate() { return site_context()->isolate(); } |
7964 | 7962 |
7965 inline bool copying() const { return copying_; } | 7963 inline bool copying() const { return copying_; } |
7966 | 7964 |
7967 private: | 7965 private: |
7968 ContextObject* site_context_; | 7966 ContextObject* site_context_; |
7969 const bool copying_; | 7967 const bool copying_; |
7970 const JSObject::DeepCopyHints hints_; | 7968 const JSObject::DeepCopyHints hints_; |
7971 }; | 7969 }; |
7972 | 7970 |
7973 template <class ContextObject, BoilerplateKind boilerplate_kind> | 7971 template <class ContextObject> |
7974 MaybeHandle<JSObject> JSObjectWalkVisitor< | 7972 MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk( |
7975 ContextObject, boilerplate_kind>::StructureWalk(Handle<JSObject> object) { | 7973 Handle<JSObject> object) { |
7976 Isolate* isolate = this->isolate(); | 7974 Isolate* isolate = this->isolate(); |
7977 bool copying = this->copying(); | 7975 bool copying = this->copying(); |
7978 bool shallow = hints_ == JSObject::kObjectIsShallow; | 7976 bool shallow = hints_ == JSObject::kObjectIsShallow; |
7979 | 7977 |
7980 if (!shallow) { | 7978 if (!shallow) { |
7981 StackLimitCheck check(isolate); | 7979 StackLimitCheck check(isolate); |
7982 | 7980 |
7983 if (check.HasOverflowed()) { | 7981 if (check.HasOverflowed()) { |
7984 isolate->StackOverflow(); | 7982 isolate->StackOverflow(); |
7985 return MaybeHandle<JSObject>(); | 7983 return MaybeHandle<JSObject>(); |
7986 } | 7984 } |
7987 } | 7985 } |
7988 | 7986 |
7989 if (object->map()->is_deprecated()) { | 7987 if (object->map()->is_deprecated()) { |
7990 JSObject::MigrateInstance(object); | 7988 JSObject::MigrateInstance(object); |
7991 } | 7989 } |
7992 | 7990 |
7993 Handle<JSObject> copy; | 7991 Handle<JSObject> copy; |
7994 if (copying) { | 7992 if (copying) { |
7995 if (boilerplate_kind == BoilerplateKind::kApiBoilerplate) { | 7993 // JSFunction objects are not allowed to be in normal boilerplates at all. |
7996 if (object->IsJSFunction()) { | 7994 DCHECK(!object->IsJSFunction()); |
7997 #ifdef DEBUG | |
7998 // Ensure that it is an Api function and template_instantiations_cache | |
7999 // contains an entry for function's FunctionTemplateInfo. | |
8000 JSFunction* function = JSFunction::cast(*object); | |
8001 CHECK(function->shared()->IsApiFunction()); | |
8002 FunctionTemplateInfo* data = function->shared()->get_api_func_data(); | |
8003 auto serial_number = handle(Smi::cast(data->serial_number()), isolate); | |
8004 CHECK(serial_number->value()); | |
8005 auto cache = isolate->template_instantiations_cache(); | |
8006 int entry = | |
8007 cache->FindEntry(static_cast<uint32_t>(serial_number->value())); | |
8008 CHECK(entry != UnseededNumberDictionary::kNotFound); | |
8009 Object* element = cache->ValueAt(entry); | |
8010 CHECK_EQ(function, element); | |
8011 #endif | |
8012 return object; | |
8013 } | |
8014 } else { | |
8015 // JSFunction objects are not allowed to be in normal boilerplates at all. | |
8016 DCHECK(!object->IsJSFunction()); | |
8017 } | |
8018 Handle<AllocationSite> site_to_pass; | 7995 Handle<AllocationSite> site_to_pass; |
8019 if (site_context()->ShouldCreateMemento(object)) { | 7996 if (site_context()->ShouldCreateMemento(object)) { |
8020 site_to_pass = site_context()->current(); | 7997 site_to_pass = site_context()->current(); |
8021 } | 7998 } |
8022 copy = isolate->factory()->CopyJSObjectWithAllocationSite( | 7999 copy = isolate->factory()->CopyJSObjectWithAllocationSite( |
8023 object, site_to_pass); | 8000 object, site_to_pass); |
8024 } else { | 8001 } else { |
8025 copy = object; | 8002 copy = object; |
8026 } | 8003 } |
8027 | 8004 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8176 } | 8153 } |
8177 } | 8154 } |
8178 | 8155 |
8179 return copy; | 8156 return copy; |
8180 } | 8157 } |
8181 | 8158 |
8182 | 8159 |
8183 MaybeHandle<JSObject> JSObject::DeepWalk( | 8160 MaybeHandle<JSObject> JSObject::DeepWalk( |
8184 Handle<JSObject> object, | 8161 Handle<JSObject> object, |
8185 AllocationSiteCreationContext* site_context) { | 8162 AllocationSiteCreationContext* site_context) { |
8186 JSObjectWalkVisitor<AllocationSiteCreationContext, | 8163 JSObjectWalkVisitor<AllocationSiteCreationContext> v(site_context, false, |
8187 BoilerplateKind::kNormalBoilerplate> v(site_context, | 8164 kNoHints); |
8188 false, kNoHints); | |
8189 MaybeHandle<JSObject> result = v.StructureWalk(object); | 8165 MaybeHandle<JSObject> result = v.StructureWalk(object); |
8190 Handle<JSObject> for_assert; | 8166 Handle<JSObject> for_assert; |
8191 DCHECK(!result.ToHandle(&for_assert) || for_assert.is_identical_to(object)); | 8167 DCHECK(!result.ToHandle(&for_assert) || for_assert.is_identical_to(object)); |
8192 return result; | 8168 return result; |
8193 } | 8169 } |
8194 | 8170 |
8195 | 8171 |
8196 MaybeHandle<JSObject> JSObject::DeepCopy( | 8172 MaybeHandle<JSObject> JSObject::DeepCopy( |
8197 Handle<JSObject> object, | 8173 Handle<JSObject> object, |
8198 AllocationSiteUsageContext* site_context, | 8174 AllocationSiteUsageContext* site_context, |
8199 DeepCopyHints hints) { | 8175 DeepCopyHints hints) { |
8200 JSObjectWalkVisitor<AllocationSiteUsageContext, | 8176 JSObjectWalkVisitor<AllocationSiteUsageContext> v(site_context, true, hints); |
8201 BoilerplateKind::kNormalBoilerplate> v(site_context, true, | |
8202 hints); | |
8203 MaybeHandle<JSObject> copy = v.StructureWalk(object); | 8177 MaybeHandle<JSObject> copy = v.StructureWalk(object); |
8204 Handle<JSObject> for_assert; | 8178 Handle<JSObject> for_assert; |
8205 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object)); | 8179 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object)); |
8206 return copy; | |
8207 } | |
8208 | |
8209 class DummyContextObject : public AllocationSiteContext { | |
8210 public: | |
8211 explicit DummyContextObject(Isolate* isolate) | |
8212 : AllocationSiteContext(isolate) {} | |
8213 | |
8214 bool ShouldCreateMemento(Handle<JSObject> object) { return false; } | |
8215 Handle<AllocationSite> EnterNewScope() { return Handle<AllocationSite>(); } | |
8216 void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object) {} | |
8217 }; | |
8218 | |
8219 MaybeHandle<JSObject> JSObject::DeepCopyApiBoilerplate( | |
8220 Handle<JSObject> object) { | |
8221 DummyContextObject dummy_context_object(object->GetIsolate()); | |
8222 JSObjectWalkVisitor<DummyContextObject, BoilerplateKind::kApiBoilerplate> v( | |
8223 &dummy_context_object, true, kNoHints); | |
8224 MaybeHandle<JSObject> copy = v.StructureWalk(object); | |
8225 Handle<JSObject> for_assert; | |
8226 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object)); | |
8227 return copy; | 8180 return copy; |
8228 } | 8181 } |
8229 | 8182 |
8230 // static | 8183 // static |
8231 MaybeHandle<Object> JSReceiver::ToPrimitive(Handle<JSReceiver> receiver, | 8184 MaybeHandle<Object> JSReceiver::ToPrimitive(Handle<JSReceiver> receiver, |
8232 ToPrimitiveHint hint) { | 8185 ToPrimitiveHint hint) { |
8233 Isolate* const isolate = receiver->GetIsolate(); | 8186 Isolate* const isolate = receiver->GetIsolate(); |
8234 Handle<Object> exotic_to_prim; | 8187 Handle<Object> exotic_to_prim; |
8235 ASSIGN_RETURN_ON_EXCEPTION( | 8188 ASSIGN_RETURN_ON_EXCEPTION( |
8236 isolate, exotic_to_prim, | 8189 isolate, exotic_to_prim, |
(...skipping 11621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19858 if (cell->value() != *new_value) { | 19811 if (cell->value() != *new_value) { |
19859 cell->set_value(*new_value); | 19812 cell->set_value(*new_value); |
19860 Isolate* isolate = cell->GetIsolate(); | 19813 Isolate* isolate = cell->GetIsolate(); |
19861 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19814 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19862 isolate, DependentCode::kPropertyCellChangedGroup); | 19815 isolate, DependentCode::kPropertyCellChangedGroup); |
19863 } | 19816 } |
19864 } | 19817 } |
19865 | 19818 |
19866 } // namespace internal | 19819 } // namespace internal |
19867 } // namespace v8 | 19820 } // namespace v8 |
OLD | NEW |