forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-freeze.c
More file actions
51 lines (42 loc) · 1.17 KB
/
test-freeze.c
File metadata and controls
51 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*===
*** test_basic (duk_safe_call)
top before: 1
top after: 1
true
true
false
final top: 1
==> rc=0, result='undefined'
*** test_invalid_index (duk_safe_call)
==> rc=1, result='RangeError: invalid stack index -1'
===*/
static duk_ret_t test_basic(duk_context *ctx, void *udata) {
(void) udata;
duk_push_object(ctx); /* [ ... obj ] */
duk_push_int(ctx, 42); /* [ ... obj 42 ] */
duk_put_prop_string(ctx, -2, "meaningOfLife"); /* [ ... obj ] */
printf("top before: %ld\n", (long) duk_get_top(ctx));
duk_freeze(ctx, -1);
printf("top after: %ld\n", (long) duk_get_top(ctx));
duk_eval_string(ctx,
"(function (v) {\n"
" print(Object.isSealed(v));\n"
" print(Object.isFrozen(v));\n"
" print(Object.isExtensible(v));\n"
"})");
duk_dup(ctx, -2);
duk_call(ctx, 1);
duk_pop(ctx);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
static duk_ret_t test_invalid_index(duk_context *ctx, void *udata) {
(void) udata;
duk_freeze(ctx, -1);
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_invalid_index);
}