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

Side by Side Diff: src/api.cc

Issue 6672029: [Isolates] Enter default isolate in initializing API. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: [Isolates] Enter default isolate in initializing API. Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-api.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 FatalErrorCallback callback = GetFatalErrorHandler(); 196 FatalErrorCallback callback = GetFatalErrorHandler();
197 { 197 {
198 LEAVE_V8; 198 LEAVE_V8;
199 callback(location, "Allocation failed - process out of memory"); 199 callback(location, "Allocation failed - process out of memory");
200 } 200 }
201 // If the callback returns, we stop execution. 201 // If the callback returns, we stop execution.
202 UNREACHABLE(); 202 UNREACHABLE();
203 } 203 }
204 204
205 205
206 void V8::SetFatalErrorHandler(FatalErrorCallback that) {
207 i::Isolate* isolate = i::Isolate::Current();
208 isolate->set_exception_behavior(that);
209 }
210
211
212 bool Utils::ReportApiFailure(const char* location, const char* message) { 206 bool Utils::ReportApiFailure(const char* location, const char* message) {
213 FatalErrorCallback callback = GetFatalErrorHandler(); 207 FatalErrorCallback callback = GetFatalErrorHandler();
214 callback(location, message); 208 callback(location, message);
215 i::V8::SetFatalError(); 209 i::V8::SetFatalError();
216 return false; 210 return false;
217 } 211 }
218 212
219 213
220 bool V8::IsDead() { 214 bool V8::IsDead() {
221 return i::V8::IsDead(); 215 return i::V8::IsDead();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (isolate->IsInitialized()) return true; 280 if (isolate->IsInitialized()) return true;
287 } 281 }
288 return ApiCheck(InitializeHelper(), location, "Error initializing V8"); 282 return ApiCheck(InitializeHelper(), location, "Error initializing V8");
289 } 283 }
290 284
291 static inline bool EnsureInitialized(const char* location) { 285 static inline bool EnsureInitialized(const char* location) {
292 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); 286 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
293 return EnsureInitializedForIsolate(isolate, location); 287 return EnsureInitializedForIsolate(isolate, location);
294 } 288 }
295 289
290 // Some initializing API functions are called early and may be
291 // called on a thread different from static initializer thread.
292 // If Isolate API is used, Isolate::Enter() will initialize TLS so
293 // Isolate::Current() works. If it's a legacy case, then the thread
294 // may not have TLS initialized yet. However, in initializing APIs it
295 // may be too early to call EnsureInitialized() - some pre-init
296 // parameters still have to be configured.
297 static inline i::Isolate* EnterIsolateIfNeeded() {
298 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
299 if (isolate != NULL)
300 return isolate;
301
302 i::Isolate::EnterDefaultIsolate();
303 isolate = i::Isolate::Current();
304 return isolate;
305 }
306
307
308 void V8::SetFatalErrorHandler(FatalErrorCallback that) {
309 i::Isolate* isolate = EnterIsolateIfNeeded();
310 isolate->set_exception_behavior(that);
311 }
312
313
296 #ifdef DEBUG 314 #ifdef DEBUG
297 void ImplementationUtilities::ZapHandleRange(i::Object** begin, 315 void ImplementationUtilities::ZapHandleRange(i::Object** begin,
298 i::Object** end) { 316 i::Object** end) {
299 i::HandleScope::ZapRange(begin, end); 317 i::HandleScope::ZapRange(begin, end);
300 } 318 }
301 #endif 319 #endif
302 320
303 321
304 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { 322 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() {
305 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); 323 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 425
408 426
409 ResourceConstraints::ResourceConstraints() 427 ResourceConstraints::ResourceConstraints()
410 : max_young_space_size_(0), 428 : max_young_space_size_(0),
411 max_old_space_size_(0), 429 max_old_space_size_(0),
412 max_executable_size_(0), 430 max_executable_size_(0),
413 stack_limit_(NULL) { } 431 stack_limit_(NULL) { }
414 432
415 433
416 bool SetResourceConstraints(ResourceConstraints* constraints) { 434 bool SetResourceConstraints(ResourceConstraints* constraints) {
417 i::Isolate* isolate = i::Isolate::Current(); 435 i::Isolate* isolate = EnterIsolateIfNeeded();
418 436
419 int young_space_size = constraints->max_young_space_size(); 437 int young_space_size = constraints->max_young_space_size();
420 int old_gen_size = constraints->max_old_space_size(); 438 int old_gen_size = constraints->max_old_space_size();
421 int max_executable_size = constraints->max_executable_size(); 439 int max_executable_size = constraints->max_executable_size();
422 if (young_space_size != 0 || old_gen_size != 0 || max_executable_size != 0) { 440 if (young_space_size != 0 || old_gen_size != 0 || max_executable_size != 0) {
441 // After initialization it's too late to change Heap constraints.
442 ASSERT(!isolate->IsInitialized());
423 bool result = isolate->heap()->ConfigureHeap(young_space_size / 2, 443 bool result = isolate->heap()->ConfigureHeap(young_space_size / 2,
424 old_gen_size, 444 old_gen_size,
425 max_executable_size); 445 max_executable_size);
426 if (!result) return false; 446 if (!result) return false;
427 } 447 }
428 if (constraints->stack_limit() != NULL) { 448 if (constraints->stack_limit() != NULL) {
429 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); 449 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
430 isolate->stack_guard()->SetStackLimit(limit); 450 isolate->stack_guard()->SetStackLimit(limit);
431 } 451 }
432 return true; 452 return true;
(...skipping 3592 matching lines...) Expand 10 before | Expand all | Expand 10 after
4025 if (fits_into_int32_t) { 4045 if (fits_into_int32_t) {
4026 return Integer::New(static_cast<int32_t>(value)); 4046 return Integer::New(static_cast<int32_t>(value));
4027 } 4047 }
4028 ENTER_V8; 4048 ENTER_V8;
4029 i::Handle<i::Object> result = FACTORY->NewNumber(value); 4049 i::Handle<i::Object> result = FACTORY->NewNumber(value);
4030 return Utils::IntegerToLocal(result); 4050 return Utils::IntegerToLocal(result);
4031 } 4051 }
4032 4052
4033 4053
4034 void V8::IgnoreOutOfMemoryException() { 4054 void V8::IgnoreOutOfMemoryException() {
4035 i::Isolate::Current()->handle_scope_implementer()->set_ignore_out_of_memory( 4055 EnterIsolateIfNeeded()->handle_scope_implementer()->set_ignore_out_of_memory(
4036 true); 4056 true);
4037 } 4057 }
4038 4058
4039 4059
4040 bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { 4060 bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) {
4041 EnsureInitialized("v8::V8::AddMessageListener()"); 4061 EnsureInitialized("v8::V8::AddMessageListener()");
4042 ON_BAILOUT("v8::V8::AddMessageListener()", return false); 4062 ON_BAILOUT("v8::V8::AddMessageListener()", return false);
4043 ENTER_V8; 4063 ENTER_V8;
4044 HandleScope scope; 4064 HandleScope scope;
4045 NeanderArray listeners(FACTORY->message_listeners()); 4065 NeanderArray listeners(FACTORY->message_listeners());
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
5246 5266
5247 5267
5248 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 5268 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
5249 HandleScopeImplementer* thread_local = 5269 HandleScopeImplementer* thread_local =
5250 reinterpret_cast<HandleScopeImplementer*>(storage); 5270 reinterpret_cast<HandleScopeImplementer*>(storage);
5251 thread_local->IterateThis(v); 5271 thread_local->IterateThis(v);
5252 return storage + ArchiveSpacePerThread(); 5272 return storage + ArchiveSpacePerThread();
5253 } 5273 }
5254 5274
5255 } } // namespace v8::internal 5275 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698