OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location, | 179 base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location, |
180 message); | 180 message); |
181 base::OS::Abort(); | 181 base::OS::Abort(); |
182 } else { | 182 } else { |
183 callback(location, message); | 183 callback(location, message); |
184 } | 184 } |
185 isolate->SignalFatalError(); | 185 isolate->SignalFatalError(); |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 bool V8::IsDead() { | |
190 i::Isolate* isolate = i::Isolate::Current(); | |
191 return isolate->IsDead(); | |
192 } | |
193 | |
194 | |
195 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { | 189 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { |
196 if (isolate->has_scheduled_exception()) { | 190 if (isolate->has_scheduled_exception()) { |
197 return isolate->scheduled_exception() == | 191 return isolate->scheduled_exception() == |
198 isolate->heap()->termination_exception(); | 192 isolate->heap()->termination_exception(); |
199 } | 193 } |
200 return false; | 194 return false; |
201 } | 195 } |
202 | 196 |
203 | 197 |
204 StartupDataDecompressor::StartupDataDecompressor() | 198 StartupDataDecompressor::StartupDataDecompressor() |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 334 |
341 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { | 335 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { |
342 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 336 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
343 i::SetSnapshotFromFile(snapshot_blob); | 337 i::SetSnapshotFromFile(snapshot_blob); |
344 #else | 338 #else |
345 CHECK(false); | 339 CHECK(false); |
346 #endif | 340 #endif |
347 } | 341 } |
348 | 342 |
349 | 343 |
350 void V8::SetFatalErrorHandler(FatalErrorCallback that) { | |
351 i::Isolate* isolate = i::Isolate::Current(); | |
352 isolate->set_exception_behavior(that); | |
353 } | |
354 | |
355 | |
356 void V8::SetAllowCodeGenerationFromStringsCallback( | |
357 AllowCodeGenerationFromStringsCallback callback) { | |
358 i::Isolate* isolate = i::Isolate::Current(); | |
359 isolate->set_allow_code_gen_callback(callback); | |
360 } | |
361 | |
362 | |
363 void V8::SetFlagsFromString(const char* str, int length) { | 344 void V8::SetFlagsFromString(const char* str, int length) { |
364 i::FlagList::SetFlagsFromString(str, length); | 345 i::FlagList::SetFlagsFromString(str, length); |
365 } | 346 } |
366 | 347 |
367 | 348 |
368 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { | 349 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { |
369 i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); | 350 i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); |
370 } | 351 } |
371 | 352 |
372 | 353 |
(...skipping 4811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5184 } | 5165 } |
5185 | 5166 |
5186 | 5167 |
5187 HeapStatistics::HeapStatistics(): total_heap_size_(0), | 5168 HeapStatistics::HeapStatistics(): total_heap_size_(0), |
5188 total_heap_size_executable_(0), | 5169 total_heap_size_executable_(0), |
5189 total_physical_size_(0), | 5170 total_physical_size_(0), |
5190 used_heap_size_(0), | 5171 used_heap_size_(0), |
5191 heap_size_limit_(0) { } | 5172 heap_size_limit_(0) { } |
5192 | 5173 |
5193 | 5174 |
5194 void v8::V8::VisitExternalResources(ExternalResourceVisitor* visitor) { | |
5195 i::Isolate* isolate = i::Isolate::Current(); | |
5196 isolate->heap()->VisitExternalResources(visitor); | |
5197 } | |
5198 | |
5199 | |
5200 class VisitorAdapter : public i::ObjectVisitor { | |
5201 public: | |
5202 explicit VisitorAdapter(PersistentHandleVisitor* visitor) | |
5203 : visitor_(visitor) {} | |
5204 virtual void VisitPointers(i::Object** start, i::Object** end) { | |
5205 UNREACHABLE(); | |
5206 } | |
5207 virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) { | |
5208 Value* value = ToApi<Value>(i::Handle<i::Object>(p)); | |
5209 visitor_->VisitPersistentHandle( | |
5210 reinterpret_cast<Persistent<Value>*>(&value), class_id); | |
5211 } | |
5212 private: | |
5213 PersistentHandleVisitor* visitor_; | |
5214 }; | |
5215 | |
5216 | |
5217 void v8::V8::VisitHandlesWithClassIds(v8::Isolate* exported_isolate, | |
5218 PersistentHandleVisitor* visitor) { | |
5219 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate); | |
5220 i::DisallowHeapAllocation no_allocation; | |
5221 | |
5222 VisitorAdapter visitor_adapter(visitor); | |
5223 isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter); | |
5224 } | |
5225 | |
5226 | |
5227 void v8::V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) { | |
5228 i::Isolate* isolate = i::Isolate::Current(); | |
5229 i::DisallowHeapAllocation no_allocation; | |
5230 | |
5231 VisitorAdapter visitor_adapter(visitor); | |
5232 isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter); | |
5233 } | |
5234 | |
5235 | |
5236 void v8::V8::VisitHandlesForPartialDependence( | |
5237 Isolate* exported_isolate, PersistentHandleVisitor* visitor) { | |
5238 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate); | |
5239 DCHECK(isolate == i::Isolate::Current()); | |
5240 i::DisallowHeapAllocation no_allocation; | |
5241 | |
5242 VisitorAdapter visitor_adapter(visitor); | |
5243 isolate->global_handles()->IterateAllRootsInNewSpaceWithClassIds( | |
5244 &visitor_adapter); | |
5245 } | |
5246 | |
5247 | |
5248 bool v8::V8::InitializeICU(const char* icu_data_file) { | 5175 bool v8::V8::InitializeICU(const char* icu_data_file) { |
5249 return i::InitializeICU(icu_data_file); | 5176 return i::InitializeICU(icu_data_file); |
5250 } | 5177 } |
5251 | 5178 |
5252 | 5179 |
5253 const char* v8::V8::GetVersion() { | 5180 const char* v8::V8::GetVersion() { |
5254 return i::Version::GetVersion(); | 5181 return i::Version::GetVersion(); |
5255 } | 5182 } |
5256 | 5183 |
5257 | 5184 |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6364 bool fits_into_int32_t = (value & (1 << 31)) == 0; | 6291 bool fits_into_int32_t = (value & (1 << 31)) == 0; |
6365 if (fits_into_int32_t) { | 6292 if (fits_into_int32_t) { |
6366 return Integer::New(isolate, static_cast<int32_t>(value)); | 6293 return Integer::New(isolate, static_cast<int32_t>(value)); |
6367 } | 6294 } |
6368 ENTER_V8(internal_isolate); | 6295 ENTER_V8(internal_isolate); |
6369 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); | 6296 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
6370 return Utils::IntegerToLocal(result); | 6297 return Utils::IntegerToLocal(result); |
6371 } | 6298 } |
6372 | 6299 |
6373 | 6300 |
6374 bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { | |
6375 i::Isolate* isolate = i::Isolate::Current(); | |
6376 ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); | |
6377 ENTER_V8(isolate); | |
6378 i::HandleScope scope(isolate); | |
6379 NeanderArray listeners(isolate->factory()->message_listeners()); | |
6380 NeanderObject obj(isolate, 2); | |
6381 obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); | |
6382 obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() | |
6383 : *Utils::OpenHandle(*data)); | |
6384 listeners.add(obj.value()); | |
6385 return true; | |
6386 } | |
6387 | |
6388 | |
6389 void V8::RemoveMessageListeners(MessageCallback that) { | |
6390 i::Isolate* isolate = i::Isolate::Current(); | |
6391 ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); | |
6392 ENTER_V8(isolate); | |
6393 i::HandleScope scope(isolate); | |
6394 NeanderArray listeners(isolate->factory()->message_listeners()); | |
6395 for (int i = 0; i < listeners.length(); i++) { | |
6396 if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones | |
6397 | |
6398 NeanderObject listener(i::JSObject::cast(listeners.get(i))); | |
6399 i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); | |
6400 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { | |
6401 listeners.set(i, isolate->heap()->undefined_value()); | |
6402 } | |
6403 } | |
6404 } | |
6405 | |
6406 | |
6407 void V8::SetCaptureStackTraceForUncaughtExceptions( | |
6408 bool capture, | |
6409 int frame_limit, | |
6410 StackTrace::StackTraceOptions options) { | |
6411 i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions( | |
6412 capture, | |
6413 frame_limit, | |
6414 options); | |
6415 } | |
6416 | |
6417 | |
6418 void V8::SetFailedAccessCheckCallbackFunction( | |
6419 FailedAccessCheckCallback callback) { | |
6420 i::Isolate* isolate = i::Isolate::Current(); | |
6421 isolate->SetFailedAccessCheckCallback(callback); | |
6422 } | |
6423 | |
6424 | |
6425 void Isolate::CollectAllGarbage(const char* gc_reason) { | 6301 void Isolate::CollectAllGarbage(const char* gc_reason) { |
6426 reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage( | 6302 reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage( |
6427 i::Heap::kNoGCFlags, gc_reason); | 6303 i::Heap::kNoGCFlags, gc_reason); |
6428 } | 6304 } |
6429 | 6305 |
6430 | 6306 |
6431 HeapProfiler* Isolate::GetHeapProfiler() { | 6307 HeapProfiler* Isolate::GetHeapProfiler() { |
6432 i::HeapProfiler* heap_profiler = | 6308 i::HeapProfiler* heap_profiler = |
6433 reinterpret_cast<i::Isolate*>(this)->heap_profiler(); | 6309 reinterpret_cast<i::Isolate*>(this)->heap_profiler(); |
6434 return reinterpret_cast<HeapProfiler*>(heap_profiler); | 6310 return reinterpret_cast<HeapProfiler*>(heap_profiler); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6544 | 6420 |
6545 void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { | 6421 void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
6546 i::Isolate* isolate = i::Isolate::Current(); | 6422 i::Isolate* isolate = i::Isolate::Current(); |
6547 isolate->heap()->AddGCPrologueCallback( | 6423 isolate->heap()->AddGCPrologueCallback( |
6548 reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback), | 6424 reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback), |
6549 gc_type, | 6425 gc_type, |
6550 false); | 6426 false); |
6551 } | 6427 } |
6552 | 6428 |
6553 | 6429 |
6554 void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { | |
6555 i::Isolate* isolate = i::Isolate::Current(); | |
6556 isolate->heap()->RemoveGCPrologueCallback( | |
6557 reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback)); | |
6558 } | |
6559 | |
6560 | |
6561 void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { | 6430 void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
6562 i::Isolate* isolate = i::Isolate::Current(); | 6431 i::Isolate* isolate = i::Isolate::Current(); |
6563 isolate->heap()->AddGCEpilogueCallback( | 6432 isolate->heap()->AddGCEpilogueCallback( |
6564 reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback), | 6433 reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback), |
6565 gc_type, | 6434 gc_type, |
6566 false); | 6435 false); |
6567 } | 6436 } |
6568 | 6437 |
6569 | 6438 |
6570 void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { | 6439 void Isolate::AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
6571 i::Isolate* isolate = i::Isolate::Current(); | 6440 ObjectSpace space, |
6572 isolate->heap()->RemoveGCEpilogueCallback( | 6441 AllocationAction action) { |
6573 reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback)); | 6442 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6574 } | |
6575 | |
6576 | |
6577 void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, | |
6578 ObjectSpace space, | |
6579 AllocationAction action) { | |
6580 i::Isolate* isolate = i::Isolate::Current(); | |
6581 isolate->memory_allocator()->AddMemoryAllocationCallback( | 6443 isolate->memory_allocator()->AddMemoryAllocationCallback( |
6582 callback, space, action); | 6444 callback, space, action); |
6583 } | 6445 } |
6584 | 6446 |
6585 | 6447 |
6586 void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { | 6448 void Isolate::RemoveMemoryAllocationCallback( |
6587 i::Isolate* isolate = i::Isolate::Current(); | 6449 MemoryAllocationCallback callback) { |
| 6450 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6588 isolate->memory_allocator()->RemoveMemoryAllocationCallback( | 6451 isolate->memory_allocator()->RemoveMemoryAllocationCallback( |
6589 callback); | 6452 callback); |
6590 } | 6453 } |
6591 | 6454 |
6592 | 6455 |
6593 void V8::TerminateExecution(Isolate* isolate) { | 6456 void Isolate::TerminateExecution() { |
6594 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6457 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6595 i_isolate->stack_guard()->RequestTerminateExecution(); | 6458 isolate->stack_guard()->RequestTerminateExecution(); |
6596 } | 6459 } |
6597 | 6460 |
6598 | 6461 |
6599 bool V8::IsExecutionTerminating(Isolate* isolate) { | 6462 bool Isolate::IsExecutionTerminating() { |
6600 i::Isolate* i_isolate = isolate != NULL ? | 6463 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6601 reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current(); | 6464 return IsExecutionTerminatingCheck(isolate); |
6602 return IsExecutionTerminatingCheck(i_isolate); | |
6603 } | 6465 } |
6604 | 6466 |
6605 | 6467 |
6606 void V8::CancelTerminateExecution(Isolate* isolate) { | 6468 void Isolate::CancelTerminateExecution() { |
6607 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6469 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6608 i_isolate->stack_guard()->ClearTerminateExecution(); | 6470 isolate->stack_guard()->ClearTerminateExecution(); |
6609 i_isolate->CancelTerminateExecution(); | 6471 isolate->CancelTerminateExecution(); |
6610 } | 6472 } |
6611 | 6473 |
6612 | 6474 |
6613 void Isolate::RequestInterrupt(InterruptCallback callback, void* data) { | 6475 void Isolate::RequestInterrupt(InterruptCallback callback, void* data) { |
6614 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this); | 6476 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6615 i_isolate->set_api_interrupt_callback(callback); | 6477 isolate->set_api_interrupt_callback(callback); |
6616 i_isolate->set_api_interrupt_callback_data(data); | 6478 isolate->set_api_interrupt_callback_data(data); |
6617 i_isolate->stack_guard()->RequestApiInterrupt(); | 6479 isolate->stack_guard()->RequestApiInterrupt(); |
6618 } | 6480 } |
6619 | 6481 |
6620 | 6482 |
6621 void Isolate::ClearInterrupt() { | 6483 void Isolate::ClearInterrupt() { |
6622 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this); | 6484 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6623 i_isolate->stack_guard()->ClearApiInterrupt(); | 6485 isolate->stack_guard()->ClearApiInterrupt(); |
6624 i_isolate->set_api_interrupt_callback(NULL); | 6486 isolate->set_api_interrupt_callback(NULL); |
6625 i_isolate->set_api_interrupt_callback_data(NULL); | 6487 isolate->set_api_interrupt_callback_data(NULL); |
6626 } | 6488 } |
6627 | 6489 |
6628 | 6490 |
6629 void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) { | 6491 void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) { |
6630 CHECK(i::FLAG_expose_gc); | 6492 CHECK(i::FLAG_expose_gc); |
6631 if (type == kMinorGarbageCollection) { | 6493 if (type == kMinorGarbageCollection) { |
6632 reinterpret_cast<i::Isolate*>(this)->heap()->CollectGarbage( | 6494 reinterpret_cast<i::Isolate*>(this)->heap()->CollectGarbage( |
6633 i::NEW_SPACE, "Isolate::RequestGarbageCollection", | 6495 i::NEW_SPACE, "Isolate::RequestGarbageCollection", |
6634 kGCCallbackFlagForced); | 6496 kGCCallbackFlagForced); |
6635 } else { | 6497 } else { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6849 | 6711 |
6850 | 6712 |
6851 void Isolate::SetAddHistogramSampleFunction( | 6713 void Isolate::SetAddHistogramSampleFunction( |
6852 AddHistogramSampleCallback callback) { | 6714 AddHistogramSampleCallback callback) { |
6853 reinterpret_cast<i::Isolate*>(this) | 6715 reinterpret_cast<i::Isolate*>(this) |
6854 ->stats_table() | 6716 ->stats_table() |
6855 ->SetAddHistogramSampleFunction(callback); | 6717 ->SetAddHistogramSampleFunction(callback); |
6856 } | 6718 } |
6857 | 6719 |
6858 | 6720 |
6859 bool v8::Isolate::IdleNotification(int idle_time_in_ms) { | 6721 bool Isolate::IdleNotification(int idle_time_in_ms) { |
6860 // Returning true tells the caller that it need not | 6722 // Returning true tells the caller that it need not |
6861 // continue to call IdleNotification. | 6723 // continue to call IdleNotification. |
6862 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 6724 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6863 if (!i::FLAG_use_idle_notification) return true; | 6725 if (!i::FLAG_use_idle_notification) return true; |
6864 return isolate->heap()->IdleNotification(idle_time_in_ms); | 6726 return isolate->heap()->IdleNotification(idle_time_in_ms); |
6865 } | 6727 } |
6866 | 6728 |
6867 | 6729 |
6868 void v8::Isolate::LowMemoryNotification() { | 6730 void Isolate::LowMemoryNotification() { |
6869 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 6731 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6870 { | 6732 { |
6871 i::HistogramTimerScope idle_notification_scope( | 6733 i::HistogramTimerScope idle_notification_scope( |
6872 isolate->counters()->gc_low_memory_notification()); | 6734 isolate->counters()->gc_low_memory_notification()); |
6873 isolate->heap()->CollectAllAvailableGarbage("low memory notification"); | 6735 isolate->heap()->CollectAllAvailableGarbage("low memory notification"); |
6874 } | 6736 } |
6875 } | 6737 } |
6876 | 6738 |
6877 | 6739 |
6878 int v8::Isolate::ContextDisposedNotification() { | 6740 int Isolate::ContextDisposedNotification() { |
6879 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 6741 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6880 return isolate->heap()->NotifyContextDisposed(); | 6742 return isolate->heap()->NotifyContextDisposed(); |
6881 } | 6743 } |
6882 | 6744 |
6883 | 6745 |
6884 void v8::Isolate::SetJitCodeEventHandler(JitCodeEventOptions options, | 6746 void Isolate::SetJitCodeEventHandler(JitCodeEventOptions options, |
6885 JitCodeEventHandler event_handler) { | 6747 JitCodeEventHandler event_handler) { |
6886 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 6748 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6887 // Ensure that logging is initialized for our isolate. | 6749 // Ensure that logging is initialized for our isolate. |
6888 isolate->InitializeLoggingAndCounters(); | 6750 isolate->InitializeLoggingAndCounters(); |
6889 isolate->logger()->SetCodeEventHandler(options, event_handler); | 6751 isolate->logger()->SetCodeEventHandler(options, event_handler); |
6890 } | 6752 } |
6891 | 6753 |
6892 | 6754 |
6893 void v8::Isolate::SetStackLimit(uintptr_t stack_limit) { | 6755 void Isolate::SetStackLimit(uintptr_t stack_limit) { |
6894 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 6756 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6895 CHECK(stack_limit); | 6757 CHECK(stack_limit); |
6896 isolate->stack_guard()->SetStackLimit(stack_limit); | 6758 isolate->stack_guard()->SetStackLimit(stack_limit); |
6897 } | 6759 } |
6898 | 6760 |
6899 | 6761 |
6900 void v8::Isolate::GetCodeRange(void** start, size_t* length_in_bytes) { | 6762 void Isolate::GetCodeRange(void** start, size_t* length_in_bytes) { |
6901 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 6763 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
6902 if (isolate->code_range()->valid()) { | 6764 if (isolate->code_range()->valid()) { |
6903 *start = isolate->code_range()->start(); | 6765 *start = isolate->code_range()->start(); |
6904 *length_in_bytes = isolate->code_range()->size(); | 6766 *length_in_bytes = isolate->code_range()->size(); |
6905 } else { | 6767 } else { |
6906 *start = NULL; | 6768 *start = NULL; |
6907 *length_in_bytes = 0; | 6769 *length_in_bytes = 0; |
6908 } | 6770 } |
6909 } | 6771 } |
6910 | 6772 |
6911 | 6773 |
| 6774 void Isolate::SetFatalErrorHandler(FatalErrorCallback that) { |
| 6775 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6776 isolate->set_exception_behavior(that); |
| 6777 } |
| 6778 |
| 6779 |
| 6780 void Isolate::SetAllowCodeGenerationFromStringsCallback( |
| 6781 AllowCodeGenerationFromStringsCallback callback) { |
| 6782 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6783 isolate->set_allow_code_gen_callback(callback); |
| 6784 } |
| 6785 |
| 6786 |
| 6787 bool Isolate::IsDead() { |
| 6788 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6789 return isolate->IsDead(); |
| 6790 } |
| 6791 |
| 6792 |
| 6793 bool Isolate::AddMessageListener(MessageCallback that, Handle<Value> data) { |
| 6794 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6795 ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); |
| 6796 ENTER_V8(isolate); |
| 6797 i::HandleScope scope(isolate); |
| 6798 NeanderArray listeners(isolate->factory()->message_listeners()); |
| 6799 NeanderObject obj(isolate, 2); |
| 6800 obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
| 6801 obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() |
| 6802 : *Utils::OpenHandle(*data)); |
| 6803 listeners.add(obj.value()); |
| 6804 return true; |
| 6805 } |
| 6806 |
| 6807 |
| 6808 void Isolate::RemoveMessageListeners(MessageCallback that) { |
| 6809 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6810 ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); |
| 6811 ENTER_V8(isolate); |
| 6812 i::HandleScope scope(isolate); |
| 6813 NeanderArray listeners(isolate->factory()->message_listeners()); |
| 6814 for (int i = 0; i < listeners.length(); i++) { |
| 6815 if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 6816 |
| 6817 NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
| 6818 i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); |
| 6819 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { |
| 6820 listeners.set(i, isolate->heap()->undefined_value()); |
| 6821 } |
| 6822 } |
| 6823 } |
| 6824 |
| 6825 |
| 6826 void Isolate::SetFailedAccessCheckCallbackFunction( |
| 6827 FailedAccessCheckCallback callback) { |
| 6828 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6829 isolate->SetFailedAccessCheckCallback(callback); |
| 6830 } |
| 6831 |
| 6832 |
| 6833 void Isolate::SetCaptureStackTraceForUncaughtExceptions( |
| 6834 bool capture, int frame_limit, StackTrace::StackTraceOptions options) { |
| 6835 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6836 isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit, |
| 6837 options); |
| 6838 } |
| 6839 |
| 6840 |
| 6841 void Isolate::VisitExternalResources(ExternalResourceVisitor* visitor) { |
| 6842 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6843 isolate->heap()->VisitExternalResources(visitor); |
| 6844 } |
| 6845 |
| 6846 |
| 6847 class VisitorAdapter : public i::ObjectVisitor { |
| 6848 public: |
| 6849 explicit VisitorAdapter(PersistentHandleVisitor* visitor) |
| 6850 : visitor_(visitor) {} |
| 6851 virtual void VisitPointers(i::Object** start, i::Object** end) { |
| 6852 UNREACHABLE(); |
| 6853 } |
| 6854 virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) { |
| 6855 Value* value = ToApi<Value>(i::Handle<i::Object>(p)); |
| 6856 visitor_->VisitPersistentHandle( |
| 6857 reinterpret_cast<Persistent<Value>*>(&value), class_id); |
| 6858 } |
| 6859 |
| 6860 private: |
| 6861 PersistentHandleVisitor* visitor_; |
| 6862 }; |
| 6863 |
| 6864 |
| 6865 void Isolate::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) { |
| 6866 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6867 i::DisallowHeapAllocation no_allocation; |
| 6868 VisitorAdapter visitor_adapter(visitor); |
| 6869 isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter); |
| 6870 } |
| 6871 |
| 6872 |
| 6873 void Isolate::VisitHandlesForPartialDependence( |
| 6874 PersistentHandleVisitor* visitor) { |
| 6875 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6876 i::DisallowHeapAllocation no_allocation; |
| 6877 VisitorAdapter visitor_adapter(visitor); |
| 6878 isolate->global_handles()->IterateAllRootsInNewSpaceWithClassIds( |
| 6879 &visitor_adapter); |
| 6880 } |
| 6881 |
| 6882 |
6912 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) | 6883 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
6913 : str_(NULL), length_(0) { | 6884 : str_(NULL), length_(0) { |
6914 i::Isolate* isolate = i::Isolate::Current(); | 6885 i::Isolate* isolate = i::Isolate::Current(); |
6915 if (obj.IsEmpty()) return; | 6886 if (obj.IsEmpty()) return; |
6916 ENTER_V8(isolate); | 6887 ENTER_V8(isolate); |
6917 i::HandleScope scope(isolate); | 6888 i::HandleScope scope(isolate); |
6918 TryCatch try_catch; | 6889 TryCatch try_catch; |
6919 Handle<String> str = obj->ToString(reinterpret_cast<v8::Isolate*>(isolate)); | 6890 Handle<String> str = obj->ToString(reinterpret_cast<v8::Isolate*>(isolate)); |
6920 if (str.IsEmpty()) return; | 6891 if (str.IsEmpty()) return; |
6921 i::Handle<i::String> i_str = Utils::OpenHandle(*str); | 6892 i::Handle<i::String> i_str = Utils::OpenHandle(*str); |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7765 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7736 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7766 Address callback_address = | 7737 Address callback_address = |
7767 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7738 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7768 VMState<EXTERNAL> state(isolate); | 7739 VMState<EXTERNAL> state(isolate); |
7769 ExternalCallbackScope call_scope(isolate, callback_address); | 7740 ExternalCallbackScope call_scope(isolate, callback_address); |
7770 callback(info); | 7741 callback(info); |
7771 } | 7742 } |
7772 | 7743 |
7773 | 7744 |
7774 } } // namespace v8::internal | 7745 } } // namespace v8::internal |
OLD | NEW |