Skip to content

Commit

Permalink
JS math patch: Use final to share the secure random singleton
Browse files Browse the repository at this point in the history
Change-Id: Ie44720d77f10b1ad6431415ec94b73b025b49a47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217144
Auto-Submit: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
  • Loading branch information
kevmoo authored and commit-bot@chromium.org committed Oct 20, 2021
1 parent 4522d4b commit 9d4f0f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sdk/lib/_internal/js_dev_runtime/patch/math_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ const int _POW2_32 = 0x100000000;

@patch
class Random {
static Random? _secureRandom;
static final Random _secureRandom = _JSSecureRandom();

@patch
factory Random([int? seed]) =>
(seed == null) ? const _JSRandom() : _Random(seed);

@patch
factory Random.secure() => _secureRandom ??= _JSSecureRandom();
factory Random.secure() => _secureRandom;
}

class _JSRandom implements Random {
Expand Down
6 changes: 3 additions & 3 deletions sdk/lib/_internal/js_runtime/lib/math_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ const int _POW2_32 = 0x100000000;

@patch
class Random {
static Random? _secureRandom;
static final Random _secureRandom = _JSSecureRandom();

@patch
factory Random([int? seed]) =>
(seed == null) ? const _JSRandom() : new _Random(seed);
(seed == null) ? const _JSRandom() : _Random(seed);

@patch
factory Random.secure() => _secureRandom ??= _JSSecureRandom();
factory Random.secure() => _secureRandom;
}

class _JSRandom implements Random {
Expand Down

0 comments on commit 9d4f0f9

Please sign in to comment.