Reviewers: Sven Panne, titzer,

Message:
titzer@: please review
svenpanne@: FYI (comments welcome as usual)

Description:
Add internal fields to JSArrayBufferViews (JSTypedArray and JSDataView)

In Blink, JSTypedArray and JSDataView objects act as "wrappers" for C++
objects. Wrapping protocol in Blink requires all wrapper JavaScript objects
to have a certain amount of internal fields that Blink uses for
book-keeping (essentially a pointer to C++ object and some type
information). This change adds those internal fields to JSTypedArray and
JSDataView, in a similiar way to how it is done for JSArrayBuffer.

[email protected],[email protected]

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

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

Affected files:
  M include/v8.h
  M src/bootstrapper.cc
  M src/objects-visiting-inl.h
  M src/objects.h
  M src/runtime.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 3afb83572a903e690e377c2b8bce5f900e60404d..caaa5c255cdb812aa75ee7ee4cef22b32d244f2c 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2489,6 +2489,11 @@ class V8EXPORT ArrayBuffer : public Object {
 };


+#ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
+#define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
+#endif
+
+
 /**
  * A base class for an instance of one of "views" over ArrayBuffer,
  * including TypedArrays and DataView (ES6 draft 15.13).
@@ -2516,6 +2521,9 @@ class V8EXPORT ArrayBufferView : public Object {

   V8_INLINE(static ArrayBufferView* Cast(Value* obj));

+  static const int kInternalFieldCount =
+      V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
+
  private:
   ArrayBufferView();
   static void CheckCast(Value* obj);
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 49333eb21ca0854e2b4d0fdc6b2f8e72a8d6b850..b49b795bc1b9e0ef31730ccadd3fcd7b2acada2c 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1289,7 +1289,7 @@ Handle<JSFunction> Genesis::InstallTypedArray(
       Builtins::kIllegal, false, true);

   Handle<Map> initial_map = isolate()->factory()->NewMap(
-      JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, elementsKind);
+ JS_TYPED_ARRAY_TYPE, JSTypedArray::kSizeWithInternalFields, elementsKind);
   result->set_initial_map(*initial_map);
   initial_map->set_constructor(*result);
   return result;
@@ -1373,7 +1373,7 @@ void Genesis::InitializeExperimentalGlobal() {
     Handle<JSFunction> data_view_fun =
         InstallFunction(
             global, "DataView", JS_DATA_VIEW_TYPE,
-            JSDataView::kSize,
+            JSDataView::kSizeWithInternalFields,
             isolate()->initial_object_prototype(),
             Builtins::kIllegal, true, true);
     native_context()->set_data_view_fun(*data_view_fun);
Index: src/objects-visiting-inl.h
diff --git a/src/objects-visiting-inl.h b/src/objects-visiting-inl.h
index cfb7d4461fc13a63cb5aa1f385c1fee34c32df33..612f937bc26fb8ab86248c606e28c2d4a346b8af 100644
--- a/src/objects-visiting-inl.h
+++ b/src/objects-visiting-inl.h
@@ -136,8 +136,8 @@ int StaticNewSpaceVisitor<StaticVisitor>::VisitJSTypedArray(
       map->GetHeap(),
       HeapObject::RawField(object,
           JSTypedArray::kWeakNextOffset + kPointerSize),
-      HeapObject::RawField(object, JSTypedArray::kSize));
-  return JSTypedArray::kSize;
+      HeapObject::RawField(object, JSTypedArray::kSizeWithInternalFields));
+  return JSTypedArray::kSizeWithInternalFields;
 }


@@ -152,8 +152,8 @@ int StaticNewSpaceVisitor<StaticVisitor>::VisitJSDataView(
       map->GetHeap(),
       HeapObject::RawField(object,
           JSDataView::kWeakNextOffset + kPointerSize),
-      HeapObject::RawField(object, JSDataView::kSize));
-  return JSDataView::kSize;
+      HeapObject::RawField(object, JSDataView::kSizeWithInternalFields));
+  return JSDataView::kSizeWithInternalFields;
 }


@@ -522,7 +522,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitJSTypedArray(
       map->GetHeap(),
       HeapObject::RawField(object,
         JSTypedArray::kWeakNextOffset + kPointerSize),
-      HeapObject::RawField(object, JSTypedArray::kSize));
+      HeapObject::RawField(object, JSTypedArray::kSizeWithInternalFields));
 }


@@ -537,7 +537,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitJSDataView(
       map->GetHeap(),
       HeapObject::RawField(object,
         JSDataView::kWeakNextOffset + kPointerSize),
-      HeapObject::RawField(object, JSDataView::kSize));
+      HeapObject::RawField(object, JSDataView::kSizeWithInternalFields));
 }


Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 416ed7fcda6ba35b5144f95144f10348225a5723..a212cbdc7f6e73787f31750ac91ebe93df2a9c5d 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -8921,6 +8921,9 @@ class JSTypedArray: public JSArrayBufferView {
   static const int kLengthOffset = kViewSize + kPointerSize;
   static const int kSize = kLengthOffset + kPointerSize;

+  static const int kSizeWithInternalFields =
+      kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
+
  private:
   DISALLOW_IMPLICIT_CONSTRUCTORS(JSTypedArray);
 };
@@ -8940,6 +8943,9 @@ class JSDataView: public JSArrayBufferView {

   static const int kSize = kViewSize;

+  static const int kSizeWithInternalFields =
+      kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
+
  private:
   DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataView);
 };
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index e3ee6d56c3c09937b1909e75644437e8a41df5dd..a53d448a964cd38ecfe0455d5ca32872e254571f 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -796,6 +796,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
   CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3);
   CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4);

+  ASSERT(holder->GetInternalFieldCount() ==
+      v8::ArrayBufferView::kInternalFieldCount);
+
   ExternalArrayType arrayType;
   size_t elementSize;
   switch (arrayId) {
@@ -1012,6 +1015,9 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) {
   CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2);
   CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3);

+  ASSERT(holder->GetInternalFieldCount() ==
+      v8::ArrayBufferView::kInternalFieldCount);
+
   holder->set_buffer(*buffer);
   ASSERT(byte_offset->IsNumber());
   ASSERT(


--
--
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/groups/opt_out.


Reply via email to