From 6ce7f90aba752951ec8468550f8e40bbea157616 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 16 Nov 2015 08:48:43 -0800 Subject: [PATCH] Map v8::Object to v8::internal::JSReceiver BUG=none R=verwaest@chromium.org,rossberg@chromium.org,bmeurer@chromium.org,neis@chromium.org LOG=y Review URL: https://codereview.chromium.org/1413463006 Cr-Commit-Position: refs/heads/master@{#32014} --- src/accessors.cc | 5 +- src/api.cc | 144 ++++++++++++++--------- src/api.h | 8 +- src/objects.cc | 51 +++++--- src/objects.h | 8 +- test/cctest/compiler/function-tester.h | 4 +- test/cctest/test-api-interceptors.cc | 3 +- test/cctest/test-api.cc | 10 +- test/cctest/test-heap-profiler.cc | 20 ++-- test/cctest/test-heap.cc | 98 +++++++-------- test/cctest/test-macro-assembler-mips.cc | 4 +- test/cctest/test-unboxed-doubles.cc | 10 +- 12 files changed, 214 insertions(+), 151 deletions(-) diff --git a/src/accessors.cc b/src/accessors.cc index 73270d187c..9084814678 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -161,7 +161,8 @@ void Accessors::ArgumentsIteratorSetter( const v8::PropertyCallbackInfo& info) { i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); HandleScope scope(isolate); - Handle object_handle = Utils::OpenHandle(*info.This()); + Handle object_handle = + Handle::cast(Utils::OpenHandle(*info.This())); Handle value_handle = Utils::OpenHandle(*val); Handle name_handle = Utils::OpenHandle(*name); @@ -205,7 +206,7 @@ void Accessors::ArrayLengthSetter( i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); HandleScope scope(isolate); - Handle object = Utils::OpenHandle(*info.This()); + Handle object = Utils::OpenHandle(*info.This()); Handle array = Handle::cast(object); Handle length_obj = Utils::OpenHandle(*val); diff --git a/src/api.cc b/src/api.cc index 5d4c9c0c41..8634a2bbd1 100644 --- a/src/api.cc +++ b/src/api.cc @@ -1956,8 +1956,9 @@ MaybeLocal ScriptCompiler::CompileFunctionInContext( i::Handle outer_info(context->closure()->shared(), isolate); for (size_t i = 0; i < context_extension_count; ++i) { - i::Handle extension = + i::Handle extension = Utils::OpenHandle(*context_extensions[i]); + if (!extension->IsJSObject()) return Local(); i::Handle closure(context->closure(), isolate); context = factory->NewWithContext(closure, context, extension); } @@ -3041,8 +3042,7 @@ void External::CheckCast(v8::Value* that) { void v8::Object::CheckCast(Value* that) { i::Handle obj = Utils::OpenHandle(that); - Utils::ApiCheck(obj->IsJSObject(), - "v8::Object::Cast()", + Utils::ApiCheck(obj->IsJSReceiver(), "v8::Object::Cast()", "Could not convert to object"); } @@ -3480,13 +3480,13 @@ Maybe v8::Object::CreateDataProperty(v8::Local context, v8::Local value) { PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", bool); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); i::Handle key_obj = Utils::OpenHandle(*key); i::Handle value_obj = Utils::OpenHandle(*value); i::LookupIterator it = i::LookupIterator::PropertyOrElement( isolate, self, key_obj, i::LookupIterator::OWN); - Maybe result = i::JSObject::CreateDataProperty(&it, value_obj); + Maybe result = i::JSReceiver::CreateDataProperty(&it, value_obj); has_pending_exception = result.IsNothing(); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); return result; @@ -3498,11 +3498,11 @@ Maybe v8::Object::CreateDataProperty(v8::Local context, v8::Local value) { PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", bool); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); i::Handle value_obj = Utils::OpenHandle(*value); i::LookupIterator it(isolate, self, index, i::LookupIterator::OWN); - Maybe result = i::JSObject::CreateDataProperty(&it, value_obj); + Maybe result = i::JSReceiver::CreateDataProperty(&it, value_obj); has_pending_exception = result.IsNothing(); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); return result; @@ -3515,13 +3515,14 @@ Maybe v8::Object::DefineOwnProperty(v8::Local context, v8::PropertyAttribute attributes) { PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()", bool); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); i::Handle key_obj = Utils::OpenHandle(*key); i::Handle value_obj = Utils::OpenHandle(*value); if (self->IsAccessCheckNeeded() && - !isolate->MayAccess(handle(isolate->context()), self)) { - isolate->ReportFailedAccessCheck(self); + !isolate->MayAccess(handle(isolate->context()), + i::Handle::cast(self))) { + isolate->ReportFailedAccessCheck(i::Handle::cast(self)); return Nothing(); } @@ -3555,8 +3556,8 @@ static i::MaybeHandle DefineObjectProperty( Maybe v8::Object::ForceSet(v8::Local context, v8::Local key, v8::Local value, v8::PropertyAttribute attribs) { - PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); - auto self = Utils::OpenHandle(this); + PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::ForceSet()", bool); + auto self = i::Handle::cast(Utils::OpenHandle(this)); auto key_obj = Utils::OpenHandle(*key); auto value_obj = Utils::OpenHandle(*value); has_pending_exception = @@ -3573,7 +3574,8 @@ bool v8::Object::ForceSet(v8::Local key, v8::Local value, PREPARE_FOR_EXECUTION_GENERIC(isolate, Local(), "v8::Object::ForceSet", false, i::HandleScope, false); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = + i::Handle::cast(Utils::OpenHandle(this)); i::Handle key_obj = Utils::OpenHandle(*key); i::Handle value_obj = Utils::OpenHandle(*value); has_pending_exception = @@ -3702,8 +3704,8 @@ Maybe v8::Object::SetPrototype(Local context, // We do not allow exceptions thrown while setting the prototype // to propagate outside. TryCatch try_catch(reinterpret_cast(isolate)); - auto result = i::JSObject::SetPrototype(self, value_obj, false, - i::Object::THROW_ON_ERROR); + auto result = i::JSReceiver::SetPrototype(self, value_obj, false, + i::Object::THROW_ON_ERROR); has_pending_exception = result.IsNothing(); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); return Just(true); @@ -3944,24 +3946,27 @@ bool v8::Object::Has(uint32_t index) { template -static Maybe ObjectSetAccessor(Local context, Object* obj, +static Maybe ObjectSetAccessor(Local context, Object* self, Local name, Getter getter, Setter setter, Data data, AccessControl settings, PropertyAttribute attributes) { PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::SetAccessor()", bool); + if (!Utils::OpenHandle(self)->IsJSObject()) return Just(false); + i::Handle obj = + i::Handle::cast(Utils::OpenHandle(self)); v8::Local signature; auto info = MakeAccessorInfo(name, getter, setter, data, settings, attributes, signature); if (info.is_null()) return Nothing(); - bool fast = Utils::OpenHandle(obj)->HasFastProperties(); + bool fast = obj->HasFastProperties(); i::Handle result; has_pending_exception = - !i::JSObject::SetAccessor(Utils::OpenHandle(obj), info).ToHandle(&result); + !i::JSObject::SetAccessor(obj, info).ToHandle(&result); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); if (result->IsUndefined()) return Nothing(); if (fast) { - i::JSObject::MigrateSlowToFast(Utils::OpenHandle(obj), 0, "APISetAccessor"); + i::JSObject::MigrateSlowToFast(obj, 0, "APISetAccessor"); } return Just(true); } @@ -4005,13 +4010,13 @@ void Object::SetAccessorProperty(Local name, Local getter, i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); ENTER_V8(isolate); i::HandleScope scope(isolate); + auto self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return; i::Handle getter_i = v8::Utils::OpenHandle(*getter); i::Handle setter_i = v8::Utils::OpenHandle(*setter, true); if (setter_i.is_null()) setter_i = isolate->factory()->null_value(); - i::JSObject::DefineAccessor(v8::Utils::OpenHandle(this), - v8::Utils::OpenHandle(*name), - getter_i, - setter_i, + i::JSObject::DefineAccessor(i::Handle::cast(self), + v8::Utils::OpenHandle(*name), getter_i, setter_i, static_cast(attribute)); } @@ -4040,8 +4045,10 @@ Maybe v8::Object::HasRealNamedProperty(Local context, PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::HasRealNamedProperty()", bool); auto self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return Just(false); auto key_val = Utils::OpenHandle(*key); - auto result = i::JSObject::HasRealNamedProperty(self, key_val); + auto result = i::JSObject::HasRealNamedProperty( + i::Handle::cast(self), key_val); has_pending_exception = result.IsNothing(); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); return result; @@ -4059,7 +4066,9 @@ Maybe v8::Object::HasRealIndexedProperty(Local context, PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::HasRealIndexedProperty()", bool); auto self = Utils::OpenHandle(this); - auto result = i::JSObject::HasRealElementProperty(self, index); + if (!self->IsJSObject()) return Just(false); + auto result = i::JSObject::HasRealElementProperty( + i::Handle::cast(self), index); has_pending_exception = result.IsNothing(); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); return result; @@ -4077,8 +4086,10 @@ Maybe v8::Object::HasRealNamedCallbackProperty(Local context, PREPARE_FOR_EXECUTION_PRIMITIVE( context, "v8::Object::HasRealNamedCallbackProperty()", bool); auto self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return Just(false); auto key_val = Utils::OpenHandle(*key); - auto result = i::JSObject::HasRealNamedCallbackProperty(self, key_val); + auto result = i::JSObject::HasRealNamedCallbackProperty( + i::Handle::cast(self), key_val); has_pending_exception = result.IsNothing(); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); return result; @@ -4093,13 +4104,15 @@ bool v8::Object::HasRealNamedCallbackProperty(Local key) { bool v8::Object::HasNamedLookupInterceptor() { auto self = Utils::OpenHandle(this); - return self->HasNamedInterceptor(); + return self->IsJSObject() && + i::Handle::cast(self)->HasNamedInterceptor(); } bool v8::Object::HasIndexedLookupInterceptor() { auto self = Utils::OpenHandle(this); - return self->HasIndexedInterceptor(); + return self->IsJSObject() && + i::Handle::cast(self)->HasIndexedInterceptor(); } @@ -4107,7 +4120,8 @@ MaybeLocal v8::Object::GetRealNamedPropertyInPrototypeChain( Local context, Local key) { PREPARE_FOR_EXECUTION( context, "v8::Object::GetRealNamedPropertyInPrototypeChain()", Value); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return MaybeLocal(); i::Handle key_obj = Utils::OpenHandle(*key); i::PrototypeIterator iter(isolate, self); if (iter.IsAtEnd()) return MaybeLocal(); @@ -4138,7 +4152,8 @@ v8::Object::GetRealNamedPropertyAttributesInPrototypeChain( PREPARE_FOR_EXECUTION_PRIMITIVE( context, "v8::Object::GetRealNamedPropertyAttributesInPrototypeChain()", PropertyAttribute); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return Nothing(); i::Handle key_obj = Utils::OpenHandle(*key); i::PrototypeIterator iter(isolate, self); if (iter.IsAtEnd()) return Nothing(); @@ -4213,7 +4228,7 @@ Maybe v8::Object::GetRealNamedPropertyAttributes( Local v8::Object::Clone() { - auto self = Utils::OpenHandle(this); + auto self = i::Handle::cast(Utils::OpenHandle(this)); auto isolate = self->GetIsolate(); ENTER_V8(isolate); auto result = isolate->factory()->CopyJSObject(self); @@ -4242,17 +4257,19 @@ bool v8::Object::SetHiddenValue(v8::Local key, i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); ENTER_V8(isolate); i::HandleScope scope(isolate); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return false; i::Handle key_obj = Utils::OpenHandle(*key); i::Handle key_string = isolate->factory()->InternalizeString(key_obj); if (value.IsEmpty()) { - i::JSObject::DeleteHiddenProperty(self, key_string); + i::JSObject::DeleteHiddenProperty(i::Handle::cast(self), + key_string); return true; } i::Handle value_obj = Utils::OpenHandle(*value); - i::Handle result = - i::JSObject::SetHiddenProperty(self, key_string, value_obj); + i::Handle result = i::JSObject::SetHiddenProperty( + i::Handle::cast(self), key_string, value_obj); return *result == *self; } @@ -4260,11 +4277,14 @@ bool v8::Object::SetHiddenValue(v8::Local key, v8::Local v8::Object::GetHiddenValue(v8::Local key) { i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); ENTER_V8(isolate); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return v8::Local(); i::Handle key_obj = Utils::OpenHandle(*key); i::Handle key_string = isolate->factory()->InternalizeString(key_obj); - i::Handle result(self->GetHiddenProperty(key_string), isolate); + i::Handle result( + i::Handle::cast(self)->GetHiddenProperty(key_string), + isolate); if (result->IsTheHole()) return v8::Local(); return Utils::ToLocal(result); } @@ -4274,11 +4294,13 @@ bool v8::Object::DeleteHiddenValue(v8::Local key) { i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); ENTER_V8(isolate); i::HandleScope scope(isolate); - i::Handle self = Utils::OpenHandle(this); + i::Handle self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return false; i::Handle key_obj = Utils::OpenHandle(*key); i::Handle key_string = isolate->factory()->InternalizeString(key_obj); - i::JSObject::DeleteHiddenProperty(self, key_string); + i::JSObject::DeleteHiddenProperty(i::Handle::cast(self), + key_string); return true; } @@ -5302,51 +5324,56 @@ uint32_t Uint32::Value() const { int v8::Object::InternalFieldCount() { - i::Handle obj = Utils::OpenHandle(this); - return obj->GetInternalFieldCount(); + i::Handle self = Utils::OpenHandle(this); + if (!self->IsJSObject()) return 0; + return i::Handle::cast(self)->GetInternalFieldCount(); } -static bool InternalFieldOK(i::Handle obj, - int index, +static bool InternalFieldOK(i::Handle obj, int index, const char* location) { - return Utils::ApiCheck(index < obj->GetInternalFieldCount(), - location, - "Internal field out of bounds"); + return Utils::ApiCheck( + obj->IsJSObject() && + (index < i::Handle::cast(obj)->GetInternalFieldCount()), + location, "Internal field out of bounds"); } Local v8::Object::SlowGetInternalField(int index) { - i::Handle obj = Utils::OpenHandle(this); + i::Handle obj = Utils::OpenHandle(this); const char* location = "v8::Object::GetInternalField()"; if (!InternalFieldOK(obj, index, location)) return Local(); - i::Handle value(obj->GetInternalField(index), obj->GetIsolate()); + i::Handle value( + i::Handle::cast(obj)->GetInternalField(index), + obj->GetIsolate()); return Utils::ToLocal(value); } void v8::Object::SetInternalField(int index, v8::Local value) { - i::Handle obj = Utils::OpenHandle(this); + i::Handle obj = Utils::OpenHandle(this); const char* location = "v8::Object::SetInternalField()"; if (!InternalFieldOK(obj, index, location)) return; i::Handle val = Utils::OpenHandle(*value); - obj->SetInternalField(index, *val); + i::Handle::cast(obj)->SetInternalField(index, *val); } void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { - i::Handle obj = Utils::OpenHandle(this); + i::Handle obj = Utils::OpenHandle(this); const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; if (!InternalFieldOK(obj, index, location)) return NULL; - return DecodeSmiToAligned(obj->GetInternalField(index), location); + return DecodeSmiToAligned( + i::Handle::cast(obj)->GetInternalField(index), location); } void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { - i::Handle obj = Utils::OpenHandle(this); + i::Handle obj = Utils::OpenHandle(this); const char* location = "v8::Object::SetAlignedPointerInInternalField()"; if (!InternalFieldOK(obj, index, location)) return; - obj->SetInternalField(index, EncodeAlignedAsSmi(value, location)); + i::Handle::cast(obj) + ->SetInternalField(index, EncodeAlignedAsSmi(value, location)); DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); } @@ -6426,7 +6453,7 @@ Local Promise::Resolver::New(Isolate* isolate) { Local Promise::Resolver::GetPromise() { - i::Handle promise = Utils::OpenHandle(this); + i::Handle promise = Utils::OpenHandle(this); return Local::Cast(Utils::ToLocal(promise)); } @@ -6534,7 +6561,7 @@ Local Promise::Then(Local handler) { bool Promise::HasHandler() { - i::Handle promise = Utils::OpenHandle(this); + i::Handle promise = Utils::OpenHandle(this); i::Isolate* isolate = promise->GetIsolate(); LOG_API(isolate, "Promise::HasRejectHandler"); ENTER_V8(isolate); @@ -7819,8 +7846,9 @@ MaybeLocal Debug::GetMirror(Local context, const int kArgc = 1; v8::Local argv[kArgc] = {obj}; Local result; - has_pending_exception = !v8_fun->Call(context, Utils::ToLocal(debug), kArgc, - argv).ToLocal(&result); + has_pending_exception = + !v8_fun->Call(context, Utils::ToLocal(debug), kArgc, argv) + .ToLocal(&result); RETURN_ON_FAILED_EXECUTION(Value); RETURN_ESCAPED(result); } diff --git a/src/api.h b/src/api.h index 08fbd7ee8f..1ed14a133f 100644 --- a/src/api.h +++ b/src/api.h @@ -145,7 +145,7 @@ class RegisteredExtension { V(TypeSwitch, TypeSwitchInfo) \ V(Data, Object) \ V(RegExp, JSRegExp) \ - V(Object, JSObject) \ + V(Object, JSReceiver) \ V(Array, JSArray) \ V(Map, JSMap) \ V(Set, JSSet) \ @@ -200,8 +200,12 @@ class Utils { v8::internal::Handle obj); static inline Local ToLocal( v8::internal::Handle obj); + static inline Local ToLocal( + v8::internal::Handle obj); static inline Local ToLocal( v8::internal::Handle obj); + static inline Local ToLocal( + v8::internal::Handle obj); static inline Local ToLocal( v8::internal::Handle obj); static inline Local ToLocal( @@ -353,7 +357,9 @@ MAKE_TO_LOCAL(ToLocal, Name, Name) MAKE_TO_LOCAL(ToLocal, String, String) MAKE_TO_LOCAL(ToLocal, Symbol, Symbol) MAKE_TO_LOCAL(ToLocal, JSRegExp, RegExp) +MAKE_TO_LOCAL(ToLocal, JSReceiver, Object) MAKE_TO_LOCAL(ToLocal, JSObject, Object) +MAKE_TO_LOCAL(ToLocal, JSProxy, Object) MAKE_TO_LOCAL(ToLocal, JSArray, Array) MAKE_TO_LOCAL(ToLocal, JSMap, Map) MAKE_TO_LOCAL(ToLocal, JSSet, Set) diff --git a/src/objects.cc b/src/objects.cc index f5ad23396b..fefdc5be48 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -2249,6 +2249,21 @@ String* JSReceiver::constructor_name() { } +Context* JSReceiver::GetCreationContext() { + Object* constructor = map()->GetConstructor(); + JSFunction* function; + if (!constructor->IsJSFunction()) { + // Functions have null as a constructor, + // but any JSFunction knows its context immediately. + function = JSFunction::cast(this); + } else { + function = JSFunction::cast(constructor); + } + + return function->context()->native_context(); +} + + static Handle WrapType(Handle type) { if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()->Map()); return type; @@ -2353,21 +2368,6 @@ void JSObject::AddSlowProperty(Handle object, } -Context* JSObject::GetCreationContext() { - Object* constructor = this->map()->GetConstructor(); - JSFunction* function; - if (!constructor->IsJSFunction()) { - // Functions have null as a constructor, - // but any JSFunction knows its context immediately. - function = JSFunction::cast(this); - } else { - function = JSFunction::cast(constructor); - } - - return function->context()->native_context(); -} - - MaybeHandle JSObject::EnqueueChangeRecord(Handle object, const char* type_str, Handle name, @@ -6495,6 +6495,15 @@ bool JSReceiver::ValidateAndApplyPropertyDescriptor( } +// static +Maybe JSReceiver::CreateDataProperty(LookupIterator* it, + Handle value) { + // TODO(rossberg): Support proxies. + if (!it->GetReceiver()->IsJSObject()) return Nothing(); + return JSObject::CreateDataProperty(it, value); +} + + // TODO(jkummerow): Consider unification with FastAsArrayLength() in // accessors.cc. bool PropertyKeyToArrayLength(Handle value, uint32_t* length) { @@ -14868,9 +14877,11 @@ MaybeHandle JSObject::GetKeysForNamedInterceptor( } if (result.IsEmpty()) return MaybeHandle(); DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || - v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements()); + (v8::Utils::OpenHandle(*result)->IsJSObject() && + Handle::cast(v8::Utils::OpenHandle(*result)) + ->HasSloppyArgumentsElements())); // Rebox before returning. - return handle(*v8::Utils::OpenHandle(*result), isolate); + return handle(JSObject::cast(*v8::Utils::OpenHandle(*result)), isolate); } @@ -14891,9 +14902,11 @@ MaybeHandle JSObject::GetKeysForIndexedInterceptor( } if (result.IsEmpty()) return MaybeHandle(); DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || - v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements()); + (v8::Utils::OpenHandle(*result)->IsJSObject() && + Handle::cast(v8::Utils::OpenHandle(*result)) + ->HasSloppyArgumentsElements())); // Rebox before returning. - return handle(*v8::Utils::OpenHandle(*result), isolate); + return handle(JSObject::cast(*v8::Utils::OpenHandle(*result)), isolate); } diff --git a/src/objects.h b/src/objects.h index c2e4983abe..d30bda2ad3 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1833,6 +1833,10 @@ class JSReceiver: public HeapObject { Handle key, PropertyDescriptor* desc, ShouldThrow should_throw); + // "virtual" dispatcher to the correct [[CreateDataProperty]] implementation. + MUST_USE_RESULT static Maybe CreateDataProperty(LookupIterator* it, + Handle value); + // ES6 9.1.6.1 static bool OrdinaryDefineOwnProperty(Isolate* isolate, Handle object, @@ -1879,6 +1883,8 @@ class JSReceiver: public HeapObject { // function that was used to instantiate the object). String* constructor_name(); + Context* GetCreationContext(); + MUST_USE_RESULT static inline Maybe GetPropertyAttributes( Handle object, Handle name); MUST_USE_RESULT static inline Maybe @@ -2463,8 +2469,6 @@ class JSObject: public JSReceiver { typedef FlexibleBodyDescriptor BodyDescriptor; - Context* GetCreationContext(); - // Enqueue change record for Object.observe. May cause GC. MUST_USE_RESULT static MaybeHandle EnqueueChangeRecord( Handle object, const char* type, Handle name, diff --git a/test/cctest/compiler/function-tester.h b/test/cctest/compiler/function-tester.h index 8741808d82..c82b7e1dfc 100644 --- a/test/cctest/compiler/function-tester.h +++ b/test/cctest/compiler/function-tester.h @@ -124,8 +124,8 @@ class FunctionTester : public InitializedHandleScope { } Handle NewObject(const char* source) { - return v8::Utils::OpenHandle( - *v8::Local::Cast(CompileRun(source))); + return Handle::cast(v8::Utils::OpenHandle( + *v8::Local::Cast(CompileRun(source)))); } Handle Val(const char* string) { diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc index 3327d782f7..19f9b400ac 100644 --- a/test/cctest/test-api-interceptors.cc +++ b/test/cctest/test-api-interceptors.cc @@ -1582,7 +1582,8 @@ void SloppyArgsIndexedPropertyEnumerator( Local result = Local::Cast(indexed_property_names_script->Run()); // Have to populate the handle manually, as it's not Cast-able. - i::Handle o = v8::Utils::OpenHandle(result); + i::Handle o = + v8::Utils::OpenHandle(result); i::Handle array(reinterpret_cast(*o)); info.GetReturnValue().Set(v8::Utils::ToLocal(array)); } diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index f47c997f51..84a63c0dc4 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -1928,7 +1928,7 @@ THREADED_TEST(ExecutableAccessorIsPreservedOnAttributeChange) { v8::HandleScope scope(isolate); LocalContext env; v8::Local res = CompileRun("var a = []; a;"); - i::Handle a(v8::Utils::OpenHandle(v8::Object::Cast(*res))); + i::Handle a(v8::Utils::OpenHandle(v8::Object::Cast(*res))); CHECK(a->map()->instance_descriptors()->IsFixedArray()); CHECK_GT(i::FixedArray::cast(a->map()->instance_descriptors())->length(), 0); CompileRun("Object.defineProperty(a, 'length', { writable: false });"); @@ -9730,7 +9730,7 @@ THREADED_TEST(Constructor) { Local cons = templ->GetFunction(); context->Global()->Set(v8_str("Fun"), cons); Local inst = cons->NewInstance(); - i::Handle obj(v8::Utils::OpenHandle(*inst)); + i::Handle obj(v8::Utils::OpenHandle(*inst)); CHECK(obj->IsJSObject()); Local value = CompileRun("(new Fun()).constructor === Fun"); CHECK(value->BooleanValue()); @@ -13741,7 +13741,7 @@ static void ObjectWithExternalArrayTestHelper(Handle context, int element_count, i::ExternalArrayType array_type, int64_t low, int64_t high) { - i::Handle jsobj = v8::Utils::OpenHandle(*obj); + i::Handle jsobj = v8::Utils::OpenHandle(*obj); i::Isolate* isolate = jsobj->GetIsolate(); obj->Set(v8_str("field"), v8::Int32::New(reinterpret_cast(isolate), 1503)); @@ -13971,8 +13971,8 @@ static void ObjectWithExternalArrayTestHelper(Handle context, CHECK_EQ(true, result->BooleanValue()); } - i::Handle array( - ExternalArrayClass::cast(jsobj->elements())); + i::Handle array(ExternalArrayClass::cast( + i::Handle::cast(jsobj)->elements())); for (int i = 0; i < element_count; i++) { array->set(i, static_cast(i)); } diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 9bdd3b81e6..a5973c7578 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -1829,31 +1829,37 @@ TEST(GetConstructorName) { v8::Local js_global = env->Global()->GetPrototype().As(); v8::Local obj1 = js_global->Get(v8_str("obj1")).As(); - i::Handle js_obj1 = v8::Utils::OpenHandle(*obj1); + i::Handle js_obj1 = + i::Handle::cast(v8::Utils::OpenHandle(*obj1)); CHECK_EQ(0, StringCmp( "Constructor1", i::V8HeapExplorer::GetConstructorName(*js_obj1))); v8::Local obj2 = js_global->Get(v8_str("obj2")).As(); - i::Handle js_obj2 = v8::Utils::OpenHandle(*obj2); + i::Handle js_obj2 = + i::Handle::cast(v8::Utils::OpenHandle(*obj2)); CHECK_EQ(0, StringCmp( "Constructor2", i::V8HeapExplorer::GetConstructorName(*js_obj2))); v8::Local obj3 = js_global->Get(v8_str("obj3")).As(); - i::Handle js_obj3 = v8::Utils::OpenHandle(*obj3); + i::Handle js_obj3 = + i::Handle::cast(v8::Utils::OpenHandle(*obj3)); // TODO(verwaest): Restore to Constructor3 once supported by the // heap-snapshot-generator. CHECK_EQ( 0, StringCmp("Object", i::V8HeapExplorer::GetConstructorName(*js_obj3))); v8::Local obj4 = js_global->Get(v8_str("obj4")).As(); - i::Handle js_obj4 = v8::Utils::OpenHandle(*obj4); + i::Handle js_obj4 = + i::Handle::cast(v8::Utils::OpenHandle(*obj4)); // TODO(verwaest): Restore to Constructor4 once supported by the // heap-snapshot-generator. CHECK_EQ( 0, StringCmp("Object", i::V8HeapExplorer::GetConstructorName(*js_obj4))); v8::Local obj5 = js_global->Get(v8_str("obj5")).As(); - i::Handle js_obj5 = v8::Utils::OpenHandle(*obj5); + i::Handle js_obj5 = + i::Handle::cast(v8::Utils::OpenHandle(*obj5)); CHECK_EQ(0, StringCmp( "Object", i::V8HeapExplorer::GetConstructorName(*js_obj5))); v8::Local obj6 = js_global->Get(v8_str("obj6")).As(); - i::Handle js_obj6 = v8::Utils::OpenHandle(*obj6); + i::Handle js_obj6 = + i::Handle::cast(v8::Utils::OpenHandle(*obj6)); CHECK_EQ(0, StringCmp( "Object", i::V8HeapExplorer::GetConstructorName(*js_obj6))); } @@ -1912,7 +1918,7 @@ TEST(FastCaseRedefinedAccessors) { "});\n"); v8::Local js_global = env->Global()->GetPrototype().As(); - i::Handle js_obj1 = + i::Handle js_obj1 = v8::Utils::OpenHandle(*js_global->Get(v8_str("obj1")).As()); USE(js_obj1); diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 41e6c24b9f..abe6025c0f 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -2635,7 +2635,7 @@ TEST(PrototypeTransitionClearing) { v8::Local ctx = CcTest::isolate()->GetCurrentContext(); CompileRun("var base = {};"); - i::Handle baseObject = + i::Handle baseObject = v8::Utils::OpenHandle(*v8::Local::Cast( CcTest::global()->Get(ctx, v8_str("base")).ToLocalChecked())); @@ -2877,7 +2877,7 @@ TEST(OptimizedAllocationAlwaysInNewSpace) { ->Int32Value(ctx) .FromJust()); - i::Handle o = + i::Handle o = v8::Utils::OpenHandle(*v8::Local::Cast(res)); CHECK(CcTest::heap()->InNewSpace(*o)); @@ -2918,14 +2918,14 @@ TEST(OptimizedPretenuringAllocationFolding) { v8::Local int_array = v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked(); - i::Handle int_array_handle = - v8::Utils::OpenHandle(*v8::Local::Cast(int_array)); + i::Handle int_array_handle = i::Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(int_array))); v8::Local double_array = v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked(); - i::Handle double_array_handle = - v8::Utils::OpenHandle(*v8::Local::Cast(double_array)); + i::Handle double_array_handle = i::Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(double_array))); - i::Handle o = + i::Handle o = v8::Utils::OpenHandle(*v8::Local::Cast(res)); CHECK(CcTest::heap()->InOldSpace(*o)); CHECK(CcTest::heap()->InOldSpace(*int_array_handle)); @@ -2967,8 +2967,8 @@ TEST(OptimizedPretenuringObjectArrayLiterals) { v8::Local res = CompileRun(source.start()); - i::Handle o = - v8::Utils::OpenHandle(*v8::Local::Cast(res)); + i::Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InOldSpace(o->elements())); CHECK(CcTest::heap()->InOldSpace(*o)); @@ -3008,8 +3008,8 @@ TEST(OptimizedPretenuringMixedInObjectProperties) { v8::Local res = CompileRun(source.start()); - i::Handle o = - v8::Utils::OpenHandle(*v8::Local::Cast(res)); + i::Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InOldSpace(*o)); FieldIndex idx1 = FieldIndex::ForPropertyIndex(o->map(), 0); @@ -3065,8 +3065,8 @@ TEST(OptimizedPretenuringDoubleArrayProperties) { v8::Local res = CompileRun(source.start()); - i::Handle o = - v8::Utils::OpenHandle(*v8::Local::Cast(res)); + i::Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InOldSpace(*o)); CHECK(CcTest::heap()->InOldSpace(o->properties())); @@ -3105,8 +3105,8 @@ TEST(OptimizedPretenuringdoubleArrayLiterals) { v8::Local res = CompileRun(source.start()); - i::Handle o = - v8::Utils::OpenHandle(*v8::Local::Cast(res)); + i::Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InOldSpace(o->elements())); CHECK(CcTest::heap()->InOldSpace(*o)); @@ -3146,14 +3146,15 @@ TEST(OptimizedPretenuringNestedMixedArrayLiterals) { v8::Local int_array = v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked(); - i::Handle int_array_handle = - v8::Utils::OpenHandle(*v8::Local::Cast(int_array)); + i::Handle int_array_handle = i::Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(int_array))); v8::Local double_array = v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked(); - i::Handle double_array_handle = - v8::Utils::OpenHandle(*v8::Local::Cast(double_array)); + i::Handle double_array_handle = i::Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(double_array))); - Handle o = v8::Utils::OpenHandle(*v8::Local::Cast(res)); + Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InOldSpace(*o)); CHECK(CcTest::heap()->InOldSpace(*int_array_handle)); CHECK(CcTest::heap()->InOldSpace(int_array_handle->elements())); @@ -3196,14 +3197,15 @@ TEST(OptimizedPretenuringNestedObjectLiterals) { v8::Local int_array_1 = v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked(); - Handle int_array_handle_1 = - v8::Utils::OpenHandle(*v8::Local::Cast(int_array_1)); + Handle int_array_handle_1 = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(int_array_1))); v8::Local int_array_2 = v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked(); - Handle int_array_handle_2 = - v8::Utils::OpenHandle(*v8::Local::Cast(int_array_2)); + Handle int_array_handle_2 = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(int_array_2))); - Handle o = v8::Utils::OpenHandle(*v8::Local::Cast(res)); + Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InOldSpace(*o)); CHECK(CcTest::heap()->InOldSpace(*int_array_handle_1)); CHECK(CcTest::heap()->InOldSpace(int_array_handle_1->elements())); @@ -3246,15 +3248,15 @@ TEST(OptimizedPretenuringNestedDoubleLiterals) { v8::Local double_array_1 = v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked(); - i::Handle double_array_handle_1 = - v8::Utils::OpenHandle(*v8::Local::Cast(double_array_1)); + i::Handle double_array_handle_1 = i::Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(double_array_1))); v8::Local double_array_2 = v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked(); - i::Handle double_array_handle_2 = - v8::Utils::OpenHandle(*v8::Local::Cast(double_array_2)); + i::Handle double_array_handle_2 = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(double_array_2))); - i::Handle o = - v8::Utils::OpenHandle(*v8::Local::Cast(res)); + i::Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InOldSpace(*o)); CHECK(CcTest::heap()->InOldSpace(*double_array_handle_1)); CHECK(CcTest::heap()->InOldSpace(double_array_handle_1->elements())); @@ -3286,8 +3288,8 @@ TEST(OptimizedAllocationArrayLiterals) { ->Int32Value(ctx) .FromJust()); - i::Handle o = - v8::Utils::OpenHandle(*v8::Local::Cast(res)); + i::Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(res))); CHECK(CcTest::heap()->InNewSpace(o->elements())); } @@ -3321,8 +3323,9 @@ TEST(Regress1465) { CompileRun("var root = new F;"); } - i::Handle root = v8::Utils::OpenHandle(*v8::Local::Cast( - CcTest::global()->Get(ctx, v8_str("root")).ToLocalChecked())); + i::Handle root = + v8::Utils::OpenHandle(*v8::Local::Cast( + CcTest::global()->Get(ctx, v8_str("root")).ToLocalChecked())); // Count number of live transitions before marking. int transitions_before = CountMapTransitions(root->map()); @@ -3352,10 +3355,11 @@ static void AddTransitions(int transitions_count) { static i::Handle GetByName(const char* name) { - return v8::Utils::OpenHandle(*v8::Local::Cast( - CcTest::global() - ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(name)) - .ToLocalChecked())); + return i::Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast( + CcTest::global() + ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(name)) + .ToLocalChecked()))); } @@ -3515,7 +3519,7 @@ TEST(Regress2143a) { // Explicitly request GC to perform final marking step and sweeping. CcTest::heap()->CollectAllGarbage(); - Handle root = v8::Utils::OpenHandle(*v8::Local::Cast( + Handle root = v8::Utils::OpenHandle(*v8::Local::Cast( CcTest::global() ->Get(CcTest::isolate()->GetCurrentContext(), v8_str("root")) .ToLocalChecked())); @@ -3558,7 +3562,7 @@ TEST(Regress2143b) { // Explicitly request GC to perform final marking step and sweeping. CcTest::heap()->CollectAllGarbage(); - Handle root = v8::Utils::OpenHandle(*v8::Local::Cast( + Handle root = v8::Utils::OpenHandle(*v8::Local::Cast( CcTest::global() ->Get(CcTest::isolate()->GetCurrentContext(), v8_str("root")) .ToLocalChecked())); @@ -3761,7 +3765,7 @@ TEST(ICInBuiltInIsClearedAppropriately) { { LocalContext env; v8::Local res = CompileRun("Function.apply"); - i::Handle maybe_apply = + i::Handle maybe_apply = v8::Utils::OpenHandle(*v8::Local::Cast(res)); apply = i::Handle::cast(maybe_apply); i::Handle vector(apply->shared()->feedback_vector()); @@ -5573,8 +5577,8 @@ TEST(ArrayShiftSweeping) { "array.shift();" "array;"); - Handle o = - v8::Utils::OpenHandle(*v8::Local::Cast(result)); + Handle o = Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast(result))); CHECK(heap->InOldSpace(o->elements())); CHECK(heap->InOldSpace(*o)); Page* page = Page::FromAddress(o->elements()->address()); @@ -5722,7 +5726,7 @@ TEST(Regress3631) { CcTest::heap()->StartIncrementalMarking(); } // Incrementally mark the backing store. - Handle obj = + Handle obj = v8::Utils::OpenHandle(*v8::Local::Cast(result)); Handle weak_map(reinterpret_cast(*obj)); while (!Marking::IsBlack( @@ -5782,7 +5786,7 @@ TEST(Regress3877) { { HandleScope inner_scope(isolate); v8::Local result = CompileRun("cls.prototype"); - Handle proto = + Handle proto = v8::Utils::OpenHandle(*v8::Local::Cast(result)); weak_prototype = inner_scope.CloseAndEscape(factory->NewWeakCell(proto)); } @@ -5810,7 +5814,7 @@ Handle AddRetainedMap(Isolate* isolate, Heap* heap) { Handle map = Map::Create(isolate, 1); v8::Local result = CompileRun("(function () { return {x : 10}; })();"); - Handle proto = + Handle proto = v8::Utils::OpenHandle(*v8::Local::Cast(result)); Map::SetPrototype(map, proto); heap->AddRetainedMap(map); diff --git a/test/cctest/test-macro-assembler-mips.cc b/test/cctest/test-macro-assembler-mips.cc index 515bac9d3a..3cb7dcdd32 100644 --- a/test/cctest/test-macro-assembler-mips.cc +++ b/test/cctest/test-macro-assembler-mips.cc @@ -144,9 +144,7 @@ static void TestNaN(const char *code) { v8::Local script = v8::Script::Compile(v8_str(code)); v8::Local result = v8::Local::Cast(script->Run()); - // Have to populate the handle manually, as it's not Cast-able. - i::Handle o = - v8::Utils::OpenHandle(result); + i::Handle o = v8::Utils::OpenHandle(*result); i::Handle array1(reinterpret_cast(*o)); i::FixedDoubleArray* a = i::FixedDoubleArray::cast(array1->elements()); double value = a->get_scalar(0); diff --git a/test/cctest/test-unboxed-doubles.cc b/test/cctest/test-unboxed-doubles.cc index 3dd56ee09e..09c185c84b 100644 --- a/test/cctest/test-unboxed-doubles.cc +++ b/test/cctest/test-unboxed-doubles.cc @@ -54,10 +54,12 @@ static Handle MakeName(const char* str, int suffix) { Handle GetObject(const char* name) { - return v8::Utils::OpenHandle(*v8::Local::Cast( - CcTest::global() - ->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str(name)) - .ToLocalChecked())); + return Handle::cast( + v8::Utils::OpenHandle(*v8::Local::Cast( + CcTest::global() + ->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), + v8_str(name)) + .ToLocalChecked()))); }