Commit 6e861419 authored by dslomov@chromium.org's avatar dslomov@chromium.org

Implementation of Uint8ClampedArray.

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/14657003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14517 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 29b00ed4
...@@ -1127,6 +1127,12 @@ class V8EXPORT Value : public Data { ...@@ -1127,6 +1127,12 @@ class V8EXPORT Value : public Data {
*/ */
bool IsUint8Array() const; bool IsUint8Array() const;
/**
* Returns true if this value is an Uint8ClampedArray.
* This is an experimental feature.
*/
bool IsUint8ClampedArray() const;
/** /**
* Returns true if this value is an Int8Array. * Returns true if this value is an Int8Array.
* This is an experimental feature. * This is an experimental feature.
...@@ -2159,6 +2165,21 @@ class V8EXPORT Uint8Array : public TypedArray { ...@@ -2159,6 +2165,21 @@ class V8EXPORT Uint8Array : public TypedArray {
}; };
/**
* An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
* This API is experimental and may change significantly.
*/
class V8EXPORT Uint8ClampedArray : public TypedArray {
public:
static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer,
size_t byte_offset, size_t length);
V8_INLINE(static Uint8ClampedArray* Cast(Value* obj));
private:
Uint8ClampedArray();
static void CheckCast(Value* obj);
};
/** /**
* An instance of Int8Array constructor (ES6 draft 15.13.6). * An instance of Int8Array constructor (ES6 draft 15.13.6).
* This API is experimental and may change significantly. * This API is experimental and may change significantly.
...@@ -4768,7 +4789,7 @@ class Internals { ...@@ -4768,7 +4789,7 @@ class Internals {
static const int kJSObjectHeaderSize = 3 * kApiPointerSize; static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
static const int kContextHeaderSize = 2 * kApiPointerSize; static const int kContextHeaderSize = 2 * kApiPointerSize;
static const int kContextEmbedderDataIndex = 64; static const int kContextEmbedderDataIndex = 65;
static const int kFullStringRepresentationMask = 0x07; static const int kFullStringRepresentationMask = 0x07;
static const int kStringEncodingMask = 0x4; static const int kStringEncodingMask = 0x4;
static const int kExternalTwoByteRepresentationTag = 0x02; static const int kExternalTwoByteRepresentationTag = 0x02;
......
...@@ -2431,7 +2431,8 @@ F(Int16Array, kExternalShortArray) \ ...@@ -2431,7 +2431,8 @@ F(Int16Array, kExternalShortArray) \
F(Uint32Array, kExternalUnsignedIntArray) \ F(Uint32Array, kExternalUnsignedIntArray) \
F(Int32Array, kExternalIntArray) \ F(Int32Array, kExternalIntArray) \
F(Float32Array, kExternalFloatArray) \ F(Float32Array, kExternalFloatArray) \
F(Float64Array, kExternalDoubleArray) F(Float64Array, kExternalDoubleArray) \
F(Uint8ClampedArray, kExternalPixelArray)
#define VALUE_IS_TYPED_ARRAY(TypedArray, type_const) \ #define VALUE_IS_TYPED_ARRAY(TypedArray, type_const) \
...@@ -5976,6 +5977,8 @@ i::Handle<i::JSTypedArray> NewTypedArray( ...@@ -5976,6 +5977,8 @@ i::Handle<i::JSTypedArray> NewTypedArray(
TYPED_ARRAY_NEW(Uint8Array, uint8_t, kExternalUnsignedByteArray, TYPED_ARRAY_NEW(Uint8Array, uint8_t, kExternalUnsignedByteArray,
i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS) i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS)
TYPED_ARRAY_NEW(Uint8ClampedArray, uint8_t, kExternalPixelArray,
i::EXTERNAL_PIXEL_ELEMENTS)
TYPED_ARRAY_NEW(Int8Array, int8_t, kExternalByteArray, TYPED_ARRAY_NEW(Int8Array, int8_t, kExternalByteArray,
i::EXTERNAL_BYTE_ELEMENTS) i::EXTERNAL_BYTE_ELEMENTS)
TYPED_ARRAY_NEW(Uint16Array, uint16_t, kExternalUnsignedShortArray, TYPED_ARRAY_NEW(Uint16Array, uint16_t, kExternalUnsignedShortArray,
......
...@@ -173,6 +173,7 @@ class RegisteredExtension { ...@@ -173,6 +173,7 @@ class RegisteredExtension {
V(ArrayBuffer, JSArrayBuffer) \ V(ArrayBuffer, JSArrayBuffer) \
V(TypedArray, JSTypedArray) \ V(TypedArray, JSTypedArray) \
V(Uint8Array, JSTypedArray) \ V(Uint8Array, JSTypedArray) \
V(Uint8ClampedArray, JSTypedArray) \
V(Int8Array, JSTypedArray) \ V(Int8Array, JSTypedArray) \
V(Uint16Array, JSTypedArray) \ V(Uint16Array, JSTypedArray) \
V(Int16Array, JSTypedArray) \ V(Int16Array, JSTypedArray) \
...@@ -222,6 +223,8 @@ class Utils { ...@@ -222,6 +223,8 @@ class Utils {
v8::internal::Handle<v8::internal::JSTypedArray> obj); v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<Uint8Array> ToLocalUint8Array( static inline Local<Uint8Array> ToLocalUint8Array(
v8::internal::Handle<v8::internal::JSTypedArray> obj); v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<Uint8ClampedArray> ToLocalUint8ClampedArray(
v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<Int8Array> ToLocalInt8Array( static inline Local<Int8Array> ToLocalInt8Array(
v8::internal::Handle<v8::internal::JSTypedArray> obj); v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<Uint16Array> ToLocalUint16Array( static inline Local<Uint16Array> ToLocalUint16Array(
...@@ -322,6 +325,7 @@ MAKE_TO_LOCAL(ToLocal, JSArrayBuffer, ArrayBuffer) ...@@ -322,6 +325,7 @@ MAKE_TO_LOCAL(ToLocal, JSArrayBuffer, ArrayBuffer)
MAKE_TO_LOCAL(ToLocal, JSTypedArray, TypedArray) MAKE_TO_LOCAL(ToLocal, JSTypedArray, TypedArray)
MAKE_TO_LOCAL_TYPED_ARRAY(Uint8Array, kExternalUnsignedByteArray) MAKE_TO_LOCAL_TYPED_ARRAY(Uint8Array, kExternalUnsignedByteArray)
MAKE_TO_LOCAL_TYPED_ARRAY(Uint8ClampedArray, kExternalPixelArray)
MAKE_TO_LOCAL_TYPED_ARRAY(Int8Array, kExternalByteArray) MAKE_TO_LOCAL_TYPED_ARRAY(Int8Array, kExternalByteArray)
MAKE_TO_LOCAL_TYPED_ARRAY(Uint16Array, kExternalUnsignedShortArray) MAKE_TO_LOCAL_TYPED_ARRAY(Uint16Array, kExternalUnsignedShortArray)
MAKE_TO_LOCAL_TYPED_ARRAY(Int16Array, kExternalShortArray) MAKE_TO_LOCAL_TYPED_ARRAY(Int16Array, kExternalShortArray)
......
...@@ -1344,7 +1344,9 @@ void Genesis::InitializeExperimentalGlobal() { ...@@ -1344,7 +1344,9 @@ void Genesis::InitializeExperimentalGlobal() {
native_context()->set_float_array_fun(*float_fun); native_context()->set_float_array_fun(*float_fun);
Handle<JSFunction> double_fun = InstallTypedArray("Float64Array"); Handle<JSFunction> double_fun = InstallTypedArray("Float64Array");
native_context()->set_double_array_fun(*double_fun); native_context()->set_double_array_fun(*double_fun);
} Handle<JSFunction> uint8c_fun = InstallTypedArray("Uint8ClampedArray");
native_context()->set_uint8c_array_fun(*uint8c_fun);
}
} }
if (FLAG_harmony_generators) { if (FLAG_harmony_generators) {
......
...@@ -132,6 +132,7 @@ enum BindingFlags { ...@@ -132,6 +132,7 @@ enum BindingFlags {
V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \ V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \
V(FLOAT_ARRAY_FUN_INDEX, JSFunction, float_array_fun) \ V(FLOAT_ARRAY_FUN_INDEX, JSFunction, float_array_fun) \
V(DOUBLE_ARRAY_FUN_INDEX, JSFunction, double_array_fun) \ V(DOUBLE_ARRAY_FUN_INDEX, JSFunction, double_array_fun) \
V(UINT8C_ARRAY_FUN_INDEX, JSFunction, uint8c_array_fun) \
V(FUNCTION_MAP_INDEX, Map, function_map) \ V(FUNCTION_MAP_INDEX, Map, function_map) \
V(STRICT_MODE_FUNCTION_MAP_INDEX, Map, strict_mode_function_map) \ V(STRICT_MODE_FUNCTION_MAP_INDEX, Map, strict_mode_function_map) \
V(FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, function_without_prototype_map) \ V(FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, function_without_prototype_map) \
...@@ -294,6 +295,7 @@ class Context: public FixedArray { ...@@ -294,6 +295,7 @@ class Context: public FixedArray {
INT32_ARRAY_FUN_INDEX, INT32_ARRAY_FUN_INDEX,
FLOAT_ARRAY_FUN_INDEX, FLOAT_ARRAY_FUN_INDEX,
DOUBLE_ARRAY_FUN_INDEX, DOUBLE_ARRAY_FUN_INDEX,
UINT8C_ARRAY_FUN_INDEX,
MESSAGE_LISTENERS_INDEX, MESSAGE_LISTENERS_INDEX,
MAKE_MESSAGE_FUN_INDEX, MAKE_MESSAGE_FUN_INDEX,
GET_STACK_TRACE_LINE_INDEX, GET_STACK_TRACE_LINE_INDEX,
......
...@@ -1092,6 +1092,10 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { ...@@ -1092,6 +1092,10 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
typed_array_fun = native_context->double_array_fun(); typed_array_fun = native_context->double_array_fun();
break; break;
case kExternalPixelArray:
typed_array_fun = native_context->uint8c_array_fun();
break;
default: default:
UNREACHABLE(); UNREACHABLE();
return Handle<JSTypedArray>(); return Handle<JSTypedArray>();
......
...@@ -774,7 +774,8 @@ enum TypedArrayId { ...@@ -774,7 +774,8 @@ enum TypedArrayId {
ARRAY_ID_UINT32 = 5, ARRAY_ID_UINT32 = 5,
ARRAY_ID_INT32 = 6, ARRAY_ID_INT32 = 6,
ARRAY_ID_FLOAT32 = 7, ARRAY_ID_FLOAT32 = 7,
ARRAY_ID_FLOAT64 = 8 ARRAY_ID_FLOAT64 = 8,
ARRAY_ID_UINT8C = 9
}; };
...@@ -831,6 +832,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { ...@@ -831,6 +832,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
arrayType = kExternalDoubleArray; arrayType = kExternalDoubleArray;
elementSize = 8; elementSize = 8;
break; break;
case ARRAY_ID_UINT8C:
elementsKind = EXTERNAL_PIXEL_ELEMENTS;
arrayType = kExternalPixelArray;
elementSize = 1;
break;
default: default:
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
......
...@@ -201,4 +201,4 @@ SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); ...@@ -201,4 +201,4 @@ SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4);
SetupTypedArray(6, "Int32Array", global.Int32Array, 4); SetupTypedArray(6, "Int32Array", global.Int32Array, 4);
SetupTypedArray(7, "Float32Array", global.Float32Array, 4); SetupTypedArray(7, "Float32Array", global.Float32Array, 4);
SetupTypedArray(8, "Float64Array", global.Float64Array, 8); SetupTypedArray(8, "Float64Array", global.Float64Array, 8);
SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1);
...@@ -15174,6 +15174,13 @@ THREADED_TEST(Float64Array) { ...@@ -15174,6 +15174,13 @@ THREADED_TEST(Float64Array) {
v8::kExternalDoubleArray, -500, 500); v8::kExternalDoubleArray, -500, 500);
} }
THREADED_TEST(Uint8ClampedArray) {
TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray, i::ExternalPixelArray>(
v8::kExternalPixelArray, 0, 0xFF);
}
#define IS_TYPED_ARRAY_TEST(TypedArray) \ #define IS_TYPED_ARRAY_TEST(TypedArray) \
THREADED_TEST(Is##TypedArray) { \ THREADED_TEST(Is##TypedArray) { \
i::FLAG_harmony_typed_arrays = true; \ i::FLAG_harmony_typed_arrays = true; \
...@@ -15195,6 +15202,7 @@ IS_TYPED_ARRAY_TEST(Uint32Array) ...@@ -15195,6 +15202,7 @@ IS_TYPED_ARRAY_TEST(Uint32Array)
IS_TYPED_ARRAY_TEST(Int32Array) IS_TYPED_ARRAY_TEST(Int32Array)
IS_TYPED_ARRAY_TEST(Float32Array) IS_TYPED_ARRAY_TEST(Float32Array)
IS_TYPED_ARRAY_TEST(Float64Array) IS_TYPED_ARRAY_TEST(Float64Array)
IS_TYPED_ARRAY_TEST(Uint8ClampedArray)
#undef IS_TYPED_ARRAY_TEST #undef IS_TYPED_ARRAY_TEST
......
...@@ -215,6 +215,28 @@ TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); ...@@ -215,6 +215,28 @@ TestTypedArray(Uint32Array, 4, 0xFFFFFFFF);
TestTypedArray(Int32Array, 4, -0x7FFFFFFF); TestTypedArray(Int32Array, 4, -0x7FFFFFFF);
TestTypedArray(Float32Array, 4, 0.5); TestTypedArray(Float32Array, 4, 0.5);
TestTypedArray(Float64Array, 8, 0.5); TestTypedArray(Float64Array, 8, 0.5);
TestTypedArray(Uint8ClampedArray, 1, 0xFF);
function TestTypedArrayOutOfRange(constructor, value, result) {
var a = new constructor(1);
a[0] = value;
assertSame(result, a[0]);
}
TestTypedArrayOutOfRange(Uint8Array, 0x1FA, 0xFA);
TestTypedArrayOutOfRange(Uint8Array, -1, 0xFF);
TestTypedArrayOutOfRange(Int8Array, 0x1FA, 0x7A - 0x80);
TestTypedArrayOutOfRange(Uint16Array, 0x1FFFA, 0xFFFA);
TestTypedArrayOutOfRange(Uint16Array, -1, 0xFFFF);
TestTypedArrayOutOfRange(Int16Array, 0x1FFFA, 0x7FFA - 0x8000);
TestTypedArrayOutOfRange(Uint32Array, 0x1FFFFFFFA, 0xFFFFFFFA);
TestTypedArrayOutOfRange(Uint32Array, -1, 0xFFFFFFFF);
TestTypedArrayOutOfRange(Int16Array, 0x1FFFFFFFA, 0x7FFFFFFA - 0x80000000);
TestTypedArrayOutOfRange(Uint8ClampedArray, 0x1FA, 0xFF);
TestTypedArrayOutOfRange(Uint8ClampedArray, -1, 0);
// General tests for properties // General tests for properties
...@@ -233,7 +255,13 @@ function TestEnumerable(func, obj) { ...@@ -233,7 +255,13 @@ function TestEnumerable(func, obj) {
} }
TestEnumerable(ArrayBuffer, new ArrayBuffer()); TestEnumerable(ArrayBuffer, new ArrayBuffer());
TestEnumerable(Uint8Array); TestEnumerable(Uint8Array);
TestEnumerable(Int8Array);
TestEnumerable(Uint16Array);
TestEnumerable(Int16Array);
TestEnumerable(Uint32Array);
TestEnumerable(Int32Array);
TestEnumerable(Float32Array);
TestEnumerable(Uint8ClampedArray);
// Test arbitrary properties on ArrayBuffer // Test arbitrary properties on ArrayBuffer
function TestArbitrary(m) { function TestArbitrary(m) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment