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.
30 lines
996 B
30 lines
996 B
/*===
|
|
{"meaningOfLife":42}
|
|
{"meaningOfLife":42,"foo":"bar"}
|
|
{"meaningOfLife":42,"foo":"bar"}
|
|
===*/
|
|
|
|
void test(duk_context *ctx) {
|
|
duk_push_object(ctx); /* [ ... obj ] */
|
|
duk_push_int(ctx, 42); /* [ ... obj 42 ] */
|
|
duk_put_prop_string(ctx, -2, "meaningOfLife"); /* [ ... obj ] */
|
|
|
|
/* compaction has no external impact */
|
|
duk_compact(ctx, -1); /* [ ... obj ] */
|
|
duk_dup_top(ctx);
|
|
printf("%s\n", duk_json_encode(ctx, -1));
|
|
duk_pop(ctx);
|
|
|
|
/* compaction doesn't prevent new properties from being added */
|
|
duk_push_string(ctx, "bar"); /* [ ... obj "bar" ] */
|
|
duk_put_prop_string(ctx, -2, "foo"); /* [ ... obj ] */
|
|
duk_dup_top(ctx);
|
|
printf("%s\n", duk_json_encode(ctx, -1));
|
|
duk_pop(ctx);
|
|
|
|
/* compaction can be done multiple times */
|
|
duk_compact(ctx, -1); /* [ ... obj ] */
|
|
duk_dup_top(ctx);
|
|
printf("%s\n", duk_json_encode(ctx, -1));
|
|
duk_pop(ctx);
|
|
}
|
|
|