mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
8 years ago
committed by
GitHub
14 changed files with 127 additions and 61 deletions
@ -0,0 +1,50 @@ |
|||
/*===
|
|||
*** test_basic (duk_safe_call) |
|||
["foo","bar","quux","bax"] |
|||
["foo"] |
|||
["foo",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null] |
|||
{"foo":123} |
|||
{"foo":123,"length":123} |
|||
final top: 0 |
|||
==> rc=0, result='undefined' |
|||
===*/ |
|||
|
|||
static duk_ret_t test_basic(duk_context *ctx, void *udata) { |
|||
(void) udata; |
|||
|
|||
duk_eval_string(ctx, "[ 'foo', 'bar', 'quux', 'bax' ]"); |
|||
duk_dup(ctx, -1); |
|||
printf("%s\n", duk_json_encode(ctx, -1)); |
|||
duk_pop(ctx); |
|||
|
|||
duk_set_length(ctx, -1, 1); |
|||
duk_dup(ctx, -1); |
|||
printf("%s\n", duk_json_encode(ctx, -1)); |
|||
duk_pop(ctx); |
|||
|
|||
duk_set_length(ctx, -1, 100); |
|||
duk_dup(ctx, -1); |
|||
printf("%s\n", duk_json_encode(ctx, -1)); |
|||
duk_pop(ctx); |
|||
|
|||
duk_pop(ctx); |
|||
|
|||
duk_eval_string(ctx, "({ foo: 123 })"); |
|||
duk_dup(ctx, -1); |
|||
printf("%s\n", duk_json_encode(ctx, -1)); |
|||
duk_pop(ctx); |
|||
|
|||
duk_set_length(ctx, -1, 123); |
|||
duk_dup(ctx, -1); |
|||
printf("%s\n", duk_json_encode(ctx, -1)); |
|||
duk_pop(ctx); |
|||
|
|||
duk_pop(ctx); |
|||
|
|||
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,23 @@ |
|||
name: duk_set_length |
|||
|
|||
proto: | |
|||
void duk_set_length(duk_context *ctx, duk_idx_t idx, duk_size_t len); |
|||
|
|||
stack: | |
|||
[ ... val! ... ] |
|||
|
|||
summary: | |
|||
<p>Set "length" for value at <code>idx</code>. Equivalent to the Ecmascript |
|||
statement <code>obj.length = len;</code>.</p> |
|||
|
|||
example: | |
|||
/* Set array length to zero, deleting elements as a side effect. */ |
|||
duk_set_length(ctx, -3, 0); |
|||
|
|||
tags: |
|||
- stack |
|||
|
|||
seealso: |
|||
- duk_get_length |
|||
|
|||
introduced: 2.0.0 |
Loading…
Reference in new issue