Let SetEntropySource() fail if called after V8::Initialize().

BUG=v8:2905
R=dslomov@chromium.org

Review URL: https://codereview.chromium.org/24357002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16889 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2013-09-23 14:11:32 +00:00
parent 4af9fa967b
commit c5751ce72c
2 changed files with 10 additions and 0 deletions

View File

@ -4540,6 +4540,9 @@ 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.
*
* \note Setting an entropy source can only be done very early prior to
* calling Initialize().
*/
static void SetEntropySource(EntropySource source);

View File

@ -5175,6 +5175,13 @@ bool v8::V8::Initialize() {
void 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();
ApiCheck(isolate != NULL && isolate->IsInitialized(),
"v8::V8::SetEntropySource",
"Cannot set entropy source once V8 is initialized.");
i::RandomNumberGenerator::SetEntropySource(entropy_source);
}