Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1486)

Unified Diff: src/typedarray.js

Issue 955963002: Add version macros. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Implement TypedArray.slice(). Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
]);
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698