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

Unified Diff: src/typedarray.js

Issue 14581005: Implement TypedArray.set function. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 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 1a4f46ca65d460dc516a0542fa279443ad92ae4b..4fade00e1000eabfa077c60a46253cc7b22cda21 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -145,6 +145,22 @@ function CreateSubArray(elementSize, constructor) {
}
}
+function TypedArraySet(obj, offset) {
+ var intOffset = IS_UNDEFINED(offset) ? 0 : TO_POSITIVE_INTEGER(offset);
+ if (%TypedArraySetFastCases(this, obj, intOffset))
+ return;
+
+ var l = obj.length;
+ if (IS_UNDEFINED(l)) {
+ throw MakeTypeError("invalid_argument");
+ }
+ if (intOffset + l > this.length) {
+ throw MakeRangeError("typed_array_set_source_too_large");
+ }
+ for (var i = 0; i < l; i++) {
+ this[intOffset + i] = obj[i];
+ }
+}
// -------------------------------------------------------------------
@@ -166,7 +182,8 @@ function SetupTypedArray(arrayId, name, constructor, elementSize) {
InstallGetter(constructor.prototype, "length", TypedArrayGetLength);
InstallFunctions(constructor.prototype, DONT_ENUM, $Array(
- "subarray", CreateSubArray(elementSize, constructor)
+ "subarray", CreateSubArray(elementSize, constructor),
+ "set", TypedArraySet
));
}

Powered by Google App Engine
This is Rietveld 408576698