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

Side by Side Diff: src/v8.cc

Issue 82763005: Reland "Implement Math.random() purely in JavaScript" plus fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added assertion 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
« no previous file with comments | « src/v8.h ('k') | src/x64/full-codegen-x64.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 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 #endif 112 #endif
113 } 113 }
114 114
115 115
116 void V8::SetReturnAddressLocationResolver( 116 void V8::SetReturnAddressLocationResolver(
117 ReturnAddressLocationResolver resolver) { 117 ReturnAddressLocationResolver resolver) {
118 StackFrame::SetReturnAddressLocationResolver(resolver); 118 StackFrame::SetReturnAddressLocationResolver(resolver);
119 } 119 }
120 120
121 121
122 // Used by JavaScript APIs
123 uint32_t V8::Random(Context* context) {
124 ASSERT(context->IsNativeContext());
125 ByteArray* seed = context->random_seed();
126 uint32_t* state = reinterpret_cast<uint32_t*>(seed->GetDataStartAddress());
127
128 // When we get here, the RNG must have been initialized,
129 // see the Genesis constructor in file bootstrapper.cc.
130 ASSERT_NE(0, state[0]);
131 ASSERT_NE(0, state[1]);
132
133 // Mix the bits. Never replaces state[i] with 0 if it is nonzero.
134 state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16);
135 state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16);
136
137 return (state[0] << 14) + (state[1] & 0x3FFFF);
138 }
139
140
141 void V8::AddCallCompletedCallback(CallCompletedCallback callback) { 122 void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
142 if (call_completed_callbacks_ == NULL) { // Lazy init. 123 if (call_completed_callbacks_ == NULL) { // Lazy init.
143 call_completed_callbacks_ = new List<CallCompletedCallback>(); 124 call_completed_callbacks_ = new List<CallCompletedCallback>();
144 } 125 }
145 for (int i = 0; i < call_completed_callbacks_->length(); i++) { 126 for (int i = 0; i < call_completed_callbacks_->length(); i++) {
146 if (callback == call_completed_callbacks_->at(i)) return; 127 if (callback == call_completed_callbacks_->at(i)) return;
147 } 128 }
148 call_completed_callbacks_->Add(callback); 129 call_completed_callbacks_->Add(callback);
149 } 130 }
150 131
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 platform_ = NULL; 201 platform_ = NULL;
221 } 202 }
222 203
223 204
224 v8::Platform* V8::GetCurrentPlatform() { 205 v8::Platform* V8::GetCurrentPlatform() {
225 ASSERT(platform_); 206 ASSERT(platform_);
226 return platform_; 207 return platform_;
227 } 208 }
228 209
229 } } // namespace v8::internal 210 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/v8.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698