From 53cc6486df3e787898294664c0991f00ce57dcef Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 20 Apr 2015 06:31:38 -0700 Subject: [PATCH] Remove support for externally backed elements from the API Embedders should use ArrayBuffers instead BUG=v8:3996 LOG=y R=verwaest@chromium.org,dslomov@chromium.org,kbr@chromium.org Review URL: https://codereview.chromium.org/1092923002 Cr-Commit-Position: refs/heads/master@{#27939} --- include/v8.h | 50 - src/api.cc | 162 +-- src/api.h | 10 +- src/d8.h | 18 - src/objects.h | 13 + .../compiler/test-simplified-lowering.cc | 2 +- test/cctest/test-api.cc | 964 +----------------- test/cctest/test-heap.cc | 24 +- test/unittests/test-utils.cc | 26 - test/unittests/test-utils.h | 2 - 10 files changed, 82 insertions(+), 1189 deletions(-) diff --git a/include/v8.h b/include/v8.h index 349597576..ebb06396e 100644 --- a/include/v8.h +++ b/include/v8.h @@ -2593,29 +2593,6 @@ enum PropertyAttribute { DontDelete = 1 << 2 }; -enum ExternalArrayType { - kExternalInt8Array = 1, - kExternalUint8Array, - kExternalInt16Array, - kExternalUint16Array, - kExternalInt32Array, - kExternalUint32Array, - kExternalFloat32Array, - kExternalFloat64Array, - kExternalUint8ClampedArray, - - // Legacy constant names - kExternalByteArray = kExternalInt8Array, - kExternalUnsignedByteArray = kExternalUint8Array, - kExternalShortArray = kExternalInt16Array, - kExternalUnsignedShortArray = kExternalUint16Array, - kExternalIntArray = kExternalInt32Array, - kExternalUnsignedIntArray = kExternalUint32Array, - kExternalFloatArray = kExternalFloat32Array, - kExternalDoubleArray = kExternalFloat64Array, - kExternalPixelArray = kExternalUint8ClampedArray -}; - /** * Accessor[Getter|Setter] are used as callback functions when * setting|getting a particular property. See Object and ObjectTemplate's @@ -2965,33 +2942,6 @@ class V8_EXPORT Object : public Value { */ Local CreationContext(); - /** - * Set the backing store of the indexed properties to be managed by the - * embedding layer. Access to the indexed properties will follow the rules - * spelled out in CanvasPixelArray. - * Note: The embedding program still owns the data and needs to ensure that - * the backing store is preserved while V8 has a reference. - */ - void SetIndexedPropertiesToPixelData(uint8_t* data, int length); - bool HasIndexedPropertiesInPixelData(); - uint8_t* GetIndexedPropertiesPixelData(); - int GetIndexedPropertiesPixelDataLength(); - - /** - * Set the backing store of the indexed properties to be managed by the - * embedding layer. Access to the indexed properties will follow the rules - * spelled out for the CanvasArray subtypes in the WebGL specification. - * Note: The embedding program still owns the data and needs to ensure that - * the backing store is preserved while V8 has a reference. - */ - void SetIndexedPropertiesToExternalArrayData(void* data, - ExternalArrayType array_type, - int number_of_elements); - bool HasIndexedPropertiesInExternalArrayData(); - void* GetIndexedPropertiesExternalArrayData(); - ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); - int GetIndexedPropertiesExternalArrayDataLength(); - /** * Checks whether a callback is set by the * ObjectTemplate::SetCallAsFunctionHandler method. diff --git a/src/api.cc b/src/api.cc index 991b9eebb..38b3679cb 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2674,11 +2674,11 @@ bool Value::IsTypedArray() const { } -#define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ - bool Value::Is##Type##Array() const { \ - i::Handle obj = Utils::OpenHandle(this); \ - return obj->IsJSTypedArray() && \ - i::JSTypedArray::cast(*obj)->type() == kExternal##Type##Array; \ +#define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ + bool Value::Is##Type##Array() const { \ + i::Handle obj = Utils::OpenHandle(this); \ + return obj->IsJSTypedArray() && \ + i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \ } TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY) @@ -3092,11 +3092,10 @@ void v8::TypedArray::CheckCast(Value* that) { #define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype, size) \ void v8::Type##Array::CheckCast(Value* that) { \ i::Handle obj = Utils::OpenHandle(that); \ - Utils::ApiCheck(obj->IsJSTypedArray() && \ - i::JSTypedArray::cast(*obj)->type() == \ - kExternal##Type##Array, \ - "v8::" #Type "Array::Cast()", \ - "Could not convert to " #Type "Array"); \ + Utils::ApiCheck( \ + obj->IsJSTypedArray() && \ + i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array, \ + "v8::" #Type "Array::Cast()", "Could not convert to " #Type "Array"); \ } @@ -4199,147 +4198,6 @@ bool v8::Object::DeleteHiddenValue(v8::Handle key) { } -namespace { - -static i::ElementsKind GetElementsKindFromExternalArrayType( - ExternalArrayType array_type) { - switch (array_type) { -#define ARRAY_TYPE_TO_ELEMENTS_KIND(Type, type, TYPE, ctype, size) \ - case kExternal##Type##Array: \ - return i::EXTERNAL_##TYPE##_ELEMENTS; - - TYPED_ARRAYS(ARRAY_TYPE_TO_ELEMENTS_KIND) -#undef ARRAY_TYPE_TO_ELEMENTS_KIND - } - UNREACHABLE(); - return i::DICTIONARY_ELEMENTS; -} - - -void PrepareExternalArrayElements(i::Handle object, - void* data, - ExternalArrayType array_type, - int length) { - i::Isolate* isolate = object->GetIsolate(); - i::Handle array = - isolate->factory()->NewExternalArray(length, array_type, data); - - i::Handle external_array_map = - i::JSObject::GetElementsTransitionMap( - object, - GetElementsKindFromExternalArrayType(array_type)); - - i::JSObject::SetMapAndElements(object, external_array_map, array); -} - -} // namespace - - -void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { - auto self = Utils::OpenHandle(this); - auto isolate = self->GetIsolate(); - ENTER_V8(isolate); - i::HandleScope scope(isolate); - if (!Utils::ApiCheck(length >= 0 && - length <= i::ExternalUint8ClampedArray::kMaxLength, - "v8::Object::SetIndexedPropertiesToPixelData()", - "length exceeds max acceptable value")) { - return; - } - if (!Utils::ApiCheck(!self->IsJSArray(), - "v8::Object::SetIndexedPropertiesToPixelData()", - "JSArray is not supported")) { - return; - } - PrepareExternalArrayElements(self, data, kExternalUint8ClampedArray, length); -} - - -bool v8::Object::HasIndexedPropertiesInPixelData() { - auto self = Utils::OpenHandle(this); - return self->HasExternalUint8ClampedElements(); -} - - -uint8_t* v8::Object::GetIndexedPropertiesPixelData() { - auto self = Utils::OpenHandle(this); - if (self->HasExternalUint8ClampedElements()) { - return i::ExternalUint8ClampedArray::cast(self->elements())-> - external_uint8_clamped_pointer(); - } - return nullptr; -} - - -int v8::Object::GetIndexedPropertiesPixelDataLength() { - auto self = Utils::OpenHandle(this); - if (self->HasExternalUint8ClampedElements()) { - return i::ExternalUint8ClampedArray::cast(self->elements())->length(); - } - return -1; -} - - -void v8::Object::SetIndexedPropertiesToExternalArrayData( - void* data, - ExternalArrayType array_type, - int length) { - auto self = Utils::OpenHandle(this); - auto isolate = self->GetIsolate(); - ENTER_V8(isolate); - i::HandleScope scope(isolate); - if (!Utils::ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength, - "v8::Object::SetIndexedPropertiesToExternalArrayData()", - "length exceeds max acceptable value")) { - return; - } - if (!Utils::ApiCheck(!self->IsJSArray(), - "v8::Object::SetIndexedPropertiesToExternalArrayData()", - "JSArray is not supported")) { - return; - } - PrepareExternalArrayElements(self, data, array_type, length); -} - - -bool v8::Object::HasIndexedPropertiesInExternalArrayData() { - auto self = Utils::OpenHandle(this); - return self->HasExternalArrayElements(); -} - - -void* v8::Object::GetIndexedPropertiesExternalArrayData() { - auto self = Utils::OpenHandle(this); - if (self->HasExternalArrayElements()) { - return i::ExternalArray::cast(self->elements())->external_pointer(); - } - return nullptr; -} - - -ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { - auto self = Utils::OpenHandle(this); - switch (self->elements()->map()->instance_type()) { -#define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ - case i::EXTERNAL_##TYPE##_ARRAY_TYPE: \ - return kExternal##Type##Array; - TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) -#undef INSTANCE_TYPE_TO_ARRAY_TYPE - default: - return static_cast(-1); - } -} - - -int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { - auto self = Utils::OpenHandle(this); - if (self->HasExternalArrayElements()) { - return i::ExternalArray::cast(self->elements())->length(); - } - return -1; -} - - bool v8::Object::IsCallable() { auto self = Utils::OpenHandle(this); return self->IsCallable(); @@ -6522,7 +6380,7 @@ size_t v8::TypedArray::Length() { } \ i::Handle buffer = Utils::OpenHandle(*array_buffer); \ i::Handle obj = isolate->factory()->NewJSTypedArray( \ - v8::kExternal##Type##Array, buffer, byte_offset, length); \ + i::kExternal##Type##Array, buffer, byte_offset, length); \ return Utils::ToLocal##Type##Array(obj); \ } diff --git a/src/api.h b/src/api.h index 7fce3e3b0..38bb92003 100644 --- a/src/api.h +++ b/src/api.h @@ -339,11 +339,11 @@ inline bool ToLocal(v8::internal::MaybeHandle maybe, } -#define MAKE_TO_LOCAL_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ - Local Utils::ToLocal##Type##Array( \ - v8::internal::Handle obj) { \ - DCHECK(obj->type() == kExternal##Type##Array); \ - return Convert(obj); \ +#define MAKE_TO_LOCAL_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ + Local Utils::ToLocal##Type##Array( \ + v8::internal::Handle obj) { \ + DCHECK(obj->type() == v8::internal::kExternal##Type##Array); \ + return Convert(obj); \ } diff --git a/src/d8.h b/src/d8.h index 1d73c0e1c..9b14c4d87 100644 --- a/src/d8.h +++ b/src/d8.h @@ -385,24 +385,6 @@ class Shell : public i::AllStatic { static Handle CreateGlobalTemplate(Isolate* isolate); static Handle CreateArrayBufferTemplate(FunctionCallback); static Handle CreateArrayTemplate(FunctionCallback); - static Handle CreateExternalArrayBuffer(Isolate* isolate, - Handle buffer, - int32_t size); - static Handle CreateExternalArray(Isolate* isolate, - Handle array, - Handle buffer, - ExternalArrayType type, - int32_t length, - int32_t byteLength, - int32_t byteOffset, - int32_t element_size); - static void CreateExternalArray( - const v8::FunctionCallbackInfo& args, - ExternalArrayType type, - int32_t element_size); - static void ExternalArrayWeakCallback(Isolate* isolate, - Persistent* object, - uint8_t* data); }; diff --git a/src/objects.h b/src/objects.h index 722a5424c..eb0c371a2 100644 --- a/src/objects.h +++ b/src/objects.h @@ -186,6 +186,19 @@ enum MutableMode { }; +enum ExternalArrayType { + kExternalInt8Array = 1, + kExternalUint8Array, + kExternalInt16Array, + kExternalUint16Array, + kExternalInt32Array, + kExternalUint32Array, + kExternalFloat32Array, + kExternalFloat64Array, + kExternalUint8ClampedArray, +}; + + static const int kGrowICDelta = STORE_AND_GROW_NO_TRANSITION - STANDARD_STORE; STATIC_ASSERT(STANDARD_STORE == 0); diff --git a/test/cctest/compiler/test-simplified-lowering.cc b/test/cctest/compiler/test-simplified-lowering.cc index 634483bf2..d1c877561 100644 --- a/test/cctest/compiler/test-simplified-lowering.cc +++ b/test/cctest/compiler/test-simplified-lowering.cc @@ -258,7 +258,7 @@ TEST(RunLoadStoreArrayBuffer) { const int index = 12; const int array_length = 2 * index; ElementAccess buffer_access = - AccessBuilder::ForTypedArrayElement(v8::kExternalInt8Array, true); + AccessBuilder::ForTypedArrayElement(kExternalInt8Array, true); Node* backing_store = t.LoadField( AccessBuilder::ForJSArrayBufferBackingStore(), t.Parameter(0)); Node* load = diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 11eda0f76..3a6ebc803 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -13507,491 +13507,12 @@ static void CheckElementValue(i::Isolate* isolate, } -THREADED_TEST(PixelArray) { - LocalContext context; - i::Isolate* isolate = CcTest::i_isolate(); - i::Factory* factory = isolate->factory(); - v8::HandleScope scope(context->GetIsolate()); - const int kElementCount = 260; - uint8_t* pixel_data = reinterpret_cast(malloc(kElementCount)); - i::Handle pixels = - i::Handle::cast( - factory->NewExternalArray(kElementCount, - v8::kExternalUint8ClampedArray, - pixel_data)); - // Force GC to trigger verification. - CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); - for (int i = 0; i < kElementCount; i++) { - pixels->set(i, i % 256); - } - // Force GC to trigger verification. - CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); - for (int i = 0; i < kElementCount; i++) { - CHECK_EQ(i % 256, pixels->get_scalar(i)); - CHECK_EQ(i % 256, pixel_data[i]); - } - - v8::Handle obj = v8::Object::New(context->GetIsolate()); - i::Handle jsobj = v8::Utils::OpenHandle(*obj); - // Set the elements to be the pixels. - // jsobj->set_elements(*pixels); - obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); - CheckElementValue(isolate, 1, jsobj, 1); - obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503)); - context->Global()->Set(v8_str("pixels"), obj); - v8::Handle result = CompileRun("pixels.field"); - CHECK_EQ(1503, result->Int32Value()); - result = CompileRun("pixels[1]"); - CHECK_EQ(1, result->Int32Value()); - - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i] = pixels[i] = -i;" - "}" - "sum;"); - CHECK_EQ(-28, result->Int32Value()); - - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i] = pixels[i] = 0;" - "}" - "sum;"); - CHECK_EQ(0, result->Int32Value()); - - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i] = pixels[i] = 255;" - "}" - "sum;"); - CHECK_EQ(8 * 255, result->Int32Value()); - - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i] = pixels[i] = 256 + i;" - "}" - "sum;"); - CHECK_EQ(2076, result->Int32Value()); - - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i] = pixels[i] = i;" - "}" - "sum;"); - CHECK_EQ(28, result->Int32Value()); - - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i];" - "}" - "sum;"); - CHECK_EQ(28, result->Int32Value()); - - i::Handle value(i::Smi::FromInt(2), - reinterpret_cast(context->GetIsolate())); - i::Handle no_failure; - no_failure = i::JSObject::SetElement( - jsobj, 1, value, NONE, i::SLOPPY).ToHandleChecked(); - DCHECK(!no_failure.is_null()); - USE(no_failure); - CheckElementValue(isolate, 2, jsobj, 1); - *value.location() = i::Smi::FromInt(256); - no_failure = i::JSObject::SetElement( - jsobj, 1, value, NONE, i::SLOPPY).ToHandleChecked(); - DCHECK(!no_failure.is_null()); - USE(no_failure); - CheckElementValue(isolate, 255, jsobj, 1); - *value.location() = i::Smi::FromInt(-1); - no_failure = i::JSObject::SetElement( - jsobj, 1, value, NONE, i::SLOPPY).ToHandleChecked(); - DCHECK(!no_failure.is_null()); - USE(no_failure); - CheckElementValue(isolate, 0, jsobj, 1); - - result = CompileRun("for (var i = 0; i < 8; i++) {" - " pixels[i] = (i * 65) - 109;" - "}" - "pixels[1] + pixels[6];"); - CHECK_EQ(255, result->Int32Value()); - CheckElementValue(isolate, 0, jsobj, 0); - CheckElementValue(isolate, 0, jsobj, 1); - CheckElementValue(isolate, 21, jsobj, 2); - CheckElementValue(isolate, 86, jsobj, 3); - CheckElementValue(isolate, 151, jsobj, 4); - CheckElementValue(isolate, 216, jsobj, 5); - CheckElementValue(isolate, 255, jsobj, 6); - CheckElementValue(isolate, 255, jsobj, 7); - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i];" - "}" - "sum;"); - CHECK_EQ(984, result->Int32Value()); - - result = CompileRun("for (var i = 0; i < 8; i++) {" - " pixels[i] = (i * 1.1);" - "}" - "pixels[1] + pixels[6];"); - CHECK_EQ(8, result->Int32Value()); - CheckElementValue(isolate, 0, jsobj, 0); - CheckElementValue(isolate, 1, jsobj, 1); - CheckElementValue(isolate, 2, jsobj, 2); - CheckElementValue(isolate, 3, jsobj, 3); - CheckElementValue(isolate, 4, jsobj, 4); - CheckElementValue(isolate, 6, jsobj, 5); - CheckElementValue(isolate, 7, jsobj, 6); - CheckElementValue(isolate, 8, jsobj, 7); - - result = CompileRun("for (var i = 0; i < 8; i++) {" - " pixels[7] = undefined;" - "}" - "pixels[7];"); - CHECK_EQ(0, result->Int32Value()); - CheckElementValue(isolate, 0, jsobj, 7); - - result = CompileRun("for (var i = 0; i < 8; i++) {" - " pixels[6] = '2.3';" - "}" - "pixels[6];"); - CHECK_EQ(2, result->Int32Value()); - CheckElementValue(isolate, 2, jsobj, 6); - - result = CompileRun("for (var i = 0; i < 8; i++) {" - " pixels[5] = NaN;" - "}" - "pixels[5];"); - CHECK_EQ(0, result->Int32Value()); - CheckElementValue(isolate, 0, jsobj, 5); - - result = CompileRun("for (var i = 0; i < 8; i++) {" - " pixels[8] = Infinity;" - "}" - "pixels[8];"); - CHECK_EQ(255, result->Int32Value()); - CheckElementValue(isolate, 255, jsobj, 8); - - result = CompileRun("for (var i = 0; i < 8; i++) {" - " pixels[9] = -Infinity;" - "}" - "pixels[9];"); - CHECK_EQ(0, result->Int32Value()); - CheckElementValue(isolate, 0, jsobj, 9); - - result = CompileRun("pixels[3] = 33;" - "delete pixels[3];" - "pixels[3];"); - CHECK_EQ(33, result->Int32Value()); - - result = CompileRun("pixels[0] = 10; pixels[1] = 11;" - "pixels[2] = 12; pixels[3] = 13;" - "pixels.__defineGetter__('2'," - "function() { return 120; });" - "pixels[2];"); - CHECK_EQ(12, result->Int32Value()); - - result = CompileRun("var js_array = new Array(40);" - "js_array[0] = 77;" - "js_array;"); - CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); - - result = CompileRun("pixels[1] = 23;" - "pixels.__proto__ = [];" - "js_array.__proto__ = pixels;" - "js_array.concat(pixels);"); - CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); - CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); - - result = CompileRun("pixels[1] = 23;"); - CHECK_EQ(23, result->Int32Value()); - - // Test for index greater than 255. Regression test for: - // http://code.google.com/p/chromium/issues/detail?id=26337. - result = CompileRun("pixels[256] = 255;"); - CHECK_EQ(255, result->Int32Value()); - result = CompileRun("var i = 0;" - "for (var j = 0; j < 8; j++) { i = pixels[256]; }" - "i"); - CHECK_EQ(255, result->Int32Value()); - - // Make sure that pixel array ICs recognize when a non-pixel array - // is passed to it. - result = CompileRun("function pa_load(p) {" - " var sum = 0;" - " for (var j = 0; j < 256; j++) { sum += p[j]; }" - " return sum;" - "}" - "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" - "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" - "just_ints = new Object();" - "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" - "for (var i = 0; i < 10; ++i) {" - " result = pa_load(just_ints);" - "}" - "result"); - CHECK_EQ(32640, result->Int32Value()); - - // Make sure that pixel array ICs recognize out-of-bound accesses. - result = CompileRun("function pa_load(p, start) {" - " var sum = 0;" - " for (var j = start; j < 256; j++) { sum += p[j]; }" - " return sum;" - "}" - "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" - "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }" - "for (var i = 0; i < 10; ++i) {" - " result = pa_load(pixels,-10);" - "}" - "result"); - CHECK_EQ(0, result->Int32Value()); - - // Make sure that generic ICs properly handles a pixel array. - result = CompileRun("function pa_load(p) {" - " var sum = 0;" - " for (var j = 0; j < 256; j++) { sum += p[j]; }" - " return sum;" - "}" - "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" - "just_ints = new Object();" - "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" - "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }" - "for (var i = 0; i < 10; ++i) {" - " result = pa_load(pixels);" - "}" - "result"); - CHECK_EQ(32640, result->Int32Value()); - - // Make sure that generic load ICs recognize out-of-bound accesses in - // pixel arrays. - result = CompileRun("function pa_load(p, start) {" - " var sum = 0;" - " for (var j = start; j < 256; j++) { sum += p[j]; }" - " return sum;" - "}" - "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" - "just_ints = new Object();" - "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" - "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }" - "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }" - "for (var i = 0; i < 10; ++i) {" - " result = pa_load(pixels,-10);" - "}" - "result"); - CHECK_EQ(0, result->Int32Value()); - - // Make sure that generic ICs properly handles other types than pixel - // arrays (that the inlined fast pixel array test leaves the right information - // in the right registers). - result = CompileRun("function pa_load(p) {" - " var sum = 0;" - " for (var j = 0; j < 256; j++) { sum += p[j]; }" - " return sum;" - "}" - "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" - "just_ints = new Object();" - "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" - "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }" - "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" - "sparse_array = new Object();" - "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }" - "sparse_array[1000000] = 3;" - "for (var i = 0; i < 10; ++i) {" - " result = pa_load(sparse_array);" - "}" - "result"); - CHECK_EQ(32640, result->Int32Value()); - - // Make sure that pixel array store ICs clamp values correctly. - result = CompileRun("function pa_store(p) {" - " for (var j = 0; j < 256; j++) { p[j] = j * 2; }" - "}" - "pa_store(pixels);" - "var sum = 0;" - "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" - "sum"); - CHECK_EQ(48896, result->Int32Value()); - - // Make sure that pixel array stores correctly handle accesses outside - // of the pixel array.. - result = CompileRun("function pa_store(p,start) {" - " for (var j = 0; j < 256; j++) {" - " p[j+start] = j * 2;" - " }" - "}" - "pa_store(pixels,0);" - "pa_store(pixels,-128);" - "var sum = 0;" - "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" - "sum"); - CHECK_EQ(65280, result->Int32Value()); - - // Make sure that the generic store stub correctly handle accesses outside - // of the pixel array.. - result = CompileRun("function pa_store(p,start) {" - " for (var j = 0; j < 256; j++) {" - " p[j+start] = j * 2;" - " }" - "}" - "pa_store(pixels,0);" - "just_ints = new Object();" - "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" - "pa_store(just_ints, 0);" - "pa_store(pixels,-128);" - "var sum = 0;" - "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" - "sum"); - CHECK_EQ(65280, result->Int32Value()); - - // Make sure that the generic keyed store stub clamps pixel array values - // correctly. - result = CompileRun("function pa_store(p) {" - " for (var j = 0; j < 256; j++) { p[j] = j * 2; }" - "}" - "pa_store(pixels);" - "just_ints = new Object();" - "pa_store(just_ints);" - "pa_store(pixels);" - "var sum = 0;" - "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" - "sum"); - CHECK_EQ(48896, result->Int32Value()); - - // Make sure that pixel array loads are optimized by crankshaft. - result = CompileRun("function pa_load(p) {" - " var sum = 0;" - " for (var i=0; i<256; ++i) {" - " sum += p[i];" - " }" - " return sum; " - "}" - "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" - "for (var i = 0; i < 5000; ++i) {" - " result = pa_load(pixels);" - "}" - "result"); - CHECK_EQ(32640, result->Int32Value()); - - // Make sure that pixel array stores are optimized by crankshaft. - result = CompileRun("function pa_init(p) {" - "for (var i = 0; i < 256; ++i) { p[i] = i; }" - "}" - "function pa_load(p) {" - " var sum = 0;" - " for (var i=0; i<256; ++i) {" - " sum += p[i];" - " }" - " return sum; " - "}" - "for (var i = 0; i < 5000; ++i) {" - " pa_init(pixels);" - "}" - "result = pa_load(pixels);" - "result"); - CHECK_EQ(32640, result->Int32Value()); - - free(pixel_data); -} - - -THREADED_TEST(PixelArrayInfo) { - LocalContext context; - v8::HandleScope scope(context->GetIsolate()); - for (int size = 0; size < 100; size += 10) { - uint8_t* pixel_data = reinterpret_cast(malloc(size)); - v8::Handle obj = v8::Object::New(context->GetIsolate()); - obj->SetIndexedPropertiesToPixelData(pixel_data, size); - CHECK(obj->HasIndexedPropertiesInPixelData()); - CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); - CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); - free(pixel_data); - } -} - - -static void NotHandledIndexedPropertyGetter( - uint32_t index, - const v8::PropertyCallbackInfo& info) { - ApiTestFuzzer::Fuzz(); -} - - -static void NotHandledIndexedPropertySetter( - uint32_t index, - Local value, - const v8::PropertyCallbackInfo& info) { - ApiTestFuzzer::Fuzz(); -} - - -THREADED_TEST(PixelArrayWithInterceptor) { - LocalContext context; - i::Factory* factory = CcTest::i_isolate()->factory(); - v8::Isolate* isolate = context->GetIsolate(); - v8::HandleScope scope(isolate); - const int kElementCount = 260; - uint8_t* pixel_data = reinterpret_cast(malloc(kElementCount)); - i::Handle pixels = - i::Handle::cast( - factory->NewExternalArray(kElementCount, - v8::kExternalUint8ClampedArray, - pixel_data)); - for (int i = 0; i < kElementCount; i++) { - pixels->set(i, i % 256); - } - v8::Handle templ = - v8::ObjectTemplate::New(context->GetIsolate()); - templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( - NotHandledIndexedPropertyGetter, NotHandledIndexedPropertySetter)); - v8::Handle obj = templ->NewInstance(); - obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); - context->Global()->Set(v8_str("pixels"), obj); - v8::Handle result = CompileRun("pixels[1]"); - CHECK_EQ(1, result->Int32Value()); - result = CompileRun("var sum = 0;" - "for (var i = 0; i < 8; i++) {" - " sum += pixels[i] = pixels[i] = -i;" - "}" - "sum;"); - CHECK_EQ(-28, result->Int32Value()); - result = CompileRun("pixels.hasOwnProperty('1')"); - CHECK(result->BooleanValue()); - free(pixel_data); -} - - -static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { - switch (array_type) { - case v8::kExternalInt8Array: - case v8::kExternalUint8Array: - case v8::kExternalUint8ClampedArray: - return 1; - break; - case v8::kExternalInt16Array: - case v8::kExternalUint16Array: - return 2; - break; - case v8::kExternalInt32Array: - case v8::kExternalUint32Array: - case v8::kExternalFloat32Array: - return 4; - break; - case v8::kExternalFloat64Array: - return 8; - break; - default: - UNREACHABLE(); - return -1; - } - UNREACHABLE(); - return -1; -} - - template -static void ObjectWithExternalArrayTestHelper( - Handle context, - v8::Handle obj, - int element_count, - v8::ExternalArrayType array_type, - int64_t low, int64_t high) { +static void ObjectWithExternalArrayTestHelper(Handle context, + v8::Handle obj, + int element_count, + i::ExternalArrayType array_type, + int64_t low, int64_t high) { i::Handle jsobj = v8::Utils::OpenHandle(*obj); i::Isolate* isolate = jsobj->GetIsolate(); obj->Set(v8_str("field"), @@ -14135,8 +13656,8 @@ static void ObjectWithExternalArrayTestHelper( "}" "ext_array[7];"); CHECK_EQ(0, result->Int32Value()); - if (array_type == v8::kExternalFloat64Array || - array_type == v8::kExternalFloat32Array) { + if (array_type == i::kExternalFloat64Array || + array_type == i::kExternalFloat32Array) { CHECK(std::isnan( i::Object::GetElement(isolate, jsobj, 7).ToHandleChecked()->Number())); } else { @@ -14153,8 +13674,8 @@ static void ObjectWithExternalArrayTestHelper( i::Object::GetElement( isolate, jsobj, 6).ToHandleChecked()->Number())); - if (array_type != v8::kExternalFloat32Array && - array_type != v8::kExternalFloat64Array) { + if (array_type != i::kExternalFloat32Array && + array_type != i::kExternalFloat64Array) { // Though the specification doesn't state it, be explicit about // converting NaNs and +/-Infinity to zero. result = CompileRun("for (var i = 0; i < 8; i++) {" @@ -14175,7 +13696,7 @@ static void ObjectWithExternalArrayTestHelper( "}" "ext_array[5];"); int expected_value = - (array_type == v8::kExternalUint8ClampedArray) ? 255 : 0; + (array_type == i::kExternalUint8ClampedArray) ? 255 : 0; CHECK_EQ(expected_value, result->Int32Value()); CheckElementValue(isolate, expected_value, jsobj, 5); @@ -14199,11 +13720,10 @@ static void ObjectWithExternalArrayTestHelper( const char* pixel_data = "var source_data = [0.6, 10.6];" "var expected_results = [1, 11];"; - bool is_unsigned = - (array_type == v8::kExternalUint8Array || - array_type == v8::kExternalUint16Array || - array_type == v8::kExternalUint32Array); - bool is_pixel_data = array_type == v8::kExternalUint8ClampedArray; + bool is_unsigned = (array_type == i::kExternalUint8Array || + array_type == i::kExternalUint16Array || + array_type == i::kExternalUint32Array); + bool is_pixel_data = array_type == i::kExternalUint8ClampedArray; i::SNPrintF(test_buf, "%s" @@ -14288,13 +13808,10 @@ static void ObjectWithExternalArrayTestHelper( } -template -static void FixedTypedArrayTestHelper( - v8::ExternalArrayType array_type, - ElementType low, - ElementType high) { +static void FixedTypedArrayTestHelper(i::ExternalArrayType array_type, + ElementType low, ElementType high) { i::FLAG_allow_natives_syntax = true; LocalContext context; i::Isolate* isolate = CcTest::i_isolate(); @@ -14333,442 +13850,62 @@ static void FixedTypedArrayTestHelper( THREADED_TEST(FixedUint8Array) { FixedTypedArrayTestHelper( - v8::kExternalUint8Array, - 0x0, 0xFF); + i::kExternalUint8Array, 0x0, 0xFF); } THREADED_TEST(FixedUint8ClampedArray) { FixedTypedArrayTestHelper( - v8::kExternalUint8ClampedArray, - 0x0, 0xFF); + i::kExternalUint8ClampedArray, 0x0, 0xFF); } THREADED_TEST(FixedInt8Array) { FixedTypedArrayTestHelper( - v8::kExternalInt8Array, - -0x80, 0x7F); + i::kExternalInt8Array, -0x80, 0x7F); } THREADED_TEST(FixedUint16Array) { FixedTypedArrayTestHelper( - v8::kExternalUint16Array, - 0x0, 0xFFFF); + i::kExternalUint16Array, 0x0, 0xFFFF); } THREADED_TEST(FixedInt16Array) { FixedTypedArrayTestHelper( - v8::kExternalInt16Array, - -0x8000, 0x7FFF); + i::kExternalInt16Array, -0x8000, 0x7FFF); } THREADED_TEST(FixedUint32Array) { FixedTypedArrayTestHelper( - v8::kExternalUint32Array, - 0x0, UINT_MAX); + i::kExternalUint32Array, 0x0, UINT_MAX); } THREADED_TEST(FixedInt32Array) { FixedTypedArrayTestHelper( - v8::kExternalInt32Array, - INT_MIN, INT_MAX); + i::kExternalInt32Array, INT_MIN, INT_MAX); } THREADED_TEST(FixedFloat32Array) { FixedTypedArrayTestHelper( - v8::kExternalFloat32Array, - -500, 500); + i::kExternalFloat32Array, -500, 500); } THREADED_TEST(FixedFloat64Array) { FixedTypedArrayTestHelper( - v8::kExternalFloat64Array, - -500, 500); -} - - -template -static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, - int64_t low, - int64_t high) { - LocalContext context; - i::Isolate* isolate = CcTest::i_isolate(); - i::Factory* factory = isolate->factory(); - v8::HandleScope scope(context->GetIsolate()); - const int kElementCount = 40; - int element_size = ExternalArrayElementSize(array_type); - ElementType* array_data = - static_cast(malloc(kElementCount * element_size)); - i::Handle array = - i::Handle::cast( - factory->NewExternalArray(kElementCount, array_type, array_data)); - // Force GC to trigger verification. - CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); - for (int i = 0; i < kElementCount; i++) { - array->set(i, static_cast(i)); - } - // Force GC to trigger verification. - CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); - for (int i = 0; i < kElementCount; i++) { - CHECK_EQ(static_cast(i), - static_cast(array->get_scalar(i))); - CHECK_EQ(static_cast(i), static_cast(array_data[i])); - } - - v8::Handle obj = v8::Object::New(context->GetIsolate()); - i::Handle jsobj = v8::Utils::OpenHandle(*obj); - // Set the elements to be the external array. - obj->SetIndexedPropertiesToExternalArrayData(array_data, - array_type, - kElementCount); - CHECK_EQ(1, - static_cast( - i::Object::GetElement( - isolate, jsobj, 1).ToHandleChecked()->Number())); - - ObjectWithExternalArrayTestHelper( - context.local(), obj, kElementCount, array_type, low, high); - - v8::Handle result; - - // Test more complex manipulations which cause eax to contain values - // that won't be completely overwritten by loads from the arrays. - // This catches bugs in the instructions used for the KeyedLoadIC - // for byte and word types. - { - const int kXSize = 300; - const int kYSize = 300; - const int kLargeElementCount = kXSize * kYSize * 4; - ElementType* large_array_data = - static_cast(malloc(kLargeElementCount * element_size)); - v8::Handle large_obj = v8::Object::New(context->GetIsolate()); - // Set the elements to be the external array. - large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data, - array_type, - kLargeElementCount); - context->Global()->Set(v8_str("large_array"), large_obj); - // Initialize contents of a few rows. - for (int x = 0; x < 300; x++) { - int row = 0; - int offset = row * 300 * 4; - large_array_data[offset + 4 * x + 0] = (ElementType) 127; - large_array_data[offset + 4 * x + 1] = (ElementType) 0; - large_array_data[offset + 4 * x + 2] = (ElementType) 0; - large_array_data[offset + 4 * x + 3] = (ElementType) 127; - row = 150; - offset = row * 300 * 4; - large_array_data[offset + 4 * x + 0] = (ElementType) 127; - large_array_data[offset + 4 * x + 1] = (ElementType) 0; - large_array_data[offset + 4 * x + 2] = (ElementType) 0; - large_array_data[offset + 4 * x + 3] = (ElementType) 127; - row = 298; - offset = row * 300 * 4; - large_array_data[offset + 4 * x + 0] = (ElementType) 127; - large_array_data[offset + 4 * x + 1] = (ElementType) 0; - large_array_data[offset + 4 * x + 2] = (ElementType) 0; - large_array_data[offset + 4 * x + 3] = (ElementType) 127; - } - // The goal of the code below is to make "offset" large enough - // that the computation of the index (which goes into eax) has - // high bits set which will not be overwritten by a byte or short - // load. - result = CompileRun("var failed = false;" - "var offset = 0;" - "for (var i = 0; i < 300; i++) {" - " if (large_array[4 * i] != 127 ||" - " large_array[4 * i + 1] != 0 ||" - " large_array[4 * i + 2] != 0 ||" - " large_array[4 * i + 3] != 127) {" - " failed = true;" - " }" - "}" - "offset = 150 * 300 * 4;" - "for (var i = 0; i < 300; i++) {" - " if (large_array[offset + 4 * i] != 127 ||" - " large_array[offset + 4 * i + 1] != 0 ||" - " large_array[offset + 4 * i + 2] != 0 ||" - " large_array[offset + 4 * i + 3] != 127) {" - " failed = true;" - " }" - "}" - "offset = 298 * 300 * 4;" - "for (var i = 0; i < 300; i++) {" - " if (large_array[offset + 4 * i] != 127 ||" - " large_array[offset + 4 * i + 1] != 0 ||" - " large_array[offset + 4 * i + 2] != 0 ||" - " large_array[offset + 4 * i + 3] != 127) {" - " failed = true;" - " }" - "}" - "!failed;"); - CHECK_EQ(true, result->BooleanValue()); - free(large_array_data); - } - - // The "" property descriptor is overloaded to store information about - // the external array. Ensure that setting and accessing the "" property - // works (it should overwrite the information cached about the external - // array in the DescriptorArray) in various situations. - result = CompileRun("ext_array[''] = 23; ext_array['']"); - CHECK_EQ(23, result->Int32Value()); - - // Property "" set after the external array is associated with the object. - { - v8::Handle obj2 = v8::Object::New(context->GetIsolate()); - obj2->Set(v8_str("ee_test_field"), - v8::Int32::New(context->GetIsolate(), 256)); - obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503)); - // Set the elements to be the external array. - obj2->SetIndexedPropertiesToExternalArrayData(array_data, - array_type, - kElementCount); - context->Global()->Set(v8_str("ext_array"), obj2); - result = CompileRun("ext_array['']"); - CHECK_EQ(1503, result->Int32Value()); - } - - // Property "" set after the external array is associated with the object. - { - v8::Handle obj2 = v8::Object::New(context->GetIsolate()); - obj2->Set(v8_str("ee_test_field_2"), - v8::Int32::New(context->GetIsolate(), 256)); - // Set the elements to be the external array. - obj2->SetIndexedPropertiesToExternalArrayData(array_data, - array_type, - kElementCount); - obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503)); - context->Global()->Set(v8_str("ext_array"), obj2); - result = CompileRun("ext_array['']"); - CHECK_EQ(1503, result->Int32Value()); - } - - // Should reuse the map from previous test. - { - v8::Handle obj2 = v8::Object::New(context->GetIsolate()); - obj2->Set(v8_str("ee_test_field_2"), - v8::Int32::New(context->GetIsolate(), 256)); - // Set the elements to be the external array. Should re-use the map - // from previous test. - obj2->SetIndexedPropertiesToExternalArrayData(array_data, - array_type, - kElementCount); - context->Global()->Set(v8_str("ext_array"), obj2); - result = CompileRun("ext_array['']"); - } - - // Property "" is a constant function that shouldn't not be interfered with - // when an external array is set. - { - v8::Handle obj2 = v8::Object::New(context->GetIsolate()); - // Start - obj2->Set(v8_str("ee_test_field3"), - v8::Int32::New(context->GetIsolate(), 256)); - - // Add a constant function to an object. - context->Global()->Set(v8_str("ext_array"), obj2); - result = CompileRun("ext_array[''] = function() {return 1503;};" - "ext_array['']();"); - - // Add an external array transition to the same map that - // has the constant transition. - v8::Handle obj3 = v8::Object::New(context->GetIsolate()); - obj3->Set(v8_str("ee_test_field3"), - v8::Int32::New(context->GetIsolate(), 256)); - obj3->SetIndexedPropertiesToExternalArrayData(array_data, - array_type, - kElementCount); - context->Global()->Set(v8_str("ext_array"), obj3); - } - - // If a external array transition is in the map, it should get clobbered - // by a constant function. - { - // Add an external array transition. - v8::Handle obj3 = v8::Object::New(context->GetIsolate()); - obj3->Set(v8_str("ee_test_field4"), - v8::Int32::New(context->GetIsolate(), 256)); - obj3->SetIndexedPropertiesToExternalArrayData(array_data, - array_type, - kElementCount); - - // Add a constant function to the same map that just got an external array - // transition. - v8::Handle obj2 = v8::Object::New(context->GetIsolate()); - obj2->Set(v8_str("ee_test_field4"), - v8::Int32::New(context->GetIsolate(), 256)); - context->Global()->Set(v8_str("ext_array"), obj2); - result = CompileRun("ext_array[''] = function() {return 1503;};" - "ext_array['']();"); - } - - free(array_data); -} - - -THREADED_TEST(ExternalInt8Array) { - ExternalArrayTestHelper( - v8::kExternalInt8Array, - -128, - 127); -} - - -THREADED_TEST(ExternalUint8Array) { - ExternalArrayTestHelper( - v8::kExternalUint8Array, - 0, - 255); -} - - -THREADED_TEST(ExternalUint8ClampedArray) { - ExternalArrayTestHelper( - v8::kExternalUint8ClampedArray, - 0, - 255); -} - - -THREADED_TEST(ExternalInt16Array) { - ExternalArrayTestHelper( - v8::kExternalInt16Array, - -32768, - 32767); -} - - -THREADED_TEST(ExternalUint16Array) { - ExternalArrayTestHelper( - v8::kExternalUint16Array, - 0, - 65535); -} - - -THREADED_TEST(ExternalInt32Array) { - ExternalArrayTestHelper( - v8::kExternalInt32Array, - INT_MIN, // -2147483648 - INT_MAX); // 2147483647 -} - - -THREADED_TEST(ExternalUint32Array) { - ExternalArrayTestHelper( - v8::kExternalUint32Array, - 0, - UINT_MAX); // 4294967295 -} - - -THREADED_TEST(ExternalFloat32Array) { - ExternalArrayTestHelper( - v8::kExternalFloat32Array, - -500, - 500); -} - - -THREADED_TEST(ExternalFloat64Array) { - ExternalArrayTestHelper( - v8::kExternalFloat64Array, - -500, - 500); -} - - -THREADED_TEST(ExternalArrays) { - TestExternalInt8Array(); - TestExternalUint8Array(); - TestExternalInt16Array(); - TestExternalUint16Array(); - TestExternalInt32Array(); - TestExternalUint32Array(); - TestExternalFloat32Array(); + i::kExternalFloat64Array, -500, 500); } -void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { - LocalContext context; - v8::HandleScope scope(context->GetIsolate()); - for (int size = 0; size < 100; size += 10) { - int element_size = ExternalArrayElementSize(array_type); - void* external_data = malloc(size * element_size); - v8::Handle obj = v8::Object::New(context->GetIsolate()); - obj->SetIndexedPropertiesToExternalArrayData( - external_data, array_type, size); - CHECK(obj->HasIndexedPropertiesInExternalArrayData()); - CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); - CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); - CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); - free(external_data); - } -} - - -THREADED_TEST(ExternalArrayInfo) { - ExternalArrayInfoTestHelper(v8::kExternalInt8Array); - ExternalArrayInfoTestHelper(v8::kExternalUint8Array); - ExternalArrayInfoTestHelper(v8::kExternalInt16Array); - ExternalArrayInfoTestHelper(v8::kExternalUint16Array); - ExternalArrayInfoTestHelper(v8::kExternalInt32Array); - ExternalArrayInfoTestHelper(v8::kExternalUint32Array); - ExternalArrayInfoTestHelper(v8::kExternalFloat32Array); - ExternalArrayInfoTestHelper(v8::kExternalFloat64Array); - ExternalArrayInfoTestHelper(v8::kExternalUint8ClampedArray); -} - - -void ExtArrayLimitsHelper(v8::Isolate* isolate, - v8::ExternalArrayType array_type, - int size) { - v8::Handle obj = v8::Object::New(isolate); - v8::V8::SetFatalErrorHandler(StoringErrorCallback); - last_location = last_message = NULL; - obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size); - CHECK(!obj->HasIndexedPropertiesInExternalArrayData()); - CHECK(last_location); - CHECK(last_message); -} - - -TEST(ExternalArrayLimits) { - LocalContext context; - v8::Isolate* isolate = context->GetIsolate(); - v8::HandleScope scope(isolate); - ExtArrayLimitsHelper(isolate, v8::kExternalInt8Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalInt8Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalUint8Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalUint8Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalInt16Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalInt16Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalUint16Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalUint16Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalInt32Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalInt32Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalUint32Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalUint32Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalFloat32Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalFloat32Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalFloat64Array, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalFloat64Array, 0xffffffff); - ExtArrayLimitsHelper(isolate, v8::kExternalUint8ClampedArray, 0x40000000); - ExtArrayLimitsHelper(isolate, v8::kExternalUint8ClampedArray, 0xffffffff); -} - - -template -void TypedArrayTestHelper(v8::ExternalArrayType array_type, - int64_t low, int64_t high) { +template +void TypedArrayTestHelper(i::ExternalArrayType array_type, int64_t low, + int64_t high) { const int kElementCount = 50; i::ScopedVector backing_store(kElementCount+2); @@ -14800,58 +13937,56 @@ void TypedArrayTestHelper(v8::ExternalArrayType array_type, THREADED_TEST(Uint8Array) { TypedArrayTestHelper( - v8::kExternalUint8Array, 0, 0xFF); + i::kExternalUint8Array, 0, 0xFF); } THREADED_TEST(Int8Array) { TypedArrayTestHelper( - v8::kExternalInt8Array, -0x80, 0x7F); + i::kExternalInt8Array, -0x80, 0x7F); } THREADED_TEST(Uint16Array) { - TypedArrayTestHelper( - v8::kExternalUint16Array, 0, 0xFFFF); + TypedArrayTestHelper( + i::kExternalUint16Array, 0, 0xFFFF); } THREADED_TEST(Int16Array) { TypedArrayTestHelper( - v8::kExternalInt16Array, -0x8000, 0x7FFF); + i::kExternalInt16Array, -0x8000, 0x7FFF); } THREADED_TEST(Uint32Array) { TypedArrayTestHelper( - v8::kExternalUint32Array, 0, UINT_MAX); + i::kExternalUint32Array, 0, UINT_MAX); } THREADED_TEST(Int32Array) { TypedArrayTestHelper( - v8::kExternalInt32Array, INT_MIN, INT_MAX); + i::kExternalInt32Array, INT_MIN, INT_MAX); } THREADED_TEST(Float32Array) { TypedArrayTestHelper( - v8::kExternalFloat32Array, -500, 500); + i::kExternalFloat32Array, -500, 500); } THREADED_TEST(Float64Array) { TypedArrayTestHelper( - v8::kExternalFloat64Array, -500, 500); + i::kExternalFloat64Array, -500, 500); } THREADED_TEST(Uint8ClampedArray) { - TypedArrayTestHelper( - v8::kExternalUint8ClampedArray, 0, 0xFF); + TypedArrayTestHelper( + i::kExternalUint8ClampedArray, 0, 0xFF); } @@ -19583,23 +18718,6 @@ THREADED_TEST(Regress142088) { } -THREADED_TEST(Regress3337) { - LocalContext context; - v8::Isolate* isolate = context->GetIsolate(); - v8::HandleScope scope(isolate); - Local o1 = Object::New(isolate); - Local o2 = Object::New(isolate); - i::Handle io1 = v8::Utils::OpenHandle(*o1); - i::Handle io2 = v8::Utils::OpenHandle(*o2); - CHECK(io1->map() == io2->map()); - o1->SetIndexedPropertiesToExternalArrayData( - NULL, v8::kExternalUint32Array, 0); - o2->SetIndexedPropertiesToExternalArrayData( - NULL, v8::kExternalUint32Array, 0); - CHECK(io1->map() == io2->map()); -} - - THREADED_TEST(Regress137496) { i::FLAG_expose_gc = true; LocalContext context; diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 93540560f..60f62d517 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -5317,7 +5317,7 @@ TEST(WritableVsImmortalRoots) { } -static void TestRightTrimFixedTypedArray(v8::ExternalArrayType type, +static void TestRightTrimFixedTypedArray(i::ExternalArrayType type, int initial_length, int elements_to_trim) { v8::HandleScope scope(CcTest::isolate()); @@ -5353,17 +5353,17 @@ TEST(Regress472513) { // typed array header smashing with free space filler (crbug/472513). // 64-bit cases. - TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 32, 6); - TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 32 - 7, 6); - TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 16, 6); - TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 16 - 3, 6); - TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 8, 6); - TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 8 - 1, 6); + TestRightTrimFixedTypedArray(i::kExternalUint8Array, 32, 6); + TestRightTrimFixedTypedArray(i::kExternalUint8Array, 32 - 7, 6); + TestRightTrimFixedTypedArray(i::kExternalUint16Array, 16, 6); + TestRightTrimFixedTypedArray(i::kExternalUint16Array, 16 - 3, 6); + TestRightTrimFixedTypedArray(i::kExternalUint32Array, 8, 6); + TestRightTrimFixedTypedArray(i::kExternalUint32Array, 8 - 1, 6); // 32-bit cases. - TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 16, 3); - TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 16 - 3, 3); - TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 8, 3); - TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 8 - 1, 3); - TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 4, 3); + TestRightTrimFixedTypedArray(i::kExternalUint8Array, 16, 3); + TestRightTrimFixedTypedArray(i::kExternalUint8Array, 16 - 3, 3); + TestRightTrimFixedTypedArray(i::kExternalUint16Array, 8, 3); + TestRightTrimFixedTypedArray(i::kExternalUint16Array, 8 - 1, 3); + TestRightTrimFixedTypedArray(i::kExternalUint32Array, 4, 3); } diff --git a/test/unittests/test-utils.cc b/test/unittests/test-utils.cc index 5d1c1f14f..c49aac521 100644 --- a/test/unittests/test-utils.cc +++ b/test/unittests/test-utils.cc @@ -10,32 +10,6 @@ namespace v8 { -std::ostream& operator<<(std::ostream& os, ExternalArrayType type) { - switch (type) { - case kExternalInt8Array: - return os << "ExternalInt8Array"; - case kExternalUint8Array: - return os << "ExternalUint8Array"; - case kExternalInt16Array: - return os << "ExternalInt16Array"; - case kExternalUint16Array: - return os << "ExternalUint16Array"; - case kExternalInt32Array: - return os << "ExternalInt32Array"; - case kExternalUint32Array: - return os << "ExternalUint32Array"; - case kExternalFloat32Array: - return os << "ExternalFloat32Array"; - case kExternalFloat64Array: - return os << "ExternalFloat64Array"; - case kExternalUint8ClampedArray: - return os << "ExternalUint8ClampedArray"; - } - UNREACHABLE(); - return os; -} - - // static Isolate* TestWithIsolate::isolate_ = NULL; diff --git a/test/unittests/test-utils.h b/test/unittests/test-utils.h index 42831a7db..72eb2c055 100644 --- a/test/unittests/test-utils.h +++ b/test/unittests/test-utils.h @@ -13,8 +13,6 @@ namespace v8 { -std::ostream& operator<<(std::ostream&, ExternalArrayType); - class TestWithIsolate : public virtual ::testing::Test { public: -- 2.34.1