OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Patch file for dart:math library. | 5 // Patch file for dart:math library. |
6 import 'dart:_foreign_helper' show JS; | 6 import 'dart:_foreign_helper' show JS; |
7 import 'dart:_js_helper' show patch, checkNum; | 7 import 'dart:_js_helper' show patch, checkNum; |
8 | 8 |
9 @patch | 9 @patch |
10 double sqrt(num x) | 10 double sqrt(num x) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 return JS('num', r'Math.pow(#, #)', x, exponent); | 53 return JS('num', r'Math.pow(#, #)', x, exponent); |
54 } | 54 } |
55 | 55 |
56 const int _POW2_32 = 0x100000000; | 56 const int _POW2_32 = 0x100000000; |
57 | 57 |
58 @patch | 58 @patch |
59 class Random { | 59 class Random { |
60 @patch | 60 @patch |
61 factory Random([int seed]) => | 61 factory Random([int seed]) => |
62 (seed == null) ? const _JSRandom() : new _Random(seed); | 62 (seed == null) ? const _JSRandom() : new _Random(seed); |
63 | |
64 @patch | |
65 factory Random.secure() { | |
66 throw new UnsupportedError("Unsupported secure random generator"); | |
Lasse Reichstein Nielsen
2015/10/14 11:08:45
No need to write "unsupported" in the message too,
regis
2015/10/14 20:22:35
Done.
I used the message you suggested for the VM:
| |
67 } | |
63 } | 68 } |
64 | 69 |
65 class _JSRandom implements Random { | 70 class _JSRandom implements Random { |
66 // The Dart2JS implementation of Random doesn't use a seed. | 71 // The Dart2JS implementation of Random doesn't use a seed. |
67 const _JSRandom(); | 72 const _JSRandom(); |
68 | 73 |
69 int nextInt(int max) { | 74 int nextInt(int max) { |
70 if (max <= 0 || max > _POW2_32) { | 75 if (max <= 0 || max > _POW2_32) { |
71 throw new RangeError("max must be in range 0 < max ≤ 2^32, was $max"); | 76 throw new RangeError("max must be in range 0 < max ≤ 2^32, was $max"); |
72 } | 77 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 _nextState(); | 234 _nextState(); |
230 int bits27 = _lo & ((1 << 27) - 1); | 235 int bits27 = _lo & ((1 << 27) - 1); |
231 return (bits26 * _POW2_27_D + bits27) / _POW2_53_D; | 236 return (bits26 * _POW2_27_D + bits27) / _POW2_53_D; |
232 } | 237 } |
233 | 238 |
234 bool nextBool() { | 239 bool nextBool() { |
235 _nextState(); | 240 _nextState(); |
236 return (_lo & 1) == 0; | 241 return (_lo & 1) == 0; |
237 } | 242 } |
238 } | 243 } |
OLD | NEW |