[webkit-changes] cvs commit: JavaScriptCore/kjs math_object.cpp

Geoffrey ggaren at opensource.apple.com
Thu Dec 29 03:02:07 PST 2005


ggaren      05/12/29 03:02:07

  Modified:    .        ChangeLog
               kjs      math_object.cpp
  Log:
          Reviewed by mjs.
  
          - Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4026
          Math.random() not seeded.
  
          Added call to sranddev() -- it executes the first time a process
          calls Math.random().
  
          * kjs/math_object.cpp:
          (MathFuncImp::callAsFunction):
  
  Revision  Changes    Path
  1.938     +13 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.937
  retrieving revision 1.938
  diff -u -r1.937 -r1.938
  --- ChangeLog	29 Dec 2005 10:11:21 -0000	1.937
  +++ ChangeLog	29 Dec 2005 11:02:05 -0000	1.938
  @@ -1,5 +1,18 @@
   2005-12-29  Geoffrey Garen  <ggaren at apple.com>
   
  +        Reviewed by mjs.
  +
  +        - Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4026
  +        Math.random() not seeded.
  +
  +        Added call to sranddev() -- it executes the first time a process
  +        calls Math.random().
  +
  +        * kjs/math_object.cpp:
  +        (MathFuncImp::callAsFunction):
  +
  +2005-12-29  Geoffrey Garen  <ggaren at apple.com>
  +
           Reviewed by darin.
   
           - Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=6265
  
  
  
  1.23      +9 -3      JavaScriptCore/kjs/math_object.cpp
  
  Index: math_object.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/math_object.cpp,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- math_object.cpp	11 Dec 2005 02:05:45 -0000	1.22
  +++ math_object.cpp	29 Dec 2005 11:02:07 -0000	1.23
  @@ -23,6 +23,7 @@
   #include <math.h>
   #include <stdlib.h>
   #include <assert.h>
  +#include <time.h>
   
   #include "value.h"
   #include "object.h"
  @@ -150,6 +151,8 @@
   
   // ------------------------------ MathObjectImp --------------------------------
   
  +static bool randomSeeded = false;
  +
   MathFuncImp::MathFuncImp(ExecState *exec, int i, int l)
     : InternalFunctionImp(
       static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype())
  @@ -258,9 +261,12 @@
         result = ::pow(arg, arg2);
       break;
     case MathObjectImp::Random:
  -    result = ::rand();
  -    result = result / RAND_MAX;
  -    break;
  +      if (!randomSeeded) {
  +          sranddev();
  +          randomSeeded = true;
  +      }
  +      result = (double)rand() / RAND_MAX;
  +      break;
     case MathObjectImp::Round:
       if (signbit(arg) && arg >= -0.5)
           result = -0.0;
  
  
  



More information about the webkit-changes mailing list