зеркало из https://github.com/mozilla/gecko-dev.git
b=593396; implement BYTES_PER_ELEMENT on typed arrays; r=shaver
This commit is contained in:
Родитель
796209cd43
Коммит
293ddefb00
|
@ -482,6 +482,7 @@ class TypedArrayTemplate
|
|||
: public TypedArray
|
||||
{
|
||||
public:
|
||||
typedef NativeType ThisType;
|
||||
typedef TypedArrayTemplate<NativeType> ThisTypeArray;
|
||||
static const int ArrayTypeID() { return TypeIDOfType<NativeType>(); }
|
||||
static const bool ArrayTypeIsUnsigned() { return TypeIsUnsigned<NativeType>(); }
|
||||
|
@ -1548,6 +1549,19 @@ do { \
|
|||
NULL, NULL); \
|
||||
if (!proto) \
|
||||
return NULL; \
|
||||
JSObject *ctor = JS_GetConstructor(cx, proto); \
|
||||
if (!ctor || \
|
||||
!JS_DefineProperty(cx, ctor, "BYTES_PER_ELEMENT", \
|
||||
INT_TO_JSVAL(sizeof(_typedArray::ThisType)), \
|
||||
JS_PropertyStub, JS_PropertyStub, \
|
||||
JSPROP_PERMANENT | JSPROP_READONLY) || \
|
||||
!JS_DefineProperty(cx, proto, "BYTES_PER_ELEMENT", \
|
||||
INT_TO_JSVAL(sizeof(_typedArray::ThisType)), \
|
||||
JS_PropertyStub, JS_PropertyStub, \
|
||||
JSPROP_PERMANENT | JSPROP_READONLY)) \
|
||||
{ \
|
||||
return NULL; \
|
||||
} \
|
||||
proto->setPrivate(0); \
|
||||
} while (0)
|
||||
|
||||
|
|
|
@ -312,6 +312,12 @@ function test()
|
|||
checkThrows(function() new Int32Array(Int32Array));
|
||||
checkThrows(function() new Int32Array(Float64Array));
|
||||
|
||||
check(function() Int32Array.BYTES_PER_ELEMENT == 4);
|
||||
check(function() (new Int32Array(4)).BYTES_PER_ELEMENT == 4);
|
||||
check(function() (new Int32Array()).BYTES_PER_ELEMENT == 4);
|
||||
check(function() (new Int32Array(0)).BYTES_PER_ELEMENT == 4);
|
||||
check(function() Int16Array.BYTES_PER_ELEMENT == Uint16Array.BYTES_PER_ELEMENT);
|
||||
|
||||
print ("done");
|
||||
|
||||
reportCompare(0, TestFailCount, "typed array tests");
|
||||
|
|
Загрузка…
Ссылка в новой задаче