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

Side by Side Diff: src/typedarray.js

Issue 1086683002: Revert of Wrap typed array implementations in functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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/string-iterator.js ('k') | no next file » | 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() {
6
7 "use strict"; 5 "use strict";
8 6
9 %CheckIsBootstrapping(); 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js:
9 // var $Array = global.Array;
10 var $ArrayBuffer = global.ArrayBuffer;
10 11
11 var GlobalArray = global.Array;
12 var GlobalArrayBuffer = global.ArrayBuffer;
13 12
14 // --------------- Typed Arrays --------------------- 13 // --------------- Typed Arrays ---------------------
15 macro TYPED_ARRAYS(FUNCTION) 14 macro TYPED_ARRAYS(FUNCTION)
16 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. 15 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
17 FUNCTION(1, Uint8Array, 1) 16 FUNCTION(1, Uint8Array, 1)
18 FUNCTION(2, Int8Array, 1) 17 FUNCTION(2, Int8Array, 1)
19 FUNCTION(3, Uint16Array, 2) 18 FUNCTION(3, Uint16Array, 2)
20 FUNCTION(4, Int16Array, 2) 19 FUNCTION(4, Int16Array, 2)
21 FUNCTION(5, Uint32Array, 4) 20 FUNCTION(5, Uint32Array, 4)
22 FUNCTION(6, Int32Array, 4) 21 FUNCTION(6, Int32Array, 4)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 71 }
73 72
74 function NAMEConstructByLength(obj, length) { 73 function NAMEConstructByLength(obj, length) {
75 var l = IS_UNDEFINED(length) ? 74 var l = IS_UNDEFINED(length) ?
76 0 : ToPositiveInteger(length, "invalid_typed_array_length"); 75 0 : ToPositiveInteger(length, "invalid_typed_array_length");
77 if (l > %_MaxSmi()) { 76 if (l > %_MaxSmi()) {
78 throw MakeRangeError("invalid_typed_array_length"); 77 throw MakeRangeError("invalid_typed_array_length");
79 } 78 }
80 var byteLength = l * ELEMENT_SIZE; 79 var byteLength = l * ELEMENT_SIZE;
81 if (byteLength > %_TypedArrayMaxSizeInHeap()) { 80 if (byteLength > %_TypedArrayMaxSizeInHeap()) {
82 var buffer = new GlobalArrayBuffer(byteLength); 81 var buffer = new $ArrayBuffer(byteLength);
83 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); 82 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength);
84 } else { 83 } else {
85 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); 84 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength);
86 } 85 }
87 } 86 }
88 87
89 function NAMEConstructByArrayLike(obj, arrayLike) { 88 function NAMEConstructByArrayLike(obj, arrayLike) {
90 var length = arrayLike.length; 89 var length = arrayLike.length;
91 var l = ToPositiveInteger(length, "invalid_typed_array_length"); 90 var l = ToPositiveInteger(length, "invalid_typed_array_length");
92 91
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 rightIndex >= leftIndex && targetPtr >= sourcePtr; 236 rightIndex >= leftIndex && targetPtr >= sourcePtr;
238 rightIndex--) { 237 rightIndex--) {
239 target[offset + rightIndex] = source[rightIndex]; 238 target[offset + rightIndex] = source[rightIndex];
240 targetPtr -= targetElementSize; 239 targetPtr -= targetElementSize;
241 sourcePtr -= sourceElementSize; 240 sourcePtr -= sourceElementSize;
242 } 241 }
243 return rightIndex; 242 return rightIndex;
244 } 243 }
245 var rightIndex = CopyRightPart(); 244 var rightIndex = CopyRightPart();
246 245
247 var temp = new GlobalArray(rightIndex + 1 - leftIndex); 246 var temp = new $Array(rightIndex + 1 - leftIndex);
248 for (var i = leftIndex; i <= rightIndex; i++) { 247 for (var i = leftIndex; i <= rightIndex; i++) {
249 temp[i - leftIndex] = source[i]; 248 temp[i - leftIndex] = source[i];
250 } 249 }
251 for (i = leftIndex; i <= rightIndex; i++) { 250 for (i = leftIndex; i <= rightIndex; i++) {
252 target[offset + i] = temp[i - leftIndex]; 251 target[offset + i] = temp[i - leftIndex];
253 } 252 }
254 } 253 }
255 254
256 function TypedArraySet(obj, offset) { 255 function TypedArraySet(obj, offset) {
257 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); 256 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 293
295 function TypedArrayGetToStringTag() { 294 function TypedArrayGetToStringTag() {
296 if (!%IsTypedArray(this)) return; 295 if (!%IsTypedArray(this)) return;
297 var name = %_ClassOf(this); 296 var name = %_ClassOf(this);
298 if (IS_UNDEFINED(name)) return; 297 if (IS_UNDEFINED(name)) return;
299 return name; 298 return name;
300 } 299 }
301 300
302 // ------------------------------------------------------------------- 301 // -------------------------------------------------------------------
303 302
303 function SetupTypedArrays() {
304 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 304 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
305 %CheckIsBootstrapping(); 305 %CheckIsBootstrapping();
306 %SetCode(global.NAME, NAMEConstructor); 306 %SetCode(global.NAME, NAMEConstructor);
307 %FunctionSetPrototype(global.NAME, new $Object()); 307 %FunctionSetPrototype(global.NAME, new $Object());
308 308
309 %AddNamedProperty(global.NAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, 309 %AddNamedProperty(global.NAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
310 READ_ONLY | DONT_ENUM | DONT_DELETE); 310 READ_ONLY | DONT_ENUM | DONT_DELETE);
311 %AddNamedProperty(global.NAME.prototype, 311 %AddNamedProperty(global.NAME.prototype,
312 "constructor", global.NAME, DONT_ENUM); 312 "constructor", global.NAME, DONT_ENUM);
313 %AddNamedProperty(global.NAME.prototype, 313 %AddNamedProperty(global.NAME.prototype,
314 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 314 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
315 READ_ONLY | DONT_ENUM | DONT_DELETE); 315 READ_ONLY | DONT_ENUM | DONT_DELETE);
316 InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer); 316 InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer);
317 InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset, 317 InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset,
318 DONT_ENUM | DONT_DELETE); 318 DONT_ENUM | DONT_DELETE);
319 InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength, 319 InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength,
320 DONT_ENUM | DONT_DELETE); 320 DONT_ENUM | DONT_DELETE);
321 InstallGetter(global.NAME.prototype, "length", NAME_GetLength, 321 InstallGetter(global.NAME.prototype, "length", NAME_GetLength,
322 DONT_ENUM | DONT_DELETE); 322 DONT_ENUM | DONT_DELETE);
323 InstallGetter(global.NAME.prototype, symbolToStringTag, 323 InstallGetter(global.NAME.prototype, symbolToStringTag,
324 TypedArrayGetToStringTag); 324 TypedArrayGetToStringTag);
325 InstallFunctions(global.NAME.prototype, DONT_ENUM, [ 325 InstallFunctions(global.NAME.prototype, DONT_ENUM, [
326 "subarray", NAMESubArray, 326 "subarray", NAMESubArray,
327 "set", TypedArraySet 327 "set", TypedArraySet
328 ]); 328 ]);
329 endmacro 329 endmacro
330 330
331 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 331 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
332 }
333
334 SetupTypedArrays();
332 335
333 // --------------------------- DataView ----------------------------- 336 // --------------------------- DataView -----------------------------
334 337
335 var $DataView = global.DataView; 338 var $DataView = global.DataView;
336 339
337 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 340 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
338 if (%_IsConstructCall()) { 341 if (%_IsConstructCall()) {
339 if (!IS_ARRAYBUFFER(buffer)) { 342 if (!IS_ARRAYBUFFER(buffer)) {
340 throw MakeTypeError('data_view_not_array_buffer', []); 343 throw MakeTypeError('data_view_not_array_buffer', []);
341 } 344 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 } 432 }
430 %DataViewSetTYPENAME(this, 433 %DataViewSetTYPENAME(this,
431 ToPositiveDataViewOffset(offset), 434 ToPositiveDataViewOffset(offset),
432 TO_NUMBER_INLINE(value), 435 TO_NUMBER_INLINE(value),
433 !!little_endian); 436 !!little_endian);
434 } 437 }
435 endmacro 438 endmacro
436 439
437 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) 440 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)
438 441
439 // Setup the DataView constructor. 442 function SetupDataView() {
440 %SetCode($DataView, DataViewConstructor); 443 %CheckIsBootstrapping();
441 %FunctionSetPrototype($DataView, new $Object);
442 444
443 // Set up constructor property on the DataView prototype. 445 // Setup the DataView constructor.
444 %AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); 446 %SetCode($DataView, DataViewConstructor);
445 %AddNamedProperty( 447 %FunctionSetPrototype($DataView, new $Object);
446 $DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|DONT_ENUM);
447 448
448 InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS); 449 // Set up constructor property on the DataView prototype.
449 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset); 450 %AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM);
450 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength); 451 %AddNamedProperty(
452 $DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|DONT_ENUM);
451 453
452 InstallFunctions($DataView.prototype, DONT_ENUM, [ 454 InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS);
453 "getInt8", DataViewGetInt8JS, 455 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset);
454 "setInt8", DataViewSetInt8JS, 456 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength);
455 457
456 "getUint8", DataViewGetUint8JS, 458 InstallFunctions($DataView.prototype, DONT_ENUM, [
457 "setUint8", DataViewSetUint8JS, 459 "getInt8", DataViewGetInt8JS,
460 "setInt8", DataViewSetInt8JS,
458 461
459 "getInt16", DataViewGetInt16JS, 462 "getUint8", DataViewGetUint8JS,
460 "setInt16", DataViewSetInt16JS, 463 "setUint8", DataViewSetUint8JS,
461 464
462 "getUint16", DataViewGetUint16JS, 465 "getInt16", DataViewGetInt16JS,
463 "setUint16", DataViewSetUint16JS, 466 "setInt16", DataViewSetInt16JS,
464 467
465 "getInt32", DataViewGetInt32JS, 468 "getUint16", DataViewGetUint16JS,
466 "setInt32", DataViewSetInt32JS, 469 "setUint16", DataViewSetUint16JS,
467 470
468 "getUint32", DataViewGetUint32JS, 471 "getInt32", DataViewGetInt32JS,
469 "setUint32", DataViewSetUint32JS, 472 "setInt32", DataViewSetInt32JS,
470 473
471 "getFloat32", DataViewGetFloat32JS, 474 "getUint32", DataViewGetUint32JS,
472 "setFloat32", DataViewSetFloat32JS, 475 "setUint32", DataViewSetUint32JS,
473 476
474 "getFloat64", DataViewGetFloat64JS, 477 "getFloat32", DataViewGetFloat32JS,
475 "setFloat64", DataViewSetFloat64JS 478 "setFloat32", DataViewSetFloat32JS,
476 ]);
477 479
478 })(); 480 "getFloat64", DataViewGetFloat64JS,
481 "setFloat64", DataViewSetFloat64JS
482 ]);
483 }
484
485 SetupDataView();
OLDNEW
« no previous file with comments | « src/string-iterator.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698