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

Side by Side Diff: src/typedarray.js

Issue 1121453003: Revert of Wrap v8natives.js into a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/third_party/fdlibm/fdlibm.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
11 var GlobalArray = global.Array; 11 var GlobalArray = global.Array;
12 var GlobalArrayBuffer = global.ArrayBuffer; 12 var GlobalArrayBuffer = global.ArrayBuffer;
13 var GlobalDataView = global.DataView;
14 var GlobalObject = global.Object;
15 13
14 // --------------- Typed Arrays ---------------------
16 macro TYPED_ARRAYS(FUNCTION) 15 macro TYPED_ARRAYS(FUNCTION)
17 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. 16 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
18 FUNCTION(1, Uint8Array, 1) 17 FUNCTION(1, Uint8Array, 1)
19 FUNCTION(2, Int8Array, 1) 18 FUNCTION(2, Int8Array, 1)
20 FUNCTION(3, Uint16Array, 2) 19 FUNCTION(3, Uint16Array, 2)
21 FUNCTION(4, Int16Array, 2) 20 FUNCTION(4, Int16Array, 2)
22 FUNCTION(5, Uint32Array, 4) 21 FUNCTION(5, Uint32Array, 4)
23 FUNCTION(6, Int32Array, 4) 22 FUNCTION(6, Int32Array, 4)
24 FUNCTION(7, Float32Array, 4) 23 FUNCTION(7, Float32Array, 4)
25 FUNCTION(8, Float64Array, 8) 24 FUNCTION(8, Float64Array, 8)
26 FUNCTION(9, Uint8ClampedArray, 1) 25 FUNCTION(9, Uint8ClampedArray, 1)
27 endmacro 26 endmacro
28 27
29 macro DECLARE_GLOBALS(INDEX, NAME, SIZE)
30 var GlobalNAME = global.NAME;
31 endmacro
32
33 TYPED_ARRAYS(DECLARE_GLOBALS)
34
35 // --------------- Typed Arrays ---------------------
36
37 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) 28 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
38 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { 29 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
39 if (!IS_UNDEFINED(byteOffset)) { 30 if (!IS_UNDEFINED(byteOffset)) {
40 byteOffset = 31 byteOffset =
41 ToPositiveInteger(byteOffset, "invalid_typed_array_length"); 32 ToPositiveInteger(byteOffset, "invalid_typed_array_length");
42 } 33 }
43 if (!IS_UNDEFINED(length)) { 34 if (!IS_UNDEFINED(length)) {
44 length = ToPositiveInteger(length, "invalid_typed_array_length"); 35 length = ToPositiveInteger(length, "invalid_typed_array_length");
45 } 36 }
46 37
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return %_ArrayBufferViewGetByteOffset(this); 138 return %_ArrayBufferViewGetByteOffset(this);
148 } 139 }
149 140
150 function NAME_GetLength() { 141 function NAME_GetLength() {
151 if (!(%_ClassOf(this) === 'NAME')) { 142 if (!(%_ClassOf(this) === 'NAME')) {
152 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this); 143 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this);
153 } 144 }
154 return %_TypedArrayGetLength(this); 145 return %_TypedArrayGetLength(this);
155 } 146 }
156 147
148 var $NAME = global.NAME;
149
157 function NAMESubArray(begin, end) { 150 function NAMESubArray(begin, end) {
158 if (!(%_ClassOf(this) === 'NAME')) { 151 if (!(%_ClassOf(this) === 'NAME')) {
159 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); 152 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this);
160 } 153 }
161 var beginInt = TO_INTEGER(begin); 154 var beginInt = TO_INTEGER(begin);
162 if (!IS_UNDEFINED(end)) { 155 if (!IS_UNDEFINED(end)) {
163 end = TO_INTEGER(end); 156 end = TO_INTEGER(end);
164 } 157 }
165 158
166 var srcLength = %_TypedArrayGetLength(this); 159 var srcLength = %_TypedArrayGetLength(this);
167 if (beginInt < 0) { 160 if (beginInt < 0) {
168 beginInt = $max(0, srcLength + beginInt); 161 beginInt = $max(0, srcLength + beginInt);
169 } else { 162 } else {
170 beginInt = $min(srcLength, beginInt); 163 beginInt = $min(srcLength, beginInt);
171 } 164 }
172 165
173 var endInt = IS_UNDEFINED(end) ? srcLength : end; 166 var endInt = IS_UNDEFINED(end) ? srcLength : end;
174 if (endInt < 0) { 167 if (endInt < 0) {
175 endInt = $max(0, srcLength + endInt); 168 endInt = $max(0, srcLength + endInt);
176 } else { 169 } else {
177 endInt = $min(endInt, srcLength); 170 endInt = $min(endInt, srcLength);
178 } 171 }
179 if (endInt < beginInt) { 172 if (endInt < beginInt) {
180 endInt = beginInt; 173 endInt = beginInt;
181 } 174 }
182 var newLength = endInt - beginInt; 175 var newLength = endInt - beginInt;
183 var beginByteOffset = 176 var beginByteOffset =
184 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; 177 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
185 return new GlobalNAME(%TypedArrayGetBuffer(this), 178 return new $NAME(%TypedArrayGetBuffer(this),
186 beginByteOffset, newLength); 179 beginByteOffset, newLength);
187 } 180 }
188 endmacro 181 endmacro
189 182
190 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) 183 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
191 184
192 185
193 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { 186 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
194 if (offset > 0) { 187 if (offset > 0) {
195 for (var i = 0; i < sourceLength; i++) { 188 for (var i = 0; i < sourceLength; i++) {
196 target[offset + i] = source[i]; 189 target[offset + i] = source[i];
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 function TypedArrayGetToStringTag() { 290 function TypedArrayGetToStringTag() {
298 if (!%IsTypedArray(this)) return; 291 if (!%IsTypedArray(this)) return;
299 var name = %_ClassOf(this); 292 var name = %_ClassOf(this);
300 if (IS_UNDEFINED(name)) return; 293 if (IS_UNDEFINED(name)) return;
301 return name; 294 return name;
302 } 295 }
303 296
304 // ------------------------------------------------------------------- 297 // -------------------------------------------------------------------
305 298
306 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 299 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
307 %SetCode(GlobalNAME, NAMEConstructor); 300 %SetCode(global.NAME, NAMEConstructor);
308 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); 301 %FunctionSetPrototype(global.NAME, new $Object());
309 302
310 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, 303 %AddNamedProperty(global.NAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
311 READ_ONLY | DONT_ENUM | DONT_DELETE); 304 READ_ONLY | DONT_ENUM | DONT_DELETE);
312 %AddNamedProperty(GlobalNAME.prototype, 305 %AddNamedProperty(global.NAME.prototype,
313 "constructor", global.NAME, DONT_ENUM); 306 "constructor", global.NAME, DONT_ENUM);
314 %AddNamedProperty(GlobalNAME.prototype, 307 %AddNamedProperty(global.NAME.prototype,
315 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 308 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
316 READ_ONLY | DONT_ENUM | DONT_DELETE); 309 READ_ONLY | DONT_ENUM | DONT_DELETE);
317 $installGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer); 310 InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer);
318 $installGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset, 311 InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset,
319 DONT_ENUM | DONT_DELETE); 312 DONT_ENUM | DONT_DELETE);
320 $installGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength, 313 InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength,
321 DONT_ENUM | DONT_DELETE); 314 DONT_ENUM | DONT_DELETE);
322 $installGetter(GlobalNAME.prototype, "length", NAME_GetLength, 315 InstallGetter(global.NAME.prototype, "length", NAME_GetLength,
323 DONT_ENUM | DONT_DELETE); 316 DONT_ENUM | DONT_DELETE);
324 $installGetter(GlobalNAME.prototype, symbolToStringTag, 317 InstallGetter(global.NAME.prototype, symbolToStringTag,
325 TypedArrayGetToStringTag); 318 TypedArrayGetToStringTag);
326 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ 319 InstallFunctions(global.NAME.prototype, DONT_ENUM, [
327 "subarray", NAMESubArray, 320 "subarray", NAMESubArray,
328 "set", TypedArraySet 321 "set", TypedArraySet
329 ]); 322 ]);
330 endmacro 323 endmacro
331 324
332 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 325 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
333 326
334 // --------------------------- DataView ----------------------------- 327 // --------------------------- DataView -----------------------------
335 328
329 var $DataView = global.DataView;
330
336 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 331 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
337 if (%_IsConstructCall()) { 332 if (%_IsConstructCall()) {
338 if (!IS_ARRAYBUFFER(buffer)) { 333 if (!IS_ARRAYBUFFER(buffer)) {
339 throw MakeTypeError('data_view_not_array_buffer', []); 334 throw MakeTypeError('data_view_not_array_buffer', []);
340 } 335 }
341 if (!IS_UNDEFINED(byteOffset)) { 336 if (!IS_UNDEFINED(byteOffset)) {
342 byteOffset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); 337 byteOffset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
343 } 338 }
344 if (!IS_UNDEFINED(byteLength)) { 339 if (!IS_UNDEFINED(byteLength)) {
345 byteLength = TO_INTEGER(byteLength); 340 byteLength = TO_INTEGER(byteLength);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 %DataViewSetTYPENAME(this, 423 %DataViewSetTYPENAME(this,
429 ToPositiveDataViewOffset(offset), 424 ToPositiveDataViewOffset(offset),
430 TO_NUMBER_INLINE(value), 425 TO_NUMBER_INLINE(value),
431 !!little_endian); 426 !!little_endian);
432 } 427 }
433 endmacro 428 endmacro
434 429
435 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) 430 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)
436 431
437 // Setup the DataView constructor. 432 // Setup the DataView constructor.
438 %SetCode(GlobalDataView, DataViewConstructor); 433 %SetCode($DataView, DataViewConstructor);
439 %FunctionSetPrototype(GlobalDataView, new GlobalObject); 434 %FunctionSetPrototype($DataView, new $Object);
440 435
441 // Set up constructor property on the DataView prototype. 436 // Set up constructor property on the DataView prototype.
442 %AddNamedProperty(GlobalDataView.prototype, "constructor", GlobalDataView, 437 %AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM);
443 DONT_ENUM); 438 %AddNamedProperty(
444 %AddNamedProperty(GlobalDataView.prototype, symbolToStringTag, "DataView", 439 $DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|DONT_ENUM);
445 READ_ONLY|DONT_ENUM);
446 440
447 $installGetter(GlobalDataView.prototype, "buffer", DataViewGetBufferJS); 441 InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS);
448 $installGetter(GlobalDataView.prototype, "byteOffset", DataViewGetByteOffset); 442 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset);
449 $installGetter(GlobalDataView.prototype, "byteLength", DataViewGetByteLength); 443 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength);
450 444
451 $installFunctions(GlobalDataView.prototype, DONT_ENUM, [ 445 InstallFunctions($DataView.prototype, DONT_ENUM, [
452 "getInt8", DataViewGetInt8JS, 446 "getInt8", DataViewGetInt8JS,
453 "setInt8", DataViewSetInt8JS, 447 "setInt8", DataViewSetInt8JS,
454 448
455 "getUint8", DataViewGetUint8JS, 449 "getUint8", DataViewGetUint8JS,
456 "setUint8", DataViewSetUint8JS, 450 "setUint8", DataViewSetUint8JS,
457 451
458 "getInt16", DataViewGetInt16JS, 452 "getInt16", DataViewGetInt16JS,
459 "setInt16", DataViewSetInt16JS, 453 "setInt16", DataViewSetInt16JS,
460 454
461 "getUint16", DataViewGetUint16JS, 455 "getUint16", DataViewGetUint16JS,
462 "setUint16", DataViewSetUint16JS, 456 "setUint16", DataViewSetUint16JS,
463 457
464 "getInt32", DataViewGetInt32JS, 458 "getInt32", DataViewGetInt32JS,
465 "setInt32", DataViewSetInt32JS, 459 "setInt32", DataViewSetInt32JS,
466 460
467 "getUint32", DataViewGetUint32JS, 461 "getUint32", DataViewGetUint32JS,
468 "setUint32", DataViewSetUint32JS, 462 "setUint32", DataViewSetUint32JS,
469 463
470 "getFloat32", DataViewGetFloat32JS, 464 "getFloat32", DataViewGetFloat32JS,
471 "setFloat32", DataViewSetFloat32JS, 465 "setFloat32", DataViewSetFloat32JS,
472 466
473 "getFloat64", DataViewGetFloat64JS, 467 "getFloat64", DataViewGetFloat64JS,
474 "setFloat64", DataViewSetFloat64JS 468 "setFloat64", DataViewSetFloat64JS
475 ]); 469 ]);
476 470
477 })(); 471 })();
OLDNEW
« no previous file with comments | « src/third_party/fdlibm/fdlibm.js ('k') | src/uri.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698