OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "use strict"; | 6 "use strict"; |
7 | 7 |
8 %CheckIsBootstrapping(); | 8 %CheckIsBootstrapping(); |
9 | 9 |
10 // ------------------------------------------------------------------- | 10 // ------------------------------------------------------------------- |
(...skipping 29 matching lines...) Expand all Loading... |
40 randomNumbers = %GenerateRandomNumbers(randomNumbers); | 40 randomNumbers = %GenerateRandomNumbers(randomNumbers); |
41 if (%_IsTypedArray(randomNumbers)) { | 41 if (%_IsTypedArray(randomNumbers)) { |
42 nextRandomIndex = %_TypedArrayGetLength(randomNumbers); | 42 nextRandomIndex = %_TypedArrayGetLength(randomNumbers); |
43 } else { | 43 } else { |
44 nextRandomIndex = randomNumbers.length; | 44 nextRandomIndex = randomNumbers.length; |
45 } | 45 } |
46 } | 46 } |
47 return randomNumbers[--nextRandomIndex]; | 47 return randomNumbers[--nextRandomIndex]; |
48 } | 48 } |
49 | 49 |
50 function MathRandomRaw() { | |
51 if (nextRandomIndex <= kRandomNumberStart) { | |
52 randomNumbers = %GenerateRandomNumbers(randomNumbers); | |
53 nextRandomIndex = %_TypedArrayGetLength(randomNumbers); | |
54 } | |
55 return %_DoubleLo(randomNumbers[--nextRandomIndex]) & 0x3FFFFFFF; | |
56 } | |
57 | |
58 // ES6 draft 09-27-13, section 20.2.2.28. | 50 // ES6 draft 09-27-13, section 20.2.2.28. |
59 function MathSign(x) { | 51 function MathSign(x) { |
60 x = +x; | 52 x = +x; |
61 if (x > 0) return 1; | 53 if (x > 0) return 1; |
62 if (x < 0) return -1; | 54 if (x < 0) return -1; |
63 // -0, 0 or NaN. | 55 // -0, 0 or NaN. |
64 return x; | 56 return x; |
65 } | 57 } |
66 | 58 |
67 // ES6 draft 09-27-13, section 20.2.2.5. | 59 // ES6 draft 09-27-13, section 20.2.2.5. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 ]); | 127 ]); |
136 | 128 |
137 %SetForceInlineFlag(MathRandom); | 129 %SetForceInlineFlag(MathRandom); |
138 %SetForceInlineFlag(MathSign); | 130 %SetForceInlineFlag(MathSign); |
139 | 131 |
140 // ------------------------------------------------------------------- | 132 // ------------------------------------------------------------------- |
141 // Exports | 133 // Exports |
142 | 134 |
143 utils.Export(function(to) { | 135 utils.Export(function(to) { |
144 to.MathAbs = MathAbs; | 136 to.MathAbs = MathAbs; |
145 to.IntRandom = MathRandomRaw; | 137 to.MathRandom = MathRandom; |
146 }); | 138 }); |
147 | 139 |
148 }) | 140 }) |
OLD | NEW |