Commit c7715c2f authored by jochen's avatar jochen Committed by Commit bot

Add HasOwnProperty with array indexes

This way embedders don't have to manually convert them to strings

BUG=chromium:619166
R=verwaest@chromium.org

Review-Url: https://codereview.chromium.org/2085223002
Cr-Commit-Position: refs/heads/master@{#37179}
parent 03996851
...@@ -2897,6 +2897,8 @@ class V8_EXPORT Object : public Value { ...@@ -2897,6 +2897,8 @@ class V8_EXPORT Object : public Value {
V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key)); V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context, V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
Local<Name> key); Local<Name> key);
V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
uint32_t index);
V8_DEPRECATE_SOON("Use maybe version", V8_DEPRECATE_SOON("Use maybe version",
bool HasRealNamedProperty(Local<String> key)); bool HasRealNamedProperty(Local<String> key));
V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context, V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
......
...@@ -4184,6 +4184,14 @@ Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context, ...@@ -4184,6 +4184,14 @@ Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context,
return result; return result;
} }
Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context, uint32_t index) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, HasOwnProperty, bool);
auto self = Utils::OpenHandle(this);
auto result = i::JSReceiver::HasOwnProperty(self, index);
has_pending_exception = result.IsNothing();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return result;
}
bool v8::Object::HasOwnProperty(Local<String> key) { bool v8::Object::HasOwnProperty(Local<String> key) {
auto context = ContextFromHeapObject(Utils::OpenHandle(this)); auto context = ContextFromHeapObject(Utils::OpenHandle(this));
......
...@@ -7178,6 +7178,19 @@ Maybe<bool> JSReceiver::HasOwnProperty(Handle<JSReceiver> object, ...@@ -7178,6 +7178,19 @@ Maybe<bool> JSReceiver::HasOwnProperty(Handle<JSReceiver> object,
return Just(attributes.FromJust() != ABSENT); return Just(attributes.FromJust() != ABSENT);
} }
Maybe<bool> JSReceiver::HasOwnProperty(Handle<JSReceiver> object,
uint32_t index) {
if (object->IsJSObject()) { // Shortcut
LookupIterator it(object->GetIsolate(), object, index, object,
LookupIterator::OWN);
return HasProperty(&it);
}
Maybe<PropertyAttributes> attributes =
JSReceiver::GetOwnPropertyAttributes(object, index);
MAYBE_RETURN(attributes, Nothing<bool>());
return Just(attributes.FromJust() != ABSENT);
}
Maybe<PropertyAttributes> JSReceiver::GetPropertyAttributes( Maybe<PropertyAttributes> JSReceiver::GetPropertyAttributes(
Handle<JSReceiver> object, Handle<Name> name) { Handle<JSReceiver> object, Handle<Name> name) {
...@@ -7194,6 +7207,12 @@ Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes( ...@@ -7194,6 +7207,12 @@ Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes(
return GetPropertyAttributes(&it); return GetPropertyAttributes(&it);
} }
Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes(
Handle<JSReceiver> object, uint32_t index) {
LookupIterator it(object->GetIsolate(), object, index, object,
LookupIterator::OWN);
return GetPropertyAttributes(&it);
}
Maybe<bool> JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) { Maybe<bool> JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) {
LookupIterator it(object->GetIsolate(), object, index, object); LookupIterator it(object->GetIsolate(), object, index, object);
......
...@@ -1854,6 +1854,8 @@ class JSReceiver: public HeapObject { ...@@ -1854,6 +1854,8 @@ class JSReceiver: public HeapObject {
MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty( MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(
Handle<JSReceiver> object, Handle<Name> name); Handle<JSReceiver> object, Handle<Name> name);
MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(
Handle<JSReceiver> object, uint32_t index);
MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty(
Isolate* isolate, Handle<JSReceiver> receiver, const char* key); Isolate* isolate, Handle<JSReceiver> receiver, const char* key);
...@@ -1951,6 +1953,8 @@ class JSReceiver: public HeapObject { ...@@ -1951,6 +1953,8 @@ class JSReceiver: public HeapObject {
Handle<JSReceiver> object, Handle<Name> name); Handle<JSReceiver> object, Handle<Name> name);
MUST_USE_RESULT static inline Maybe<PropertyAttributes> MUST_USE_RESULT static inline Maybe<PropertyAttributes>
GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name); GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name);
MUST_USE_RESULT static inline Maybe<PropertyAttributes>
GetOwnPropertyAttributes(Handle<JSReceiver> object, uint32_t index);
MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttributes( MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttributes(
Handle<JSReceiver> object, uint32_t index); Handle<JSReceiver> object, uint32_t index);
......
...@@ -20478,6 +20478,7 @@ TEST(HasOwnProperty) { ...@@ -20478,6 +20478,7 @@ TEST(HasOwnProperty) {
HasOwnPropertyNamedPropertyGetter)); HasOwnPropertyNamedPropertyGetter));
Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
CHECK(!instance->HasOwnProperty(env.local(), v8_str("42")).FromJust()); CHECK(!instance->HasOwnProperty(env.local(), v8_str("42")).FromJust());
CHECK(!instance->HasOwnProperty(env.local(), 42).FromJust());
CHECK(instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); CHECK(instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust());
CHECK(!instance->HasOwnProperty(env.local(), v8_str("bar")).FromJust()); CHECK(!instance->HasOwnProperty(env.local(), v8_str("bar")).FromJust());
} }
...@@ -20487,7 +20488,9 @@ TEST(HasOwnProperty) { ...@@ -20487,7 +20488,9 @@ TEST(HasOwnProperty) {
HasOwnPropertyIndexedPropertyGetter)); HasOwnPropertyIndexedPropertyGetter));
Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
CHECK(instance->HasOwnProperty(env.local(), v8_str("42")).FromJust()); CHECK(instance->HasOwnProperty(env.local(), v8_str("42")).FromJust());
CHECK(instance->HasOwnProperty(env.local(), 42).FromJust());
CHECK(!instance->HasOwnProperty(env.local(), v8_str("43")).FromJust()); CHECK(!instance->HasOwnProperty(env.local(), v8_str("43")).FromJust());
CHECK(!instance->HasOwnProperty(env.local(), 43).FromJust());
CHECK(!instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust()); CHECK(!instance->HasOwnProperty(env.local(), v8_str("foo")).FromJust());
} }
{ // Check named query interceptors. { // Check named query interceptors.
...@@ -20504,7 +20507,9 @@ TEST(HasOwnProperty) { ...@@ -20504,7 +20507,9 @@ TEST(HasOwnProperty) {
0, 0, HasOwnPropertyIndexedPropertyQuery)); 0, 0, HasOwnPropertyIndexedPropertyQuery));
Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
CHECK(instance->HasOwnProperty(env.local(), v8_str("42")).FromJust()); CHECK(instance->HasOwnProperty(env.local(), v8_str("42")).FromJust());
CHECK(instance->HasOwnProperty(env.local(), 42).FromJust());
CHECK(!instance->HasOwnProperty(env.local(), v8_str("41")).FromJust()); CHECK(!instance->HasOwnProperty(env.local(), v8_str("41")).FromJust());
CHECK(!instance->HasOwnProperty(env.local(), 41).FromJust());
} }
{ // Check callbacks. { // Check callbacks.
Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
......
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