/* Duktape.Buffer */
static duk_ret_t test_duktape_buffer_indexed_1a(duk_context *ctx) {
	duk_push_dynamic_buffer(ctx, 100);
	setup_duktape_buffer(ctx, -1);
	shared_read_write_index(ctx, 95);

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
static duk_ret_t test_json_serialize_1(duk_context *ctx, void *udata) {
	unsigned char *data;
	int i;
	duk_uarridx_t arridx = 0;

	(void) udata;

	data = (unsigned char *) duk_push_dynamic_buffer(ctx, 20);
	for (i = 0; i < 20; i++) {
		data[i] = 0x40 + i;
	}

	duk_push_array(ctx);  /* index 1 */
	setup_duktape_buffer(ctx, 0);
	duk_put_prop_index(ctx, 1, arridx++);
	setup_nodejs_buffer(ctx, 0);
	duk_put_prop_index(ctx, 1, arridx++);
	setup_nodejs_buffer_slice(ctx, 0, 3, 5);
	duk_put_prop_index(ctx, 1, arridx++);
	setup_arraybuffer(ctx, 0);
	duk_put_prop_index(ctx, 1, arridx++);
	setup_typedarray(ctx, 0, "Uint8Array");
	duk_put_prop_index(ctx, 1, arridx++);
	setup_typedarray_slice(ctx, 0, "Uint8Array", 2, 6);
	duk_put_prop_index(ctx, 1, arridx++);
	setup_typedarray(ctx, 0, "Uint32Array");
	duk_put_prop_index(ctx, 1, arridx++);
	setup_typedarray_slice(ctx, 0, "Uint32Array", 4, 1);
	duk_put_prop_index(ctx, 1, arridx++);

	/* Serialize with a full backing buffer first. */

	for (i = 20; i >= 0; i--) {
		printf("resize to %d\n", i);
		duk_resize_buffer(ctx, 0, i);

		duk_dup(ctx, 1);
		duk_json_encode(ctx, -1);
		printf("%s\n", duk_to_string(ctx, -1));
		duk_pop(ctx);
		duk_eval_string(ctx, "(function (v) { print(Duktape.enc('jx', v)); })");
		duk_dup(ctx, 1);
		duk_call(ctx, 1);
		duk_pop(ctx);
	}

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}