| 1 | // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
|---|---|
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #include "vm/longjump.h" |
| 6 | |
| 7 | #include "include/dart_api.h" |
| 8 | |
| 9 | #include "vm/dart_api_impl.h" |
| 10 | #include "vm/isolate.h" |
| 11 | #include "vm/object.h" |
| 12 | #include "vm/os.h" |
| 13 | |
| 14 | namespace dart { |
| 15 | |
| 16 | jmp_buf* LongJumpScope::Set() { |
| 17 | ASSERT(top_ == NULL); |
| 18 | top_ = Thread::Current()->top_resource(); |
| 19 | return &environment_; |
| 20 | } |
| 21 | |
| 22 | void LongJumpScope::Jump(int value, const Error& error) { |
| 23 | // A zero is the default return value from setting up a LongJumpScope |
| 24 | // using Set. |
| 25 | ASSERT(value != 0); |
| 26 | ASSERT(!error.IsNull()); |
| 27 | |
| 28 | Thread* thread = Thread::Current(); |
| 29 | DEBUG_ASSERT(thread->TopErrorHandlerIsSetJump()); |
| 30 | |
| 31 | #if defined(DEBUG) |
| 32 | #define CHECK_REUSABLE_HANDLE(name) \ |
| 33 | ASSERT(!thread->reusable_##name##_handle_scope_active()); |
| 34 | REUSABLE_HANDLE_LIST(CHECK_REUSABLE_HANDLE) |
| 35 | #undef CHECK_REUSABLE_HANDLE |
| 36 | #endif // defined(DEBUG) |
| 37 | |
| 38 | // Remember the error in the sticky error of this isolate. |
| 39 | thread->set_sticky_error(error); |
| 40 | |
| 41 | // Destruct all the active StackResource objects. |
| 42 | StackResource::UnwindAbove(thread, top_); |
| 43 | longjmp(environment_, value); |
| 44 | UNREACHABLE(); |
| 45 | } |
| 46 | |
| 47 | } // namespace dart |
| 48 |