OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
| 14 macro TYPED_ARRAYS(FUNCTION) |
| 15 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 16 FUNCTION(Uint8Array) |
| 17 FUNCTION(Int8Array) |
| 18 FUNCTION(Uint16Array) |
| 19 FUNCTION(Int16Array) |
| 20 FUNCTION(Uint32Array) |
| 21 FUNCTION(Int32Array) |
| 22 FUNCTION(Float32Array) |
| 23 FUNCTION(Float64Array) |
| 24 FUNCTION(Uint8ClampedArray) |
| 25 endmacro |
14 | 26 |
15 macro DECLARE_GLOBALS(NAME) | 27 macro DECLARE_GLOBALS(NAME) |
16 var GlobalNAME = global.NAME; | 28 var GlobalNAME = global.NAME; |
17 endmacro | 29 endmacro |
18 | 30 |
| 31 TYPED_ARRAYS(DECLARE_GLOBALS) |
19 DECLARE_GLOBALS(Array) | 32 DECLARE_GLOBALS(Array) |
20 DECLARE_GLOBALS(Uint8Array) | |
21 DECLARE_GLOBALS(Int8Array) | |
22 DECLARE_GLOBALS(Uint16Array) | |
23 DECLARE_GLOBALS(Int16Array) | |
24 DECLARE_GLOBALS(Uint32Array) | |
25 DECLARE_GLOBALS(Int32Array) | |
26 DECLARE_GLOBALS(Float32Array) | |
27 DECLARE_GLOBALS(Float64Array) | |
28 DECLARE_GLOBALS(Uint8ClampedArray) | |
29 | 33 |
30 var ArrayFrom; | 34 var ArrayFrom; |
31 var ArrayToString; | 35 var ArrayToString; |
32 var InnerArrayCopyWithin; | 36 var InnerArrayCopyWithin; |
33 var InnerArrayEvery; | 37 var InnerArrayEvery; |
34 var InnerArrayFill; | 38 var InnerArrayFill; |
35 var InnerArrayFilter; | 39 var InnerArrayFilter; |
36 var InnerArrayFind; | 40 var InnerArrayFind; |
37 var InnerArrayFindIndex; | 41 var InnerArrayFindIndex; |
38 var InnerArrayForEach; | 42 var InnerArrayForEach; |
39 var InnerArrayIndexOf; | 43 var InnerArrayIndexOf; |
40 var InnerArrayJoin; | 44 var InnerArrayJoin; |
41 var InnerArrayLastIndexOf; | 45 var InnerArrayLastIndexOf; |
42 var InnerArrayMap; | 46 var InnerArrayMap; |
43 var InnerArrayReverse; | 47 var InnerArrayReverse; |
44 var InnerArraySome; | 48 var InnerArraySome; |
45 var InnerArraySort; | 49 var InnerArraySort; |
46 var InnerArrayToLocaleString; | 50 var InnerArrayToLocaleString; |
47 var IsNaN; | 51 var IsNaN; |
48 var MathMax; | 52 var MathMax; |
49 var MathMin; | 53 var MathMin; |
50 var TypedArray = GlobalUint8Array.__proto__; | |
51 var TypedArrayPrototype = GlobalUint8Array.prototype.__proto__; | |
52 | 54 |
53 utils.Import(function(from) { | 55 utils.Import(function(from) { |
54 ArrayFrom = from.ArrayFrom; | 56 ArrayFrom = from.ArrayFrom; |
55 ArrayToString = from.ArrayToString; | 57 ArrayToString = from.ArrayToString; |
56 InnerArrayCopyWithin = from.InnerArrayCopyWithin; | 58 InnerArrayCopyWithin = from.InnerArrayCopyWithin; |
57 InnerArrayEvery = from.InnerArrayEvery; | 59 InnerArrayEvery = from.InnerArrayEvery; |
58 InnerArrayFill = from.InnerArrayFill; | 60 InnerArrayFill = from.InnerArrayFill; |
59 InnerArrayFilter = from.InnerArrayFilter; | 61 InnerArrayFilter = from.InnerArrayFilter; |
60 InnerArrayFind = from.InnerArrayFind; | 62 InnerArrayFind = from.InnerArrayFind; |
61 InnerArrayFindIndex = from.InnerArrayFindIndex; | 63 InnerArrayFindIndex = from.InnerArrayFindIndex; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 369 |
368 | 370 |
369 function TypedArrayFrom(source, mapfn, thisArg) { | 371 function TypedArrayFrom(source, mapfn, thisArg) { |
370 // TODO(littledan): Investigate if there is a receiver which could be | 372 // TODO(littledan): Investigate if there is a receiver which could be |
371 // faster to accumulate on than Array, e.g., a TypedVector. | 373 // faster to accumulate on than Array, e.g., a TypedVector. |
372 var array = %_CallFunction(GlobalArray, source, mapfn, thisArg, ArrayFrom); | 374 var array = %_CallFunction(GlobalArray, source, mapfn, thisArg, ArrayFrom); |
373 return ConstructTypedArray(this, array); | 375 return ConstructTypedArray(this, array); |
374 } | 376 } |
375 %FunctionSetLength(TypedArrayFrom, 1); | 377 %FunctionSetLength(TypedArrayFrom, 1); |
376 | 378 |
| 379 // TODO(littledan): Fix the TypedArray proto chain (bug v8:4085). |
| 380 macro EXTEND_TYPED_ARRAY(NAME) |
377 // Set up non-enumerable functions on the object. | 381 // Set up non-enumerable functions on the object. |
378 utils.InstallFunctions(TypedArray, DONT_ENUM | DONT_DELETE | READ_ONLY, [ | 382 utils.InstallFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ |
379 "from", TypedArrayFrom, | 383 "from", TypedArrayFrom, |
380 "of", TypedArrayOf | 384 "of", TypedArrayOf |
381 ]); | 385 ]); |
382 | 386 |
383 // Set up non-enumerable functions on the prototype object. | 387 // Set up non-enumerable functions on the prototype object. |
384 utils.InstallFunctions(TypedArrayPrototype, DONT_ENUM, [ | 388 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
385 "copyWithin", TypedArrayCopyWithin, | 389 "copyWithin", TypedArrayCopyWithin, |
386 "every", TypedArrayEvery, | 390 "every", TypedArrayEvery, |
387 "fill", TypedArrayFill, | 391 "fill", TypedArrayFill, |
388 "filter", TypedArrayFilter, | 392 "filter", TypedArrayFilter, |
389 "find", TypedArrayFind, | 393 "find", TypedArrayFind, |
390 "findIndex", TypedArrayFindIndex, | 394 "findIndex", TypedArrayFindIndex, |
391 "indexOf", TypedArrayIndexOf, | 395 "indexOf", TypedArrayIndexOf, |
392 "join", TypedArrayJoin, | 396 "join", TypedArrayJoin, |
393 "lastIndexOf", TypedArrayLastIndexOf, | 397 "lastIndexOf", TypedArrayLastIndexOf, |
394 "forEach", TypedArrayForEach, | 398 "forEach", TypedArrayForEach, |
395 "map", TypedArrayMap, | 399 "map", TypedArrayMap, |
396 "reduce", TypedArrayReduce, | 400 "reduce", TypedArrayReduce, |
397 "reduceRight", TypedArrayReduceRight, | 401 "reduceRight", TypedArrayReduceRight, |
398 "reverse", TypedArrayReverse, | 402 "reverse", TypedArrayReverse, |
399 "slice", TypedArraySlice, | 403 "slice", TypedArraySlice, |
400 "some", TypedArraySome, | 404 "some", TypedArraySome, |
401 "sort", TypedArraySort, | 405 "sort", TypedArraySort, |
402 "toString", TypedArrayToString, | 406 "toString", TypedArrayToString, |
403 "toLocaleString", TypedArrayToLocaleString | 407 "toLocaleString", TypedArrayToLocaleString |
404 ]); | 408 ]); |
| 409 endmacro |
| 410 |
| 411 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
405 | 412 |
406 }) | 413 }) |
OLD | NEW |