| OLD | NEW |
| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 // --- S t a t i c s --- | 262 // --- S t a t i c s --- |
| 263 | 263 |
| 264 | 264 |
| 265 static bool InitializeHelper() { | 265 static bool InitializeHelper() { |
| 266 if (i::Snapshot::Initialize()) return true; | 266 if (i::Snapshot::Initialize()) return true; |
| 267 return i::V8::Initialize(NULL); | 267 return i::V8::Initialize(NULL); |
| 268 } | 268 } |
| 269 | 269 |
| 270 | 270 |
| 271 static inline bool EnsureInitialized(const char* location) { | 271 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
| 272 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); | 272 const char* location) { |
| 273 if (isolate != NULL) { | 273 if (isolate != NULL) { |
| 274 if (isolate->IsDefaultIsolate()) { | 274 if (isolate->IsDefaultIsolate()) { |
| 275 if (i::V8::IsRunning()) { | 275 if (i::V8::IsRunning()) { |
| 276 return true; | 276 return true; |
| 277 } | 277 } |
| 278 if (IsDeadCheck(location)) { | 278 if (IsDeadCheck(location)) { |
| 279 return false; | 279 return false; |
| 280 } | 280 } |
| 281 } else { | 281 } else { |
| 282 if (isolate->IsInitialized()) { | 282 if (isolate->IsInitialized()) { |
| 283 return true; | 283 return true; |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 return ApiCheck(InitializeHelper(), location, "Error initializing V8"); | 287 return ApiCheck(InitializeHelper(), location, "Error initializing V8"); |
| 288 } | 288 } |
| 289 | 289 |
| 290 static inline bool EnsureInitialized(const char* location) { |
| 291 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 292 return EnsureInitializedForIsolate(isolate, location); |
| 293 } |
| 290 | 294 |
| 291 #ifdef DEBUG | 295 #ifdef DEBUG |
| 292 void ImplementationUtilities::ZapHandleRange(i::Object** begin, | 296 void ImplementationUtilities::ZapHandleRange(i::Object** begin, |
| 293 i::Object** end) { | 297 i::Object** end) { |
| 294 i::HandleScope::ZapRange(begin, end); | 298 i::HandleScope::ZapRange(begin, end); |
| 295 } | 299 } |
| 296 #endif | 300 #endif |
| 297 | 301 |
| 298 | 302 |
| 299 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { | 303 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { |
| 300 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); | 304 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); |
| 301 return v8::Handle<Primitive>(ToApi<Primitive>(FACTORY->undefined_value())); | 305 return v8::Handle<Primitive>(ToApi<Primitive>(FACTORY->undefined_value())); |
| 302 } | 306 } |
| 303 | 307 |
| 304 | 308 |
| 305 v8::Handle<v8::Primitive> ImplementationUtilities::Null() { | 309 v8::Handle<v8::Primitive> ImplementationUtilities::Null() { |
| 306 if (!EnsureInitialized("v8::Null()")) return v8::Handle<v8::Primitive>(); | 310 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 307 return v8::Handle<Primitive>(ToApi<Primitive>(FACTORY->null_value())); | 311 if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) |
| 312 return v8::Handle<v8::Primitive>(); |
| 313 return v8::Handle<Primitive>( |
| 314 ToApi<Primitive>(isolate->factory()->null_value())); |
| 308 } | 315 } |
| 309 | 316 |
| 310 | 317 |
| 311 v8::Handle<v8::Boolean> ImplementationUtilities::True() { | 318 v8::Handle<v8::Boolean> ImplementationUtilities::True() { |
| 312 if (!EnsureInitialized("v8::True()")) return v8::Handle<v8::Boolean>(); | 319 if (!EnsureInitialized("v8::True()")) return v8::Handle<v8::Boolean>(); |
| 313 return v8::Handle<v8::Boolean>(ToApi<Boolean>(FACTORY->true_value())); | 320 return v8::Handle<v8::Boolean>(ToApi<Boolean>(FACTORY->true_value())); |
| 314 } | 321 } |
| 315 | 322 |
| 316 | 323 |
| 317 v8::Handle<v8::Boolean> ImplementationUtilities::False() { | 324 v8::Handle<v8::Boolean> ImplementationUtilities::False() { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 #endif | 512 #endif |
| 506 } | 513 } |
| 507 | 514 |
| 508 | 515 |
| 509 int HandleScope::NumberOfHandles() { | 516 int HandleScope::NumberOfHandles() { |
| 510 EnsureInitialized("HandleScope::NumberOfHandles"); | 517 EnsureInitialized("HandleScope::NumberOfHandles"); |
| 511 return i::HandleScope::NumberOfHandles(); | 518 return i::HandleScope::NumberOfHandles(); |
| 512 } | 519 } |
| 513 | 520 |
| 514 | 521 |
| 515 i::Object** v8::HandleScope::CreateHandle(i::Object* value) { | 522 i::Object** HandleScope::CreateHandle(i::Object* value) { |
| 516 return i::HandleScope::CreateHandle(value, i::Isolate::Current()); | 523 return i::HandleScope::CreateHandle(value, i::Isolate::Current()); |
| 517 } | 524 } |
| 518 | 525 |
| 519 | 526 |
| 527 i::Object** HandleScope::CreateHandle(i::HeapObject* value) { |
| 528 ASSERT(value->IsHeapObject()); |
| 529 return reinterpret_cast<i::Object**>( |
| 530 i::HandleScope::CreateHandle(value, value->GetIsolate())); |
| 531 } |
| 532 |
| 533 |
| 520 void Context::Enter() { | 534 void Context::Enter() { |
| 521 if (IsDeadCheck("v8::Context::Enter()")) return; | 535 if (IsDeadCheck("v8::Context::Enter()")) return; |
| 522 ENTER_V8; | 536 ENTER_V8; |
| 523 i::Handle<i::Context> env = Utils::OpenHandle(this); | 537 i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 524 // TODO(isolates): Context should have a pointer to isolate. | 538 // TODO(isolates): Context should have a pointer to isolate. |
| 525 i::Isolate* isolate = i::Isolate::Current(); | 539 i::Isolate* isolate = i::Isolate::Current(); |
| 526 isolate->handle_scope_implementer()->EnterContext(env); | 540 isolate->handle_scope_implementer()->EnterContext(env); |
| 527 | 541 |
| 528 isolate->handle_scope_implementer()->SaveContext(isolate->context()); | 542 isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
| 529 isolate->set_context(*env); | 543 isolate->set_context(*env); |
| (...skipping 3320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3850 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. | 3864 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 3851 value = i::OS::nan_value(); | 3865 value = i::OS::nan_value(); |
| 3852 } | 3866 } |
| 3853 ENTER_V8; | 3867 ENTER_V8; |
| 3854 i::Handle<i::Object> result = FACTORY->NewNumber(value); | 3868 i::Handle<i::Object> result = FACTORY->NewNumber(value); |
| 3855 return Utils::NumberToLocal(result); | 3869 return Utils::NumberToLocal(result); |
| 3856 } | 3870 } |
| 3857 | 3871 |
| 3858 | 3872 |
| 3859 Local<Integer> v8::Integer::New(int32_t value) { | 3873 Local<Integer> v8::Integer::New(int32_t value) { |
| 3860 EnsureInitialized("v8::Integer::New()"); | 3874 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 3875 EnsureInitializedForIsolate(isolate, "v8::Integer::New()"); |
| 3861 if (i::Smi::IsValid(value)) { | 3876 if (i::Smi::IsValid(value)) { |
| 3862 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value))); | 3877 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
| 3878 isolate)); |
| 3863 } | 3879 } |
| 3864 ENTER_V8; | 3880 ENTER_V8; |
| 3865 i::Handle<i::Object> result = FACTORY->NewNumber(value); | 3881 i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
| 3866 return Utils::IntegerToLocal(result); | 3882 return Utils::IntegerToLocal(result); |
| 3867 } | 3883 } |
| 3868 | 3884 |
| 3869 | 3885 |
| 3870 Local<Integer> Integer::NewFromUnsigned(uint32_t value) { | 3886 Local<Integer> Integer::NewFromUnsigned(uint32_t value) { |
| 3871 bool fits_into_int32_t = (value & (1 << 31)) == 0; | 3887 bool fits_into_int32_t = (value & (1 << 31)) == 0; |
| 3872 if (fits_into_int32_t) { | 3888 if (fits_into_int32_t) { |
| 3873 return Integer::New(static_cast<int32_t>(value)); | 3889 return Integer::New(static_cast<int32_t>(value)); |
| 3874 } | 3890 } |
| 3875 ENTER_V8; | 3891 ENTER_V8; |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5007 | 5023 |
| 5008 | 5024 |
| 5009 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5025 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 5010 HandleScopeImplementer* thread_local = | 5026 HandleScopeImplementer* thread_local = |
| 5011 reinterpret_cast<HandleScopeImplementer*>(storage); | 5027 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 5012 thread_local->IterateThis(v); | 5028 thread_local->IterateThis(v); |
| 5013 return storage + ArchiveSpacePerThread(); | 5029 return storage + ArchiveSpacePerThread(); |
| 5014 } | 5030 } |
| 5015 | 5031 |
| 5016 } } // namespace v8::internal | 5032 } } // namespace v8::internal |
| OLD | NEW |