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

Side by Side Diff: src/runtime/runtime-maths.cc

Issue 1798863003: Revert of Allow Math.random to be called when creating a custom startup snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@testserialize
Patch Set: Created 4 years, 9 months 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 unified diff | Download patch
« no previous file with comments | « src/js/math.js ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/base/utils/random-number-generator.h" 9 #include "src/base/utils/random-number-generator.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 222 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
223 lazily_initialize_fast_sqrt(isolate); 223 lazily_initialize_fast_sqrt(isolate);
224 return *isolate->factory()->NewNumber(fast_sqrt(x, isolate)); 224 return *isolate->factory()->NewNumber(fast_sqrt(x, isolate));
225 } 225 }
226 226
227 227
228 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { 228 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) {
229 HandleScope scope(isolate); 229 HandleScope scope(isolate);
230 DCHECK(args.length() == 1); 230 DCHECK(args.length() == 1);
231 if (isolate->serializer_enabled()) { 231 // Random numbers in the snapshot are not really that random.
232 // Random numbers in the snapshot are not really that random. And we cannot 232 CHECK(!isolate->serializer_enabled());
233 // return a typed array as it cannot be serialized. To make calling
234 // Math.random possible when creating a custom startup snapshot, we simply
235 // return a normal array with a single random number.
236 Handle<HeapNumber> random_number = isolate->factory()->NewHeapNumber(
237 isolate->random_number_generator()->NextDouble());
238 Handle<FixedArray> array_backing = isolate->factory()->NewFixedArray(1);
239 array_backing->set(0, *random_number);
240 return *isolate->factory()->NewJSArrayWithElements(array_backing);
241 }
242
243 static const int kState0Offset = 0; 233 static const int kState0Offset = 0;
244 static const int kState1Offset = 1; 234 static const int kState1Offset = 1;
245 static const int kRandomBatchSize = 64; 235 static const int kRandomBatchSize = 64;
246 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_typed_array, 0); 236 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_typed_array, 0);
247 Handle<JSTypedArray> typed_array; 237 Handle<JSTypedArray> typed_array;
248 // Allocate typed array if it does not yet exist. 238 // Allocate typed array if it does not yet exist.
249 if (maybe_typed_array->IsJSTypedArray()) { 239 if (maybe_typed_array->IsJSTypedArray()) {
250 typed_array = Handle<JSTypedArray>::cast(maybe_typed_array); 240 typed_array = Handle<JSTypedArray>::cast(maybe_typed_array);
251 } else { 241 } else {
252 static const int kByteLength = kRandomBatchSize * kDoubleSize; 242 static const int kByteLength = kRandomBatchSize * kDoubleSize;
(...skipping 22 matching lines...) Expand all
275 base::RandomNumberGenerator::XorShift128(&state0, &state1); 265 base::RandomNumberGenerator::XorShift128(&state0, &state1);
276 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); 266 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1);
277 } 267 }
278 // Persist current state. 268 // Persist current state.
279 array[kState0Offset] = uint64_to_double(state0); 269 array[kState0Offset] = uint64_to_double(state0);
280 array[kState1Offset] = uint64_to_double(state1); 270 array[kState1Offset] = uint64_to_double(state1);
281 return *typed_array; 271 return *typed_array;
282 } 272 }
283 } // namespace internal 273 } // namespace internal
284 } // namespace v8 274 } // namespace v8
OLDNEW
« no previous file with comments | « src/js/math.js ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698