Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: src/runtime/runtime-maths.cc

Issue 1806713003: Reland of Allow Math.random to be called when creating a custom startup snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@testserialize
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/js/math.js ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-maths.cc
diff --git a/src/runtime/runtime-maths.cc b/src/runtime/runtime-maths.cc
index 59bf372b00a8bab3becb3c05c6111285c98617cf..8a43c2758eb2c0051a3b3be7dbdb990ab57ef24b 100644
--- a/src/runtime/runtime-maths.cc
+++ b/src/runtime/runtime-maths.cc
@@ -228,8 +228,18 @@
RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
- // Random numbers in the snapshot are not really that random.
- CHECK(!isolate->serializer_enabled());
+ if (isolate->serializer_enabled()) {
+ // Random numbers in the snapshot are not really that random. And we cannot
+ // return a typed array as it cannot be serialized. To make calling
+ // Math.random possible when creating a custom startup snapshot, we simply
+ // return a normal array with a single random number.
+ Handle<HeapNumber> random_number = isolate->factory()->NewHeapNumber(
+ isolate->random_number_generator()->NextDouble());
+ Handle<FixedArray> array_backing = isolate->factory()->NewFixedArray(1);
+ array_backing->set(0, *random_number);
+ return *isolate->factory()->NewJSArrayWithElements(array_backing);
+ }
+
static const int kState0Offset = 0;
static const int kState1Offset = 1;
static const int kRandomBatchSize = 64;
« no previous file with comments | « src/js/math.js ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698