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

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

Issue 1425693006: Store RNG state on function context. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/third_party/fdlibm/fdlibm.js » ('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 504261679e448b79aa4b15d0b47fc8d838a10b59..cbf33a75d4c353aa98875caccd9bf9ce53549afb 100644
--- a/src/runtime/runtime-maths.cc
+++ b/src/runtime/runtime-maths.cc
@@ -6,6 +6,7 @@
#include "src/arguments.h"
#include "src/assembler.h"
+#include "src/base/utils/random-number-generator.h"
#include "src/codegen.h"
#include "src/third_party/fdlibm/fdlibm.h"
@@ -244,5 +245,20 @@ RUNTIME_FUNCTION(Runtime_IsMinusZero) {
HeapNumber* number = HeapNumber::cast(obj);
return isolate->heap()->ToBoolean(IsMinusZero(number->value()));
}
+
+
+RUNTIME_FUNCTION(Runtime_InitializeRNG) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 0);
+ static const int kSize = 4;
+ Handle<FixedArray> array = isolate->factory()->NewFixedArray(kSize);
+ uint16_t seeds[kSize];
+ do {
+ isolate->random_number_generator()->NextBytes(seeds,
+ kSize * sizeof(*seeds));
+ } while (!(seeds[0] && seeds[1] && seeds[2] && seeds[3]));
+ for (int i = 0; i < kSize; i++) array->set(i, Smi::FromInt(seeds[i]));
+ return *isolate->factory()->NewJSArrayWithElements(array);
+}
} // namespace internal
} // namespace v8
« no previous file with comments | « src/runtime/runtime.h ('k') | src/third_party/fdlibm/fdlibm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698