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 |
(...skipping 30 matching lines...) Expand all Loading... |
41 var InnerArrayFindIndex; | 41 var InnerArrayFindIndex; |
42 var InnerArrayForEach; | 42 var InnerArrayForEach; |
43 var InnerArrayIndexOf; | 43 var InnerArrayIndexOf; |
44 var InnerArrayJoin; | 44 var InnerArrayJoin; |
45 var InnerArrayLastIndexOf; | 45 var InnerArrayLastIndexOf; |
46 var InnerArrayMap; | 46 var InnerArrayMap; |
47 var InnerArraySome; | 47 var InnerArraySome; |
48 var InnerArraySort; | 48 var InnerArraySort; |
49 var InnerArrayToLocaleString; | 49 var InnerArrayToLocaleString; |
50 var IsNaN; | 50 var IsNaN; |
51 var MathMax; | |
52 var MathMin; | |
53 var PackedArrayReverse; | 51 var PackedArrayReverse; |
54 | 52 |
55 utils.Import(function(from) { | 53 utils.Import(function(from) { |
56 ArrayFrom = from.ArrayFrom; | 54 ArrayFrom = from.ArrayFrom; |
57 ArrayToString = from.ArrayToString; | 55 ArrayToString = from.ArrayToString; |
58 InnerArrayCopyWithin = from.InnerArrayCopyWithin; | 56 InnerArrayCopyWithin = from.InnerArrayCopyWithin; |
59 InnerArrayEvery = from.InnerArrayEvery; | 57 InnerArrayEvery = from.InnerArrayEvery; |
60 InnerArrayFill = from.InnerArrayFill; | 58 InnerArrayFill = from.InnerArrayFill; |
61 InnerArrayFilter = from.InnerArrayFilter; | 59 InnerArrayFilter = from.InnerArrayFilter; |
62 InnerArrayFind = from.InnerArrayFind; | 60 InnerArrayFind = from.InnerArrayFind; |
63 InnerArrayFindIndex = from.InnerArrayFindIndex; | 61 InnerArrayFindIndex = from.InnerArrayFindIndex; |
64 InnerArrayForEach = from.InnerArrayForEach; | 62 InnerArrayForEach = from.InnerArrayForEach; |
65 InnerArrayIndexOf = from.InnerArrayIndexOf; | 63 InnerArrayIndexOf = from.InnerArrayIndexOf; |
66 InnerArrayJoin = from.InnerArrayJoin; | 64 InnerArrayJoin = from.InnerArrayJoin; |
67 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf; | 65 InnerArrayLastIndexOf = from.InnerArrayLastIndexOf; |
68 InnerArrayMap = from.InnerArrayMap; | 66 InnerArrayMap = from.InnerArrayMap; |
69 InnerArrayReduce = from.InnerArrayReduce; | 67 InnerArrayReduce = from.InnerArrayReduce; |
70 InnerArrayReduceRight = from.InnerArrayReduceRight; | 68 InnerArrayReduceRight = from.InnerArrayReduceRight; |
71 InnerArraySome = from.InnerArraySome; | 69 InnerArraySome = from.InnerArraySome; |
72 InnerArraySort = from.InnerArraySort; | 70 InnerArraySort = from.InnerArraySort; |
73 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 71 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
74 IsNaN = from.IsNaN; | 72 IsNaN = from.IsNaN; |
75 MathMax = from.MathMax; | |
76 MathMin = from.MathMin; | |
77 PackedArrayReverse = from.PackedArrayReverse; | 73 PackedArrayReverse = from.PackedArrayReverse; |
78 }); | 74 }); |
79 | 75 |
80 // ------------------------------------------------------------------- | 76 // ------------------------------------------------------------------- |
81 | 77 |
82 function ConstructTypedArray(constructor, arg) { | 78 function ConstructTypedArray(constructor, arg) { |
83 // TODO(littledan): This is an approximation of the spec, which requires | 79 // TODO(littledan): This is an approximation of the spec, which requires |
84 // that only real TypedArray classes should be accepted (22.2.2.1.1) | 80 // that only real TypedArray classes should be accepted (22.2.2.1.1) |
85 if (!%IsConstructor(constructor) || IS_UNDEFINED(constructor.prototype) || | 81 if (!%IsConstructor(constructor) || IS_UNDEFINED(constructor.prototype) || |
86 !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT")) { | 82 !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT")) { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 308 |
313 | 309 |
314 function TypedArraySlice(start, end) { | 310 function TypedArraySlice(start, end) { |
315 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 311 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
316 var len = %_TypedArrayGetLength(this); | 312 var len = %_TypedArrayGetLength(this); |
317 | 313 |
318 var relativeStart = TO_INTEGER(start); | 314 var relativeStart = TO_INTEGER(start); |
319 | 315 |
320 var k; | 316 var k; |
321 if (relativeStart < 0) { | 317 if (relativeStart < 0) { |
322 k = MathMax(len + relativeStart, 0); | 318 k = MAX_SIMPLE(len + relativeStart, 0); |
323 } else { | 319 } else { |
324 k = MathMin(relativeStart, len); | 320 k = MIN_SIMPLE(relativeStart, len); |
325 } | 321 } |
326 | 322 |
327 var relativeEnd; | 323 var relativeEnd; |
328 if (IS_UNDEFINED(end)) { | 324 if (IS_UNDEFINED(end)) { |
329 relativeEnd = len; | 325 relativeEnd = len; |
330 } else { | 326 } else { |
331 relativeEnd = TO_INTEGER(end); | 327 relativeEnd = TO_INTEGER(end); |
332 } | 328 } |
333 | 329 |
334 var final; | 330 var final; |
335 if (relativeEnd < 0) { | 331 if (relativeEnd < 0) { |
336 final = MathMax(len + relativeEnd, 0); | 332 final = MAX_SIMPLE(len + relativeEnd, 0); |
337 } else { | 333 } else { |
338 final = MathMin(relativeEnd, len); | 334 final = MIN_SIMPLE(relativeEnd, len); |
339 } | 335 } |
340 | 336 |
341 var count = MathMax(final - k, 0); | 337 var count = MAX_SIMPLE(final - k, 0); |
342 var array = ConstructTypedArrayLike(this, count); | 338 var array = ConstructTypedArrayLike(this, count); |
343 // The code below is the 'then' branch; the 'else' branch species | 339 // The code below is the 'then' branch; the 'else' branch species |
344 // a memcpy. Because V8 doesn't canonicalize NaN, the difference is | 340 // a memcpy. Because V8 doesn't canonicalize NaN, the difference is |
345 // unobservable. | 341 // unobservable. |
346 var n = 0; | 342 var n = 0; |
347 while (k < final) { | 343 while (k < final) { |
348 var kValue = this[k]; | 344 var kValue = this[k]; |
349 // TODO(littledan): The spec says to throw on an error in setting; | 345 // TODO(littledan): The spec says to throw on an error in setting; |
350 // does this throw? | 346 // does this throw? |
351 array[n] = kValue; | 347 array[n] = kValue; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 "some", TypedArraySome, | 399 "some", TypedArraySome, |
404 "sort", TypedArraySort, | 400 "sort", TypedArraySort, |
405 "toString", TypedArrayToString, | 401 "toString", TypedArrayToString, |
406 "toLocaleString", TypedArrayToLocaleString | 402 "toLocaleString", TypedArrayToLocaleString |
407 ]); | 403 ]); |
408 endmacro | 404 endmacro |
409 | 405 |
410 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 406 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
411 | 407 |
412 }) | 408 }) |
OLD | NEW |