Simplify GetProperty helpers to ease element support
authorverwaest <verwaest@chromium.org>
Thu, 21 May 2015 14:34:52 +0000 (07:34 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 21 May 2015 14:34:32 +0000 (14:34 +0000)
BUG=v8:4137
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#28556}

src/ic/ic.cc
src/lookup.cc
src/lookup.h
src/objects.cc
src/objects.h
src/runtime/runtime-debug.cc

index 68745dc22f1133bb736406bf0bca563061ef5971..6f2fa2bebe8ceaa83458c05cf08b2f6b9003ca37 100644 (file)
@@ -2787,7 +2787,8 @@ RUNTIME_FUNCTION(LoadPropertyWithInterceptorOnly) {
   Handle<JSObject> holder =
       args.at<JSObject>(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex);
   HandleScope scope(isolate);
-  auto res = JSObject::GetPropertyWithInterceptor(holder, receiver, name);
+  LookupIterator it(receiver, name, holder, LookupIterator::OWN);
+  auto res = JSObject::GetPropertyWithInterceptor(&it);
   RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
   Handle<Object> result;
   if (res.ToHandle(&result)) return *result;
index 8eb5571e51e8dec93eae765b6bc79da9dd877097..79407d93ee6b4a398c0d6c25c3084f27580a5d31 100644 (file)
@@ -355,7 +355,7 @@ void LookupIterator::WriteDataValue(Handle<Object> value) {
 
 
 bool LookupIterator::IsIntegerIndexedExotic(JSReceiver* holder) {
-  DCHECK(ExoticIndexState::kNotExotic != exotic_index_state_);
+  DCHECK(exotic_index_state_ != ExoticIndexState::kNotExotic);
   // Currently typed arrays are the only such objects.
   if (!holder->IsJSTypedArray()) return false;
   if (exotic_index_state_ == ExoticIndexState::kExotic) return true;
@@ -386,6 +386,14 @@ bool LookupIterator::HasInterceptor(Map* map) const {
 }
 
 
+Handle<InterceptorInfo> LookupIterator::GetInterceptor() const {
+  DCHECK_EQ(INTERCEPTOR, state_);
+  Handle<JSObject> js_holder = Handle<JSObject>::cast(holder_);
+  if (IsElement()) return handle(js_holder->GetIndexedInterceptor(), isolate_);
+  return handle(js_holder->GetNamedInterceptor(), isolate_);
+}
+
+
 bool LookupIterator::SkipInterceptor(JSObject* holder) {
   auto info = holder->GetNamedInterceptor();
   // TODO(dcarney): check for symbol/can_intercept_symbols here as well.
index 48dce3a645732df9e45a06f41be205a2a7873bb7..849ce57bd668bd2dbad7b1581907e0f1915c9a29 100644 (file)
@@ -188,6 +188,7 @@ class LookupIterator final BASE_EMBEDDED {
   int GetConstantIndex() const;
   Handle<PropertyCell> GetPropertyCell() const;
   Handle<Object> GetAccessors() const;
+  Handle<InterceptorInfo> GetInterceptor() const;
   Handle<Object> GetDataValue() const;
   // Usually returns the value that was passed in, but may perform
   // non-observable modifications on it, such as internalize strings.
index 24ecc6b50e99272e7d10110f2e286369aca12bbc..90985eea7dfb4c3c6defb83c14a75541f1582b14 100644 (file)
@@ -136,8 +136,8 @@ MaybeHandle<Object> Object::GetProperty(LookupIterator* it) {
         return JSProxy::GetPropertyWithHandler(it->GetHolder<JSProxy>(),
                                                it->GetReceiver(), it->name());
       case LookupIterator::INTERCEPTOR: {
-        MaybeHandle<Object> maybe_result = JSObject::GetPropertyWithInterceptor(
-            it->GetHolder<JSObject>(), it->GetReceiver(), it->name());
+        MaybeHandle<Object> maybe_result =
+            JSObject::GetPropertyWithInterceptor(it);
         if (!maybe_result.is_null()) return maybe_result;
         if (it->isolate()->has_pending_exception()) return maybe_result;
         break;
@@ -146,9 +146,7 @@ MaybeHandle<Object> Object::GetProperty(LookupIterator* it) {
         if (it->HasAccess()) break;
         return JSObject::GetPropertyWithFailedAccessCheck(it);
       case LookupIterator::ACCESSOR:
-        return GetPropertyWithAccessor(it->GetReceiver(), it->name(),
-                                       it->GetHolder<JSObject>(),
-                                       it->GetAccessors());
+        return GetPropertyWithAccessor(it);
       case LookupIterator::INTEGER_INDEXED_EXOTIC:
         return it->factory()->undefined_value();
       case LookupIterator::DATA:
@@ -303,14 +301,16 @@ MaybeHandle<Object> JSProxy::GetPropertyWithHandler(Handle<JSProxy> proxy,
 }
 
 
-MaybeHandle<Object> Object::GetPropertyWithAccessor(Handle<Object> receiver,
-                                                    Handle<Name> name,
-                                                    Handle<JSObject> holder,
-                                                    Handle<Object> structure) {
-  Isolate* isolate = name->GetIsolate();
+MaybeHandle<Object> Object::GetPropertyWithAccessor(LookupIterator* it) {
+  Isolate* isolate = it->isolate();
+  Handle<Object> structure = it->GetAccessors();
+  Handle<Object> receiver = it->GetReceiver();
+
   DCHECK(!structure->IsForeign());
   // api style callbacks.
   if (structure->IsAccessorInfo()) {
+    Handle<JSObject> holder = it->GetHolder<JSObject>();
+    Handle<Name> name = it->name();
     Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure);
     if (!info->IsCompatibleReceiver(*receiver)) {
       THROW_NEW_ERROR(isolate,
@@ -491,14 +491,10 @@ MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck(
   Handle<JSObject> checked = it->GetHolder<JSObject>();
   while (FindAllCanReadHolder(it)) {
     if (it->state() == LookupIterator::ACCESSOR) {
-      return GetPropertyWithAccessor(it->GetReceiver(), it->name(),
-                                     it->GetHolder<JSObject>(),
-                                     it->GetAccessors());
+      return GetPropertyWithAccessor(it);
     }
     DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state());
-    auto receiver = Handle<JSObject>::cast(it->GetReceiver());
-    auto result = GetPropertyWithInterceptor(it->GetHolder<JSObject>(),
-                                             receiver, it->name());
+    auto result = GetPropertyWithInterceptor(it);
     if (it->isolate()->has_scheduled_exception()) break;
     if (!result.is_null()) return result;
   }
@@ -12764,8 +12760,7 @@ MaybeHandle<Object> JSObject::GetElementWithCallback(
         v8::ToCData<v8::AccessorNameGetterCallback>(fun_obj);
     if (call_fun == NULL) return isolate->factory()->undefined_value();
     Handle<JSObject> holder_handle = Handle<JSObject>::cast(holder);
-    Handle<Object> number = isolate->factory()->NewNumberFromUint(index);
-    Handle<String> key = isolate->factory()->NumberToString(number);
+    Handle<String> key = isolate->factory()->Uint32ToString(index);
     LOG(isolate, ApiNamedPropertyAccess("load", *holder_handle, *key));
     PropertyCallbackArguments
         args(isolate, data->data(), *receiver, *holder_handle);
@@ -12813,8 +12808,7 @@ MaybeHandle<Object> JSObject::SetElementWithCallback(
     v8::AccessorNameSetterCallback call_fun =
         v8::ToCData<v8::AccessorNameSetterCallback>(call_obj);
     if (call_fun == NULL) return value;
-    Handle<Object> number = isolate->factory()->NewNumberFromUint(index);
-    Handle<String> key(isolate->factory()->NumberToString(number));
+    Handle<String> key(isolate->factory()->Uint32ToString(index));
     LOG(isolate, ApiNamedPropertyAccess("store", *holder, *key));
     PropertyCallbackArguments
         args(isolate, data->data(), *object, *holder);
@@ -14030,15 +14024,15 @@ InterceptorInfo* JSObject::GetIndexedInterceptor() {
 }
 
 
-MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(
-    Handle<JSObject> holder,
-    Handle<Object> receiver,
-    Handle<Name> name) {
-  Isolate* isolate = holder->GetIsolate();
-
-  Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor(), isolate);
+MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(LookupIterator* it) {
+  DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state());
+  Isolate* isolate = it->isolate();
+  Handle<InterceptorInfo> interceptor = it->GetInterceptor();
   if (interceptor->getter()->IsUndefined()) return MaybeHandle<Object>();
 
+  Handle<Name> name = it->name();
+  Handle<JSObject> holder = it->GetHolder<JSObject>();
+
   if (name->IsSymbol() && !interceptor->can_intercept_symbols()) {
     return MaybeHandle<Object>();
   }
@@ -14048,8 +14042,8 @@ MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(
           interceptor->getter());
   LOG(isolate,
       ApiNamedPropertyAccess("interceptor-named-get", *holder, *name));
-  PropertyCallbackArguments
-      args(isolate, interceptor->data(), *receiver, *holder);
+  PropertyCallbackArguments args(isolate, interceptor->data(),
+                                 *it->GetReceiver(), *holder);
   v8::Handle<v8::Value> result = args.Call(getter, v8::Utils::ToLocal(name));
   RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
   if (result.IsEmpty()) return MaybeHandle<Object>();
index 665da0384ce861d661fed39ac2101fd03a31bc2a..129c6c35ac9e58f09fc69b881a8c7c2ff1d22726 100644 (file)
@@ -1187,10 +1187,7 @@ class Object {
       Handle<Name> key);
 
   MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithAccessor(
-      Handle<Object> receiver,
-      Handle<Name> name,
-      Handle<JSObject> holder,
-      Handle<Object> structure);
+      LookupIterator* it);
   MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithAccessor(
       Handle<Object> receiver, Handle<Name> name, Handle<Object> value,
       Handle<JSObject> holder, Handle<Object> structure,
@@ -1895,9 +1892,7 @@ class JSObject: public JSReceiver {
       Handle<AccessorInfo> info);
 
   MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor(
-      Handle<JSObject> object,
-      Handle<Object> receiver,
-      Handle<Name> name);
+      LookupIterator* it);
 
   // Accessors for hidden properties object.
   //
index 0d2f65d571e2e7101e4f4d98494e8ccae88f8bce..660fc7ffa2b1055010db4f37751b3a297c8b2e26 100644 (file)
@@ -80,9 +80,8 @@ static Handle<Object> DebugGetProperty(LookupIterator* it,
         if (!accessors->IsAccessorInfo()) {
           return it->isolate()->factory()->undefined_value();
         }
-        MaybeHandle<Object> maybe_result = JSObject::GetPropertyWithAccessor(
-            it->GetReceiver(), it->name(), it->GetHolder<JSObject>(),
-            accessors);
+        MaybeHandle<Object> maybe_result =
+            JSObject::GetPropertyWithAccessor(it);
         Handle<Object> result;
         if (!maybe_result.ToHandle(&result)) {
           result = handle(it->isolate()->pending_exception(), it->isolate());