Index: src/typedarray.js |
diff --git a/src/typedarray.js b/src/typedarray.js |
index 4e3b9385863a20c94234d3dc63bafb31191e31f1..2d89b0c2cbcaa7825f2a218cee7abb0c99d9157f 100644 |
--- a/src/typedarray.js |
+++ b/src/typedarray.js |
@@ -147,6 +147,40 @@ function NAME_GetLength() { |
var $NAME = global.NAME; |
+function NAMESlice(begin, end) { |
+ if (!(%_ClassOf(this) === 'NAME')) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.slice", this); |
+ } |
+ var beginInt = TO_INTEGER(begin); |
+ if (!IS_UNDEFINED(end)) { |
+ end = TO_INTEGER(end); |
+ } |
+ |
+ var srcLength = %_TypedArrayGetLength(this); |
+ if (beginInt < 0) { |
+ beginInt = $max(0, srcLength + beginInt); |
+ } else { |
+ beginInt = $min(srcLength, beginInt); |
+ } |
+ |
+ var endInt = IS_UNDEFINED(end) ? srcLength : end; |
+ if (endInt < 0) { |
+ endInt = $max(0, srcLength + endInt); |
+ } else { |
+ endInt = $min(endInt, srcLength); |
+ } |
+ if (endInt < beginInt) { |
+ endInt = beginInt; |
+ } |
+ var newLength = endInt - beginInt; |
+ var beginByteOffset = |
+ %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
+ var arrayBuffer = %TypedArrayGetBuffer(this); |
+ var arrayBufferSlice = new GlobalArrayBuffer(newLength * ELEMENT_SIZE); |
+ %ArrayBufferSliceImpl(arrayBuffer, arrayBufferSlice, beginByteOffset); |
+ return new $NAME(arrayBufferSlice, 0, newLength); |
+} |
+ |
function NAMESubArray(begin, end) { |
if (!(%_ClassOf(this) === 'NAME')) { |
throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); |
@@ -317,6 +351,7 @@ macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
InstallGetter(global.NAME.prototype, symbolToStringTag, |
TypedArrayGetToStringTag); |
InstallFunctions(global.NAME.prototype, DONT_ENUM, [ |
+ "slice", NAMESlice, |
"subarray", NAMESubArray, |
"set", TypedArraySet |
]); |