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

Side by Side Diff: src/typedarray.js

Issue 142813003: A64: Synchronize with r15358. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 11 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/type-info.cc ('k') | src/types.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 19 matching lines...) Expand all
30 // This file relies on the fact that the following declaration has been made 30 // This file relies on the fact that the following declaration has been made
31 // in runtime.js: 31 // in runtime.js:
32 // var $Array = global.Array; 32 // var $Array = global.Array;
33 33
34 34
35 35
36 // --------------- Typed Arrays --------------------- 36 // --------------- Typed Arrays ---------------------
37 37
38 function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) { 38 function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) {
39 function ConstructByArrayBuffer(obj, buffer, byteOffset, length) { 39 function ConstructByArrayBuffer(obj, buffer, byteOffset, length) {
40 var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_POSITIVE_INTEGER(byteOffset); 40 var offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length")
41 41
42 if (offset % elementSize !== 0) { 42 if (offset % elementSize !== 0) {
43 throw MakeRangeError("invalid_typed_array_alignment", 43 throw MakeRangeError("invalid_typed_array_alignment",
44 "start offset", name, elementSize); 44 "start offset", name, elementSize);
45 } 45 }
46 var bufferByteLength = %ArrayBufferGetByteLength(buffer); 46 var bufferByteLength = %ArrayBufferGetByteLength(buffer);
47 if (offset > bufferByteLength) { 47 if (offset > bufferByteLength) {
48 throw MakeRangeError("invalid_typed_array_offset"); 48 throw MakeRangeError("invalid_typed_array_offset");
49 } 49 }
50 50
51 var newByteLength; 51 var newByteLength;
52 var newLength; 52 var newLength;
53 if (IS_UNDEFINED(length)) { 53 if (IS_UNDEFINED(length)) {
54 if (bufferByteLength % elementSize !== 0) { 54 if (bufferByteLength % elementSize !== 0) {
55 throw MakeRangeError("invalid_typed_array_alignment", 55 throw MakeRangeError("invalid_typed_array_alignment",
56 "byte length", name, elementSize); 56 "byte length", name, elementSize);
57 } 57 }
58 newByteLength = bufferByteLength - offset; 58 newByteLength = bufferByteLength - offset;
59 newLength = newByteLength / elementSize; 59 newLength = newByteLength / elementSize;
60 } else { 60 } else {
61 var newLength = TO_POSITIVE_INTEGER(length); 61 var newLength = ToPositiveInteger(length, "invalid_typed_array_length");
62 newByteLength = newLength * elementSize; 62 newByteLength = newLength * elementSize;
63 } 63 }
64 if (offset + newByteLength > bufferByteLength) { 64 if (offset + newByteLength > bufferByteLength) {
65 throw MakeRangeError("invalid_typed_array_length"); 65 throw MakeRangeError("invalid_typed_array_length");
66 } 66 }
67 %TypedArrayInitialize(obj, arrayId, buffer, offset, newByteLength); 67 %TypedArrayInitialize(obj, arrayId, buffer, offset, newByteLength);
68 } 68 }
69 69
70 function ConstructByLength(obj, length) { 70 function ConstructByLength(obj, length) {
71 var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); 71 var l = ToPositiveInteger(length, "invalid_typed_array_length");
72 var byteLength = l * elementSize; 72 var byteLength = l * elementSize;
73 var buffer = new global.ArrayBuffer(byteLength); 73 var buffer = new global.ArrayBuffer(byteLength);
74 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); 74 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength);
75 } 75 }
76 76
77 function ConstructByArrayLike(obj, arrayLike) { 77 function ConstructByArrayLike(obj, arrayLike) {
78 var length = arrayLike.length; 78 var length = arrayLike.length;
79 var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); 79 var l = ToPositiveInteger(length, "invalid_typed_array_length");
80 var byteLength = l * elementSize; 80 var byteLength = l * elementSize;
81 var buffer = new $ArrayBuffer(byteLength); 81 var buffer = new $ArrayBuffer(byteLength);
82 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); 82 %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength);
83 for (var i = 0; i < l; i++) { 83 for (var i = 0; i < l; i++) {
84 obj[i] = arrayLike[i]; 84 obj[i] = arrayLike[i];
85 } 85 }
86 } 86 }
87 87
88 return function (arg1, arg2, arg3) { 88 return function (arg1, arg2, arg3) {
89 if (%_IsConstructCall()) { 89 if (%_IsConstructCall()) {
90 if (IS_ARRAYBUFFER(arg1)) { 90 if (IS_ARRAYBUFFER(arg1)) {
91 ConstructByArrayBuffer(this, arg1, arg2, arg3); 91 ConstructByArrayBuffer(this, arg1, arg2, arg3);
92 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || IS_BOOLEAN(arg1)) { 92 } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || IS_BOOLEAN(arg1)) {
93 ConstructByLength(this, arg1); 93 ConstructByLength(this, arg1);
94 } else if (!IS_UNDEFINED(arg1)){ 94 } else if (!IS_UNDEFINED(arg1)){
95 ConstructByArrayLike(this, arg1); 95 ConstructByArrayLike(this, arg1);
96 } else { 96 } else {
97 throw MakeTypeError("parameterless_typed_array_constr", [name]); 97 throw MakeTypeError("parameterless_typed_array_constr", [name]);
98 } 98 }
99 } else { 99 } else {
100 return new constructor(arg1, arg2, arg3); 100 throw MakeTypeError("constructor_not_function", [name])
101 } 101 }
102 } 102 }
103 } 103 }
104 104
105 function TypedArrayGetBuffer() { 105 function TypedArrayGetBuffer() {
106 return %TypedArrayGetBuffer(this); 106 return %TypedArrayGetBuffer(this);
107 } 107 }
108 108
109 function TypedArrayGetByteLength() { 109 function TypedArrayGetByteLength() {
110 return %TypedArrayGetByteLength(this); 110 return %TypedArrayGetByteLength(this);
(...skipping 28 matching lines...) Expand all
139 } 139 }
140 var newLength = endInt - beginInt; 140 var newLength = endInt - beginInt;
141 var beginByteOffset = 141 var beginByteOffset =
142 %TypedArrayGetByteOffset(this) + beginInt * elementSize; 142 %TypedArrayGetByteOffset(this) + beginInt * elementSize;
143 return new constructor(%TypedArrayGetBuffer(this), 143 return new constructor(%TypedArrayGetBuffer(this),
144 beginByteOffset, newLength); 144 beginByteOffset, newLength);
145 } 145 }
146 } 146 }
147 147
148 function TypedArraySet(obj, offset) { 148 function TypedArraySet(obj, offset) {
149 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_POSITIVE_INTEGER(offset); 149 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset);
150 if (intOffset < 0) {
151 throw MakeTypeError("typed_array_set_negative_offset");
152 }
150 if (%TypedArraySetFastCases(this, obj, intOffset)) 153 if (%TypedArraySetFastCases(this, obj, intOffset))
151 return; 154 return;
152 155
153 var l = obj.length; 156 var l = obj.length;
154 if (IS_UNDEFINED(l)) { 157 if (IS_UNDEFINED(l)) {
155 throw MakeTypeError("invalid_argument"); 158 throw MakeTypeError("invalid_argument");
156 } 159 }
157 if (intOffset + l > this.length) { 160 if (intOffset + l > this.length) {
158 throw MakeRangeError("typed_array_set_source_too_large"); 161 throw MakeRangeError("typed_array_set_source_too_large");
159 } 162 }
(...skipping 30 matching lines...) Expand all
190 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. 193 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
191 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1); 194 SetupTypedArray(1, "Uint8Array", global.Uint8Array, 1);
192 SetupTypedArray(2, "Int8Array", global.Int8Array, 1); 195 SetupTypedArray(2, "Int8Array", global.Int8Array, 1);
193 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2); 196 SetupTypedArray(3, "Uint16Array", global.Uint16Array, 2);
194 SetupTypedArray(4, "Int16Array", global.Int16Array, 2); 197 SetupTypedArray(4, "Int16Array", global.Int16Array, 2);
195 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4); 198 SetupTypedArray(5, "Uint32Array", global.Uint32Array, 4);
196 SetupTypedArray(6, "Int32Array", global.Int32Array, 4); 199 SetupTypedArray(6, "Int32Array", global.Int32Array, 4);
197 SetupTypedArray(7, "Float32Array", global.Float32Array, 4); 200 SetupTypedArray(7, "Float32Array", global.Float32Array, 4);
198 SetupTypedArray(8, "Float64Array", global.Float64Array, 8); 201 SetupTypedArray(8, "Float64Array", global.Float64Array, 8);
199 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1); 202 SetupTypedArray(9, "Uint8ClampedArray", global.Uint8ClampedArray, 1);
203
204
205 // --------------------------- DataView -----------------------------
206
207 var $DataView = global.DataView;
208
209 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
210 if (%_IsConstructCall()) {
211 if (!IS_ARRAYBUFFER(buffer)) {
212 throw MakeTypeError('data_view_not_array_buffer', []);
213 }
214 var bufferByteLength = %ArrayBufferGetByteLength(buffer);
215 var offset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
216 if (offset > bufferByteLength) {
217 throw MakeRangeError('invalid_data_view_offset');
218 }
219 var length = IS_UNDEFINED(byteLength) ?
220 bufferByteLength - offset : TO_INTEGER(byteLength);
221 if (length < 0 || offset + length > bufferByteLength) {
222 throw new MakeRangeError('invalid_data_view_length');
223 }
224 %DataViewInitialize(this, buffer, offset, length);
225 } else {
226 throw MakeTypeError('constructor_not_function', ["DataView"]);
227 }
228 }
229
230 function DataViewGetBuffer() {
231 if (!IS_DATAVIEW(this)) {
232 throw MakeTypeError('incompatible_method_reciever',
233 ['DataView.buffer', this]);
234 }
235 return %DataViewGetBuffer(this);
236 }
237
238 function DataViewGetByteOffset() {
239 if (!IS_DATAVIEW(this)) {
240 throw MakeTypeError('incompatible_method_reciever',
241 ['DataView.byteOffset', this]);
242 }
243 return %DataViewGetByteOffset(this);
244 }
245
246 function DataViewGetByteLength() {
247 if (!IS_DATAVIEW(this)) {
248 throw MakeTypeError('incompatible_method_reciever',
249 ['DataView.byteLength', this]);
250 }
251 return %DataViewGetByteLength(this);
252 }
253
254 function ToPositiveDataViewOffset(offset) {
255 return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset');
256 }
257
258 function DataViewGetInt8(offset, little_endian) {
259 if (!IS_DATAVIEW(this)) {
260 throw MakeTypeError('incompatible_method_reciever',
261 ['DataView.getInt8', this]);
262 }
263 return %DataViewGetInt8(this,
264 ToPositiveDataViewOffset(offset),
265 !!little_endian);
266 }
267
268 function DataViewSetInt8(offset, value, little_endian) {
269 if (!IS_DATAVIEW(this)) {
270 throw MakeTypeError('incompatible_method_reciever',
271 ['DataView.setInt8', this]);
272 }
273 %DataViewSetInt8(this,
274 ToPositiveDataViewOffset(offset),
275 TO_NUMBER_INLINE(value),
276 !!little_endian);
277 }
278
279 function DataViewGetUint8(offset, little_endian) {
280 if (!IS_DATAVIEW(this)) {
281 throw MakeTypeError('incompatible_method_reciever',
282 ['DataView.getUint8', this]);
283 }
284 return %DataViewGetUint8(this,
285 ToPositiveDataViewOffset(offset),
286 !!little_endian);
287 }
288
289 function DataViewSetUint8(offset, value, little_endian) {
290 if (!IS_DATAVIEW(this)) {
291 throw MakeTypeError('incompatible_method_reciever',
292 ['DataView.setUint8', this]);
293 }
294 %DataViewSetUint8(this,
295 ToPositiveDataViewOffset(offset),
296 TO_NUMBER_INLINE(value),
297 !!little_endian);
298 }
299
300 function DataViewGetInt16(offset, little_endian) {
301 if (!IS_DATAVIEW(this)) {
302 throw MakeTypeError('incompatible_method_reciever',
303 ['DataView.getInt16', this]);
304 }
305 return %DataViewGetInt16(this,
306 ToPositiveDataViewOffset(offset),
307 !!little_endian);
308 }
309
310 function DataViewSetInt16(offset, value, little_endian) {
311 if (!IS_DATAVIEW(this)) {
312 throw MakeTypeError('incompatible_method_reciever',
313 ['DataView.setInt16', this]);
314 }
315 %DataViewSetInt16(this,
316 ToPositiveDataViewOffset(offset),
317 TO_NUMBER_INLINE(value),
318 !!little_endian);
319 }
320
321 function DataViewGetUint16(offset, little_endian) {
322 if (!IS_DATAVIEW(this)) {
323 throw MakeTypeError('incompatible_method_reciever',
324 ['DataView.getUint16', this]);
325 }
326 return %DataViewGetUint16(this,
327 ToPositiveDataViewOffset(offset),
328 !!little_endian);
329 }
330
331 function DataViewSetUint16(offset, value, little_endian) {
332 if (!IS_DATAVIEW(this)) {
333 throw MakeTypeError('incompatible_method_reciever',
334 ['DataView.setUint16', this]);
335 }
336 %DataViewSetUint16(this,
337 ToPositiveDataViewOffset(offset),
338 TO_NUMBER_INLINE(value),
339 !!little_endian);
340 }
341
342 function DataViewGetInt32(offset, little_endian) {
343 if (!IS_DATAVIEW(this)) {
344 throw MakeTypeError('incompatible_method_reciever',
345 ['DataView.getInt32', this]);
346 }
347 return %DataViewGetInt32(this,
348 ToPositiveDataViewOffset(offset),
349 !!little_endian);
350 }
351
352 function DataViewSetInt32(offset, value, little_endian) {
353 if (!IS_DATAVIEW(this)) {
354 throw MakeTypeError('incompatible_method_reciever',
355 ['DataView.setInt32', this]);
356 }
357 %DataViewSetInt32(this,
358 ToPositiveDataViewOffset(offset),
359 TO_NUMBER_INLINE(value),
360 !!little_endian);
361 }
362
363 function DataViewGetUint32(offset, little_endian) {
364 if (!IS_DATAVIEW(this)) {
365 throw MakeTypeError('incompatible_method_reciever',
366 ['DataView.getUint32', this]);
367 }
368 return %DataViewGetUint32(this,
369 ToPositiveDataViewOffset(offset),
370 !!little_endian);
371 }
372
373 function DataViewSetUint32(offset, value, little_endian) {
374 if (!IS_DATAVIEW(this)) {
375 throw MakeTypeError('incompatible_method_reciever',
376 ['DataView.setUint32', this]);
377 }
378 %DataViewSetUint32(this,
379 ToPositiveDataViewOffset(offset),
380 TO_NUMBER_INLINE(value),
381 !!little_endian);
382 }
383
384 function DataViewGetFloat32(offset, little_endian) {
385 if (!IS_DATAVIEW(this)) {
386 throw MakeTypeError('incompatible_method_reciever',
387 ['DataView.getFloat32', this]);
388 }
389 return %DataViewGetFloat32(this,
390 ToPositiveDataViewOffset(offset),
391 !!little_endian);
392 }
393
394 function DataViewSetFloat32(offset, value, little_endian) {
395 if (!IS_DATAVIEW(this)) {
396 throw MakeTypeError('incompatible_method_reciever',
397 ['DataView.setFloat32', this]);
398 }
399 %DataViewSetFloat32(this,
400 ToPositiveDataViewOffset(offset),
401 TO_NUMBER_INLINE(value),
402 !!little_endian);
403 }
404
405 function DataViewGetFloat64(offset, little_endian) {
406 if (!IS_DATAVIEW(this)) {
407 throw MakeTypeError('incompatible_method_reciever',
408 ['DataView.getFloat64', this]);
409 }
410 offset = TO_INTEGER(offset);
411 if (offset < 0) {
412 throw MakeRangeError("invalid_data_view_accessor_offset");
413 }
414 return %DataViewGetFloat64(this,
415 ToPositiveDataViewOffset(offset),
416 !!little_endian);
417 }
418
419 function DataViewSetFloat64(offset, value, little_endian) {
420 if (!IS_DATAVIEW(this)) {
421 throw MakeTypeError('incompatible_method_reciever',
422 ['DataView.setFloat64', this]);
423 }
424 offset = TO_INTEGER(offset);
425 if (offset < 0) {
426 throw MakeRangeError("invalid_data_view_accessor_offset");
427 }
428 %DataViewSetFloat64(this,
429 ToPositiveDataViewOffset(offset),
430 TO_NUMBER_INLINE(value),
431 !!little_endian);
432 }
433
434 function SetupDataView() {
435 %CheckIsBootstrapping();
436
437 // Setup the DataView constructor.
438 %SetCode($DataView, DataViewConstructor);
439 %FunctionSetPrototype($DataView, new $Object);
440
441 // Set up constructor property on the DataView prototype.
442 %SetProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM);
443
444 InstallGetter($DataView.prototype, "buffer", DataViewGetBuffer);
445 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset);
446 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength);
447
448 InstallFunctions($DataView.prototype, DONT_ENUM, $Array(
449 "getInt8", DataViewGetInt8,
450 "setInt8", DataViewSetInt8,
451
452 "getUint8", DataViewGetUint8,
453 "setUint8", DataViewSetUint8,
454
455 "getInt16", DataViewGetInt16,
456 "setInt16", DataViewSetInt16,
457
458 "getUint16", DataViewGetUint16,
459 "setUint16", DataViewSetUint16,
460
461 "getInt32", DataViewGetInt32,
462 "setInt32", DataViewSetInt32,
463
464 "getUint32", DataViewGetUint32,
465 "setUint32", DataViewSetUint32,
466
467 "getFloat32", DataViewGetFloat32,
468 "setFloat32", DataViewSetFloat32,
469
470 "getFloat64", DataViewGetFloat64,
471 "setFloat64", DataViewSetFloat64
472 ));
473 }
474
475 SetupDataView();
OLDNEW
« no previous file with comments | « src/type-info.cc ('k') | src/types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698