Reviewers: rossberg,
Message:
PTAL
Description:
Implementation of Uint8ClampedArray.
[email protected]
Please review this at https://codereview.chromium.org/14657003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M include/v8.h
M src/api.h
M src/api.cc
M src/bootstrapper.cc
M src/contexts.h
M src/factory.cc
M src/runtime.cc
M src/typedarray.js
M test/cctest/test-api.cc
M test/mjsunit/harmony/typedarrays.js
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
0da1fa6af168c0b8926881c222a4262a6a8236c2..a23abf2fb5b107dece3edd57693fd6aa39fa3d92
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1128,6 +1128,12 @@ class V8EXPORT Value : public Data {
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.
* This is an experimental feature.
*/
@@ -2160,6 +2166,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).
* This API is experimental and may change significantly.
*/
@@ -4768,7 +4789,7 @@ class Internals {
static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
static const int kFixedArrayHeaderSize = 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 kStringEncodingMask = 0x4;
static const int kExternalTwoByteRepresentationTag = 0x02;
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
e7a03245676eb11649f2e18beb70df48b297c996..990886079919267c981fa1335de759786b5e38b1
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2431,7 +2431,8 @@ F(Int16Array, kExternalShortArray) \
F(Uint32Array, kExternalUnsignedIntArray) \
F(Int32Array, kExternalIntArray) \
F(Float32Array, kExternalFloatArray) \
-F(Float64Array, kExternalDoubleArray)
+F(Float64Array, kExternalDoubleArray) \
+F(Uint8ClampedArray, kExternalPixelArray)
#define VALUE_IS_TYPED_ARRAY(TypedArray,
type_const) \
@@ -5976,6 +5977,8 @@ i::Handle<i::JSTypedArray> NewTypedArray(
TYPED_ARRAY_NEW(Uint8Array, uint8_t, kExternalUnsignedByteArray,
i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS)
+TYPED_ARRAY_NEW(Uint8ClampedArray, uint8_t, kExternalPixelArray,
+ i::EXTERNAL_PIXEL_ELEMENTS)
TYPED_ARRAY_NEW(Int8Array, int8_t, kExternalByteArray,
i::EXTERNAL_BYTE_ELEMENTS)
TYPED_ARRAY_NEW(Uint16Array, uint16_t, kExternalUnsignedShortArray,
Index: src/api.h
diff --git a/src/api.h b/src/api.h
index
a9563469fd1899cd86e2e70b4eb2b84b8f26f510..eb97dbc9ec785f9fc22dc0238b9a8c77ca73b546
100644
--- a/src/api.h
+++ b/src/api.h
@@ -173,6 +173,7 @@ class RegisteredExtension {
V(ArrayBuffer, JSArrayBuffer) \
V(TypedArray, JSTypedArray) \
V(Uint8Array, JSTypedArray) \
+ V(Uint8ClampedArray, JSTypedArray) \
V(Int8Array, JSTypedArray) \
V(Uint16Array, JSTypedArray) \
V(Int16Array, JSTypedArray) \
@@ -222,6 +223,8 @@ class Utils {
v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<Uint8Array> ToLocalUint8Array(
v8::internal::Handle<v8::internal::JSTypedArray> obj);
+ static inline Local<Uint8ClampedArray> ToLocalUint8ClampedArray(
+ v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<Int8Array> ToLocalInt8Array(
v8::internal::Handle<v8::internal::JSTypedArray> obj);
static inline Local<Uint16Array> ToLocalUint16Array(
@@ -322,6 +325,7 @@ MAKE_TO_LOCAL(ToLocal, JSArrayBuffer, ArrayBuffer)
MAKE_TO_LOCAL(ToLocal, JSTypedArray, TypedArray)
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(Uint16Array, kExternalUnsignedShortArray)
MAKE_TO_LOCAL_TYPED_ARRAY(Int16Array, kExternalShortArray)
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index
16567b5b381d493603628a453cc6ec115add0b70..43e3249f812a6b2806514941fefd313be286fa96
100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1344,7 +1344,9 @@ void Genesis::InitializeExperimentalGlobal() {
native_context()->set_float_array_fun(*float_fun);
Handle<JSFunction> double_fun = InstallTypedArray("Float64Array");
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) {
Index: src/contexts.h
diff --git a/src/contexts.h b/src/contexts.h
index
2672487531f4ec478e7f18ef89aa9bcfb2f148a0..7a877f8dcb5e2d50247fa81a4f8a72d225a707e9
100644
--- a/src/contexts.h
+++ b/src/contexts.h
@@ -132,6 +132,7 @@ enum BindingFlags {
V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \
V(FLOAT_ARRAY_FUN_INDEX, JSFunction, float_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(STRICT_MODE_FUNCTION_MAP_INDEX, Map, strict_mode_function_map) \
V(FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map,
function_without_prototype_map) \
@@ -294,6 +295,7 @@ class Context: public FixedArray {
INT32_ARRAY_FUN_INDEX,
FLOAT_ARRAY_FUN_INDEX,
DOUBLE_ARRAY_FUN_INDEX,
+ UINT8C_ARRAY_FUN_INDEX,
MESSAGE_LISTENERS_INDEX,
MAKE_MESSAGE_FUN_INDEX,
GET_STACK_TRACE_LINE_INDEX,
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index
8dfab1803f165169b020a9c975cfb117b9826619..46bd4ae244bf56062603c3db227d47b5c30592b1
100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -1092,6 +1092,10 @@ Handle<JSTypedArray>
Factory::NewJSTypedArray(ExternalArrayType type) {
typed_array_fun = native_context->double_array_fun();
break;
+ case kExternalPixelArray:
+ typed_array_fun = native_context->uint8c_array_fun();
+ break;
+
default:
UNREACHABLE();
return Handle<JSTypedArray>();
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
6be77a9972a477e8ff498a558bc82ccb425bf1dc..bde802fdef0d3ebae839b8c85f96d6e3424d30fb
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -774,7 +774,8 @@ enum TypedArrayId {
ARRAY_ID_UINT32 = 5,
ARRAY_ID_INT32 = 6,
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) {
arrayType = kExternalDoubleArray;
elementSize = 8;
break;
+ case ARRAY_ID_UINT8C:
+ elementsKind = EXTERNAL_PIXEL_ELEMENTS;
+ arrayType = kExternalPixelArray;
+ elementSize = 1;
+ break;
default:
UNREACHABLE();
return NULL;
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index
96d968fe814dc70853766e2408f4bbb98c0fa5c5..d5b286641f9a250a0885fd2e438239628cd9d450
100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -201,4 +201,4 @@ SetupTypedArray(5, "Uint32Array", global.Uint32Array,
4);
SetupTypedArray(6, "Int32Array", global.Int32Array, 4);
SetupTypedArray(7, "Float32Array", global.Float32Array, 4);
SetupTypedArray(8, "Float64Array", global.Float64Array, 8);
-
+SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1);
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
17047e0918c35ac4d451572cbacc221c3f1ba2b7..bc4b155130899cb8bbce4b2b7a26ee3da310ddff
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -15174,6 +15174,13 @@ THREADED_TEST(Float64Array) {
v8::kExternalDoubleArray, -500, 500);
}
+
+THREADED_TEST(Uint8ClampedArray) {
+ TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray,
i::ExternalPixelArray>(
+ v8::kExternalPixelArray, 0, 0xFF);
+}
+
+
#define IS_TYPED_ARRAY_TEST(TypedArray) \
THREADED_TEST(Is##TypedArray)
{ \
i::FLAG_harmony_typed_arrays =
true; \
@@ -15195,6 +15202,7 @@ IS_TYPED_ARRAY_TEST(Uint32Array)
IS_TYPED_ARRAY_TEST(Int32Array)
IS_TYPED_ARRAY_TEST(Float32Array)
IS_TYPED_ARRAY_TEST(Float64Array)
+IS_TYPED_ARRAY_TEST(Uint8ClampedArray)
#undef IS_TYPED_ARRAY_TEST
Index: test/mjsunit/harmony/typedarrays.js
diff --git a/test/mjsunit/harmony/typedarrays.js
b/test/mjsunit/harmony/typedarrays.js
index
2e0398526258b52b3540faeacc51f61a97a0c948..4b946bdf58794517373fa94fe6a7eea148dae649
100644
--- a/test/mjsunit/harmony/typedarrays.js
+++ b/test/mjsunit/harmony/typedarrays.js
@@ -215,6 +215,28 @@ TestTypedArray(Uint32Array, 4, 0xFFFFFFFF);
TestTypedArray(Int32Array, 4, -0x7FFFFFFF);
TestTypedArray(Float32Array, 4, 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
@@ -233,7 +255,13 @@ function TestEnumerable(func, obj) {
}
TestEnumerable(ArrayBuffer, new ArrayBuffer());
TestEnumerable(Uint8Array);
-
+TestEnumerable(Int8Array);
+TestEnumerable(Uint16Array);
+TestEnumerable(Int16Array);
+TestEnumerable(Uint32Array);
+TestEnumerable(Int32Array);
+TestEnumerable(Float32Array);
+TestEnumerable(Uint8ClampedArray);
// Test arbitrary properties on ArrayBuffer
function TestArbitrary(m) {
--
--
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.