Chromium Code Reviews| Index: src/typedarray.js |
| diff --git a/src/typedarray.js b/src/typedarray.js |
| index 65659147ee7777cf1e8bc69196d4fc09a4beee89..92b32c423b5efc0934aae6230948549ec4e314bc 100644 |
| --- a/src/typedarray.js |
| +++ b/src/typedarray.js |
| @@ -45,6 +45,36 @@ utils.Import(function(from) { |
| // --------------- Typed Arrays --------------------- |
| +function TypedArray() { } |
| + |
| +function TypedArray_GetBuffer() { |
| + if (!%IsTypedArray(this)) { |
| + throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this); |
| + } |
| + return %TypedArrayGetBuffer(this); |
| +} |
| + |
| +function TypedArray_GetByteLength() { |
| + if (!%IsTypedArray(this)) { |
| + throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.byteLength", this); |
|
arv (Not doing code reviews)
2015/06/15 16:23:12
long line
Dan Ehrenberg
2015/06/15 23:28:34
Done.
|
| + } |
| + return %_ArrayBufferViewGetByteLength(this); |
| +} |
| + |
| +function TypedArray_GetByteOffset() { |
| + if (!%IsTypedArray(this)) { |
| + throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.byteOffset", this); |
| + } |
| + return %_ArrayBufferViewGetByteOffset(this); |
| +} |
| + |
| +function TypedArray_GetLength() { |
| + if (!%IsTypedArray(this)) { |
| + throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.length", this); |
| + } |
| + return %_TypedArrayGetLength(this); |
| +} |
| + |
| macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| if (!IS_UNDEFINED(byteOffset)) { |
| @@ -145,34 +175,6 @@ function NAMEConstructor(arg1, arg2, arg3) { |
| } |
| } |
| -function NAME_GetBuffer() { |
| - if (!(%_ClassOf(this) === 'NAME')) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this); |
| - } |
| - return %TypedArrayGetBuffer(this); |
| -} |
| - |
| -function NAME_GetByteLength() { |
| - if (!(%_ClassOf(this) === 'NAME')) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteLength", this); |
| - } |
| - return %_ArrayBufferViewGetByteLength(this); |
| -} |
| - |
| -function NAME_GetByteOffset() { |
| - if (!(%_ClassOf(this) === 'NAME')) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteOffset", this); |
| - } |
| - return %_ArrayBufferViewGetByteOffset(this); |
| -} |
| - |
| -function NAME_GetLength() { |
| - if (!(%_ClassOf(this) === 'NAME')) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this); |
| - } |
| - return %_TypedArrayGetLength(this); |
| -} |
| - |
| function NAMESubArray(begin, end) { |
| if (!(%_ClassOf(this) === 'NAME')) { |
| throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); |
| @@ -320,29 +322,33 @@ function TypedArrayGetToStringTag() { |
| // ------------------------------------------------------------------- |
| +utils.InstallGetter(TypedArray.prototype, "buffer", TypedArray_GetBuffer); |
| +utils.InstallGetter(TypedArray.prototype, "byteOffset", |
| + TypedArray_GetByteOffset, DONT_ENUM | DONT_DELETE); |
|
arv (Not doing code reviews)
2015/06/15 16:23:12
why DONT_DELETE?
Dan Ehrenberg
2015/06/15 23:28:34
Oops, fixed it.
|
| +utils.InstallGetter(TypedArray.prototype, "byteLength", |
| + TypedArray_GetByteLength, DONT_ENUM | DONT_DELETE); |
|
arv (Not doing code reviews)
2015/06/15 16:23:12
same here and other places. We should also have te
Dan Ehrenberg
2015/06/15 23:28:34
Done.
|
| +utils.InstallGetter(TypedArray.prototype, "length", TypedArray_GetLength, |
| + DONT_ENUM | DONT_DELETE); |
| +utils.InstallGetter(TypedArray.prototype, symbolToStringTag, |
| + TypedArrayGetToStringTag); |
|
arv (Not doing code reviews)
2015/06/15 16:23:12
DONT_ENUM?
Dan Ehrenberg
2015/06/15 23:28:34
Done.
|
| +utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [ |
| + "set", TypedArraySet |
| +]); |
| + |
| macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| %SetCode(GlobalNAME, NAMEConstructor); |
| - %FunctionSetPrototype(GlobalNAME, new GlobalObject()); |
| + %InternalSetPrototype(GlobalNAME, TypedArray); |
| + %FunctionSetPrototype(GlobalNAME, new TypedArray()); |
| + %AddNamedProperty(GlobalNAME.prototype, |
| + "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| + READ_ONLY | DONT_ENUM | DONT_DELETE); |
| %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| READ_ONLY | DONT_ENUM | DONT_DELETE); |
| %AddNamedProperty(GlobalNAME.prototype, |
| "constructor", global.NAME, DONT_ENUM); |
| - %AddNamedProperty(GlobalNAME.prototype, |
| - "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| - READ_ONLY | DONT_ENUM | DONT_DELETE); |
| - utils.InstallGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer); |
| - utils.InstallGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset, |
| - DONT_ENUM | DONT_DELETE); |
| - utils.InstallGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength, |
| - DONT_ENUM | DONT_DELETE); |
| - utils.InstallGetter(GlobalNAME.prototype, "length", NAME_GetLength, |
| - DONT_ENUM | DONT_DELETE); |
| - utils.InstallGetter(GlobalNAME.prototype, symbolToStringTag, |
| - TypedArrayGetToStringTag); |
| utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
| - "subarray", NAMESubArray, |
| - "set", TypedArraySet |
| + "subarray", NAMESubArray |
| ]); |
| endmacro |