@@ -36,10 +36,11 @@ const JSTypedArrayType TypedArrayTypes[] = {
3636 [TypedArrayUint16] = kJSTypedArrayTypeUint16Array ,
3737 [TypedArrayUint32] = kJSTypedArrayTypeUint32Array ,
3838 [TypedArrayFloat32] = kJSTypedArrayTypeFloat32Array ,
39- [TypedArrayFloat64] = kJSTypedArrayTypeFloat64Array
39+ [TypedArrayFloat64] = kJSTypedArrayTypeFloat64Array ,
40+ /* not a TypedArray */ kJSTypedArrayTypeArrayBuffer
4041};
4142
42- const int kJSTypedArrayTypeLast = kJSTypedArrayTypeFloat64Array ;
43+ const int kJSTypedArrayTypeLast = kJSTypedArrayTypeArrayBuffer ;
4344
4445
4546template <typename ArrayType>JSObject * CreateTypedArray (JSC::ExecState* exec, size_t length) {
@@ -50,6 +51,14 @@ template <typename ArrayType>JSObject * CreateTypedArray(JSC::ExecState* exec, s
5051 return asObject (toJS (exec, exec->lexicalGlobalObject (), array.get ()));
5152}
5253
54+ template <typename BufferType>JSObject * CreateArrayBuffer (JSC::ExecState* exec, size_t length) {
55+ RefPtr<BufferType> array = BufferType::create (length, 1 );
56+ if ( !array.get () ) {
57+ return NULL ;
58+ }
59+ return asObject (toJS (exec, exec->lexicalGlobalObject (), array.get ()));
60+ }
61+
5362typedef JSObject*(*CreateTypedArrayFuncPtr)(JSC::ExecState*, size_t );
5463const CreateTypedArrayFuncPtr CreateTypedArrayFunc[] = {
5564 [kJSTypedArrayTypeNone ] = NULL ,
@@ -61,7 +70,8 @@ const CreateTypedArrayFuncPtr CreateTypedArrayFunc[] = {
6170 [kJSTypedArrayTypeUint16Array ] = CreateTypedArray<Uint16Array>,
6271 [kJSTypedArrayTypeUint32Array ] = CreateTypedArray<Uint32Array>,
6372 [kJSTypedArrayTypeFloat32Array ] = CreateTypedArray<Float32Array>,
64- [kJSTypedArrayTypeFloat64Array ] = CreateTypedArray<Float64Array>
73+ [kJSTypedArrayTypeFloat64Array ] = CreateTypedArray<Float64Array>,
74+ [kJSTypedArrayTypeArrayBuffer ] = CreateArrayBuffer<ArrayBuffer>,
6575};
6676
6777
@@ -72,10 +82,15 @@ JSTypedArrayType JSTypedArrayGetType(JSContextRef ctx, JSValueRef value) {
7282 APIEntryShim entryShim (exec);
7383
7484 JSValue jsValue = toJS (exec, value);
75- if ( JSObject* object = jsValue.getObject () ) {
76- return TypedArrayTypes[object->classInfo ()->typedArrayStorageType ];
85+ JSTypedArrayType type = kJSTypedArrayTypeNone ;
86+ if ( jsValue.inherits (&JSArrayBufferView::s_info) ) {
87+ JSObject* object = jsValue.getObject ();
88+ type = TypedArrayTypes[object->classInfo ()->typedArrayStorageType ];
89+ }
90+ else if ( jsValue.inherits (&JSArrayBuffer::s_info) ) {
91+ type = kJSTypedArrayTypeArrayBuffer ;
7792 }
78- return kJSTypedArrayTypeNone ;
93+ return type ;
7994}
8095
8196JSObjectRef JSTypedArrayMake (JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements) {
@@ -101,6 +116,12 @@ void * JSTypedArrayGetDataPtr(JSContextRef ctx, JSValueRef value, size_t * byteL
101116 }
102117 return view->baseAddress ();
103118 }
119+ else if ( ArrayBuffer * buffer = toArrayBuffer (jsValue) ) {
120+ if ( byteLength ) {
121+ *byteLength = buffer->byteLength ();
122+ }
123+ return buffer->data ();
124+ }
104125
105126 if ( byteLength ) {
106127 *byteLength = 0 ;
0 commit comments