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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/stub-cache.cc ('k') | src/unicode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 30 matching lines...) Expand all
41 FUNCTION(3, Uint16Array, 2) 41 FUNCTION(3, Uint16Array, 2)
42 FUNCTION(4, Int16Array, 2) 42 FUNCTION(4, Int16Array, 2)
43 FUNCTION(5, Uint32Array, 4) 43 FUNCTION(5, Uint32Array, 4)
44 FUNCTION(6, Int32Array, 4) 44 FUNCTION(6, Int32Array, 4)
45 FUNCTION(7, Float32Array, 4) 45 FUNCTION(7, Float32Array, 4)
46 FUNCTION(8, Float64Array, 8) 46 FUNCTION(8, Float64Array, 8)
47 FUNCTION(9, Uint8ClampedArray, 1) 47 FUNCTION(9, Uint8ClampedArray, 1)
48 endmacro 48 endmacro
49 49
50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) 50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
51 function NAMEConstructor(arg1, arg2, arg3) { 51 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
52 function ConstructByArrayBuffer(obj, buffer, byteOffset, length) { 52 var bufferByteLength = buffer.byteLength;
53 var offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length") 53 var offset;
54 if (IS_UNDEFINED(byteOffset)) {
55 offset = 0;
56 } else {
57 offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length");
54 58
55 if (offset % ELEMENT_SIZE !== 0) { 59 if (offset % ELEMENT_SIZE !== 0) {
56 throw MakeRangeError("invalid_typed_array_alignment", 60 throw MakeRangeError("invalid_typed_array_alignment",
57 "start offset", "NAME", ELEMENT_SIZE); 61 "start offset", "NAME", ELEMENT_SIZE);
58 } 62 }
59 var bufferByteLength = %ArrayBufferGetByteLength(buffer);
60 if (offset > bufferByteLength) { 63 if (offset > bufferByteLength) {
61 throw MakeRangeError("invalid_typed_array_offset"); 64 throw MakeRangeError("invalid_typed_array_offset");
62 } 65 }
63
64 var newByteLength;
65 var newLength;
66 if (IS_UNDEFINED(length)) {
67 if (bufferByteLength % ELEMENT_SIZE !== 0) {
68 throw MakeRangeError("invalid_typed_array_alignment",
69 "byte length", "NAME", ELEMENT_SIZE);
70 }
71 newByteLength = bufferByteLength - offset;
72 newLength = newByteLength / ELEMENT_SIZE;
73 } else {
74 var newLength = ToPositiveInteger(length, "invalid_typed_array_length");
75 newByteLength = newLength * ELEMENT_SIZE;
76 }
77 if (offset + newByteLength > bufferByteLength) {
78 throw MakeRangeError("invalid_typed_array_length");
79 }
80 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
81 } 66 }
82 67
83 function ConstructByLength(obj, length) { 68 var newByteLength;
84 var l = ToPositiveInteger(length, "invalid_typed_array_length"); 69 var newLength;
85 var byteLength = l * ELEMENT_SIZE; 70 if (IS_UNDEFINED(length)) {
86 var buffer = new $ArrayBuffer(byteLength); 71 if (bufferByteLength % ELEMENT_SIZE !== 0) {
87 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); 72 throw MakeRangeError("invalid_typed_array_alignment",
73 "byte length", "NAME", ELEMENT_SIZE);
74 }
75 newByteLength = bufferByteLength - offset;
76 newLength = newByteLength / ELEMENT_SIZE;
77 } else {
78 var newLength = ToPositiveInteger(length, "invalid_typed_array_length");
79 newByteLength = newLength * ELEMENT_SIZE;
88 } 80 }
81 if (offset + newByteLength > bufferByteLength) {
82 throw MakeRangeError("invalid_typed_array_length");
83 }
84 %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
85 }
89 86
90 function ConstructByArrayLike(obj, arrayLike) { 87 function NAMEConstructByLength(obj, length) {
91 var length = arrayLike.length; 88 var l = IS_UNDEFINED(length) ?
92 var l = ToPositiveInteger(length, "invalid_typed_array_length"); 89 0 : ToPositiveInteger(length, "invalid_typed_array_length");
93 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { 90 var byteLength = l * ELEMENT_SIZE;
94 for (var i = 0; i < l; i++) { 91 var buffer = new $ArrayBuffer(byteLength);
95 // It is crucial that we let any execptions from arrayLike[i] 92 %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
96 // propagate outside the function. 93 }
97 obj[i] = arrayLike[i]; 94
98 } 95 function NAMEConstructByArrayLike(obj, arrayLike) {
96 var length = arrayLike.length;
97 var l = ToPositiveInteger(length, "invalid_typed_array_length");
98 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
99 for (var i = 0; i < l; i++) {
100 // It is crucial that we let any execptions from arrayLike[i]
101 // propagate outside the function.
102 obj[i] = arrayLike[i];
99 } 103 }
100 } 104 }
105 }
106
107 function NAMEConstructor(arg1, arg2, arg3) {
101 108
102 if (%_IsConstructCall()) { 109 if (%_IsConstructCall()) {
103 if (IS_ARRAYBUFFER(arg1)) { 110 if (IS_ARRAYBUFFER(arg1)) {
104 ConstructByArrayBuffer(this, arg1, arg2, arg3); 111 NAMEConstructByArrayBuffer(this, arg1, arg2, arg3);
105 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || 112 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) ||
106 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { 113 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
107 ConstructByLength(this, arg1); 114 NAMEConstructByLength(this, arg1);
108 } else { 115 } else {
109 ConstructByArrayLike(this, arg1); 116 NAMEConstructByArrayLike(this, arg1);
110 } 117 }
111 } else { 118 } else {
112 throw MakeTypeError("constructor_not_function", ["NAME"]) 119 throw MakeTypeError("constructor_not_function", ["NAME"])
113 } 120 }
114 } 121 }
115 endmacro 122 endmacro
116 123
117 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) 124 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
118 125
119 function TypedArrayGetBuffer() { 126 function TypedArrayGetBuffer() {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset); 284 InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset);
278 InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength); 285 InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength);
279 InstallGetter(constructor.prototype, "length", TypedArrayGetLength); 286 InstallGetter(constructor.prototype, "length", TypedArrayGetLength);
280 287
281 InstallFunctions(constructor.prototype, DONT_ENUM, $Array( 288 InstallFunctions(constructor.prototype, DONT_ENUM, $Array(
282 "subarray", CreateSubArray(elementSize, constructor), 289 "subarray", CreateSubArray(elementSize, constructor),
283 "set", TypedArraySet 290 "set", TypedArraySet
284 )); 291 ));
285 } 292 }
286 293
287
288 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 294 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
289 SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE); 295 SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE);
290 endmacro 296 endmacro
291 297
292 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 298 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
293 299
294 // --------------------------- DataView ----------------------------- 300 // --------------------------- DataView -----------------------------
295 301
296 var $DataView = global.DataView; 302 var $DataView = global.DataView;
297 303
298 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 304 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
299 if (%_IsConstructCall()) { 305 if (%_IsConstructCall()) {
300 if (!IS_ARRAYBUFFER(buffer)) { 306 if (!IS_ARRAYBUFFER(buffer)) {
301 throw MakeTypeError('data_view_not_array_buffer', []); 307 throw MakeTypeError('data_view_not_array_buffer', []);
302 } 308 }
303 var bufferByteLength = %ArrayBufferGetByteLength(buffer); 309 var bufferByteLength = %ArrayBufferGetByteLength(buffer);
304 var offset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); 310 var offset = IS_UNDEFINED(byteOffset) ?
311 0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
305 if (offset > bufferByteLength) { 312 if (offset > bufferByteLength) {
306 throw MakeRangeError('invalid_data_view_offset'); 313 throw MakeRangeError('invalid_data_view_offset');
307 } 314 }
308 var length = IS_UNDEFINED(byteLength) ? 315 var length = IS_UNDEFINED(byteLength) ?
309 bufferByteLength - offset : TO_INTEGER(byteLength); 316 bufferByteLength - offset : TO_INTEGER(byteLength);
310 if (length < 0 || offset + length > bufferByteLength) { 317 if (length < 0 || offset + length > bufferByteLength) {
311 throw new MakeRangeError('invalid_data_view_length'); 318 throw new MakeRangeError('invalid_data_view_length');
312 } 319 }
313 %DataViewInitialize(this, buffer, offset, length); 320 %DataViewInitialize(this, buffer, offset, length);
314 } else { 321 } else {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 602
596 "getFloat32", DataViewGetFloat32, 603 "getFloat32", DataViewGetFloat32,
597 "setFloat32", DataViewSetFloat32, 604 "setFloat32", DataViewSetFloat32,
598 605
599 "getFloat64", DataViewGetFloat64, 606 "getFloat64", DataViewGetFloat64,
600 "setFloat64", DataViewSetFloat64 607 "setFloat64", DataViewSetFloat64
601 )); 608 ));
602 } 609 }
603 610
604 SetupDataView(); 611 SetupDataView();
OLDNEW
« 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