Index: src/bootstrapper.cc |
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc |
index 92ff269535209235ce9f05d42acdc4e9b11655de..764c8462f870665ea87348c8f9f10a1c04d59cfc 100644 |
--- a/src/bootstrapper.cc |
+++ b/src/bootstrapper.cc |
@@ -1316,13 +1316,9 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, |
Handle<FixedArray> embedder_data = factory->NewFixedArray(2); |
native_context()->set_embedder_data(*embedder_data); |
- { |
- // Initialize the random seed slot. |
- Handle<ByteArray> zeroed_byte_array( |
- factory->NewByteArray(kRandomStateSize)); |
- native_context()->set_random_seed(*zeroed_byte_array); |
- memset(zeroed_byte_array->GetDataStartAddress(), 0, kRandomStateSize); |
- } |
+ // Allocate the random seed slot. |
+ Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize); |
+ native_context()->set_random_seed(*random_seed); |
} |
@@ -2647,6 +2643,14 @@ Genesis::Genesis(Isolate* isolate, |
InitializeExperimentalGlobal(); |
if (!InstallExperimentalNatives()) return; |
+ // Initially seed the per-context random number generator |
+ // using the per-isolate random number generator. |
+ uint32_t* state = reinterpret_cast<uint32_t*>( |
+ native_context()->random_seed()->GetDataStartAddress()); |
+ do { |
+ isolate->random_number_generator()->NextBytes(state, kRandomStateSize); |
+ } while (state[0] == 0 || state[1] == 0); |
+ |
result_ = native_context(); |
} |