Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: src/runtime.cc

Issue 21924007: Make new Harmony constructors subclassing-friendly (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.h ('k') | src/typedarray.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 97751470426cc62109970a2f17477e364c9e5ba4..6eb9c57b1a3ab9f6d78468527f77dc78fe2a2b48 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -747,11 +747,34 @@ bool Runtime::SetupArrayBufferAllocatingData(
}
+static Failure* ThrowTypeError(Isolate* isolate,
+ const char* message_id,
+ const char* arg) {
+ HandleScope scope(isolate);
+ Handle<Object> name_obj =
+ isolate->factory()->NewStringFromAscii(CStrVector(arg));
+ Handle<Object> args[1] = { name_obj };
+ return isolate->Throw(
+ *isolate->factory()->NewTypeError(
+ message_id, HandleVector(args, 1)));
+}
+
+
RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) {
HandleScope scope(isolate);
ASSERT(args.length() == 2);
- CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, byteLength, 1);
+
+ if (!this_obj->IsJSArrayBuffer()) {
+ return ThrowTypeError(isolate, "constructor_not_function", "ArrayBuffer");
+ }
+ Handle<JSArrayBuffer> holder(JSArrayBuffer::cast(*this_obj));
+ if (!holder->byte_length()->IsUndefined()) {
+ return ThrowTypeError(
+ isolate, "object_already_initialized", "ArrayBuffer");
+ }
+
size_t allocated_length;
if (byteLength->IsSmi()) {
allocated_length = Smi::cast(*byteLength)->value();
@@ -822,7 +845,8 @@ enum TypedArrayId {
};
static void ArrayIdToTypeAndSize(
- int arrayId, ExternalArrayType* array_type, size_t* element_size) {
+ int arrayId,
+ ExternalArrayType* array_type, size_t* element_size) {
switch (arrayId) {
case ARRAY_ID_UINT8:
*array_type = kExternalUnsignedByteArray;
@@ -866,25 +890,62 @@ static void ArrayIdToTypeAndSize(
}
+static const char * GetTypedArrayName(int arrayId) {
+ switch (arrayId) {
+ case ARRAY_ID_UINT8:
+ return "Uint8Array";
+ case ARRAY_ID_INT8:
+ return "Int8Array";
+ case ARRAY_ID_UINT16:
+ return "Uint16Array";
+ case ARRAY_ID_INT16:
+ return "Int16Array";
+ case ARRAY_ID_UINT32:
+ return "Uint32Array";
+ case ARRAY_ID_INT32:
+ return "Int32Array";
+ case ARRAY_ID_FLOAT32:
+ return "Float32Array";
+ case ARRAY_ID_FLOAT64:
+ return "Float64Array";
+ case ARRAY_ID_UINT8C:
+ return "Uint8ClampedArray";
+ default:
+ UNREACHABLE();
+ return NULL;
+ }
+}
+
+
RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
HandleScope scope(isolate);
ASSERT(args.length() == 5);
- CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0);
CONVERT_SMI_ARG_CHECKED(arrayId, 1);
CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3);
CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4);
+ ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
+ size_t element_size = 1; // Bogus initialization.
+ ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
+
+ if (!this_obj->IsJSTypedArray()) {
+ return ThrowTypeError(isolate, "constructor_not_function",
+ GetTypedArrayName(arrayId));
+ }
+ Handle<JSTypedArray> holder(JSTypedArray::cast(*this_obj));
+ if (!holder->buffer()->IsUndefined()) {
+ return ThrowTypeError(
+ isolate, "object_already_initialized", GetTypedArrayName(arrayId));
+ }
+
ASSERT(holder->GetInternalFieldCount() ==
v8::ArrayBufferView::kInternalFieldCount);
for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
holder->SetInternalField(i, Smi::FromInt(0));
}
- ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
- size_t element_size = 1; // Bogus initialization.
- ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
-
holder->set_buffer(*buffer);
holder->set_byte_offset(*byte_offset_object);
holder->set_byte_length(*byte_length_object);
@@ -916,21 +977,31 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitializeFromArrayLike) {
HandleScope scope(isolate);
ASSERT(args.length() == 4);
- CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0);
CONVERT_SMI_ARG_CHECKED(arrayId, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, source, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3);
+ ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
+ size_t element_size = 1; // Bogus initialization.
+ ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
+
+ if (!this_obj->IsJSTypedArray()) {
+ return ThrowTypeError(isolate, "constructor_not_function",
+ GetTypedArrayName(arrayId));
+ }
+ Handle<JSTypedArray> holder(JSTypedArray::cast(*this_obj));
+ if (!holder->buffer()->IsUndefined()) {
+ return ThrowTypeError(
+ isolate, "object_already_initialized", GetTypedArrayName(arrayId));
+ }
+
ASSERT(holder->GetInternalFieldCount() ==
v8::ArrayBufferView::kInternalFieldCount);
for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
holder->SetInternalField(i, Smi::FromInt(0));
}
- ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
- size_t element_size = 1; // Bogus initialization.
- ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
-
Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
size_t length = NumberToSize(isolate, *length_obj);
size_t byte_length = length * element_size;
@@ -1089,11 +1160,20 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArraySetFastCases) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) {
HandleScope scope(isolate);
ASSERT(args.length() == 4);
- CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, this_obj, 0);
CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3);
+ if (!this_obj->IsJSDataView()) {
+ return ThrowTypeError(isolate, "constructor_not_function", "DataView");
+ }
+ Handle<JSDataView> holder(JSDataView::cast(*this_obj));
+ if (!holder->buffer()->IsUndefined()) {
+ return ThrowTypeError(
+ isolate, "object_already_initialized", "DataView");
+ }
+
ASSERT(holder->GetInternalFieldCount() ==
v8::ArrayBufferView::kInternalFieldCount);
for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
@@ -1361,10 +1441,28 @@ DATA_VIEW_SETTER(Float64, double)
#undef DATA_VIEW_SETTER
-
RUNTIME_FUNCTION(MaybeObject*, Runtime_SetInitialize) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
+ if (!holder->IsJSSet()) {
+ return ThrowTypeError(isolate, "constructor_not_function", "Set");
+ }
+ Handle<JSSet> set(JSSet::cast(*holder));
+
+ if (!set->table()->IsUndefined()) {
+ return ThrowTypeError(isolate, "object_already_initialized", "Set");
+ }
+
+ Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0);
+ set->set_table(*table);
+ return *holder;
+}
+
+
+RUNTIME_FUNCTION(MaybeObject*, Runtime_SetClear) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0);
holder->set_table(*table);
@@ -1418,8 +1516,27 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetGetSize) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_MapInitialize) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);
- CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
+ if (!holder->IsJSMap()) {
+ return ThrowTypeError(isolate, "constructor_not_function", "Map");
+ }
+ Handle<JSMap> map(JSMap::cast(*holder));
+
+ if (!map->table()->IsUndefined()) {
+ return ThrowTypeError(isolate, "object_already_initialized", "Map");
+ }
+
Handle<ObjectHashTable> table = isolate->factory()->NewObjectHashTable(0);
+ map->set_table(*table);
+ return *holder;
+}
+
+
+RUNTIME_FUNCTION(MaybeObject*, Runtime_MapClear) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
+ Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0);
holder->set_table(*table);
return *holder;
}
@@ -1493,7 +1610,37 @@ static JSWeakCollection* WeakCollectionInitialize(Isolate* isolate,
}
-RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionInitialize) {
+RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakMapInitialize) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
+ if (!holder->IsJSWeakMap()) {
+ return ThrowTypeError(isolate, "constructor_not_function", "WeakMap");
+ }
+ Handle<JSWeakMap> map(JSWeakMap::cast(*holder));
+ if (!map->table()->IsUndefined()) {
+ return ThrowTypeError(isolate, "object_already_initialized", "WeakMap");
+ }
+ return WeakCollectionInitialize(isolate, map);
+}
+
+
+RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakSetInitialize) {
+ HandleScope scope(isolate);
+ ASSERT(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0);
+ if (!holder->IsJSWeakSet()) {
+ return ThrowTypeError(isolate, "constructor_not_function", "WeakSet");
+ }
+ Handle<JSWeakSet> set(JSWeakSet::cast(*holder));
+ if (!set->table()->IsUndefined()) {
+ return ThrowTypeError(isolate, "object_already_initialized", "WeakSet");
+ }
+ return WeakCollectionInitialize(isolate, set);
+}
+
+
+RUNTIME_FUNCTION(MaybeObject*, Runtime_WeakCollectionClear) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
« no previous file with comments | « src/runtime.h ('k') | src/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698