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