|
|
@ -4,6 +4,15 @@ |
|
|
|
|
|
|
|
#include "duk_internal.h" |
|
|
|
|
|
|
|
typedef struct duk_internal_thread_state duk_internal_thread_state; |
|
|
|
|
|
|
|
struct duk_internal_thread_state { |
|
|
|
duk_ljstate lj; |
|
|
|
duk_bool_t handling_error; |
|
|
|
duk_hthread *curr_thread; |
|
|
|
duk_int_t call_recursion_depth; |
|
|
|
}; |
|
|
|
|
|
|
|
DUK_EXTERNAL |
|
|
|
duk_context *duk_create_heap(duk_alloc_function alloc_func, |
|
|
|
duk_realloc_function realloc_func, |
|
|
@ -69,6 +78,55 @@ DUK_EXTERNAL void duk_destroy_heap(duk_context *ctx) { |
|
|
|
duk_heap_free(heap); |
|
|
|
} |
|
|
|
|
|
|
|
DUK_EXTERNAL void duk_suspend(duk_context *ctx, duk_thread_state *state) { |
|
|
|
duk_hthread *thr = (duk_hthread *) ctx; |
|
|
|
duk_internal_thread_state *snapshot = (duk_internal_thread_state *) state; |
|
|
|
duk_heap *heap; |
|
|
|
duk_ljstate *lj; |
|
|
|
|
|
|
|
DUK_ASSERT_CTX_VALID(ctx); |
|
|
|
DUK_ASSERT(thr != NULL); |
|
|
|
DUK_ASSERT(thr->heap != NULL); |
|
|
|
|
|
|
|
heap = thr->heap; |
|
|
|
lj = &heap->lj; |
|
|
|
|
|
|
|
duk_push_tval(ctx, &lj->value1); |
|
|
|
duk_push_tval(ctx, &lj->value2); |
|
|
|
|
|
|
|
DUK_MEMMOVE((void *) &snapshot->lj, (const void *) lj, sizeof(duk_ljstate)); |
|
|
|
snapshot->handling_error = heap->handling_error; |
|
|
|
snapshot->curr_thread = heap->curr_thread; |
|
|
|
snapshot->call_recursion_depth = heap->call_recursion_depth; |
|
|
|
|
|
|
|
lj->jmpbuf_ptr = NULL; |
|
|
|
lj->type = DUK_LJ_TYPE_UNKNOWN; |
|
|
|
DUK_TVAL_SET_UNDEFINED(&lj->value1); |
|
|
|
DUK_TVAL_SET_UNDEFINED(&lj->value2); |
|
|
|
heap->handling_error = 0; |
|
|
|
heap->curr_thread = NULL; |
|
|
|
heap->call_recursion_depth = 0; |
|
|
|
} |
|
|
|
|
|
|
|
DUK_EXTERNAL void duk_resume(duk_context *ctx, const duk_thread_state *state) { |
|
|
|
duk_hthread *thr = (duk_hthread *) ctx; |
|
|
|
const duk_internal_thread_state *snapshot = (const duk_internal_thread_state *) state; |
|
|
|
duk_heap *heap; |
|
|
|
|
|
|
|
DUK_ASSERT_CTX_VALID(ctx); |
|
|
|
DUK_ASSERT(thr != NULL); |
|
|
|
DUK_ASSERT(thr->heap != NULL); |
|
|
|
|
|
|
|
heap = thr->heap; |
|
|
|
|
|
|
|
DUK_MEMMOVE((void *) &heap->lj, (const void *) &snapshot->lj, sizeof(duk_ljstate)); |
|
|
|
heap->handling_error = snapshot->handling_error; |
|
|
|
heap->curr_thread = snapshot->curr_thread; |
|
|
|
heap->call_recursion_depth = snapshot->call_recursion_depth; |
|
|
|
|
|
|
|
duk_pop_2(ctx); |
|
|
|
} |
|
|
|
|
|
|
|
/* XXX: better place for this */ |
|
|
|
DUK_EXTERNAL void duk_set_global_object(duk_context *ctx) { |
|
|
|
duk_hthread *thr = (duk_hthread *) ctx; |
|
|
|