Reviewers: Dmitry Lomov (chromium),
Message:
PTAL
Description:
Let SetEntropySource() fail if called after V8::Initialize().
BUG=v8:2905
Please review this at https://codereview.chromium.org/24357002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+15, -2 lines):
M include/v8.h
M src/api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
79f4478ea6f626ff297314b4ed227d5dc088abed..0425d625f85d200974046a27e2afdf194fb24fc6
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -4511,8 +4511,13 @@ class V8_EXPORT V8 {
/**
* Allows the host application to provide a callback which can be used
* as a source of entropy for random number generators.
+ *
+ * \returns true if the entropy source was installed successfully, false
+ * on failure.
+ * \note Setting an entropy source can only be done very early prior to
+ * calling any other V8-related function.
*/
- static void SetEntropySource(EntropySource source);
+ static bool SetEntropySource(EntropySource source);
/**
* Allows the host application to provide a callback that allows v8 to
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
415bd41bb19496036f3bda9a6c78ac55ec033ecd..5e9cd65d2c206bda763ddf8ce84cb9b238088d7f
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -5181,8 +5181,16 @@ bool v8::V8::Initialize() {
}
-void v8::V8::SetEntropySource(EntropySource entropy_source) {
+bool v8::V8::SetEntropySource(EntropySource entropy_source) {
+ // The entropy source must be set before the library is initialized,
+ // as otherwise not all random number generators will pick up the
+ // entropy source and will fall back to weak entropy instead.
+ i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+ if (isolate != NULL && isolate->IsInitialized())
+ return false;
+
i::RandomNumberGenerator::SetEntropySource(entropy_source);
+ return true;
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.