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 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2258 : isolate_(i::Isolate::Current()), | 2258 : isolate_(i::Isolate::Current()), |
2259 next_(isolate_->try_catch_handler()), | 2259 next_(isolate_->try_catch_handler()), |
2260 is_verbose_(false), | 2260 is_verbose_(false), |
2261 can_continue_(true), | 2261 can_continue_(true), |
2262 capture_message_(true), | 2262 capture_message_(true), |
2263 rethrow_(false), | 2263 rethrow_(false), |
2264 has_terminated_(false) { | 2264 has_terminated_(false) { |
2265 ResetInternal(); | 2265 ResetInternal(); |
2266 // Special handling for simulators which have a separate JS stack. | 2266 // Special handling for simulators which have a separate JS stack. |
2267 js_stack_comparable_address_ = | 2267 js_stack_comparable_address_ = |
2268 reinterpret_cast<void*>(v8::internal::SimulatorStack::RegisterCTryCatch( | 2268 reinterpret_cast<void*>(i::SimulatorStack::RegisterCTryCatch( |
2269 isolate_, v8::internal::GetCurrentStackPosition())); | 2269 isolate_, i::GetCurrentStackPosition())); |
2270 isolate_->RegisterTryCatchHandler(this); | 2270 isolate_->RegisterTryCatchHandler(this); |
2271 } | 2271 } |
2272 | 2272 |
2273 | 2273 |
2274 v8::TryCatch::TryCatch(v8::Isolate* isolate) | 2274 v8::TryCatch::TryCatch(v8::Isolate* isolate) |
2275 : isolate_(reinterpret_cast<i::Isolate*>(isolate)), | 2275 : isolate_(reinterpret_cast<i::Isolate*>(isolate)), |
2276 next_(isolate_->try_catch_handler()), | 2276 next_(isolate_->try_catch_handler()), |
2277 is_verbose_(false), | 2277 is_verbose_(false), |
2278 can_continue_(true), | 2278 can_continue_(true), |
2279 capture_message_(true), | 2279 capture_message_(true), |
2280 rethrow_(false), | 2280 rethrow_(false), |
2281 has_terminated_(false) { | 2281 has_terminated_(false) { |
2282 ResetInternal(); | 2282 ResetInternal(); |
2283 // Special handling for simulators which have a separate JS stack. | 2283 // Special handling for simulators which have a separate JS stack. |
2284 js_stack_comparable_address_ = | 2284 js_stack_comparable_address_ = |
2285 reinterpret_cast<void*>(v8::internal::SimulatorStack::RegisterCTryCatch( | 2285 reinterpret_cast<void*>(i::SimulatorStack::RegisterCTryCatch( |
2286 isolate_, v8::internal::GetCurrentStackPosition())); | 2286 isolate_, i::GetCurrentStackPosition())); |
2287 isolate_->RegisterTryCatchHandler(this); | 2287 isolate_->RegisterTryCatchHandler(this); |
2288 } | 2288 } |
2289 | 2289 |
2290 | 2290 |
2291 v8::TryCatch::~TryCatch() { | 2291 v8::TryCatch::~TryCatch() { |
2292 if (rethrow_) { | 2292 if (rethrow_) { |
2293 v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_); | 2293 v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_); |
2294 v8::HandleScope scope(isolate); | 2294 v8::HandleScope scope(isolate); |
2295 v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(isolate, Exception()); | 2295 v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(isolate, Exception()); |
2296 if (HasCaught() && capture_message_) { | 2296 if (HasCaught() && capture_message_) { |
2297 // If an exception was caught and rethrow_ is indicated, the saved | 2297 // If an exception was caught and rethrow_ is indicated, the saved |
2298 // message, script, and location need to be restored to Isolate TLS | 2298 // message, script, and location need to be restored to Isolate TLS |
2299 // for reuse. capture_message_ needs to be disabled so that Throw() | 2299 // for reuse. capture_message_ needs to be disabled so that Throw() |
2300 // does not create a new message. | 2300 // does not create a new message. |
2301 isolate_->thread_local_top()->rethrowing_message_ = true; | 2301 isolate_->thread_local_top()->rethrowing_message_ = true; |
2302 isolate_->RestorePendingMessageFromTryCatch(this); | 2302 isolate_->RestorePendingMessageFromTryCatch(this); |
2303 } | 2303 } |
2304 isolate_->UnregisterTryCatchHandler(this); | 2304 isolate_->UnregisterTryCatchHandler(this); |
2305 v8::internal::SimulatorStack::UnregisterCTryCatch(isolate_); | 2305 i::SimulatorStack::UnregisterCTryCatch(isolate_); |
2306 reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc); | 2306 reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc); |
2307 DCHECK(!isolate_->thread_local_top()->rethrowing_message_); | 2307 DCHECK(!isolate_->thread_local_top()->rethrowing_message_); |
2308 } else { | 2308 } else { |
2309 if (HasCaught() && isolate_->has_scheduled_exception()) { | 2309 if (HasCaught() && isolate_->has_scheduled_exception()) { |
2310 // If an exception was caught but is still scheduled because no API call | 2310 // If an exception was caught but is still scheduled because no API call |
2311 // promoted it, then it is canceled to prevent it from being propagated. | 2311 // promoted it, then it is canceled to prevent it from being propagated. |
2312 // Note that this will not cancel termination exceptions. | 2312 // Note that this will not cancel termination exceptions. |
2313 isolate_->CancelScheduledExceptionFromTryCatch(this); | 2313 isolate_->CancelScheduledExceptionFromTryCatch(this); |
2314 } | 2314 } |
2315 isolate_->UnregisterTryCatchHandler(this); | 2315 isolate_->UnregisterTryCatchHandler(this); |
2316 v8::internal::SimulatorStack::UnregisterCTryCatch(isolate_); | 2316 i::SimulatorStack::UnregisterCTryCatch(isolate_); |
2317 } | 2317 } |
2318 } | 2318 } |
2319 | 2319 |
2320 | 2320 |
2321 bool v8::TryCatch::HasCaught() const { | 2321 bool v8::TryCatch::HasCaught() const { |
2322 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(isolate_); | 2322 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(isolate_); |
2323 } | 2323 } |
2324 | 2324 |
2325 | 2325 |
2326 bool v8::TryCatch::CanContinue() const { | 2326 bool v8::TryCatch::CanContinue() const { |
(...skipping 5078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7405 } else { | 7405 } else { |
7406 isolate->ScheduleThrow(*Utils::OpenHandle(*value)); | 7406 isolate->ScheduleThrow(*Utils::OpenHandle(*value)); |
7407 } | 7407 } |
7408 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 7408 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
7409 } | 7409 } |
7410 | 7410 |
7411 | 7411 |
7412 void Isolate::SetObjectGroupId(internal::Object** object, UniqueId id) { | 7412 void Isolate::SetObjectGroupId(internal::Object** object, UniqueId id) { |
7413 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); | 7413 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
7414 internal_isolate->global_handles()->SetObjectGroupId( | 7414 internal_isolate->global_handles()->SetObjectGroupId( |
7415 v8::internal::Handle<v8::internal::Object>(object).location(), | 7415 i::Handle<i::Object>(object).location(), id); |
7416 id); | |
7417 } | 7416 } |
7418 | 7417 |
7419 | 7418 |
7420 void Isolate::SetReferenceFromGroup(UniqueId id, internal::Object** object) { | 7419 void Isolate::SetReferenceFromGroup(UniqueId id, internal::Object** object) { |
7421 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); | 7420 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
7422 internal_isolate->global_handles()->SetReferenceFromGroup( | 7421 internal_isolate->global_handles()->SetReferenceFromGroup( |
7423 id, | 7422 id, i::Handle<i::Object>(object).location()); |
7424 v8::internal::Handle<v8::internal::Object>(object).location()); | |
7425 } | 7423 } |
7426 | 7424 |
7427 | 7425 |
7428 void Isolate::SetReference(internal::Object** parent, | 7426 void Isolate::SetReference(internal::Object** parent, |
7429 internal::Object** child) { | 7427 internal::Object** child) { |
7430 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); | 7428 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
7431 i::Object** parent_location = | 7429 i::Object** parent_location = i::Handle<i::Object>(parent).location(); |
7432 v8::internal::Handle<v8::internal::Object>(parent).location(); | |
7433 internal_isolate->global_handles()->SetReference( | 7430 internal_isolate->global_handles()->SetReference( |
7434 reinterpret_cast<i::HeapObject**>(parent_location), | 7431 reinterpret_cast<i::HeapObject**>(parent_location), |
7435 v8::internal::Handle<v8::internal::Object>(child).location()); | 7432 i::Handle<i::Object>(child).location()); |
7436 } | 7433 } |
7437 | 7434 |
7438 | 7435 |
7439 void Isolate::AddGCPrologueCallback(GCCallback callback, GCType gc_type) { | 7436 void Isolate::AddGCPrologueCallback(GCCallback callback, GCType gc_type) { |
7440 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); | 7437 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
7441 isolate->heap()->AddGCPrologueCallback(callback, gc_type); | 7438 isolate->heap()->AddGCPrologueCallback(callback, gc_type); |
7442 } | 7439 } |
7443 | 7440 |
7444 | 7441 |
7445 void Isolate::RemoveGCPrologueCallback(GCCallback callback) { | 7442 void Isolate::RemoveGCPrologueCallback(GCCallback callback) { |
(...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9097 Address callback_address = | 9094 Address callback_address = |
9098 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9095 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9099 VMState<EXTERNAL> state(isolate); | 9096 VMState<EXTERNAL> state(isolate); |
9100 ExternalCallbackScope call_scope(isolate, callback_address); | 9097 ExternalCallbackScope call_scope(isolate, callback_address); |
9101 callback(info); | 9098 callback(info); |
9102 } | 9099 } |
9103 | 9100 |
9104 | 9101 |
9105 } // namespace internal | 9102 } // namespace internal |
9106 } // namespace v8 | 9103 } // namespace v8 |
OLD | NEW |