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

Unified Diff: src/typedarray.js

Issue 132373011: A64: Synchronize with r17635. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 | « src/stub-cache.cc ('k') | src/unicode.h » ('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 f2b5d2da2c311e0ba47b4925e29cb26d73088202..d435803a5aa603793c5cce5ada2bd884979f0a24 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -48,65 +48,72 @@ FUNCTION(9, Uint8ClampedArray, 1)
endmacro
macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
- function NAMEConstructor(arg1, arg2, arg3) {
- function ConstructByArrayBuffer(obj, buffer, byteOffset, length) {
- var offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length")
+ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
+ var bufferByteLength = buffer.byteLength;
+ var offset;
+ if (IS_UNDEFINED(byteOffset)) {
+ offset = 0;
+ } else {
+ offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length");
if (offset % ELEMENT_SIZE !== 0) {
throw MakeRangeError("invalid_typed_array_alignment",
"start offset", "NAME", ELEMENT_SIZE);
}
- var bufferByteLength = %ArrayBufferGetByteLength(buffer);
if (offset > bufferByteLength) {
throw MakeRangeError("invalid_typed_array_offset");
}
+ }
- var newByteLength;
- var newLength;
- if (IS_UNDEFINED(length)) {
- if (bufferByteLength % ELEMENT_SIZE !== 0) {
- throw MakeRangeError("invalid_typed_array_alignment",
- "byte length", "NAME", ELEMENT_SIZE);
- }
- newByteLength = bufferByteLength - offset;
- newLength = newByteLength / ELEMENT_SIZE;
- } else {
- var newLength = ToPositiveInteger(length, "invalid_typed_array_length");
- newByteLength = newLength * ELEMENT_SIZE;
- }
- if (offset + newByteLength > bufferByteLength) {
- throw MakeRangeError("invalid_typed_array_length");
+ var newByteLength;
+ var newLength;
+ if (IS_UNDEFINED(length)) {
+ if (bufferByteLength % ELEMENT_SIZE !== 0) {
+ throw MakeRangeError("invalid_typed_array_alignment",
+ "byte length", "NAME", ELEMENT_SIZE);
}
- %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
+ newByteLength = bufferByteLength - offset;
+ newLength = newByteLength / ELEMENT_SIZE;
+ } else {
+ var newLength = ToPositiveInteger(length, "invalid_typed_array_length");
+ newByteLength = newLength * ELEMENT_SIZE;
}
-
- function ConstructByLength(obj, length) {
- var l = ToPositiveInteger(length, "invalid_typed_array_length");
- var byteLength = l * ELEMENT_SIZE;
- var buffer = new $ArrayBuffer(byteLength);
- %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
+ if (offset + newByteLength > bufferByteLength) {
+ throw MakeRangeError("invalid_typed_array_length");
}
+ %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
+ }
- function ConstructByArrayLike(obj, arrayLike) {
- var length = arrayLike.length;
- var l = ToPositiveInteger(length, "invalid_typed_array_length");
- if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
- for (var i = 0; i < l; i++) {
- // It is crucial that we let any execptions from arrayLike[i]
- // propagate outside the function.
- obj[i] = arrayLike[i];
- }
+ function NAMEConstructByLength(obj, length) {
+ var l = IS_UNDEFINED(length) ?
+ 0 : ToPositiveInteger(length, "invalid_typed_array_length");
+ var byteLength = l * ELEMENT_SIZE;
+ var buffer = new $ArrayBuffer(byteLength);
+ %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
+ }
+
+ function NAMEConstructByArrayLike(obj, arrayLike) {
+ var length = arrayLike.length;
+ var l = ToPositiveInteger(length, "invalid_typed_array_length");
+ if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
+ for (var i = 0; i < l; i++) {
+ // It is crucial that we let any execptions from arrayLike[i]
+ // propagate outside the function.
+ obj[i] = arrayLike[i];
}
}
+ }
+
+ function NAMEConstructor(arg1, arg2, arg3) {
if (%_IsConstructCall()) {
if (IS_ARRAYBUFFER(arg1)) {
- ConstructByArrayBuffer(this, arg1, arg2, arg3);
+ NAMEConstructByArrayBuffer(this, arg1, arg2, arg3);
} else if (IS_NUMBER(arg1) || IS_STRING(arg1) ||
IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
- ConstructByLength(this, arg1);
+ NAMEConstructByLength(this, arg1);
} else {
- ConstructByArrayLike(this, arg1);
+ NAMEConstructByArrayLike(this, arg1);
}
} else {
throw MakeTypeError("constructor_not_function", ["NAME"])
@@ -284,7 +291,6 @@ function SetupTypedArray(constructor, fun, elementSize) {
));
}
-
macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE);
endmacro
@@ -301,7 +307,8 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
throw MakeTypeError('data_view_not_array_buffer', []);
}
var bufferByteLength = %ArrayBufferGetByteLength(buffer);
- var offset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
+ var offset = IS_UNDEFINED(byteOffset) ?
+ 0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
if (offset > bufferByteLength) {
throw MakeRangeError('invalid_data_view_offset');
}
« no previous file with comments | « src/stub-cache.cc ('k') | src/unicode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698