diff --git a/api-testcases/test-global-stash.c b/api-testcases/test-global-stash.c new file mode 100644 index 00000000..42626ae2 --- /dev/null +++ b/api-testcases/test-global-stash.c @@ -0,0 +1,25 @@ +/*=== +top: 0 +top: 1 +top: 0 +value: 123 +top: 0 +===*/ + +void test(duk_context *ctx) { + printf("top: %d\n", duk_get_top(ctx)); + duk_push_global_stash(ctx); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_int(ctx, 123); + duk_put_prop_string(ctx, -2, "myvalue"); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_global_stash(ctx); + duk_get_prop_string(ctx, -1, "myvalue"); + printf("value: %d\n", duk_get_int(ctx, -1)); + duk_pop(ctx); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); +} diff --git a/api-testcases/test-heap-stash.c b/api-testcases/test-heap-stash.c new file mode 100644 index 00000000..4ad6b9a1 --- /dev/null +++ b/api-testcases/test-heap-stash.c @@ -0,0 +1,25 @@ +/*=== +top: 0 +top: 1 +top: 0 +value: 123 +top: 0 +===*/ + +void test(duk_context *ctx) { + printf("top: %d\n", duk_get_top(ctx)); + duk_push_heap_stash(ctx); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_int(ctx, 123); + duk_put_prop_string(ctx, -2, "myvalue"); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_heap_stash(ctx); + duk_get_prop_string(ctx, -1, "myvalue"); + printf("value: %d\n", duk_get_int(ctx, -1)); + duk_pop(ctx); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); +} diff --git a/api-testcases/test-thread-stash.c b/api-testcases/test-thread-stash.c new file mode 100644 index 00000000..30769c1b --- /dev/null +++ b/api-testcases/test-thread-stash.c @@ -0,0 +1,52 @@ +/*=== +top: 2 +top: 3 +top: 2 +top: 3 +top: 2 +value: 123 +top: 2 +value: 234 +top: 2 +===*/ + +void test(duk_context *ctx) { + duk_context *ctx1; + duk_context *ctx2; + + duk_push_thread(ctx); + ctx1 = duk_get_context(ctx, -1); + duk_push_thread(ctx); + ctx2 = duk_get_context(ctx, -1); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_thread_stash(ctx, ctx1); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_int(ctx, 123); + duk_put_prop_string(ctx, -2, "myvalue"); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_thread_stash(ctx, ctx2); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_int(ctx, 234); + duk_put_prop_string(ctx, -2, "myvalue"); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_thread_stash(ctx, ctx1); + duk_get_prop_string(ctx, -1, "myvalue"); + printf("value: %d\n", duk_get_int(ctx, -1)); + duk_pop(ctx); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); + + duk_push_thread_stash(ctx, ctx2); + duk_get_prop_string(ctx, -1, "myvalue"); + printf("value: %d\n", duk_get_int(ctx, -1)); + duk_pop(ctx); + duk_pop(ctx); + printf("top: %d\n", duk_get_top(ctx)); +}