Commit 4a956ab1 authored by verwaest@chromium.org's avatar verwaest@chromium.org

Change Has* and Get*Attributes to return Maybe<*>, indicating possible exceptions.

BUG=
R=ishell@chromium.org

Review URL: https://codereview.chromium.org/418383002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22624 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3c873c43
...@@ -895,6 +895,13 @@ struct Maybe { ...@@ -895,6 +895,13 @@ struct Maybe {
}; };
// Convenience wrapper.
template <class T>
inline Maybe<T> maybe(T t) {
return Maybe<T>(t);
}
// --- Special objects --- // --- Special objects ---
......
...@@ -1905,7 +1905,11 @@ v8::Local<Value> v8::TryCatch::StackTrace() const { ...@@ -1905,7 +1905,11 @@ v8::Local<Value> v8::TryCatch::StackTrace() const {
i::HandleScope scope(isolate_); i::HandleScope scope(isolate_);
i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
i::Handle<i::String> name = isolate_->factory()->stack_string(); i::Handle<i::String> name = isolate_->factory()->stack_string();
if (!i::JSReceiver::HasProperty(obj, name)) return v8::Local<Value>(); EXCEPTION_PREAMBLE(isolate_);
Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name);
has_pending_exception = !maybe.has_value;
EXCEPTION_BAILOUT_CHECK(isolate_, v8::Local<Value>());
if (!maybe.value) return v8::Local<Value>();
i::Handle<i::Object> value; i::Handle<i::Object> value;
if (!i::Object::GetProperty(obj, name).ToHandle(&value)) { if (!i::Object::GetProperty(obj, name).ToHandle(&value)) {
return v8::Local<Value>(); return v8::Local<Value>();
...@@ -3139,10 +3143,13 @@ PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { ...@@ -3139,10 +3143,13 @@ PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) {
EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
} }
i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj); i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj);
PropertyAttributes result = EXCEPTION_PREAMBLE(isolate);
Maybe<PropertyAttributes> result =
i::JSReceiver::GetPropertyAttributes(self, key_name); i::JSReceiver::GetPropertyAttributes(self, key_name);
if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); has_pending_exception = !result.has_value;
return static_cast<PropertyAttribute>(result); EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
if (result.value == ABSENT) return static_cast<PropertyAttribute>(NONE);
return static_cast<PropertyAttribute>(result.value);
} }
...@@ -3399,7 +3406,11 @@ bool v8::Object::Has(uint32_t index) { ...@@ -3399,7 +3406,11 @@ bool v8::Object::Has(uint32_t index) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false);
i::Handle<i::JSObject> self = Utils::OpenHandle(this); i::Handle<i::JSObject> self = Utils::OpenHandle(this);
return i::JSReceiver::HasElement(self, index); EXCEPTION_PREAMBLE(isolate);
Maybe<bool> maybe = i::JSReceiver::HasElement(self, index);
has_pending_exception = !maybe.has_value;
EXCEPTION_BAILOUT_CHECK(isolate, false);
return maybe.value;
} }
...@@ -3478,8 +3489,12 @@ bool v8::Object::HasOwnProperty(Handle<String> key) { ...@@ -3478,8 +3489,12 @@ bool v8::Object::HasOwnProperty(Handle<String> key) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()",
return false); return false);
return i::JSReceiver::HasOwnProperty( EXCEPTION_PREAMBLE(isolate);
Utils::OpenHandle(this), Utils::OpenHandle(*key)); Maybe<bool> maybe = i::JSReceiver::HasOwnProperty(Utils::OpenHandle(this),
Utils::OpenHandle(*key));
has_pending_exception = !maybe.has_value;
EXCEPTION_BAILOUT_CHECK(isolate, false);
return maybe.value;
} }
...@@ -3487,8 +3502,12 @@ bool v8::Object::HasRealNamedProperty(Handle<String> key) { ...@@ -3487,8 +3502,12 @@ bool v8::Object::HasRealNamedProperty(Handle<String> key) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
return false); return false);
return i::JSObject::HasRealNamedProperty(Utils::OpenHandle(this), EXCEPTION_PREAMBLE(isolate);
Utils::OpenHandle(*key)); Maybe<bool> maybe = i::JSObject::HasRealNamedProperty(
Utils::OpenHandle(this), Utils::OpenHandle(*key));
has_pending_exception = !maybe.has_value;
EXCEPTION_BAILOUT_CHECK(isolate, false);
return maybe.value;
} }
...@@ -3496,7 +3515,12 @@ bool v8::Object::HasRealIndexedProperty(uint32_t index) { ...@@ -3496,7 +3515,12 @@ bool v8::Object::HasRealIndexedProperty(uint32_t index) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()", ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()",
return false); return false);
return i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index); EXCEPTION_PREAMBLE(isolate);
Maybe<bool> maybe =
i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index);
has_pending_exception = !maybe.has_value;
EXCEPTION_BAILOUT_CHECK(isolate, false);
return maybe.value;
} }
...@@ -3506,8 +3530,12 @@ bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { ...@@ -3506,8 +3530,12 @@ bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) {
"v8::Object::HasRealNamedCallbackProperty()", "v8::Object::HasRealNamedCallbackProperty()",
return false); return false);
ENTER_V8(isolate); ENTER_V8(isolate);
return i::JSObject::HasRealNamedCallbackProperty(Utils::OpenHandle(this), EXCEPTION_PREAMBLE(isolate);
Utils::OpenHandle(*key)); Maybe<bool> maybe = i::JSObject::HasRealNamedCallbackProperty(
Utils::OpenHandle(this), Utils::OpenHandle(*key));
has_pending_exception = !maybe.has_value;
EXCEPTION_BAILOUT_CHECK(isolate, false);
return maybe.value;
} }
......
...@@ -106,15 +106,18 @@ Handle<Object> Context::Lookup(Handle<String> name, ...@@ -106,15 +106,18 @@ Handle<Object> Context::Lookup(Handle<String> name,
// Context extension objects needs to behave as if they have no // Context extension objects needs to behave as if they have no
// prototype. So even if we want to follow prototype chains, we need // prototype. So even if we want to follow prototype chains, we need
// to only do a local lookup for context extension objects. // to only do a local lookup for context extension objects.
Maybe<PropertyAttributes> maybe;
if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
object->IsJSContextExtensionObject()) { object->IsJSContextExtensionObject()) {
*attributes = JSReceiver::GetOwnPropertyAttributes(object, name); maybe = JSReceiver::GetOwnPropertyAttributes(object, name);
} else { } else {
*attributes = JSReceiver::GetPropertyAttributes(object, name); maybe = JSReceiver::GetPropertyAttributes(object, name);
} }
if (isolate->has_pending_exception()) return Handle<Object>(); if (!maybe.has_value) return Handle<Object>();
ASSERT(!isolate->has_pending_exception());
*attributes = maybe.value;
if (*attributes != ABSENT) { if (maybe.value != ABSENT) {
if (FLAG_trace_contexts) { if (FLAG_trace_contexts) {
PrintF("=> found property in context object %p\n", PrintF("=> found property in context object %p\n",
reinterpret_cast<void*>(*object)); reinterpret_cast<void*>(*object));
......
...@@ -419,7 +419,9 @@ void SetResolvedNumberSettings(Isolate* isolate, ...@@ -419,7 +419,9 @@ void SetResolvedNumberSettings(Isolate* isolate,
Handle<String> key = Handle<String> key =
factory->NewStringFromStaticAscii("minimumSignificantDigits"); factory->NewStringFromStaticAscii("minimumSignificantDigits");
if (JSReceiver::HasOwnProperty(resolved, key)) { Maybe<bool> maybe = JSReceiver::HasOwnProperty(resolved, key);
CHECK(maybe.has_value);
if (maybe.value) {
JSObject::SetProperty( JSObject::SetProperty(
resolved, resolved,
factory->NewStringFromStaticAscii("minimumSignificantDigits"), factory->NewStringFromStaticAscii("minimumSignificantDigits"),
...@@ -428,7 +430,9 @@ void SetResolvedNumberSettings(Isolate* isolate, ...@@ -428,7 +430,9 @@ void SetResolvedNumberSettings(Isolate* isolate,
} }
key = factory->NewStringFromStaticAscii("maximumSignificantDigits"); key = factory->NewStringFromStaticAscii("maximumSignificantDigits");
if (JSReceiver::HasOwnProperty(resolved, key)) { maybe = JSReceiver::HasOwnProperty(resolved, key);
CHECK(maybe.has_value);
if (maybe.value) {
JSObject::SetProperty( JSObject::SetProperty(
resolved, resolved,
factory->NewStringFromStaticAscii("maximumSignificantDigits"), factory->NewStringFromStaticAscii("maximumSignificantDigits"),
...@@ -783,7 +787,9 @@ icu::SimpleDateFormat* DateFormat::UnpackDateFormat( ...@@ -783,7 +787,9 @@ icu::SimpleDateFormat* DateFormat::UnpackDateFormat(
Handle<JSObject> obj) { Handle<JSObject> obj) {
Handle<String> key = Handle<String> key =
isolate->factory()->NewStringFromStaticAscii("dateFormat"); isolate->factory()->NewStringFromStaticAscii("dateFormat");
if (JSReceiver::HasOwnProperty(obj, key)) { Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
CHECK(maybe.has_value);
if (maybe.value) {
return reinterpret_cast<icu::SimpleDateFormat*>( return reinterpret_cast<icu::SimpleDateFormat*>(
obj->GetInternalField(0)); obj->GetInternalField(0));
} }
...@@ -857,7 +863,9 @@ icu::DecimalFormat* NumberFormat::UnpackNumberFormat( ...@@ -857,7 +863,9 @@ icu::DecimalFormat* NumberFormat::UnpackNumberFormat(
Handle<JSObject> obj) { Handle<JSObject> obj) {
Handle<String> key = Handle<String> key =
isolate->factory()->NewStringFromStaticAscii("numberFormat"); isolate->factory()->NewStringFromStaticAscii("numberFormat");
if (JSReceiver::HasOwnProperty(obj, key)) { Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
CHECK(maybe.has_value);
if (maybe.value) {
return reinterpret_cast<icu::DecimalFormat*>(obj->GetInternalField(0)); return reinterpret_cast<icu::DecimalFormat*>(obj->GetInternalField(0));
} }
...@@ -912,7 +920,9 @@ icu::Collator* Collator::InitializeCollator( ...@@ -912,7 +920,9 @@ icu::Collator* Collator::InitializeCollator(
icu::Collator* Collator::UnpackCollator(Isolate* isolate, icu::Collator* Collator::UnpackCollator(Isolate* isolate,
Handle<JSObject> obj) { Handle<JSObject> obj) {
Handle<String> key = isolate->factory()->NewStringFromStaticAscii("collator"); Handle<String> key = isolate->factory()->NewStringFromStaticAscii("collator");
if (JSReceiver::HasOwnProperty(obj, key)) { Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
CHECK(maybe.has_value);
if (maybe.value) {
return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0)); return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0));
} }
...@@ -971,7 +981,9 @@ icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate, ...@@ -971,7 +981,9 @@ icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate,
Handle<JSObject> obj) { Handle<JSObject> obj) {
Handle<String> key = Handle<String> key =
isolate->factory()->NewStringFromStaticAscii("breakIterator"); isolate->factory()->NewStringFromStaticAscii("breakIterator");
if (JSReceiver::HasOwnProperty(obj, key)) { Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
CHECK(maybe.has_value);
if (maybe.value) {
return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0)); return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0));
} }
......
...@@ -106,15 +106,18 @@ typedef ZoneList<Handle<Object> > ZoneObjectList; ...@@ -106,15 +106,18 @@ typedef ZoneList<Handle<Object> > ZoneObjectList;
// Macros for MaybeHandle. // Macros for MaybeHandle.
#define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \ #define RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, value) \
do { \ do { \
Isolate* __isolate__ = (isolate); \ Isolate* __isolate__ = (isolate); \
if (__isolate__->has_scheduled_exception()) { \ if (__isolate__->has_scheduled_exception()) { \
__isolate__->PromoteScheduledException(); \ __isolate__->PromoteScheduledException(); \
return MaybeHandle<T>(); \ return value; \
} \ } \
} while (false) } while (false)
#define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \
RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, MaybeHandle<T>())
#define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \ #define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \
do { \ do { \
if (!(call).ToHandle(&dst)) { \ if (!(call).ToHandle(&dst)) { \
......
...@@ -1166,7 +1166,8 @@ MaybeHandle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy, ...@@ -1166,7 +1166,8 @@ MaybeHandle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy,
} }
bool JSProxy::HasElementWithHandler(Handle<JSProxy> proxy, uint32_t index) { Maybe<bool> JSProxy::HasElementWithHandler(Handle<JSProxy> proxy,
uint32_t index) {
Isolate* isolate = proxy->GetIsolate(); Isolate* isolate = proxy->GetIsolate();
Handle<String> name = isolate->factory()->Uint32ToString(index); Handle<String> name = isolate->factory()->Uint32ToString(index);
return HasPropertyWithHandler(proxy, name); return HasPropertyWithHandler(proxy, name);
...@@ -6629,27 +6630,32 @@ Object* JSReceiver::GetConstructor() { ...@@ -6629,27 +6630,32 @@ Object* JSReceiver::GetConstructor() {
} }
bool JSReceiver::HasProperty(Handle<JSReceiver> object, Maybe<bool> JSReceiver::HasProperty(Handle<JSReceiver> object,
Handle<Name> name) { Handle<Name> name) {
if (object->IsJSProxy()) { if (object->IsJSProxy()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object); Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasPropertyWithHandler(proxy, name); return JSProxy::HasPropertyWithHandler(proxy, name);
} }
return GetPropertyAttributes(object, name) != ABSENT; Maybe<PropertyAttributes> result = GetPropertyAttributes(object, name);
if (!result.has_value) return Maybe<bool>();
return maybe(result.value != ABSENT);
} }
bool JSReceiver::HasOwnProperty(Handle<JSReceiver> object, Handle<Name> name) { Maybe<bool> JSReceiver::HasOwnProperty(Handle<JSReceiver> object,
Handle<Name> name) {
if (object->IsJSProxy()) { if (object->IsJSProxy()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object); Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasPropertyWithHandler(proxy, name); return JSProxy::HasPropertyWithHandler(proxy, name);
} }
return GetOwnPropertyAttributes(object, name) != ABSENT; Maybe<PropertyAttributes> result = GetOwnPropertyAttributes(object, name);
if (!result.has_value) return Maybe<bool>();
return maybe(result.value != ABSENT);
} }
PropertyAttributes JSReceiver::GetPropertyAttributes(Handle<JSReceiver> object, Maybe<PropertyAttributes> JSReceiver::GetPropertyAttributes(
Handle<Name> key) { Handle<JSReceiver> object, Handle<Name> key) {
uint32_t index; uint32_t index;
if (object->IsJSObject() && key->AsArrayIndex(&index)) { if (object->IsJSObject() && key->AsArrayIndex(&index)) {
return GetElementAttribute(object, index); return GetElementAttribute(object, index);
...@@ -6659,8 +6665,8 @@ PropertyAttributes JSReceiver::GetPropertyAttributes(Handle<JSReceiver> object, ...@@ -6659,8 +6665,8 @@ PropertyAttributes JSReceiver::GetPropertyAttributes(Handle<JSReceiver> object,
} }
PropertyAttributes JSReceiver::GetElementAttribute(Handle<JSReceiver> object, Maybe<PropertyAttributes> JSReceiver::GetElementAttribute(
uint32_t index) { Handle<JSReceiver> object, uint32_t index) {
if (object->IsJSProxy()) { if (object->IsJSProxy()) {
return JSProxy::GetElementAttributeWithHandler( return JSProxy::GetElementAttributeWithHandler(
Handle<JSProxy>::cast(object), object, index); Handle<JSProxy>::cast(object), object, index);
...@@ -6696,27 +6702,32 @@ Object* JSReceiver::GetIdentityHash() { ...@@ -6696,27 +6702,32 @@ Object* JSReceiver::GetIdentityHash() {
} }
bool JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) { Maybe<bool> JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) {
if (object->IsJSProxy()) { if (object->IsJSProxy()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object); Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasElementWithHandler(proxy, index); return JSProxy::HasElementWithHandler(proxy, index);
} }
return JSObject::GetElementAttributeWithReceiver( Maybe<PropertyAttributes> result = JSObject::GetElementAttributeWithReceiver(
Handle<JSObject>::cast(object), object, index, true) != ABSENT; Handle<JSObject>::cast(object), object, index, true);
if (!result.has_value) return Maybe<bool>();
return maybe(result.value != ABSENT);
} }
bool JSReceiver::HasOwnElement(Handle<JSReceiver> object, uint32_t index) { Maybe<bool> JSReceiver::HasOwnElement(Handle<JSReceiver> object,
uint32_t index) {
if (object->IsJSProxy()) { if (object->IsJSProxy()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object); Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasElementWithHandler(proxy, index); return JSProxy::HasElementWithHandler(proxy, index);
} }
return JSObject::GetElementAttributeWithReceiver( Maybe<PropertyAttributes> result = JSObject::GetElementAttributeWithReceiver(
Handle<JSObject>::cast(object), object, index, false) != ABSENT; Handle<JSObject>::cast(object), object, index, false);
if (!result.has_value) return Maybe<bool>();
return maybe(result.value != ABSENT);
} }
PropertyAttributes JSReceiver::GetOwnElementAttribute( Maybe<PropertyAttributes> JSReceiver::GetOwnElementAttribute(
Handle<JSReceiver> object, uint32_t index) { Handle<JSReceiver> object, uint32_t index) {
if (object->IsJSProxy()) { if (object->IsJSProxy()) {
return JSProxy::GetElementAttributeWithHandler( return JSProxy::GetElementAttributeWithHandler(
......
This diff is collapsed.
...@@ -1960,10 +1960,14 @@ class JSReceiver: public HeapObject { ...@@ -1960,10 +1960,14 @@ class JSReceiver: public HeapObject {
StrictMode strict_mode); StrictMode strict_mode);
// Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6. // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6.
static inline bool HasProperty(Handle<JSReceiver> object, Handle<Name> name); MUST_USE_RESULT static inline Maybe<bool> HasProperty(
static inline bool HasOwnProperty(Handle<JSReceiver>, Handle<Name> name); Handle<JSReceiver> object, Handle<Name> name);
static inline bool HasElement(Handle<JSReceiver> object, uint32_t index); MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(Handle<JSReceiver>,
static inline bool HasOwnElement(Handle<JSReceiver> object, uint32_t index); Handle<Name> name);
MUST_USE_RESULT static inline Maybe<bool> HasElement(
Handle<JSReceiver> object, uint32_t index);
MUST_USE_RESULT static inline Maybe<bool> HasOwnElement(
Handle<JSReceiver> object, uint32_t index);
// Implementation of [[Delete]], ECMA-262 5th edition, section 8.12.7. // Implementation of [[Delete]], ECMA-262 5th edition, section 8.12.7.
MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty( MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
...@@ -1985,20 +1989,17 @@ class JSReceiver: public HeapObject { ...@@ -1985,20 +1989,17 @@ class JSReceiver: public HeapObject {
// function that was used to instantiate the object). // function that was used to instantiate the object).
String* constructor_name(); String* constructor_name();
static inline PropertyAttributes GetPropertyAttributes( MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes(
Handle<JSReceiver> object, Handle<JSReceiver> object, Handle<Name> name);
Handle<Name> name); MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
static PropertyAttributes GetPropertyAttributes(LookupIterator* it); LookupIterator* it);
static PropertyAttributes GetOwnPropertyAttributes( MUST_USE_RESULT static Maybe<PropertyAttributes> GetOwnPropertyAttributes(
Handle<JSReceiver> object, Handle<JSReceiver> object, Handle<Name> name);
Handle<Name> name);
static inline PropertyAttributes GetElementAttribute( MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttribute(
Handle<JSReceiver> object, Handle<JSReceiver> object, uint32_t index);
uint32_t index); MUST_USE_RESULT static inline Maybe<PropertyAttributes>
static inline PropertyAttributes GetOwnElementAttribute( GetOwnElementAttribute(Handle<JSReceiver> object, uint32_t index);
Handle<JSReceiver> object,
uint32_t index);
// Return the constructor function (may be Heap::null_value()). // Return the constructor function (may be Heap::null_value()).
inline Object* GetConstructor(); inline Object* GetConstructor();
...@@ -2198,17 +2199,16 @@ class JSObject: public JSReceiver { ...@@ -2198,17 +2199,16 @@ class JSObject: public JSReceiver {
InterceptorInfo* GetIndexedInterceptor(); InterceptorInfo* GetIndexedInterceptor();
// Used from JSReceiver. // Used from JSReceiver.
static Maybe<PropertyAttributes> GetPropertyAttributesWithInterceptor( MUST_USE_RESULT static Maybe<PropertyAttributes>
Handle<JSObject> holder, GetPropertyAttributesWithInterceptor(Handle<JSObject> holder,
Handle<Object> receiver, Handle<Object> receiver,
Handle<Name> name); Handle<Name> name);
static PropertyAttributes GetPropertyAttributesWithFailedAccessCheck( MUST_USE_RESULT static Maybe<PropertyAttributes>
LookupIterator* it); GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it);
static PropertyAttributes GetElementAttributeWithReceiver( MUST_USE_RESULT static Maybe<PropertyAttributes>
Handle<JSObject> object, GetElementAttributeWithReceiver(Handle<JSObject> object,
Handle<JSReceiver> receiver, Handle<JSReceiver> receiver,
uint32_t index, uint32_t index, bool check_prototype);
bool check_prototype);
// Retrieves an AccessorPair property from the given object. Might return // Retrieves an AccessorPair property from the given object. Might return
// undefined if the property doesn't exist or is of a different kind. // undefined if the property doesn't exist or is of a different kind.
...@@ -2218,13 +2218,12 @@ class JSObject: public JSReceiver { ...@@ -2218,13 +2218,12 @@ class JSObject: public JSReceiver {
AccessorComponent component); AccessorComponent component);
// Defines an AccessorPair property on the given object. // Defines an AccessorPair property on the given object.
// TODO(mstarzinger): Rename to SetAccessor() and return empty handle on // TODO(mstarzinger): Rename to SetAccessor().
// exception instead of letting callers check for scheduled exception. static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object,
static void DefineAccessor(Handle<JSObject> object, Handle<Name> name,
Handle<Name> name, Handle<Object> getter,
Handle<Object> getter, Handle<Object> setter,
Handle<Object> setter, PropertyAttributes attributes);
PropertyAttributes attributes);
// Defines an AccessorInfo property on the given object. // Defines an AccessorInfo property on the given object.
MUST_USE_RESULT static MaybeHandle<Object> SetAccessor( MUST_USE_RESULT static MaybeHandle<Object> SetAccessor(
...@@ -2381,11 +2380,12 @@ class JSObject: public JSReceiver { ...@@ -2381,11 +2380,12 @@ class JSObject: public JSReceiver {
Handle<JSReceiver> receiver); Handle<JSReceiver> receiver);
// Support functions for v8 api (needed for correct interceptor behavior). // Support functions for v8 api (needed for correct interceptor behavior).
static bool HasRealNamedProperty(Handle<JSObject> object, MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty(
Handle<Name> key); Handle<JSObject> object, Handle<Name> key);
static bool HasRealElementProperty(Handle<JSObject> object, uint32_t index); MUST_USE_RESULT static Maybe<bool> HasRealElementProperty(
static bool HasRealNamedCallbackProperty(Handle<JSObject> object, Handle<JSObject> object, uint32_t index);
Handle<Name> key); MUST_USE_RESULT static Maybe<bool> HasRealNamedCallbackProperty(
Handle<JSObject> object, Handle<Name> key);
// Get the header size for a JSObject. Used to compute the index of // Get the header size for a JSObject. Used to compute the index of
// internal fields as well as the number of internal fields. // internal fields as well as the number of internal fields.
...@@ -2658,16 +2658,15 @@ class JSObject: public JSReceiver { ...@@ -2658,16 +2658,15 @@ class JSObject: public JSReceiver {
uint32_t index, uint32_t index,
Handle<Object> holder); Handle<Object> holder);
static PropertyAttributes GetElementAttributeWithInterceptor( MUST_USE_RESULT static Maybe<PropertyAttributes>
Handle<JSObject> object, GetElementAttributeWithInterceptor(Handle<JSObject> object,
Handle<JSReceiver> receiver, Handle<JSReceiver> receiver,
uint32_t index, uint32_t index, bool continue_search);
bool continue_search); MUST_USE_RESULT static Maybe<PropertyAttributes>
static PropertyAttributes GetElementAttributeWithoutInterceptor( GetElementAttributeWithoutInterceptor(Handle<JSObject> object,
Handle<JSObject> object, Handle<JSReceiver> receiver,
Handle<JSReceiver> receiver, uint32_t index,
uint32_t index, bool continue_search);
bool continue_search);
MUST_USE_RESULT static MaybeHandle<Object> SetElementWithCallback( MUST_USE_RESULT static MaybeHandle<Object> SetElementWithCallback(
Handle<JSObject> object, Handle<JSObject> object,
Handle<Object> structure, Handle<Object> structure,
...@@ -9947,14 +9946,14 @@ class JSProxy: public JSReceiver { ...@@ -9947,14 +9946,14 @@ class JSProxy: public JSReceiver {
Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name, Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
Handle<Object> value, StrictMode strict_mode, bool* done); Handle<Object> value, StrictMode strict_mode, bool* done);
static PropertyAttributes GetPropertyAttributesWithHandler( MUST_USE_RESULT static Maybe<PropertyAttributes>
Handle<JSProxy> proxy, GetPropertyAttributesWithHandler(Handle<JSProxy> proxy,
Handle<Object> receiver, Handle<Object> receiver,
Handle<Name> name); Handle<Name> name);
static PropertyAttributes GetElementAttributeWithHandler( MUST_USE_RESULT static Maybe<PropertyAttributes>
Handle<JSProxy> proxy, GetElementAttributeWithHandler(Handle<JSProxy> proxy,
Handle<JSReceiver> receiver, Handle<JSReceiver> receiver,
uint32_t index); uint32_t index);
MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithHandler( MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithHandler(
Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name, Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
Handle<Object> value, StrictMode strict_mode); Handle<Object> value, StrictMode strict_mode);
...@@ -10004,9 +10003,10 @@ class JSProxy: public JSReceiver { ...@@ -10004,9 +10003,10 @@ class JSProxy: public JSReceiver {
Handle<Object> value, Handle<Object> value,
StrictMode strict_mode); StrictMode strict_mode);
static bool HasPropertyWithHandler(Handle<JSProxy> proxy, Handle<Name> name); MUST_USE_RESULT static Maybe<bool> HasPropertyWithHandler(
static inline bool HasElementWithHandler(Handle<JSProxy> proxy, Handle<JSProxy> proxy, Handle<Name> name);
uint32_t index); MUST_USE_RESULT static inline Maybe<bool> HasElementWithHandler(
Handle<JSProxy> proxy, uint32_t index);
MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithHandler( MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithHandler(
Handle<JSProxy> proxy, Handle<JSProxy> proxy,
......
This diff is collapsed.
...@@ -210,7 +210,9 @@ TEST(HeapObjects) { ...@@ -210,7 +210,9 @@ TEST(HeapObjects) {
Handle<String> object_string = Handle<String>::cast(factory->Object_string()); Handle<String> object_string = Handle<String>::cast(factory->Object_string());
Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
CHECK(JSReceiver::HasOwnProperty(global, object_string)); v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, object_string);
CHECK(maybe.has_value);
CHECK(maybe.value);
// Check ToString for oddballs // Check ToString for oddballs
CheckOddball(isolate, heap->true_value(), "true"); CheckOddball(isolate, heap->true_value(), "true");
...@@ -277,7 +279,9 @@ TEST(GarbageCollection) { ...@@ -277,7 +279,9 @@ TEST(GarbageCollection) {
heap->CollectGarbage(NEW_SPACE); heap->CollectGarbage(NEW_SPACE);
// Function should be alive. // Function should be alive.
CHECK(JSReceiver::HasOwnProperty(global, name)); v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, name);
CHECK(maybe.has_value);
CHECK(maybe.value);
// Check function is retained. // Check function is retained.
Handle<Object> func_value = Handle<Object> func_value =
Object::GetProperty(global, name).ToHandleChecked(); Object::GetProperty(global, name).ToHandleChecked();
...@@ -295,7 +299,9 @@ TEST(GarbageCollection) { ...@@ -295,7 +299,9 @@ TEST(GarbageCollection) {
// After gc, it should survive. // After gc, it should survive.
heap->CollectGarbage(NEW_SPACE); heap->CollectGarbage(NEW_SPACE);
CHECK(JSReceiver::HasOwnProperty(global, obj_name)); maybe = JSReceiver::HasOwnProperty(global, obj_name);
CHECK(maybe.has_value);
CHECK(maybe.value);
Handle<Object> obj = Handle<Object> obj =
Object::GetProperty(global, obj_name).ToHandleChecked(); Object::GetProperty(global, obj_name).ToHandleChecked();
CHECK(obj->IsJSObject()); CHECK(obj->IsJSObject());
...@@ -652,55 +658,85 @@ TEST(ObjectProperties) { ...@@ -652,55 +658,85 @@ TEST(ObjectProperties) {
Handle<Smi> two(Smi::FromInt(2), isolate); Handle<Smi> two(Smi::FromInt(2), isolate);
// check for empty // check for empty
CHECK(!JSReceiver::HasOwnProperty(obj, first)); v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(maybe.has_value);
CHECK(!maybe.value);
// add first // add first
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
CHECK(JSReceiver::HasOwnProperty(obj, first)); maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(maybe.has_value);
CHECK(maybe.value);
// delete first // delete first
JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check(); JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check();
CHECK(!JSReceiver::HasOwnProperty(obj, first)); maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(maybe.has_value);
CHECK(!maybe.value);
// add first and then second // add first and then second
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
CHECK(JSReceiver::HasOwnProperty(obj, first)); maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(JSReceiver::HasOwnProperty(obj, second)); CHECK(maybe.has_value);
CHECK(maybe.value);
maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(maybe.value);
// delete first and then second // delete first and then second
JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check(); JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check();
CHECK(JSReceiver::HasOwnProperty(obj, second)); maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(maybe.value);
JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check(); JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check();
CHECK(!JSReceiver::HasOwnProperty(obj, first)); maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(!JSReceiver::HasOwnProperty(obj, second)); CHECK(maybe.has_value);
CHECK(!maybe.value);
maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(!maybe.value);
// add first and then second // add first and then second
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
CHECK(JSReceiver::HasOwnProperty(obj, first)); maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(JSReceiver::HasOwnProperty(obj, second)); CHECK(maybe.has_value);
CHECK(maybe.value);
maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(maybe.value);
// delete second and then first // delete second and then first
JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check(); JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check();
CHECK(JSReceiver::HasOwnProperty(obj, first)); maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(maybe.has_value);
CHECK(maybe.value);
JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check(); JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check();
CHECK(!JSReceiver::HasOwnProperty(obj, first)); maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(!JSReceiver::HasOwnProperty(obj, second)); CHECK(maybe.has_value);
CHECK(!maybe.value);
maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(!maybe.value);
// check string and internalized string match // check string and internalized string match
const char* string1 = "fisk"; const char* string1 = "fisk";
Handle<String> s1 = factory->NewStringFromAsciiChecked(string1); Handle<String> s1 = factory->NewStringFromAsciiChecked(string1);
JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check(); JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check();
Handle<String> s1_string = factory->InternalizeUtf8String(string1); Handle<String> s1_string = factory->InternalizeUtf8String(string1);
CHECK(JSReceiver::HasOwnProperty(obj, s1_string)); maybe = JSReceiver::HasOwnProperty(obj, s1_string);
CHECK(maybe.has_value);
CHECK(maybe.value);
// check internalized string and string match // check internalized string and string match
const char* string2 = "fugl"; const char* string2 = "fugl";
Handle<String> s2_string = factory->InternalizeUtf8String(string2); Handle<String> s2_string = factory->InternalizeUtf8String(string2);
JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check(); JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check();
Handle<String> s2 = factory->NewStringFromAsciiChecked(string2); Handle<String> s2 = factory->NewStringFromAsciiChecked(string2);
CHECK(JSReceiver::HasOwnProperty(obj, s2)); maybe = JSReceiver::HasOwnProperty(obj, s2);
CHECK(maybe.has_value);
CHECK(maybe.value);
} }
......
...@@ -167,7 +167,9 @@ TEST(MarkCompactCollector) { ...@@ -167,7 +167,9 @@ TEST(MarkCompactCollector) {
{ HandleScope scope(isolate); { HandleScope scope(isolate);
Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); Handle<String> func_name = factory->InternalizeUtf8String("theFunction");
CHECK(JSReceiver::HasOwnProperty(global, func_name)); v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, func_name);
CHECK(maybe.has_value);
CHECK(maybe.value);
Handle<Object> func_value = Handle<Object> func_value =
Object::GetProperty(global, func_name).ToHandleChecked(); Object::GetProperty(global, func_name).ToHandleChecked();
CHECK(func_value->IsJSFunction()); CHECK(func_value->IsJSFunction());
...@@ -185,7 +187,9 @@ TEST(MarkCompactCollector) { ...@@ -185,7 +187,9 @@ TEST(MarkCompactCollector) {
{ HandleScope scope(isolate); { HandleScope scope(isolate);
Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); Handle<String> obj_name = factory->InternalizeUtf8String("theObject");
CHECK(JSReceiver::HasOwnProperty(global, obj_name)); v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, obj_name);
CHECK(maybe.has_value);
CHECK(maybe.value);
Handle<Object> object = Handle<Object> object =
Object::GetProperty(global, obj_name).ToHandleChecked(); Object::GetProperty(global, obj_name).ToHandleChecked();
CHECK(object->IsJSObject()); CHECK(object->IsJSObject());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment