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

Unified Diff: src/typedarray.js

Issue 1126313003: Make one copy for all TypedArray methods (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Adding test and fixing failures (TypedArray.from and TypedArray.prototype.subarray) Created 5 years, 7 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
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index 926920427275132efa4ead35d2a634b1d1dd656c..372dd511bee72ea0febc9b406da88f6516c2457f 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -153,10 +153,11 @@ function NAME_GetLength() {
}
return %_TypedArrayGetLength(this);
}
+endmacro
-function NAMESubArray(begin, end) {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this);
+function TypedArraySubArray(begin, end) {
adamk 2015/05/08 01:13:34 We probably want to change this in the future, but
+ if (!%IsTypedArray(this)) {
+ throw MakeTypeError('not_typed_array', []);
}
var beginInt = TO_INTEGER(begin);
if (!IS_UNDEFINED(end)) {
@@ -181,11 +182,10 @@ function NAMESubArray(begin, end) {
}
var newLength = endInt - beginInt;
var beginByteOffset =
- %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
- return new GlobalNAME(%TypedArrayGetBuffer(this),
- beginByteOffset, newLength);
+ %_ArrayBufferViewGetByteOffset(this) + beginInt * this.BYTES_PER_ELEMENT;
+ return new this.constructor(%TypedArrayGetBuffer(this),
+ beginByteOffset, newLength);
}
-endmacro
TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
@@ -322,7 +322,7 @@ macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
$installGetter(GlobalNAME.prototype, symbolToStringTag,
TypedArrayGetToStringTag);
$installFunctions(GlobalNAME.prototype, DONT_ENUM, [
- "subarray", NAMESubArray,
+ "subarray", TypedArraySubArray,
"set", TypedArraySet
]);
endmacro

Powered by Google App Engine
This is Rietveld 408576698