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

Side by Side Diff: src/typedarray.js

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