Reviewers: Jakob,

Description:
Tighten OpenHandle's extra checks.

Please review this at https://codereview.chromium.org/240113010/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+52, -44 lines):
  M include/v8.h
  M src/accessors.cc
  M src/api.h
  M src/objects.h
  M src/objects.cc
  M src/objects-inl.h
  M src/runtime.cc
  M test/cctest/test-api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 128973094762b35a4f85d32e14c0364d1243d754..26a9c48e70a97630b6434dab51d54b8820799cf8 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2522,7 +2522,7 @@ class PropertyCallbackInfo {
  public:
   V8_INLINE Isolate* GetIsolate() const;
   V8_INLINE Local<Value> Data() const;
-  V8_INLINE Local<Object> This() const;
+  V8_INLINE Local<Value> This() const;
   V8_INLINE Local<Object> Holder() const;
   V8_INLINE ReturnValue<T> GetReturnValue() const;
   // This shouldn't be public, but the arm compiler needs it.
@@ -6495,8 +6495,8 @@ Local<Value> PropertyCallbackInfo<T>::Data() const {


 template<typename T>
-Local<Object> PropertyCallbackInfo<T>::This() const {
-  return Local<Object>(reinterpret_cast<Object*>(&args_[kThisIndex]));
+Local<Value> PropertyCallbackInfo<T>::This() const {
+  return Local<Value>(reinterpret_cast<Value*>(&args_[kThisIndex]));
 }


Index: src/accessors.cc
diff --git a/src/accessors.cc b/src/accessors.cc
index 9913943501690345451a6ddd567799d81dd7145c..0a3f8248352b094952a4fef732c7393fc384d199 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -867,7 +867,8 @@ void Accessors::FunctionPrototypeSetter(
     const v8::PropertyCallbackInfo<void>& info) {
   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
   HandleScope scope(isolate);
-  Handle<JSObject> object = Utils::OpenHandle(*info.This());
+  Handle<JSObject> object =
+      Handle<JSObject>::cast(Utils::OpenHandle(*info.This()));
   Handle<Object> value = Utils::OpenHandle(*val);

   SetFunctionPrototype(isolate, object, value);
Index: src/api.h
diff --git a/src/api.h b/src/api.h
index 128087c895137c876bd62de869ba022a8d074afa..28aea2da9e5e998c7fd4394e472afff168f015ec 100644
--- a/src/api.h
+++ b/src/api.h
@@ -186,9 +186,9 @@ class RegisteredExtension {
   V(Script, JSFunction)                        \
   V(UnboundScript, SharedFunctionInfo)         \
   V(Function, JSFunction)                      \
-  V(Message, JSObject)                         \
+  V(Message, JSMessageObject)                  \
   V(Context, Context)                          \
-  V(External, Foreign)                         \
+  V(External, Object)                          \
   V(StackTrace, JSArray)                       \
   V(StackFrame, JSObject)                      \
   V(DeclaredAccessorDescriptor, DeclaredAccessorDescriptor)
@@ -393,8 +393,8 @@ MAKE_TO_LOCAL(ToLocal, DeclaredAccessorDescriptor, DeclaredAccessorDescriptor) const v8::From* that, bool allow_empty_handle) { \ EXTRA_CHECK(allow_empty_handle || that != NULL); \ EXTRA_CHECK(that == NULL | | \ - !(*reinterpret_cast<v8::internal::To**>( \ - const_cast<v8::From*>(that)))->IsFailure()); \ + (*reinterpret_cast<v8::internal::Object**>( \ + const_cast<v8::From*>(that)))->Is##To()); \ return v8::internal::Handle<v8::internal::To>( \ reinterpret_cast<v8::internal::To**>(const_cast<v8::From*>(that))); \
   }
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 76a43d5ff9c0a18a03a4b3f8403157834da90d2f..dab3867dc87af143ed207ca31cb83ab2ac325c22 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -219,6 +219,11 @@ bool Object::IsSpecFunction() {
 }


+bool Object::IsTemplateInfo() {
+  return IsObjectTemplateInfo() || IsFunctionTemplateInfo();
+}
+
+
 bool Object::IsInternalizedString() {
   if (!this->IsHeapObject()) return false;
   uint32_t type = HeapObject::cast(this)->map()->instance_type();
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 2a7252ca13825355cb715eb2bb5b543e16db838d..2044484b92290511cf4105915b7592cd33eccff2 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -6422,8 +6422,8 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
           FixedArray);
       ASSIGN_RETURN_ON_EXCEPTION(
           isolate, content,
-          FixedArray::AddKeysFromJSArray(
-              content, Handle<JSArray>::cast(names)),
+          FixedArray::AddKeysFromArrayLike(
+              content, Handle<JSObject>::cast(names)),
           FixedArray);
       break;
     }
@@ -6451,12 +6451,12 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,

     // Add the element keys from the interceptor.
     if (current->HasIndexedInterceptor()) {
-      Handle<JSArray> result;
+      Handle<JSObject> result;
       if (JSObject::GetKeysForIndexedInterceptor(
               current, object).ToHandle(&result)) {
         ASSIGN_RETURN_ON_EXCEPTION(
             isolate, content,
-            FixedArray::AddKeysFromJSArray(content, result),
+            FixedArray::AddKeysFromArrayLike(content, result),
             FixedArray);
       }
       ASSERT(ContainsOnlyValidKeys(content));
@@ -6488,12 +6488,12 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,

     // Add the property keys from the interceptor.
     if (current->HasNamedInterceptor()) {
-      Handle<JSArray> result;
+      Handle<JSObject> result;
       if (JSObject::GetKeysForNamedInterceptor(
               current, object).ToHandle(&result)) {
         ASSIGN_RETURN_ON_EXCEPTION(
             isolate, content,
-            FixedArray::AddKeysFromJSArray(content, result),
+            FixedArray::AddKeysFromArrayLike(content, result),
             FixedArray);
       }
       ASSERT(ContainsOnlyValidKeys(content));
@@ -8231,9 +8231,10 @@ void FixedArray::Shrink(int new_length) {
 }


-MaybeHandle<FixedArray> FixedArray::AddKeysFromJSArray(
+MaybeHandle<FixedArray> FixedArray::AddKeysFromArrayLike(
     Handle<FixedArray> content,
-    Handle<JSArray> array) {
+    Handle<JSObject> array) {
+  ASSERT(array->IsJSArray() || array->HasSloppyArgumentsElements());
   ElementsAccessor* accessor = array->GetElementsAccessor();
   Handle<FixedArray> result;
   ASSIGN_RETURN_ON_EXCEPTION(
@@ -13905,13 +13906,13 @@ MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(

 // Compute the property keys from the interceptor.
 // TODO(rossberg): support symbols in API, and filter here if needed.
-MaybeHandle<JSArray> JSObject::GetKeysForNamedInterceptor(
+MaybeHandle<JSObject> JSObject::GetKeysForNamedInterceptor(
     Handle<JSObject> object, Handle<JSReceiver> receiver) {
   Isolate* isolate = receiver->GetIsolate();
   Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
   PropertyCallbackArguments
       args(isolate, interceptor->data(), *receiver, *object);
-  v8::Handle<v8::Array> result;
+  v8::Handle<v8::Object> result;
   if (!interceptor->enumerator()->IsUndefined()) {
     v8::NamedPropertyEnumeratorCallback enum_fun =
         v8::ToCData<v8::NamedPropertyEnumeratorCallback>(
@@ -13919,9 +13920,10 @@ MaybeHandle<JSArray> JSObject::GetKeysForNamedInterceptor(
     LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
     result = args.Call(enum_fun);
   }
-  if (result.IsEmpty()) return MaybeHandle<JSArray>();
+  if (result.IsEmpty()) return MaybeHandle<JSObject>();
 #if ENABLE_EXTRA_CHECKS
-  CHECK(v8::Utils::OpenHandle(*result)->IsJSObject());
+  CHECK(v8::Utils::OpenHandle(*result)->IsJSArray() ||
+        v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements());
 #endif
   // Rebox before returning.
   return handle(*v8::Utils::OpenHandle(*result), isolate);
@@ -13929,13 +13931,13 @@ MaybeHandle<JSArray> JSObject::GetKeysForNamedInterceptor(


 // Compute the element keys from the interceptor.
-MaybeHandle<JSArray> JSObject::GetKeysForIndexedInterceptor(
+MaybeHandle<JSObject> JSObject::GetKeysForIndexedInterceptor(
     Handle<JSObject> object, Handle<JSReceiver> receiver) {
   Isolate* isolate = receiver->GetIsolate();
   Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
   PropertyCallbackArguments
       args(isolate, interceptor->data(), *receiver, *object);
-  v8::Handle<v8::Array> result;
+  v8::Handle<v8::Object> result;
   if (!interceptor->enumerator()->IsUndefined()) {
     v8::IndexedPropertyEnumeratorCallback enum_fun =
         v8::ToCData<v8::IndexedPropertyEnumeratorCallback>(
@@ -13943,9 +13945,10 @@ MaybeHandle<JSArray> JSObject::GetKeysForIndexedInterceptor(
     LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
     result = args.Call(enum_fun);
   }
-  if (result.IsEmpty()) return MaybeHandle<JSArray>();
+  if (result.IsEmpty()) return MaybeHandle<JSObject>();
 #if ENABLE_EXTRA_CHECKS
-  CHECK(v8::Utils::OpenHandle(*result)->IsJSObject());
+  CHECK(v8::Utils::OpenHandle(*result)->IsJSArray() ||
+        v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements());
 #endif
   // Rebox before returning.
   return handle(*v8::Utils::OpenHandle(*result), isolate);
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index d926165c3e06e358ff595567f5ba58a175286743..541ffab99efa094cfcd5452e37b44ae180d50505 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -772,8 +772,6 @@ enum InstanceType {
   CONSTANT_POOL_ARRAY_TYPE,
   SHARED_FUNCTION_INFO_TYPE,

-  JS_MESSAGE_OBJECT_TYPE,
-
// All the following types are subtypes of JSReceiver, which corresponds to
   // objects in the JS sense. The first and the last type in this range are
   // the two forms of function. This organization enables using the same
@@ -783,6 +781,7 @@ enum InstanceType {
   JS_PROXY_TYPE,  // LAST_JS_PROXY_TYPE

   JS_VALUE_TYPE,  // FIRST_JS_OBJECT_TYPE
+  JS_MESSAGE_OBJECT_TYPE,
   JS_DATE_TYPE,
   JS_OBJECT_TYPE,
   JS_CONTEXT_EXTENSION_OBJECT_TYPE,
@@ -1444,6 +1443,7 @@ class Object : public MaybeObject {

   INLINE(bool IsSpecObject());
   INLINE(bool IsSpecFunction());
+  INLINE(bool IsTemplateInfo());
   bool IsCallable();

   // Oddball testing.
@@ -2534,10 +2534,10 @@ class JSObject: public JSReceiver {

// Computes the enumerable keys from interceptors. Used for debug mirrors and
   // by JSReceiver::GetKeys.
-  MUST_USE_RESULT static MaybeHandle<JSArray> GetKeysForNamedInterceptor(
+  MUST_USE_RESULT static MaybeHandle<JSObject> GetKeysForNamedInterceptor(
       Handle<JSObject> object,
       Handle<JSReceiver> receiver);
-  MUST_USE_RESULT static MaybeHandle<JSArray> GetKeysForIndexedInterceptor(
+ MUST_USE_RESULT static MaybeHandle<JSObject> GetKeysForIndexedInterceptor(
       Handle<JSObject> object,
       Handle<JSReceiver> receiver);

@@ -3088,9 +3088,9 @@ class FixedArray: public FixedArrayBase {
PretenureFlag pretenure = NOT_TENURED);

   // Add the elements of a JSArray to this FixedArray.
-  MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromJSArray(
+  MUST_USE_RESULT static MaybeHandle<FixedArray> AddKeysFromArrayLike(
       Handle<FixedArray> content,
-      Handle<JSArray> array);
+      Handle<JSObject> array);

   // Computes the union of keys and return the result.
   // Used for implementing "for (n in object) { }"
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index c63a93885d631614cfa6c19058663f480b6693dc..c28c690bb678e13ee621791daf208b6e3367ac85 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -6034,7 +6034,7 @@ RUNTIME_FUNCTION(Runtime_GetNamedInterceptorPropertyNames) {
   CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);

   if (obj->HasNamedInterceptor()) {
-    Handle<JSArray> result;
+    Handle<JSObject> result;
     if (JSObject::GetKeysForNamedInterceptor(obj, obj).ToHandle(&result)) {
       return *result;
     }
@@ -6051,7 +6051,7 @@ RUNTIME_FUNCTION(Runtime_GetIndexedInterceptorElementNames) {
   CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);

   if (obj->HasIndexedInterceptor()) {
-    Handle<JSArray> result;
+    Handle<JSObject> result;
if (JSObject::GetKeysForIndexedInterceptor(obj, obj).ToHandle(&result)) {
       return *result;
     }
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index e346df265d798d5c87541f8df4c3e74c37a22699..6148dc3bced15e32ccf2ba8aeeade07f2b0a5dd8 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1917,14 +1917,14 @@ static void EchoNamedProperty(Local<String> name,

 void SimpleAccessorGetter(Local<String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
-  Handle<Object> self = info.This();
+  Handle<Object> self = Handle<Object>::Cast(info.This());
   info.GetReturnValue().Set(
       self->Get(String::Concat(v8_str("accessor_"), name)));
 }

 void SimpleAccessorSetter(Local<String> name, Local<Value> value,
                           const v8::PropertyCallbackInfo<void>& info) {
-  Handle<Object> self = info.This();
+  Handle<Object> self = Handle<Object>::Cast(info.This());
   self->Set(String::Concat(v8_str("accessor_"), name), value);
 }

@@ -1947,7 +1947,7 @@ void InterceptorGetter(Local<String> name,
   for (i = 0; name_str[i] && prefix[i]; ++i) {
     if (name_str[i] != prefix[i]) return;
   }
-  Handle<Object> self = info.This();
+  Handle<Object> self = Handle<Object>::Cast(info.This());
   info.GetReturnValue().Set(self->GetHiddenValue(v8_str(name_str + i)));
 }

@@ -1966,7 +1966,7 @@ void InterceptorSetter(Local<String> name,
   if (!prefix[i]) return;

   if (value->IsInt32() && value->Int32Value() < 10000) {
-    Handle<Object> self = info.This();
+    Handle<Object> self = Handle<Object>::Cast(info.This());
     self->SetHiddenValue(name, value);
     info.GetReturnValue().Set(value);
   }
@@ -8205,10 +8205,9 @@ static void YGetter(Local<String> name,
 static void YSetter(Local<String> name,
                     Local<Value> value,
                     const v8::PropertyCallbackInfo<void>& info) {
-  if (info.This()->Has(name)) {
-    info.This()->Delete(name);
-  }
-  info.This()->Set(name, value);
+  Local<Object> this_obj = Local<Object>::Cast(info.This());
+  if (this_obj->Has(name)) this_obj->Delete(name);
+  this_obj->Set(name, value);
 }


@@ -11458,7 +11457,7 @@ THREADED_TEST(InterceptorLoadICInvalidatedFieldViaGlobal) {
 static void SetOnThis(Local<String> name,
                       Local<Value> value,
                       const v8::PropertyCallbackInfo<void>& info) {
-  info.This()->ForceSet(name, value);
+  Local<Object>::Cast(info.This())->ForceSet(name, value);
 }


@@ -18545,7 +18544,7 @@ static void SetterWhichSetsYOnThisTo23(
     const v8::PropertyCallbackInfo<void>& info) {
   CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
   CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
-  info.This()->Set(v8_str("y"), v8_num(23));
+  Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23));
 }


@@ -18564,7 +18563,7 @@ void FooSetInterceptor(Local<String> name,
   CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
   CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
   if (!name->Equals(v8_str("foo"))) return;
-  info.This()->Set(v8_str("y"), v8_num(23));
+  Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23));
   info.GetReturnValue().Set(v8_num(23));
 }

@@ -18617,7 +18616,7 @@ static void NamedPropertySetterWhichSetsYOnThisTo23(
     Local<Value> value,
     const v8::PropertyCallbackInfo<v8::Value>& info) {
   if (name->Equals(v8_str("x"))) {
-    info.This()->Set(v8_str("y"), v8_num(23));
+    Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23));
   }
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to