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

Side by Side Diff: src/bootstrapper.cc

Issue 68723002: Implement Math.random() purely in JavaScript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 native_context()->set_call_as_constructor_delegate(*delegate); 1301 native_context()->set_call_as_constructor_delegate(*delegate);
1302 delegate->shared()->DontAdaptArguments(); 1302 delegate->shared()->DontAdaptArguments();
1303 } 1303 }
1304 1304
1305 // Initialize the out of memory slot. 1305 // Initialize the out of memory slot.
1306 native_context()->set_out_of_memory(heap->false_value()); 1306 native_context()->set_out_of_memory(heap->false_value());
1307 1307
1308 // Initialize the embedder data slot. 1308 // Initialize the embedder data slot.
1309 Handle<FixedArray> embedder_data = factory->NewFixedArray(2); 1309 Handle<FixedArray> embedder_data = factory->NewFixedArray(2);
1310 native_context()->set_embedder_data(*embedder_data); 1310 native_context()->set_embedder_data(*embedder_data);
1311
1312 // Allocate the random seed slot.
1313 Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize);
1314 native_context()->set_random_seed(*random_seed);
1315 } 1311 }
1316 1312
1317 1313
1318 Handle<JSFunction> Genesis::InstallTypedArray( 1314 Handle<JSFunction> Genesis::InstallTypedArray(
1319 const char* name, ElementsKind elementsKind) { 1315 const char* name, ElementsKind elementsKind) {
1320 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); 1316 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
1321 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, 1317 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE,
1322 JSTypedArray::kSize, isolate()->initial_object_prototype(), 1318 JSTypedArray::kSize, isolate()->initial_object_prototype(),
1323 Builtins::kIllegal, false, true); 1319 Builtins::kIllegal, false, true);
1324 1320
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 if (!ConfigureGlobalObjects(global_template)) return; 2626 if (!ConfigureGlobalObjects(global_template)) return;
2631 isolate->counters()->contexts_created_from_scratch()->Increment(); 2627 isolate->counters()->contexts_created_from_scratch()->Increment();
2632 } 2628 }
2633 2629
2634 // Initialize experimental globals and install experimental natives. 2630 // Initialize experimental globals and install experimental natives.
2635 InitializeExperimentalGlobal(); 2631 InitializeExperimentalGlobal();
2636 if (!InstallExperimentalNatives()) return; 2632 if (!InstallExperimentalNatives()) return;
2637 2633
2638 // Initially seed the per-context random number generator 2634 // Initially seed the per-context random number generator
2639 // using the per-isolate random number generator. 2635 // using the per-isolate random number generator.
2640 uint32_t* state = reinterpret_cast<uint32_t*>( 2636 uint32_t state[2];
2641 native_context()->random_seed()->GetDataStartAddress());
2642 do { 2637 do {
2643 isolate->random_number_generator()->NextBytes(state, kRandomStateSize); 2638 isolate->random_number_generator()->NextBytes(state, sizeof(state));
2644 } while (state[0] == 0 || state[1] == 0); 2639 } while (state[0] == 0 || state[1] == 0);
2640 Handle<JSBuiltinsObject> builtins(native_context()->builtins());
2641 ForceSetProperty(builtins,
2642 factory()->InternalizeOneByteString(
2643 STATIC_ASCII_VECTOR("random0")),
2644 factory()->NewHeapNumber(state[0]),
Michael Starzinger 2013/11/11 14:11:12 Better use Factory::NewNumberFromUint here and in
Sven Panne 2013/11/12 07:09:12 Done.
2645 NONE);
2646 ForceSetProperty(builtins,
2647 factory()->InternalizeOneByteString(
2648 STATIC_ASCII_VECTOR("random1")),
2649 factory()->NewHeapNumber(state[1]),
2650 NONE);
2645 2651
2646 result_ = native_context(); 2652 result_ = native_context();
2647 } 2653 }
2648 2654
2649 2655
2650 // Support for thread preemption. 2656 // Support for thread preemption.
2651 2657
2652 // Reserve space for statics needing saving and restoring. 2658 // Reserve space for statics needing saving and restoring.
2653 int Bootstrapper::ArchiveSpacePerThread() { 2659 int Bootstrapper::ArchiveSpacePerThread() {
2654 return sizeof(NestingCounterType); 2660 return sizeof(NestingCounterType);
(...skipping 14 matching lines...) Expand all
2669 return from + sizeof(NestingCounterType); 2675 return from + sizeof(NestingCounterType);
2670 } 2676 }
2671 2677
2672 2678
2673 // Called when the top-level V8 mutex is destroyed. 2679 // Called when the top-level V8 mutex is destroyed.
2674 void Bootstrapper::FreeThreadResources() { 2680 void Bootstrapper::FreeThreadResources() {
2675 ASSERT(!IsActive()); 2681 ASSERT(!IsActive());
2676 } 2682 }
2677 2683
2678 } } // namespace v8::internal 2684 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698