Ignore:
Timestamp:
Dec 16, 2008, 1:15:22 PM (16 years ago)
Author:
Nikolas Zimmermann
Message:

Reviewed by Darin Adler.

Fixes: https://bugs.webkit.org/show_bug.cgi?id=22876

Unify random number generation in JavaScriptCore & WebCore, by introducing
wtf/RandomNumber.h and moving wtf_random/wtf_random_init out of MathExtras.h.

wtf_random_init() has been renamed to initializeRandomNumberGenerator() and
lives in it's own private header: wtf/RandomNumberSeed.h, only intended to
be used from within JavaScriptCore.

wtf_random() has been renamed to randomNumber() and lives in a public header
wtf/RandomNumber.h, usable from within JavaScriptCore & WebCore. It encapsulates
the code taking care of initializing the random number generator (only when
building without ENABLE(JSC_MULTIPLE_THREADS), otherwhise initializeThreading()
already took care of that).

Functional change on darwin: Use random() instead of rand(), as it got a larger
period (more randomness). HTMLFormElement already contains this implementation
and I just moved it in randomNumber(), as special case for PLATFORM(DARWIN).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/MathObject.cpp

    r38440 r39337  
    2727#include <wtf/Assertions.h>
    2828#include <wtf/MathExtras.h>
     29#include <wtf/RandomNumber.h>
    2930
    3031namespace JSC {
     
    211212JSValue* mathProtoFuncRandom(ExecState* exec, JSObject*, JSValue*, const ArgList&)
    212213{
    213 #if !ENABLE(JSC_MULTIPLE_THREADS)
    214     static bool didInitRandom;
    215     if (!didInitRandom) {
    216         wtf_random_init();
    217         didInitRandom = true;
    218     }
    219 #endif
    220 
    221     return jsNumber(exec, wtf_random());
     214    return jsNumber(exec, randomNumber());
    222215}
    223216
Note: See TracChangeset for help on using the changeset viewer.