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

Unified Diff: src/bootstrapper.cc

Issue 68723002: Implement Math.random() purely in JavaScript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 234a2118bdd7002189906df3e21f6446869f594e..c2c6d1b6e7a244793313a971aa57aaf5b8c28e19 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1308,10 +1308,6 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
// Initialize the embedder data slot.
Handle<FixedArray> embedder_data = factory->NewFixedArray(2);
native_context()->set_embedder_data(*embedder_data);
-
- // Allocate the random seed slot.
- Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize);
- native_context()->set_random_seed(*random_seed);
}
@@ -2637,11 +2633,21 @@ Genesis::Genesis(Isolate* isolate,
// 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());
+ uint32_t state[2];
do {
- isolate->random_number_generator()->NextBytes(state, kRandomStateSize);
+ isolate->random_number_generator()->NextBytes(state, sizeof(state));
} while (state[0] == 0 || state[1] == 0);
+ Handle<JSBuiltinsObject> builtins(native_context()->builtins());
+ ForceSetProperty(builtins,
+ factory()->InternalizeOneByteString(
+ STATIC_ASCII_VECTOR("random0")),
+ factory()->NewHeapNumber(state[0]),
Michael Starzinger 2013/11/11 14:11:12 Better use Factory::NewNumberFromUint here and in
Sven Panne 2013/11/12 07:09:12 Done.
+ NONE);
+ ForceSetProperty(builtins,
+ factory()->InternalizeOneByteString(
+ STATIC_ASCII_VECTOR("random1")),
+ factory()->NewHeapNumber(state[1]),
+ NONE);
result_ = native_context();
}

Powered by Google App Engine
This is Rietveld 408576698