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() { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 } | 510 } |
507 | 511 |
508 | 512 |
509 int HandleScope::NumberOfHandles() { | 513 int HandleScope::NumberOfHandles() { |
510 EnsureInitialized("HandleScope::NumberOfHandles"); | 514 EnsureInitialized("HandleScope::NumberOfHandles"); |
511 return i::HandleScope::NumberOfHandles(); | 515 return i::HandleScope::NumberOfHandles(); |
512 } | 516 } |
513 | 517 |
514 | 518 |
515 i::Object** v8::HandleScope::CreateHandle(i::Object* value) { | 519 i::Object** v8::HandleScope::CreateHandle(i::Object* value) { |
516 return i::HandleScope::CreateHandle(value, i::Isolate::Current()); | 520 ASSERT(value->IsHeapObject()); |
Vitaly Repeshko
2010/11/25 23:04:09
This will break if someone tries to create handle
| |
521 return reinterpret_cast<i::Object**>(i::HandleScope::CreateHandle( | |
522 value, static_cast<i::JSObject*>(value)->GetIsolate())); | |
Vitaly Repeshko
2010/11/25 23:04:09
JSObject -> HeapObject.
| |
517 } | 523 } |
518 | 524 |
519 | 525 |
520 void Context::Enter() { | 526 void Context::Enter() { |
521 if (IsDeadCheck("v8::Context::Enter()")) return; | 527 if (IsDeadCheck("v8::Context::Enter()")) return; |
522 ENTER_V8; | 528 ENTER_V8; |
523 i::Handle<i::Context> env = Utils::OpenHandle(this); | 529 i::Handle<i::Context> env = Utils::OpenHandle(this); |
524 // TODO(isolates): Context should have a pointer to isolate. | 530 // TODO(isolates): Context should have a pointer to isolate. |
525 i::Isolate* isolate = i::Isolate::Current(); | 531 i::Isolate* isolate = i::Isolate::Current(); |
526 isolate->handle_scope_implementer()->EnterContext(env); | 532 isolate->handle_scope_implementer()->EnterContext(env); |
(...skipping 3323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3850 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. | 3856 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
3851 value = i::OS::nan_value(); | 3857 value = i::OS::nan_value(); |
3852 } | 3858 } |
3853 ENTER_V8; | 3859 ENTER_V8; |
3854 i::Handle<i::Object> result = FACTORY->NewNumber(value); | 3860 i::Handle<i::Object> result = FACTORY->NewNumber(value); |
3855 return Utils::NumberToLocal(result); | 3861 return Utils::NumberToLocal(result); |
3856 } | 3862 } |
3857 | 3863 |
3858 | 3864 |
3859 Local<Integer> v8::Integer::New(int32_t value) { | 3865 Local<Integer> v8::Integer::New(int32_t value) { |
3860 EnsureInitialized("v8::Integer::New()"); | 3866 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
3867 EnsureInitializedForIsolate(isolate, "v8::Integer::New()"); | |
3861 if (i::Smi::IsValid(value)) { | 3868 if (i::Smi::IsValid(value)) { |
3862 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value))); | 3869 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
3870 isolate)); | |
3863 } | 3871 } |
3864 ENTER_V8; | 3872 ENTER_V8; |
3865 i::Handle<i::Object> result = FACTORY->NewNumber(value); | 3873 i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
3866 return Utils::IntegerToLocal(result); | 3874 return Utils::IntegerToLocal(result); |
3867 } | 3875 } |
3868 | 3876 |
3869 | 3877 |
3870 Local<Integer> Integer::NewFromUnsigned(uint32_t value) { | 3878 Local<Integer> Integer::NewFromUnsigned(uint32_t value) { |
3871 bool fits_into_int32_t = (value & (1 << 31)) == 0; | 3879 bool fits_into_int32_t = (value & (1 << 31)) == 0; |
3872 if (fits_into_int32_t) { | 3880 if (fits_into_int32_t) { |
3873 return Integer::New(static_cast<int32_t>(value)); | 3881 return Integer::New(static_cast<int32_t>(value)); |
3874 } | 3882 } |
3875 ENTER_V8; | 3883 ENTER_V8; |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5007 | 5015 |
5008 | 5016 |
5009 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5017 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
5010 HandleScopeImplementer* thread_local = | 5018 HandleScopeImplementer* thread_local = |
5011 reinterpret_cast<HandleScopeImplementer*>(storage); | 5019 reinterpret_cast<HandleScopeImplementer*>(storage); |
5012 thread_local->IterateThis(v); | 5020 thread_local->IterateThis(v); |
5013 return storage + ArchiveSpacePerThread(); | 5021 return storage + ArchiveSpacePerThread(); |
5014 } | 5022 } |
5015 | 5023 |
5016 } } // namespace v8::internal | 5024 } } // namespace v8::internal |
OLD | NEW |