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 {
};
// Convenience wrapper.
template <class T>
inline Maybe<T> maybe(T t) {
return Maybe<T>(t);
}
// --- Special objects ---
......
......@@ -1905,7 +1905,11 @@ v8::Local<Value> v8::TryCatch::StackTrace() const {
i::HandleScope scope(isolate_);
i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
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;
if (!i::Object::GetProperty(obj, name).ToHandle(&value)) {
return v8::Local<Value>();
......@@ -3139,10 +3143,13 @@ PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) {
EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
}
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);
if (result == ABSENT) return static_cast<PropertyAttribute>(NONE);
return static_cast<PropertyAttribute>(result);
has_pending_exception = !result.has_value;
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) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false);
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) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()",
return false);
return i::JSReceiver::HasOwnProperty(
Utils::OpenHandle(this), Utils::OpenHandle(*key));
EXCEPTION_PREAMBLE(isolate);
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) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
return false);
return i::JSObject::HasRealNamedProperty(Utils::OpenHandle(this),
Utils::OpenHandle(*key));
EXCEPTION_PREAMBLE(isolate);
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) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()",
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) {
"v8::Object::HasRealNamedCallbackProperty()",
return false);
ENTER_V8(isolate);
return i::JSObject::HasRealNamedCallbackProperty(Utils::OpenHandle(this),
Utils::OpenHandle(*key));
EXCEPTION_PREAMBLE(isolate);
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,
// Context extension objects needs to behave as if they have no
// prototype. So even if we want to follow prototype chains, we need
// to only do a local lookup for context extension objects.
Maybe<PropertyAttributes> maybe;
if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
object->IsJSContextExtensionObject()) {
*attributes = JSReceiver::GetOwnPropertyAttributes(object, name);
maybe = JSReceiver::GetOwnPropertyAttributes(object, name);
} 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) {
PrintF("=> found property in context object %p\n",
reinterpret_cast<void*>(*object));
......
......@@ -419,7 +419,9 @@ void SetResolvedNumberSettings(Isolate* isolate,
Handle<String> key =
factory->NewStringFromStaticAscii("minimumSignificantDigits");
if (JSReceiver::HasOwnProperty(resolved, key)) {
Maybe<bool> maybe = JSReceiver::HasOwnProperty(resolved, key);
CHECK(maybe.has_value);
if (maybe.value) {
JSObject::SetProperty(
resolved,
factory->NewStringFromStaticAscii("minimumSignificantDigits"),
......@@ -428,7 +430,9 @@ void SetResolvedNumberSettings(Isolate* isolate,
}
key = factory->NewStringFromStaticAscii("maximumSignificantDigits");
if (JSReceiver::HasOwnProperty(resolved, key)) {
maybe = JSReceiver::HasOwnProperty(resolved, key);
CHECK(maybe.has_value);
if (maybe.value) {
JSObject::SetProperty(
resolved,
factory->NewStringFromStaticAscii("maximumSignificantDigits"),
......@@ -783,7 +787,9 @@ icu::SimpleDateFormat* DateFormat::UnpackDateFormat(
Handle<JSObject> obj) {
Handle<String> key =
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*>(
obj->GetInternalField(0));
}
......@@ -857,7 +863,9 @@ icu::DecimalFormat* NumberFormat::UnpackNumberFormat(
Handle<JSObject> obj) {
Handle<String> key =
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));
}
......@@ -912,7 +920,9 @@ icu::Collator* Collator::InitializeCollator(
icu::Collator* Collator::UnpackCollator(Isolate* isolate,
Handle<JSObject> obj) {
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));
}
......@@ -971,7 +981,9 @@ icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate,
Handle<JSObject> obj) {
Handle<String> key =
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));
}
......
......@@ -106,15 +106,18 @@ typedef ZoneList<Handle<Object> > ZoneObjectList;
// Macros for MaybeHandle.
#define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \
#define RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, value) \
do { \
Isolate* __isolate__ = (isolate); \
if (__isolate__->has_scheduled_exception()) { \
__isolate__->PromoteScheduledException(); \
return MaybeHandle<T>(); \
return value; \
} \
} 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) \
do { \
if (!(call).ToHandle(&dst)) { \
......
......@@ -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();
Handle<String> name = isolate->factory()->Uint32ToString(index);
return HasPropertyWithHandler(proxy, name);
......@@ -6629,27 +6630,32 @@ Object* JSReceiver::GetConstructor() {
}
bool JSReceiver::HasProperty(Handle<JSReceiver> object,
Maybe<bool> JSReceiver::HasProperty(Handle<JSReceiver> object,
Handle<Name> name) {
if (object->IsJSProxy()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
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()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
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,
Handle<Name> key) {
Maybe<PropertyAttributes> JSReceiver::GetPropertyAttributes(
Handle<JSReceiver> object, Handle<Name> key) {
uint32_t index;
if (object->IsJSObject() && key->AsArrayIndex(&index)) {
return GetElementAttribute(object, index);
......@@ -6659,8 +6665,8 @@ PropertyAttributes JSReceiver::GetPropertyAttributes(Handle<JSReceiver> object,
}
PropertyAttributes JSReceiver::GetElementAttribute(Handle<JSReceiver> object,
uint32_t index) {
Maybe<PropertyAttributes> JSReceiver::GetElementAttribute(
Handle<JSReceiver> object, uint32_t index) {
if (object->IsJSProxy()) {
return JSProxy::GetElementAttributeWithHandler(
Handle<JSProxy>::cast(object), object, index);
......@@ -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()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasElementWithHandler(proxy, index);
}
return JSObject::GetElementAttributeWithReceiver(
Handle<JSObject>::cast(object), object, index, true) != ABSENT;
Maybe<PropertyAttributes> result = JSObject::GetElementAttributeWithReceiver(
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()) {
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasElementWithHandler(proxy, index);
}
return JSObject::GetElementAttributeWithReceiver(
Handle<JSObject>::cast(object), object, index, false) != ABSENT;
Maybe<PropertyAttributes> result = JSObject::GetElementAttributeWithReceiver(
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) {
if (object->IsJSProxy()) {
return JSProxy::GetElementAttributeWithHandler(
......
This diff is collapsed.
......@@ -1960,10 +1960,14 @@ class JSReceiver: public HeapObject {
StrictMode strict_mode);
// Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6.
static inline bool HasProperty(Handle<JSReceiver> object, Handle<Name> name);
static inline bool HasOwnProperty(Handle<JSReceiver>, Handle<Name> name);
static inline bool HasElement(Handle<JSReceiver> object, uint32_t index);
static inline bool HasOwnElement(Handle<JSReceiver> object, uint32_t index);
MUST_USE_RESULT static inline Maybe<bool> HasProperty(
Handle<JSReceiver> object, Handle<Name> name);
MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(Handle<JSReceiver>,
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.
MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
......@@ -1985,20 +1989,17 @@ class JSReceiver: public HeapObject {
// function that was used to instantiate the object).
String* constructor_name();
static inline PropertyAttributes GetPropertyAttributes(
Handle<JSReceiver> object,
Handle<Name> name);
static PropertyAttributes GetPropertyAttributes(LookupIterator* it);
static PropertyAttributes GetOwnPropertyAttributes(
Handle<JSReceiver> object,
Handle<Name> name);
MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes(
Handle<JSReceiver> object, Handle<Name> name);
MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
LookupIterator* it);
MUST_USE_RESULT static Maybe<PropertyAttributes> GetOwnPropertyAttributes(
Handle<JSReceiver> object, Handle<Name> name);
static inline PropertyAttributes GetElementAttribute(
Handle<JSReceiver> object,
uint32_t index);
static inline PropertyAttributes GetOwnElementAttribute(
Handle<JSReceiver> object,
uint32_t index);
MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttribute(
Handle<JSReceiver> object, uint32_t index);
MUST_USE_RESULT static inline Maybe<PropertyAttributes>
GetOwnElementAttribute(Handle<JSReceiver> object, uint32_t index);
// Return the constructor function (may be Heap::null_value()).
inline Object* GetConstructor();
......@@ -2198,17 +2199,16 @@ class JSObject: public JSReceiver {
InterceptorInfo* GetIndexedInterceptor();
// Used from JSReceiver.
static Maybe<PropertyAttributes> GetPropertyAttributesWithInterceptor(
Handle<JSObject> holder,
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetPropertyAttributesWithInterceptor(Handle<JSObject> holder,
Handle<Object> receiver,
Handle<Name> name);
static PropertyAttributes GetPropertyAttributesWithFailedAccessCheck(
LookupIterator* it);
static PropertyAttributes GetElementAttributeWithReceiver(
Handle<JSObject> object,
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it);
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetElementAttributeWithReceiver(Handle<JSObject> object,
Handle<JSReceiver> receiver,
uint32_t index,
bool check_prototype);
uint32_t index, bool check_prototype);
// Retrieves an AccessorPair property from the given object. Might return
// undefined if the property doesn't exist or is of a different kind.
......@@ -2218,9 +2218,8 @@ class JSObject: public JSReceiver {
AccessorComponent component);
// Defines an AccessorPair property on the given object.
// TODO(mstarzinger): Rename to SetAccessor() and return empty handle on
// exception instead of letting callers check for scheduled exception.
static void DefineAccessor(Handle<JSObject> object,
// TODO(mstarzinger): Rename to SetAccessor().
static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object,
Handle<Name> name,
Handle<Object> getter,
Handle<Object> setter,
......@@ -2381,11 +2380,12 @@ class JSObject: public JSReceiver {
Handle<JSReceiver> receiver);
// Support functions for v8 api (needed for correct interceptor behavior).
static bool HasRealNamedProperty(Handle<JSObject> object,
Handle<Name> key);
static bool HasRealElementProperty(Handle<JSObject> object, uint32_t index);
static bool HasRealNamedCallbackProperty(Handle<JSObject> object,
Handle<Name> key);
MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty(
Handle<JSObject> object, Handle<Name> key);
MUST_USE_RESULT static Maybe<bool> HasRealElementProperty(
Handle<JSObject> object, uint32_t index);
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
// internal fields as well as the number of internal fields.
......@@ -2658,13 +2658,12 @@ class JSObject: public JSReceiver {
uint32_t index,
Handle<Object> holder);
static PropertyAttributes GetElementAttributeWithInterceptor(
Handle<JSObject> object,
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetElementAttributeWithInterceptor(Handle<JSObject> object,
Handle<JSReceiver> receiver,
uint32_t index,
bool continue_search);
static PropertyAttributes GetElementAttributeWithoutInterceptor(
Handle<JSObject> object,
uint32_t index, bool continue_search);
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetElementAttributeWithoutInterceptor(Handle<JSObject> object,
Handle<JSReceiver> receiver,
uint32_t index,
bool continue_search);
......@@ -9947,12 +9946,12 @@ class JSProxy: public JSReceiver {
Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
Handle<Object> value, StrictMode strict_mode, bool* done);
static PropertyAttributes GetPropertyAttributesWithHandler(
Handle<JSProxy> proxy,
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetPropertyAttributesWithHandler(Handle<JSProxy> proxy,
Handle<Object> receiver,
Handle<Name> name);
static PropertyAttributes GetElementAttributeWithHandler(
Handle<JSProxy> proxy,
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetElementAttributeWithHandler(Handle<JSProxy> proxy,
Handle<JSReceiver> receiver,
uint32_t index);
MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithHandler(
......@@ -10004,9 +10003,10 @@ class JSProxy: public JSReceiver {
Handle<Object> value,
StrictMode strict_mode);
static bool HasPropertyWithHandler(Handle<JSProxy> proxy, Handle<Name> name);
static inline bool HasElementWithHandler(Handle<JSProxy> proxy,
uint32_t index);
MUST_USE_RESULT static Maybe<bool> HasPropertyWithHandler(
Handle<JSProxy> proxy, Handle<Name> name);
MUST_USE_RESULT static inline Maybe<bool> HasElementWithHandler(
Handle<JSProxy> proxy, uint32_t index);
MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyWithHandler(
Handle<JSProxy> proxy,
......
This diff is collapsed.
......@@ -210,7 +210,9 @@ TEST(HeapObjects) {
Handle<String> object_string = Handle<String>::cast(factory->Object_string());
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
CheckOddball(isolate, heap->true_value(), "true");
......@@ -277,7 +279,9 @@ TEST(GarbageCollection) {
heap->CollectGarbage(NEW_SPACE);
// 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.
Handle<Object> func_value =
Object::GetProperty(global, name).ToHandleChecked();
......@@ -295,7 +299,9 @@ TEST(GarbageCollection) {
// After gc, it should survive.
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 =
Object::GetProperty(global, obj_name).ToHandleChecked();
CHECK(obj->IsJSObject());
......@@ -652,55 +658,85 @@ TEST(ObjectProperties) {
Handle<Smi> two(Smi::FromInt(2), isolate);
// 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
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
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
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
CHECK(JSReceiver::HasOwnProperty(obj, first));
CHECK(JSReceiver::HasOwnProperty(obj, second));
maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(maybe.has_value);
CHECK(maybe.value);
maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(maybe.value);
// delete first and then second
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();
CHECK(!JSReceiver::HasOwnProperty(obj, first));
CHECK(!JSReceiver::HasOwnProperty(obj, second));
maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(maybe.has_value);
CHECK(!maybe.value);
maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(!maybe.value);
// add first and then second
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
CHECK(JSReceiver::HasOwnProperty(obj, first));
CHECK(JSReceiver::HasOwnProperty(obj, second));
maybe = JSReceiver::HasOwnProperty(obj, first);
CHECK(maybe.has_value);
CHECK(maybe.value);
maybe = JSReceiver::HasOwnProperty(obj, second);
CHECK(maybe.has_value);
CHECK(maybe.value);
// delete second and then first
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();
CHECK(!JSReceiver::HasOwnProperty(obj, first));
CHECK(!JSReceiver::HasOwnProperty(obj, second));
maybe = JSReceiver::HasOwnProperty(obj, first);
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
const char* string1 = "fisk";
Handle<String> s1 = factory->NewStringFromAsciiChecked(string1);
JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check();
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
const char* string2 = "fugl";
Handle<String> s2_string = factory->InternalizeUtf8String(string2);
JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check();
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) {
{ HandleScope scope(isolate);
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 =
Object::GetProperty(global, func_name).ToHandleChecked();
CHECK(func_value->IsJSFunction());
......@@ -185,7 +187,9 @@ TEST(MarkCompactCollector) {
{ HandleScope scope(isolate);
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 =
Object::GetProperty(global, obj_name).ToHandleChecked();
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