Browse Source

Add an API testcase for prototype loop and GC

v1.0-maintenance
Sami Vaarala 10 years ago
parent
commit
f00ed4ca92
  1. 44
      api-testcases/test-dev-prototype-loop.c

44
api-testcases/test-dev-prototype-loop.c

@ -0,0 +1,44 @@
/*
* Prototype loop is tricky to handle internally and must not cause e.g.
* GC failures. Exercise a few common paths.
*/
/*===
*** test_1 (duk_safe_call)
first gc
make unreachable
second gc
==> rc=0, result='undefined'
===*/
static duk_ret_t test_1(duk_context *ctx) {
duk_push_object(ctx);
duk_push_object(ctx);
duk_dup(ctx, 0);
duk_set_prototype(ctx, 1);
duk_dup(ctx, 1);
duk_set_prototype(ctx, 0);
/* Both objects are now in a prototype loop. Force garbage
* collection to ensure nothing breaks.
*/
printf("first gc\n"); fflush(stdout);
duk_gc(ctx, 0);
/* Make the objects unreachable and re-run GC. This triggers
* e.g. finalizer checks.
*/
printf("make unreachable\n"); fflush(stdout);
duk_set_top(ctx, 0);
printf("second gc\n"); fflush(stdout);
duk_gc(ctx, 0);
return 0;
}
void test(duk_context *ctx) {
TEST_SAFE_CALL(test_1);
}
Loading…
Cancel
Save