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

Side by Side Diff: test/cctest/test-api.cc

Issue 1168723002: Add TypedArray constructors with SharedArrayBuffer to the external API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: typo Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14043 matching lines...) Expand 10 before | Expand all | Expand 10 after
14054 i::kExternalFloat32Array, -500, 500); 14054 i::kExternalFloat32Array, -500, 500);
14055 } 14055 }
14056 14056
14057 14057
14058 THREADED_TEST(FixedFloat64Array) { 14058 THREADED_TEST(FixedFloat64Array) {
14059 FixedTypedArrayTestHelper<i::FixedFloat64Array, i::FLOAT64_ELEMENTS, float>( 14059 FixedTypedArrayTestHelper<i::FixedFloat64Array, i::FLOAT64_ELEMENTS, float>(
14060 i::kExternalFloat64Array, -500, 500); 14060 i::kExternalFloat64Array, -500, 500);
14061 } 14061 }
14062 14062
14063 14063
14064 template <typename ElementType, typename TypedArray, class ExternalArrayClass> 14064 template <typename ElementType, typename TypedArray, class ExternalArrayClass,
14065 class ArrayBufferType>
14065 void TypedArrayTestHelper(i::ExternalArrayType array_type, int64_t low, 14066 void TypedArrayTestHelper(i::ExternalArrayType array_type, int64_t low,
14066 int64_t high) { 14067 int64_t high) {
14067 const int kElementCount = 50; 14068 const int kElementCount = 50;
14068 14069
14069 i::ScopedVector<ElementType> backing_store(kElementCount+2); 14070 i::ScopedVector<ElementType> backing_store(kElementCount+2);
14070 14071
14071 LocalContext env; 14072 LocalContext env;
14072 v8::Isolate* isolate = env->GetIsolate(); 14073 v8::Isolate* isolate = env->GetIsolate();
14073 v8::HandleScope handle_scope(isolate); 14074 v8::HandleScope handle_scope(isolate);
14074 14075
14075 Local<v8::ArrayBuffer> ab = 14076 Local<ArrayBufferType> ab =
14076 v8::ArrayBuffer::New(isolate, backing_store.start(), 14077 ArrayBufferType::New(isolate, backing_store.start(),
14077 (kElementCount + 2) * sizeof(ElementType)); 14078 (kElementCount + 2) * sizeof(ElementType));
14078 Local<TypedArray> ta = 14079 Local<TypedArray> ta =
14079 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); 14080 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount);
14080 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta); 14081 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta);
14081 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); 14082 CHECK_EQ(kElementCount, static_cast<int>(ta->Length()));
14082 CHECK_EQ(2 * sizeof(ElementType), ta->ByteOffset()); 14083 CHECK_EQ(2 * sizeof(ElementType), ta->ByteOffset());
14083 CHECK_EQ(kElementCount * sizeof(ElementType), ta->ByteLength()); 14084 CHECK_EQ(kElementCount * sizeof(ElementType), ta->ByteLength());
14084 CHECK(ab->Equals(ta->Buffer())); 14085 CHECK(ab->Equals(ta->Buffer()));
14085 14086
14086 ElementType* data = backing_store.start() + 2; 14087 ElementType* data = backing_store.start() + 2;
14087 for (int i = 0; i < kElementCount; i++) { 14088 for (int i = 0; i < kElementCount; i++) {
14088 data[i] = static_cast<ElementType>(i); 14089 data[i] = static_cast<ElementType>(i);
14089 } 14090 }
14090 14091
14091 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( 14092 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
14092 env.local(), ta, kElementCount, array_type, low, high); 14093 env.local(), ta, kElementCount, array_type, low, high);
14093 } 14094 }
14094 14095
14095 14096
14096 THREADED_TEST(Uint8Array) { 14097 THREADED_TEST(Uint8Array) {
14097 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array>( 14098 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array,
14098 i::kExternalUint8Array, 0, 0xFF); 14099 v8::ArrayBuffer>(i::kExternalUint8Array, 0, 0xFF);
14099 } 14100 }
14100 14101
14101 14102
14102 THREADED_TEST(Int8Array) { 14103 THREADED_TEST(Int8Array) {
14103 TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array>( 14104 TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array,
14104 i::kExternalInt8Array, -0x80, 0x7F); 14105 v8::ArrayBuffer>(i::kExternalInt8Array, -0x80, 0x7F);
14105 } 14106 }
14106 14107
14107 14108
14108 THREADED_TEST(Uint16Array) { 14109 THREADED_TEST(Uint16Array) {
14109 TypedArrayTestHelper<uint16_t, v8::Uint16Array, i::ExternalUint16Array>( 14110 TypedArrayTestHelper<uint16_t, v8::Uint16Array, i::ExternalUint16Array,
14110 i::kExternalUint16Array, 0, 0xFFFF); 14111 v8::ArrayBuffer>(i::kExternalUint16Array, 0, 0xFFFF);
14111 } 14112 }
14112 14113
14113 14114
14114 THREADED_TEST(Int16Array) { 14115 THREADED_TEST(Int16Array) {
14115 TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array>( 14116 TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array,
14116 i::kExternalInt16Array, -0x8000, 0x7FFF); 14117 v8::ArrayBuffer>(i::kExternalInt16Array, -0x8000,
14118 0x7FFF);
14117 } 14119 }
14118 14120
14119 14121
14120 THREADED_TEST(Uint32Array) { 14122 THREADED_TEST(Uint32Array) {
14121 TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array>( 14123 TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array,
14122 i::kExternalUint32Array, 0, UINT_MAX); 14124 v8::ArrayBuffer>(i::kExternalUint32Array, 0, UINT_MAX);
14123 } 14125 }
14124 14126
14125 14127
14126 THREADED_TEST(Int32Array) { 14128 THREADED_TEST(Int32Array) {
14127 TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array>( 14129 TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array,
14128 i::kExternalInt32Array, INT_MIN, INT_MAX); 14130 v8::ArrayBuffer>(i::kExternalInt32Array, INT_MIN,
14131 INT_MAX);
14129 } 14132 }
14130 14133
14131 14134
14132 THREADED_TEST(Float32Array) { 14135 THREADED_TEST(Float32Array) {
14133 TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array>( 14136 TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array,
14134 i::kExternalFloat32Array, -500, 500); 14137 v8::ArrayBuffer>(i::kExternalFloat32Array, -500, 500);
14135 } 14138 }
14136 14139
14137 14140
14138 THREADED_TEST(Float64Array) { 14141 THREADED_TEST(Float64Array) {
14139 TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array>( 14142 TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array,
14140 i::kExternalFloat64Array, -500, 500); 14143 v8::ArrayBuffer>(i::kExternalFloat64Array, -500, 500);
14141 } 14144 }
14142 14145
14143 14146
14144 THREADED_TEST(Uint8ClampedArray) { 14147 THREADED_TEST(Uint8ClampedArray) {
14145 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray, 14148 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray,
14146 i::ExternalUint8ClampedArray>( 14149 i::ExternalUint8ClampedArray, v8::ArrayBuffer>(
14147 i::kExternalUint8ClampedArray, 0, 0xFF); 14150 i::kExternalUint8ClampedArray, 0, 0xFF);
14148 } 14151 }
14149 14152
14150 14153
14151 THREADED_TEST(DataView) { 14154 THREADED_TEST(DataView) {
14152 const int kSize = 50; 14155 const int kSize = 50;
14153 14156
14154 i::ScopedVector<uint8_t> backing_store(kSize+2); 14157 i::ScopedVector<uint8_t> backing_store(kSize+2);
14155 14158
14156 LocalContext env; 14159 LocalContext env;
14157 v8::Isolate* isolate = env->GetIsolate(); 14160 v8::Isolate* isolate = env->GetIsolate();
14158 v8::HandleScope handle_scope(isolate); 14161 v8::HandleScope handle_scope(isolate);
14159 14162
14160 Local<v8::ArrayBuffer> ab = 14163 Local<v8::ArrayBuffer> ab =
14161 v8::ArrayBuffer::New(isolate, backing_store.start(), 2 + kSize); 14164 v8::ArrayBuffer::New(isolate, backing_store.start(), 2 + kSize);
14165 Local<v8::DataView> dv = v8::DataView::New(ab, 2, kSize);
14166 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
14167 CHECK_EQ(2u, dv->ByteOffset());
14168 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
14169 CHECK(ab->Equals(dv->Buffer()));
14170 }
14171
14172
14173 THREADED_TEST(SharedUint8Array) {
14174 i::FLAG_harmony_sharedarraybuffer = true;
14175 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array,
14176 v8::SharedArrayBuffer>(i::kExternalUint8Array, 0, 0xFF);
14177 }
14178
14179
14180 THREADED_TEST(SharedInt8Array) {
14181 i::FLAG_harmony_sharedarraybuffer = true;
14182 TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array,
14183 v8::SharedArrayBuffer>(i::kExternalInt8Array, -0x80,
14184 0x7F);
14185 }
14186
14187
14188 THREADED_TEST(SharedUint16Array) {
14189 i::FLAG_harmony_sharedarraybuffer = true;
14190 TypedArrayTestHelper<uint16_t, v8::Uint16Array, i::ExternalUint16Array,
14191 v8::SharedArrayBuffer>(i::kExternalUint16Array, 0,
14192 0xFFFF);
14193 }
14194
14195
14196 THREADED_TEST(SharedInt16Array) {
14197 i::FLAG_harmony_sharedarraybuffer = true;
14198 TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array,
14199 v8::SharedArrayBuffer>(i::kExternalInt16Array, -0x8000,
14200 0x7FFF);
14201 }
14202
14203
14204 THREADED_TEST(SharedUint32Array) {
14205 i::FLAG_harmony_sharedarraybuffer = true;
14206 TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array,
14207 v8::SharedArrayBuffer>(i::kExternalUint32Array, 0,
14208 UINT_MAX);
14209 }
14210
14211
14212 THREADED_TEST(SharedInt32Array) {
14213 i::FLAG_harmony_sharedarraybuffer = true;
14214 TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array,
14215 v8::SharedArrayBuffer>(i::kExternalInt32Array, INT_MIN,
14216 INT_MAX);
14217 }
14218
14219
14220 THREADED_TEST(SharedFloat32Array) {
14221 i::FLAG_harmony_sharedarraybuffer = true;
14222 TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array,
14223 v8::SharedArrayBuffer>(i::kExternalFloat32Array, -500,
14224 500);
14225 }
14226
14227
14228 THREADED_TEST(SharedFloat64Array) {
14229 i::FLAG_harmony_sharedarraybuffer = true;
14230 TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array,
14231 v8::SharedArrayBuffer>(i::kExternalFloat64Array, -500,
14232 500);
14233 }
14234
14235
14236 THREADED_TEST(SharedUint8ClampedArray) {
14237 i::FLAG_harmony_sharedarraybuffer = true;
14238 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray,
14239 i::ExternalUint8ClampedArray, v8::SharedArrayBuffer>(
14240 i::kExternalUint8ClampedArray, 0, 0xFF);
14241 }
14242
14243
14244 THREADED_TEST(SharedDataView) {
14245 i::FLAG_harmony_sharedarraybuffer = true;
14246 const int kSize = 50;
14247
14248 i::ScopedVector<uint8_t> backing_store(kSize + 2);
14249
14250 LocalContext env;
14251 v8::Isolate* isolate = env->GetIsolate();
14252 v8::HandleScope handle_scope(isolate);
14253
14254 Local<v8::SharedArrayBuffer> ab =
14255 v8::SharedArrayBuffer::New(isolate, backing_store.start(), 2 + kSize);
14162 Local<v8::DataView> dv = 14256 Local<v8::DataView> dv =
14163 v8::DataView::New(ab, 2, kSize); 14257 v8::DataView::New(ab, 2, kSize);
14164 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); 14258 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
14165 CHECK_EQ(2u, dv->ByteOffset()); 14259 CHECK_EQ(2u, dv->ByteOffset());
14166 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength())); 14260 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
14167 CHECK(ab->Equals(dv->Buffer())); 14261 CHECK(ab->Equals(dv->Buffer()));
14168 } 14262 }
14169 14263
14170 14264
14171 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \ 14265 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \
(...skipping 7245 matching lines...) Expand 10 before | Expand all | Expand 10 after
21417 CHECK_EQ(2U, set->Size()); 21511 CHECK_EQ(2U, set->Size());
21418 21512
21419 v8::Local<v8::Array> keys = set->AsArray(); 21513 v8::Local<v8::Array> keys = set->AsArray();
21420 CHECK_EQ(2U, keys->Length()); 21514 CHECK_EQ(2U, keys->Length());
21421 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); 21515 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value());
21422 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); 21516 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value());
21423 21517
21424 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); 21518 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked();
21425 CHECK_EQ(2U, set->Size()); 21519 CHECK_EQ(2U, set->Size());
21426 } 21520 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698