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

Unified Diff: src/bootstrapper.cc

Issue 23548024: Introduce a RandonNumberGenerator class. Refactor the random/private_random uses in Isolate/Context. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Initialize random_number_generator of Isolate lazily. Created 7 years, 3 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/assembler.cc ('k') | src/flags.h » ('j') | src/flags.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 92ff269535209235ce9f05d42acdc4e9b11655de..8dd7d82bcb2250ba09232b24fd327b80d63a638f 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));
Michael Starzinger 2013/09/09 17:11:25 nit: Use assignment instead of copy constructor.
Benedikt Meurer 2013/09/10 06:08:07 Done.
+ native_context()->set_random_seed(*random_seed);
}
@@ -2410,6 +2406,14 @@ bool Genesis::ConfigureGlobalObjects(
Handle<JSObject> inner_global(
JSObject::cast(native_context()->global_object()));
+ // Initially seed the per-context random number generator
+ // using the per-isolate random number generator.
Michael Starzinger 2013/09/09 17:11:25 It seems "ConfigureGlobalObjects" is a bad name fo
Benedikt Meurer 2013/09/10 06:08:07 Just this piece of code, or the whole ConfigureGlo
Michael Starzinger 2013/09/10 08:43:31 Just this new piece of initialization.
Benedikt Meurer 2013/09/10 10:52:13 Done.
+ 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);
+
if (!global_proxy_template.IsEmpty()) {
// Configure the global proxy object.
Handle<ObjectTemplateInfo> proxy_data =
« no previous file with comments | « src/assembler.cc ('k') | src/flags.h » ('j') | src/flags.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698