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

Side by Side Diff: src/typedarray.js

Issue 1126213002: Wrap runtime.js in a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix 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 unified diff | Download patch
« no previous file with comments | « src/symbol.js ('k') | src/uri.js » ('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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() { 5 (function() {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 20 matching lines...) Expand all
31 endmacro 31 endmacro
32 32
33 TYPED_ARRAYS(DECLARE_GLOBALS) 33 TYPED_ARRAYS(DECLARE_GLOBALS)
34 34
35 // --------------- Typed Arrays --------------------- 35 // --------------- Typed Arrays ---------------------
36 36
37 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) 37 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
38 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { 38 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
39 if (!IS_UNDEFINED(byteOffset)) { 39 if (!IS_UNDEFINED(byteOffset)) {
40 byteOffset = 40 byteOffset =
41 ToPositiveInteger(byteOffset, kInvalidTypedArrayLength); 41 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength);
42 } 42 }
43 if (!IS_UNDEFINED(length)) { 43 if (!IS_UNDEFINED(length)) {
44 length = ToPositiveInteger(length, kInvalidTypedArrayLength); 44 length = $toPositiveInteger(length, kInvalidTypedArrayLength);
45 } 45 }
46 46
47 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); 47 var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
48 var offset; 48 var offset;
49 if (IS_UNDEFINED(byteOffset)) { 49 if (IS_UNDEFINED(byteOffset)) {
50 offset = 0; 50 offset = 0;
51 } else { 51 } else {
52 offset = byteOffset; 52 offset = byteOffset;
53 53
54 if (offset % ELEMENT_SIZE !== 0) { 54 if (offset % ELEMENT_SIZE !== 0) {
(...skipping 20 matching lines...) Expand all
75 } 75 }
76 if ((offset + newByteLength > bufferByteLength) 76 if ((offset + newByteLength > bufferByteLength)
77 || (newLength > %_MaxSmi())) { 77 || (newLength > %_MaxSmi())) {
78 throw MakeRangeError(kInvalidTypedArrayLength); 78 throw MakeRangeError(kInvalidTypedArrayLength);
79 } 79 }
80 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); 80 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
81 } 81 }
82 82
83 function NAMEConstructByLength(obj, length) { 83 function NAMEConstructByLength(obj, length) {
84 var l = IS_UNDEFINED(length) ? 84 var l = IS_UNDEFINED(length) ?
85 0 : ToPositiveInteger(length, kInvalidTypedArrayLength); 85 0 : $toPositiveInteger(length, kInvalidTypedArrayLength);
86 if (l > %_MaxSmi()) { 86 if (l > %_MaxSmi()) {
87 throw MakeRangeError(kInvalidTypedArrayLength); 87 throw MakeRangeError(kInvalidTypedArrayLength);
88 } 88 }
89 var byteLength = l * ELEMENT_SIZE; 89 var byteLength = l * ELEMENT_SIZE;
90 if (byteLength > %_TypedArrayMaxSizeInHeap()) { 90 if (byteLength > %_TypedArrayMaxSizeInHeap()) {
91 var buffer = new GlobalArrayBuffer(byteLength); 91 var buffer = new GlobalArrayBuffer(byteLength);
92 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); 92 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
93 } else { 93 } else {
94 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); 94 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength);
95 } 95 }
96 } 96 }
97 97
98 function NAMEConstructByArrayLike(obj, arrayLike) { 98 function NAMEConstructByArrayLike(obj, arrayLike) {
99 var length = arrayLike.length; 99 var length = arrayLike.length;
100 var l = ToPositiveInteger(length, kInvalidTypedArrayLength); 100 var l = $toPositiveInteger(length, kInvalidTypedArrayLength);
101 101
102 if (l > %_MaxSmi()) { 102 if (l > %_MaxSmi()) {
103 throw MakeRangeError(kInvalidTypedArrayLength); 103 throw MakeRangeError(kInvalidTypedArrayLength);
104 } 104 }
105 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { 105 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
106 for (var i = 0; i < l; i++) { 106 for (var i = 0; i < l; i++) {
107 // It is crucial that we let any execptions from arrayLike[i] 107 // It is crucial that we let any execptions from arrayLike[i]
108 // propagate outside the function. 108 // propagate outside the function.
109 obj[i] = arrayLike[i]; 109 obj[i] = arrayLike[i];
110 } 110 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 endmacro 328 endmacro
329 329
330 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 330 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
331 331
332 // --------------------------- DataView ----------------------------- 332 // --------------------------- DataView -----------------------------
333 333
334 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 334 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
335 if (%_IsConstructCall()) { 335 if (%_IsConstructCall()) {
336 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer); 336 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer);
337 if (!IS_UNDEFINED(byteOffset)) { 337 if (!IS_UNDEFINED(byteOffset)) {
338 byteOffset = ToPositiveInteger(byteOffset, kInvalidDataViewOffset); 338 byteOffset = $toPositiveInteger(byteOffset, kInvalidDataViewOffset);
339 } 339 }
340 if (!IS_UNDEFINED(byteLength)) { 340 if (!IS_UNDEFINED(byteLength)) {
341 byteLength = TO_INTEGER(byteLength); 341 byteLength = TO_INTEGER(byteLength);
342 } 342 }
343 343
344 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); 344 var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
345 345
346 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; 346 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset;
347 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset); 347 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset);
348 348
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 FUNCTION(Int8) 385 FUNCTION(Int8)
386 FUNCTION(Uint8) 386 FUNCTION(Uint8)
387 FUNCTION(Int16) 387 FUNCTION(Int16)
388 FUNCTION(Uint16) 388 FUNCTION(Uint16)
389 FUNCTION(Int32) 389 FUNCTION(Int32)
390 FUNCTION(Uint32) 390 FUNCTION(Uint32)
391 FUNCTION(Float32) 391 FUNCTION(Float32)
392 FUNCTION(Float64) 392 FUNCTION(Float64)
393 endmacro 393 endmacro
394 394
395 function ToPositiveDataViewOffset(offset) {
396 return ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
397 }
398
399 395
400 macro DATA_VIEW_GETTER_SETTER(TYPENAME) 396 macro DATA_VIEW_GETTER_SETTER(TYPENAME)
401 function DataViewGetTYPENAMEJS(offset, little_endian) { 397 function DataViewGetTYPENAMEJS(offset, little_endian) {
402 if (!IS_DATAVIEW(this)) { 398 if (!IS_DATAVIEW(this)) {
403 throw MakeTypeError(kIncompatibleMethodReceiver, 399 throw MakeTypeError(kIncompatibleMethodReceiver,
404 'DataView.getTYPENAME', this); 400 'DataView.getTYPENAME', this);
405 } 401 }
406 if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument); 402 if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument);
407 return %DataViewGetTYPENAME(this, 403 offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset);
408 ToPositiveDataViewOffset(offset), 404 return %DataViewGetTYPENAME(this, offset, !!little_endian);
409 !!little_endian);
410 } 405 }
411 406
412 function DataViewSetTYPENAMEJS(offset, value, little_endian) { 407 function DataViewSetTYPENAMEJS(offset, value, little_endian) {
413 if (!IS_DATAVIEW(this)) { 408 if (!IS_DATAVIEW(this)) {
414 throw MakeTypeError(kIncompatibleMethodReceiver, 409 throw MakeTypeError(kIncompatibleMethodReceiver,
415 'DataView.setTYPENAME', this); 410 'DataView.setTYPENAME', this);
416 } 411 }
417 if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument); 412 if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument);
418 %DataViewSetTYPENAME(this, 413 offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset);
419 ToPositiveDataViewOffset(offset), 414 %DataViewSetTYPENAME(this, offset, TO_NUMBER_INLINE(value), !!little_endian);
420 TO_NUMBER_INLINE(value),
421 !!little_endian);
422 } 415 }
423 endmacro 416 endmacro
424 417
425 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) 418 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)
426 419
427 // Setup the DataView constructor. 420 // Setup the DataView constructor.
428 %SetCode(GlobalDataView, DataViewConstructor); 421 %SetCode(GlobalDataView, DataViewConstructor);
429 %FunctionSetPrototype(GlobalDataView, new GlobalObject); 422 %FunctionSetPrototype(GlobalDataView, new GlobalObject);
430 423
431 // Set up constructor property on the DataView prototype. 424 // Set up constructor property on the DataView prototype.
(...skipping 26 matching lines...) Expand all
458 "setUint32", DataViewSetUint32JS, 451 "setUint32", DataViewSetUint32JS,
459 452
460 "getFloat32", DataViewGetFloat32JS, 453 "getFloat32", DataViewGetFloat32JS,
461 "setFloat32", DataViewSetFloat32JS, 454 "setFloat32", DataViewSetFloat32JS,
462 455
463 "getFloat64", DataViewGetFloat64JS, 456 "getFloat64", DataViewGetFloat64JS,
464 "setFloat64", DataViewSetFloat64JS 457 "setFloat64", DataViewSetFloat64JS
465 ]); 458 ]);
466 459
467 })(); 460 })();
OLDNEW
« no previous file with comments | « src/symbol.js ('k') | src/uri.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698