mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.7 KiB
80 lines
1.7 KiB
/*===
|
|
*** test_1 (duk_safe_call)
|
|
top: 18
|
|
index 0, is-null: 1
|
|
index 1, is-null: 1
|
|
index 2, is-null: 1
|
|
index 3, is-null: 1
|
|
index 4, is-null: 1
|
|
index 5, is-null: 1
|
|
index 6, is-null: 1
|
|
index 7, is-null: 1
|
|
index 8, is-null: 1
|
|
index 9, is-null: 1
|
|
index 10, is-null: 1
|
|
index 11, is-null: 1
|
|
index 12, is-null: 1
|
|
index 13, is-null: 1
|
|
index 14, is-null: 1
|
|
index 15, is-null: 1
|
|
index 16, is-null: 1
|
|
index 17, is-null: 1
|
|
==> rc=0, result='undefined'
|
|
*** test_2 (duk_safe_call)
|
|
==> rc=1, result='Error: index out of bounds'
|
|
*** test_3 (duk_safe_call)
|
|
==> rc=1, result='Error: index out of bounds'
|
|
===*/
|
|
|
|
int test_1(duk_context *ctx) {
|
|
int i, n;
|
|
|
|
duk_set_top(ctx, 0);
|
|
duk_push_undefined(ctx);
|
|
duk_push_null(ctx);
|
|
duk_push_true(ctx);
|
|
duk_push_false(ctx);
|
|
duk_push_int(ctx, 0);
|
|
duk_push_int(ctx, 1);
|
|
duk_push_nan(ctx);
|
|
duk_push_number(ctx, INFINITY);
|
|
duk_push_string(ctx, "");
|
|
duk_push_string(ctx, "foo");
|
|
duk_push_object(ctx);
|
|
duk_push_thread(ctx);
|
|
duk_push_fixed_buffer(ctx, 0);
|
|
duk_push_fixed_buffer(ctx, 1024);
|
|
duk_push_dynamic_buffer(ctx, 0);
|
|
duk_push_dynamic_buffer(ctx, 1024);
|
|
duk_push_pointer(ctx, (void *) NULL);
|
|
duk_push_pointer(ctx, (void *) 0xdeadbeef);
|
|
|
|
n = duk_get_top(ctx);
|
|
printf("top: %d\n", n);
|
|
for (i = 0; i < n; i++) {
|
|
duk_to_null(ctx, i);
|
|
printf("index %d, is-null: %d\n", i, duk_is_null(ctx, i));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int test_2(duk_context *ctx) {
|
|
duk_set_top(ctx, 0);
|
|
duk_to_null(ctx, 3);
|
|
printf("index 3 OK\n");
|
|
return 0;
|
|
}
|
|
|
|
int test_3(duk_context *ctx) {
|
|
duk_set_top(ctx, 0);
|
|
duk_to_null(ctx, DUK_INVALID_INDEX);
|
|
printf("index DUK_INVALID_INDEX OK\n");
|
|
return 0;
|
|
}
|
|
|
|
void test(duk_context *ctx) {
|
|
TEST_SAFE_CALL(test_1);
|
|
TEST_SAFE_CALL(test_2);
|
|
TEST_SAFE_CALL(test_3);
|
|
}
|
|
|