mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
7 years ago
9 changed files with 427 additions and 3 deletions
@ -0,0 +1,32 @@ |
|||
/*===
|
|||
*** test_basic (duk_safe_call) |
|||
top: 1 |
|||
top: 2 |
|||
ret: 1 |
|||
duk_is_function: 1 |
|||
final top: 2 |
|||
==> rc=0, result='undefined' |
|||
===*/ |
|||
|
|||
static duk_ret_t test_basic(duk_context *ctx, void *udata) { |
|||
duk_bool_t ret; |
|||
void *ptr; |
|||
|
|||
(void) udata; |
|||
|
|||
(void) duk_push_string(ctx, "encodeURIComponent"); |
|||
ptr = duk_get_heapptr(ctx, -1); |
|||
|
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
ret = duk_get_global_heapptr(ctx, ptr); |
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
printf("ret: %ld\n", (long) ret); |
|||
printf("duk_is_function: %ld\n", duk_is_function(ctx, -1)); |
|||
|
|||
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|||
return 0; |
|||
} |
|||
|
|||
void test(duk_context *ctx) { |
|||
TEST_SAFE_CALL(test_basic); |
|||
} |
@ -0,0 +1,28 @@ |
|||
/*===
|
|||
*** test_basic (duk_safe_call) |
|||
top: 0 |
|||
top: 1 |
|||
ret: 1 |
|||
duk_is_function: 1 |
|||
final top: 1 |
|||
==> rc=0, result='undefined' |
|||
===*/ |
|||
|
|||
static duk_ret_t test_basic(duk_context *ctx, void *udata) { |
|||
duk_bool_t ret; |
|||
|
|||
(void) udata; |
|||
|
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
ret = duk_get_global_literal(ctx, "encodeURIComponent"); |
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
printf("ret: %ld\n", (long) ret); |
|||
printf("duk_is_function: %ld\n", duk_is_function(ctx, -1)); |
|||
|
|||
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|||
return 0; |
|||
} |
|||
|
|||
void test(duk_context *ctx) { |
|||
TEST_SAFE_CALL(test_basic); |
|||
} |
@ -0,0 +1,64 @@ |
|||
/*===
|
|||
*** test_basic (duk_safe_call) |
|||
top: 1 |
|||
top: 1 |
|||
ret: 1 |
|||
1.2.3 |
|||
final top: 1 |
|||
==> rc=0, result='undefined' |
|||
*** test_nonwritable (duk_safe_call) |
|||
top: 1 |
|||
==> rc=1, result='TypeError: not writable' |
|||
===*/ |
|||
|
|||
static duk_ret_t test_basic(duk_context *ctx, void *udata) { |
|||
duk_bool_t ret; |
|||
void *ptr; |
|||
|
|||
(void) udata; |
|||
|
|||
(void) duk_push_string(ctx, "myAppVersion"); |
|||
ptr = duk_get_heapptr(ctx, -1); |
|||
|
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
duk_push_string(ctx, "1.2.3"); |
|||
ret = duk_put_global_heapptr(ctx, ptr); |
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
printf("ret: %ld\n", (long) ret); |
|||
|
|||
duk_eval_string_noresult(ctx, "print(myAppVersion);"); |
|||
|
|||
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|||
return 0; |
|||
} |
|||
|
|||
static duk_ret_t test_nonwritable(duk_context *ctx, void *udata) { |
|||
duk_bool_t ret; |
|||
void *ptr; |
|||
|
|||
(void) udata; |
|||
|
|||
(void) duk_push_string(ctx, "nonWritable"); |
|||
ptr = duk_get_heapptr(ctx, -1); |
|||
|
|||
duk_eval_string_noresult(ctx, |
|||
"Object.defineProperty(this, 'nonWritable', " |
|||
"{ value: 'foo', writable: false, enumerable: false, configurable: false });" |
|||
); |
|||
|
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
duk_push_string(ctx, "bar"); |
|||
ret = duk_put_global_heapptr(ctx, ptr); |
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
printf("ret: %ld\n", (long) ret); |
|||
|
|||
duk_eval_string_noresult(ctx, "print(nonWritable);"); |
|||
|
|||
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|||
return 0; |
|||
} |
|||
|
|||
void test(duk_context *ctx) { |
|||
TEST_SAFE_CALL(test_basic); |
|||
TEST_SAFE_CALL(test_nonwritable); |
|||
} |
@ -0,0 +1,56 @@ |
|||
/*===
|
|||
*** test_basic (duk_safe_call) |
|||
top: 0 |
|||
top: 0 |
|||
ret: 1 |
|||
1.2.3 |
|||
final top: 0 |
|||
==> rc=0, result='undefined' |
|||
*** test_nonwritable (duk_safe_call) |
|||
top: 0 |
|||
==> rc=1, result='TypeError: not writable' |
|||
===*/ |
|||
|
|||
static duk_ret_t test_basic(duk_context *ctx, void *udata) { |
|||
duk_bool_t ret; |
|||
|
|||
(void) udata; |
|||
|
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
duk_push_string(ctx, "1.2.3"); |
|||
ret = duk_put_global_literal(ctx, "myAppVersion"); |
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
printf("ret: %ld\n", (long) ret); |
|||
|
|||
duk_eval_string_noresult(ctx, "print(myAppVersion);"); |
|||
|
|||
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|||
return 0; |
|||
} |
|||
|
|||
static duk_ret_t test_nonwritable(duk_context *ctx, void *udata) { |
|||
duk_bool_t ret; |
|||
|
|||
(void) udata; |
|||
|
|||
duk_eval_string_noresult(ctx, |
|||
"Object.defineProperty(this, 'nonWritable', " |
|||
"{ value: 'foo', writable: false, enumerable: false, configurable: false });" |
|||
); |
|||
|
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
duk_push_string(ctx, "bar"); |
|||
ret = duk_put_global_literal(ctx, "nonWritable"); |
|||
printf("top: %ld\n", (long) duk_get_top(ctx)); |
|||
printf("ret: %ld\n", (long) ret); |
|||
|
|||
duk_eval_string_noresult(ctx, "print(nonWritable);"); |
|||
|
|||
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|||
return 0; |
|||
} |
|||
|
|||
void test(duk_context *ctx) { |
|||
TEST_SAFE_CALL(test_basic); |
|||
TEST_SAFE_CALL(test_nonwritable); |
|||
} |
Loading…
Reference in new issue