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.
74 lines
1.7 KiB
74 lines
1.7 KiB
/*===
|
|
*** test_1 (duk_safe_call)
|
|
top: 3
|
|
index 0, type 6 -> 5, result: [object Object]
|
|
index 1, type 6 -> 4, result: 123
|
|
index 2, type 6 -> 3, result: true
|
|
==> rc=0, result='undefined'
|
|
*** test_2 (duk_safe_call)
|
|
==> rc=1, result='TypeError: not object'
|
|
*** test_3 (duk_safe_call)
|
|
==> rc=1, result='Error: invalid index: 3'
|
|
*** test_4 (duk_safe_call)
|
|
==> rc=1, result='Error: invalid index: -2147483648'
|
|
===*/
|
|
|
|
/* FIXME: this test is missing a lot of coverage, like different hints,
|
|
* different kinds of objects. Much of this behavior is tested by the
|
|
* Ecmascript tests.
|
|
*/
|
|
|
|
int test_1(duk_context *ctx) {
|
|
int i, n;
|
|
|
|
duk_set_top(ctx, 0);
|
|
duk_push_object(ctx);
|
|
duk_push_int(ctx, 123);
|
|
duk_to_object(ctx, -1); /* ToObject(123) is a Number object */
|
|
duk_push_true(ctx);
|
|
duk_to_object(ctx, -1); /* ToObject(true) is a Boolean object */
|
|
|
|
n = duk_get_top(ctx);
|
|
printf("top: %d\n", n);
|
|
for (i = 0; i < n; i++) {
|
|
int t1, t2;
|
|
|
|
t1 = duk_get_type(ctx, i);
|
|
duk_to_defaultvalue(ctx, i, DUK_HINT_NONE);
|
|
t2 = duk_get_type(ctx, i);
|
|
printf("index %d, type %d -> %d, result: %s\n", i, t1, t2, duk_to_string(ctx, i));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int test_2(duk_context *ctx) {
|
|
/* non-object input */
|
|
duk_set_top(ctx, 0);
|
|
duk_push_int(ctx, 123);
|
|
duk_to_defaultvalue(ctx, 0, DUK_HINT_NONE);
|
|
printf("non-object value OK\n");
|
|
return 0;
|
|
|
|
}
|
|
|
|
int test_3(duk_context *ctx) {
|
|
duk_set_top(ctx, 0);
|
|
duk_to_defaultvalue(ctx, 3, DUK_HINT_NONE);
|
|
printf("index 3 OK\n");
|
|
return 0;
|
|
}
|
|
|
|
int test_4(duk_context *ctx) {
|
|
duk_set_top(ctx, 0);
|
|
duk_to_defaultvalue(ctx, DUK_INVALID_INDEX, DUK_HINT_NONE);
|
|
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);
|
|
TEST_SAFE_CALL(test_4);
|
|
}
|
|
|