Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: src/objects.cc

Issue 1642223003: [api] Make ObjectTemplate::SetNativeDataProperty() work even if the ObjectTemplate does not have a … (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Removed asserts preventing JSReceiver properties in ObjectTemplate Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7976 matching lines...) Expand 10 before | Expand all | Expand 10 after
7987 FieldIndex index) { 7987 FieldIndex index) {
7988 Isolate* isolate = object->GetIsolate(); 7988 Isolate* isolate = object->GetIsolate();
7989 if (object->IsUnboxedDoubleField(index)) { 7989 if (object->IsUnboxedDoubleField(index)) {
7990 double value = object->RawFastDoublePropertyAt(index); 7990 double value = object->RawFastDoublePropertyAt(index);
7991 return isolate->factory()->NewHeapNumber(value); 7991 return isolate->factory()->NewHeapNumber(value);
7992 } 7992 }
7993 Handle<Object> raw_value(object->RawFastPropertyAt(index), isolate); 7993 Handle<Object> raw_value(object->RawFastPropertyAt(index), isolate);
7994 return Object::WrapForRead(isolate, raw_value, representation); 7994 return Object::WrapForRead(isolate, raw_value, representation);
7995 } 7995 }
7996 7996
7997 enum class BoilerplateKind { kNormalBoilerplate, kApiBoilerplate };
7997 7998
7998 template<class ContextObject> 7999 template <class ContextObject, BoilerplateKind boilerplate_kind>
7999 class JSObjectWalkVisitor { 8000 class JSObjectWalkVisitor {
8000 public: 8001 public:
8001 JSObjectWalkVisitor(ContextObject* site_context, bool copying, 8002 JSObjectWalkVisitor(ContextObject* site_context, bool copying,
8002 JSObject::DeepCopyHints hints) 8003 JSObject::DeepCopyHints hints)
8003 : site_context_(site_context), 8004 : site_context_(site_context),
8004 copying_(copying), 8005 copying_(copying),
8005 hints_(hints) {} 8006 hints_(hints) {}
8006 8007
8007 MUST_USE_RESULT MaybeHandle<JSObject> StructureWalk(Handle<JSObject> object); 8008 MUST_USE_RESULT MaybeHandle<JSObject> StructureWalk(Handle<JSObject> object);
8008 8009
(...skipping 11 matching lines...) Expand all
8020 inline Isolate* isolate() { return site_context()->isolate(); } 8021 inline Isolate* isolate() { return site_context()->isolate(); }
8021 8022
8022 inline bool copying() const { return copying_; } 8023 inline bool copying() const { return copying_; }
8023 8024
8024 private: 8025 private:
8025 ContextObject* site_context_; 8026 ContextObject* site_context_;
8026 const bool copying_; 8027 const bool copying_;
8027 const JSObject::DeepCopyHints hints_; 8028 const JSObject::DeepCopyHints hints_;
8028 }; 8029 };
8029 8030
8030 8031 template <class ContextObject, BoilerplateKind boilerplate_kind>
8031 template <class ContextObject> 8032 MaybeHandle<JSObject> JSObjectWalkVisitor<
8032 MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk( 8033 ContextObject, boilerplate_kind>::StructureWalk(Handle<JSObject> object) {
8033 Handle<JSObject> object) {
8034 Isolate* isolate = this->isolate(); 8034 Isolate* isolate = this->isolate();
8035 bool copying = this->copying(); 8035 bool copying = this->copying();
8036 bool shallow = hints_ == JSObject::kObjectIsShallow; 8036 bool shallow = hints_ == JSObject::kObjectIsShallow;
8037 8037
8038 if (!shallow) { 8038 if (!shallow) {
8039 StackLimitCheck check(isolate); 8039 StackLimitCheck check(isolate);
8040 8040
8041 if (check.HasOverflowed()) { 8041 if (check.HasOverflowed()) {
8042 isolate->StackOverflow(); 8042 isolate->StackOverflow();
8043 return MaybeHandle<JSObject>(); 8043 return MaybeHandle<JSObject>();
8044 } 8044 }
8045 } 8045 }
8046 8046
8047 if (object->map()->is_deprecated()) { 8047 if (object->map()->is_deprecated()) {
8048 JSObject::MigrateInstance(object); 8048 JSObject::MigrateInstance(object);
8049 } 8049 }
8050 8050
8051 Handle<JSObject> copy; 8051 Handle<JSObject> copy;
8052 if (copying) { 8052 if (copying) {
8053 if (boilerplate_kind == BoilerplateKind::kApiBoilerplate) {
8054 if (object->IsJSFunction()) {
8055 #ifdef DEBUG
8056 // Ensure that it is an Api function and template_instantiations_cache
8057 // contains an entry for function's FunctionTemplateInfo.
8058 JSFunction* function = JSFunction::cast(*object);
8059 CHECK(function->shared()->IsApiFunction());
8060 FunctionTemplateInfo* data = function->shared()->get_api_func_data();
8061 auto serial_number = handle(Smi::cast(data->serial_number()), isolate);
8062 CHECK(serial_number->value());
8063 auto cache = isolate->template_instantiations_cache();
8064 Object* element = cache->Lookup(serial_number);
8065 CHECK_EQ(function, element);
8066 #endif
8067 return object;
8068 }
8069 } else {
8070 // JSFunction objects are not allowed to be in normal boilerplates at all.
8071 DCHECK(!object->IsJSFunction());
8072 }
8053 Handle<AllocationSite> site_to_pass; 8073 Handle<AllocationSite> site_to_pass;
8054 if (site_context()->ShouldCreateMemento(object)) { 8074 if (site_context()->ShouldCreateMemento(object)) {
8055 site_to_pass = site_context()->current(); 8075 site_to_pass = site_context()->current();
8056 } 8076 }
8057 copy = isolate->factory()->CopyJSObjectWithAllocationSite( 8077 copy = isolate->factory()->CopyJSObjectWithAllocationSite(
8058 object, site_to_pass); 8078 object, site_to_pass);
8059 } else { 8079 } else {
8060 copy = object; 8080 copy = object;
8061 } 8081 }
8062 8082
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
8209 } 8229 }
8210 } 8230 }
8211 8231
8212 return copy; 8232 return copy;
8213 } 8233 }
8214 8234
8215 8235
8216 MaybeHandle<JSObject> JSObject::DeepWalk( 8236 MaybeHandle<JSObject> JSObject::DeepWalk(
8217 Handle<JSObject> object, 8237 Handle<JSObject> object,
8218 AllocationSiteCreationContext* site_context) { 8238 AllocationSiteCreationContext* site_context) {
8219 JSObjectWalkVisitor<AllocationSiteCreationContext> v(site_context, false, 8239 JSObjectWalkVisitor<AllocationSiteCreationContext,
8220 kNoHints); 8240 BoilerplateKind::kNormalBoilerplate> v(site_context,
8241 false, kNoHints);
8221 MaybeHandle<JSObject> result = v.StructureWalk(object); 8242 MaybeHandle<JSObject> result = v.StructureWalk(object);
8222 Handle<JSObject> for_assert; 8243 Handle<JSObject> for_assert;
8223 DCHECK(!result.ToHandle(&for_assert) || for_assert.is_identical_to(object)); 8244 DCHECK(!result.ToHandle(&for_assert) || for_assert.is_identical_to(object));
8224 return result; 8245 return result;
8225 } 8246 }
8226 8247
8227 8248
8228 MaybeHandle<JSObject> JSObject::DeepCopy( 8249 MaybeHandle<JSObject> JSObject::DeepCopy(
8229 Handle<JSObject> object, 8250 Handle<JSObject> object,
8230 AllocationSiteUsageContext* site_context, 8251 AllocationSiteUsageContext* site_context,
8231 DeepCopyHints hints) { 8252 DeepCopyHints hints) {
8232 JSObjectWalkVisitor<AllocationSiteUsageContext> v(site_context, true, hints); 8253 JSObjectWalkVisitor<AllocationSiteUsageContext,
8254 BoilerplateKind::kNormalBoilerplate> v(site_context, true,
8255 hints);
8233 MaybeHandle<JSObject> copy = v.StructureWalk(object); 8256 MaybeHandle<JSObject> copy = v.StructureWalk(object);
8234 Handle<JSObject> for_assert; 8257 Handle<JSObject> for_assert;
8235 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object)); 8258 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object));
8236 return copy; 8259 return copy;
8237 } 8260 }
8238 8261
8262 class DummyContextObject : public AllocationSiteContext {
8263 public:
8264 explicit DummyContextObject(Isolate* isolate)
8265 : AllocationSiteContext(isolate) {}
8266
8267 bool ShouldCreateMemento(Handle<JSObject> object) { return false; }
8268 Handle<AllocationSite> EnterNewScope() { return Handle<AllocationSite>(); }
8269 void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object) {}
8270 };
8271
8272 MaybeHandle<JSObject> JSObject::DeepCopyApiBoilerplate(
8273 Handle<JSObject> object) {
8274 DummyContextObject dummy_context_object(object->GetIsolate());
8275 JSObjectWalkVisitor<DummyContextObject, BoilerplateKind::kApiBoilerplate> v(
8276 &dummy_context_object, true, kNoHints);
8277 MaybeHandle<JSObject> copy = v.StructureWalk(object);
8278 Handle<JSObject> for_assert;
8279 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object));
8280 return copy;
8281 }
8239 8282
8240 // static 8283 // static
8241 MaybeHandle<Object> JSReceiver::ToPrimitive(Handle<JSReceiver> receiver, 8284 MaybeHandle<Object> JSReceiver::ToPrimitive(Handle<JSReceiver> receiver,
8242 ToPrimitiveHint hint) { 8285 ToPrimitiveHint hint) {
8243 Isolate* const isolate = receiver->GetIsolate(); 8286 Isolate* const isolate = receiver->GetIsolate();
8244 Handle<Object> exotic_to_prim; 8287 Handle<Object> exotic_to_prim;
8245 ASSIGN_RETURN_ON_EXCEPTION( 8288 ASSIGN_RETURN_ON_EXCEPTION(
8246 isolate, exotic_to_prim, 8289 isolate, exotic_to_prim,
8247 GetMethod(receiver, isolate->factory()->to_primitive_symbol()), Object); 8290 GetMethod(receiver, isolate->factory()->to_primitive_symbol()), Object);
8248 if (!exotic_to_prim->IsUndefined()) { 8291 if (!exotic_to_prim->IsUndefined()) {
(...skipping 11500 matching lines...) Expand 10 before | Expand all | Expand 10 after
19749 if (cell->value() != *new_value) { 19792 if (cell->value() != *new_value) {
19750 cell->set_value(*new_value); 19793 cell->set_value(*new_value);
19751 Isolate* isolate = cell->GetIsolate(); 19794 Isolate* isolate = cell->GetIsolate();
19752 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19795 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19753 isolate, DependentCode::kPropertyCellChangedGroup); 19796 isolate, DependentCode::kPropertyCellChangedGroup);
19754 } 19797 }
19755 } 19798 }
19756 19799
19757 } // namespace internal 19800 } // namespace internal
19758 } // namespace v8 19801 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698