From deda13e80e9bc4ad4d392e48de097d07c091ad61 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 15 Nov 2017 23:27:37 +0200 Subject: [PATCH] API tests for duk_get_prop_literal() etc --- tests/api/test-all-public-symbols.c | 8 +++ tests/api/test-del-prop.c | 32 +++++++++ tests/api/test-get-global-heapptr.c | 32 +++++++++ tests/api/test-get-global-literal.c | 28 ++++++++ tests/api/test-get-prop.c | 101 +++++++++++++++++++++++++++- tests/api/test-has-prop.c | 76 +++++++++++++++++++++ tests/api/test-put-global-heapptr.c | 64 ++++++++++++++++++ tests/api/test-put-global-literal.c | 56 +++++++++++++++ tests/api/test-put-prop.c | 33 ++++++++- 9 files changed, 427 insertions(+), 3 deletions(-) create mode 100644 tests/api/test-get-global-heapptr.c create mode 100644 tests/api/test-get-global-literal.c create mode 100644 tests/api/test-put-global-heapptr.c create mode 100644 tests/api/test-put-global-literal.c diff --git a/tests/api/test-all-public-symbols.c b/tests/api/test-all-public-symbols.c index 6ef3d342..18ad3dba 100644 --- a/tests/api/test-all-public-symbols.c +++ b/tests/api/test-all-public-symbols.c @@ -61,6 +61,7 @@ static duk_ret_t test_func(duk_context *ctx, void *udata) { (void) duk_def_prop(ctx, 0, 0); (void) duk_del_prop_heapptr(ctx, 0, NULL); (void) duk_del_prop_index(ctx, 0, 0); + (void) duk_del_prop_literal(ctx, 0, "dummy"); (void) duk_del_prop_lstring(ctx, 0, "dummy", 0); (void) duk_del_prop_string(ctx, 0, "dummy"); (void) duk_del_prop(ctx, 0); @@ -100,6 +101,8 @@ static duk_ret_t test_func(duk_context *ctx, void *udata) { (void) duk_get_current_magic(ctx); (void) duk_get_error_code(ctx, 0); (void) duk_get_finalizer(ctx, 0); + (void) duk_get_global_heapptr(ctx, NULL); + (void) duk_get_global_literal(ctx, "dummy"); (void) duk_get_global_lstring(ctx, "dummy", 0); (void) duk_get_global_string(ctx, "dummy"); (void) duk_get_heapptr(ctx, 0); @@ -119,6 +122,7 @@ static duk_ret_t test_func(duk_context *ctx, void *udata) { (void) duk_get_prop_desc(ctx, 0, 0); (void) duk_get_prop_heapptr(ctx, 0, NULL); (void) duk_get_prop_index(ctx, 0, 0); + (void) duk_get_prop_literal(ctx, 0, "dummy"); (void) duk_get_prop_lstring(ctx, 0, "dummy", 0); (void) duk_get_prop_string(ctx, 0, "dummy"); (void) duk_get_prop(ctx, 0); @@ -133,6 +137,7 @@ static duk_ret_t test_func(duk_context *ctx, void *udata) { (void) duk_get_uint_default(ctx, 0, 0); (void) duk_has_prop_heapptr(ctx, 0, NULL); (void) duk_has_prop_index(ctx, 0, 0); + (void) duk_has_prop_literal(ctx, 0, "dummy"); (void) duk_has_prop_lstring(ctx, 0, "dummy", 0); (void) duk_has_prop_string(ctx, 0, "dummy"); (void) duk_has_prop(ctx, 0); @@ -256,11 +261,14 @@ static duk_ret_t test_func(duk_context *ctx, void *udata) { (void) duk_push_undefined(ctx); (void) duk_push_vsprintf(ctx, "dummy", NULL); (void) duk_put_function_list(ctx, 0, NULL); + (void) duk_put_global_heapptr(ctx, NULL); + (void) duk_put_global_literal(ctx, "dummy"); (void) duk_put_global_lstring(ctx, "dummy", 0); (void) duk_put_global_string(ctx, "dummy"); (void) duk_put_number_list(ctx, 0, NULL); (void) duk_put_prop_heapptr(ctx, 0, NULL); (void) duk_put_prop_index(ctx, 0, 0); + (void) duk_put_prop_literal(ctx, 0, "dummy"); (void) duk_put_prop_lstring(ctx, 0, "dummy", 0); (void) duk_put_prop_string(ctx, 0, "dummy"); (void) duk_put_prop(ctx, 0); diff --git a/tests/api/test-del-prop.c b/tests/api/test-del-prop.c index ef504600..7f01a2be 100644 --- a/tests/api/test-del-prop.c +++ b/tests/api/test-del-prop.c @@ -98,6 +98,16 @@ delete obj.nulkey -> rc=1 {"123":"123val","foo":"fooval","bar":"barval","undefined":"undefinedval"} final top: 3 ==> rc=0, result='undefined' +*** test_delpropliteral_a_safecall (duk_safe_call) +delete obj.foo -> rc=1 +{"123":"123val","bar":"barval","nul\u0000key":"nulval","undefined":"undefinedval"} +final top: 3 +==> rc=0, result='undefined' +*** test_delpropliteral_a (duk_pcall) +delete obj.foo -> rc=1 +{"123":"123val","bar":"barval","nul\u0000key":"nulval","undefined":"undefinedval"} +final top: 3 +==> rc=0, result='undefined' *** test_delpropheapptr_a_safecall (duk_safe_call) delete obj.foo -> rc=1 delete obj.nonexistent -> rc=1 @@ -546,6 +556,25 @@ static duk_ret_t test_delproplstring_a_safecall(duk_context *ctx, void *udata) { return test_delproplstring_a(ctx); } +/* duk_del_prop_literal(), success case */ +static duk_ret_t test_delpropliteral_a(duk_context *ctx) { + duk_ret_t rc; + prep(ctx); + + rc = duk_del_prop_literal(ctx, 0, "foo"); + printf("delete obj.foo -> rc=%d\n", (int) rc); + + duk_json_encode(ctx, 0); + printf("%s\n", duk_to_string(ctx, 0)); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} +static duk_ret_t test_delpropliteral_a_safecall(duk_context *ctx, void *udata) { + (void) udata; + return test_delpropliteral_a(ctx); +} + /* duk_del_prop_heapptr(), success cases */ static duk_ret_t test_delpropheapptr_a_safecall(duk_context *ctx, void *udata) { duk_ret_t rc; @@ -689,6 +718,9 @@ void test(duk_context *ctx) { TEST_SAFE_CALL(test_delproplstring_a_safecall); TEST_PCALL(test_delproplstring_a); + TEST_SAFE_CALL(test_delpropliteral_a_safecall); + TEST_PCALL(test_delpropliteral_a); + TEST_SAFE_CALL(test_delpropheapptr_a_safecall); TEST_PCALL(test_delpropheapptr_a); TEST_SAFE_CALL(test_delpropheapptr_b_safecall); diff --git a/tests/api/test-get-global-heapptr.c b/tests/api/test-get-global-heapptr.c new file mode 100644 index 00000000..ef2879cb --- /dev/null +++ b/tests/api/test-get-global-heapptr.c @@ -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); +} diff --git a/tests/api/test-get-global-literal.c b/tests/api/test-get-global-literal.c new file mode 100644 index 00000000..fe55b9f6 --- /dev/null +++ b/tests/api/test-get-global-literal.c @@ -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); +} diff --git a/tests/api/test-get-prop.c b/tests/api/test-get-prop.c index 96a62c30..058336b8 100644 --- a/tests/api/test-get-prop.c +++ b/tests/api/test-get-prop.c @@ -17,7 +17,7 @@ final top: 3 *** test_getprop_d (duk_safe_call) Math.PI is 3.141593 configuration setting present, value: setting value -final top: 4 +final top: 3 ==> rc=0, result='undefined' *** test_getprop_e (duk_safe_call) ==> rc=1, result='TypeError: cannot read property 'foo' of null' @@ -60,6 +60,21 @@ final top: 3 ==> rc=1, result='RangeError: invalid stack index 234' *** test_getproplstring_c (duk_safe_call) ==> rc=1, result='RangeError: invalid stack index -2147483648' +*** test_getpropliteral_a (duk_safe_call) +obj.foo -> rc=1, result='fooval' +obj.nonexistent -> rc=0, result='undefined' +obj['123'] -> rc=1, result='123val' +arr.nonexistent -> rc=0, result='undefined' +arr['2'] -> rc=1, result='quux' +arr.length -> rc=1, result='3' +'test_string'['5'] -> rc=1, result='s' +'test_string'.length -> rc=1, result='11' +final top: 3 +==> rc=0, result='undefined' +*** test_getpropliteral_b (duk_safe_call) +==> rc=1, result='RangeError: invalid stack index 234' +*** test_getpropliteral_c (duk_safe_call) +==> rc=1, result='RangeError: invalid stack index -2147483648' *** test_getpropheapptr_a (duk_safe_call) obj.foo -> rc=1, result='fooval' obj.nonexistent -> rc=0, result='undefined' @@ -212,6 +227,8 @@ static duk_ret_t test_getprop_d(duk_context *ctx, void *udata) { } duk_pop(ctx); /* remember to pop, regardless of whether or not present */ + duk_pop(ctx); /* config object */ + printf("final top: %ld\n", (long) duk_get_top(ctx)); return 0; } @@ -438,6 +455,84 @@ static duk_ret_t test_getproplstring_c(duk_context *ctx, void *udata) { return 0; } +/* duk_get_prop_literal(), success cases */ +static duk_ret_t test_getpropliteral_a(duk_context *ctx, void *udata) { + duk_ret_t rc; + + (void) udata; + + prep(ctx); + + rc = duk_get_prop_literal(ctx, 0, "foo"); + printf("obj.foo -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + /* No embedded NUL test: config specific behavior. */ + + rc = duk_get_prop_literal(ctx, 0, "nonexistent"); + printf("obj.nonexistent -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + rc = duk_get_prop_literal(ctx, 0, "123"); + printf("obj['123'] -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + rc = duk_get_prop_literal(ctx, 1, "nonexistent"); + printf("arr.nonexistent -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + rc = duk_get_prop_literal(ctx, 1, "2"); + printf("arr['2'] -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + rc = duk_get_prop_literal(ctx, 1, "length"); + printf("arr.length -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + rc = duk_get_prop_literal(ctx, 2, "5"); + printf("'test_string'['5'] -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + rc = duk_get_prop_literal(ctx, 2, "length"); + printf("'test_string'.length -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} + +/* duk_get_prop_literal(), invalid index */ +static duk_ret_t test_getpropliteral_b(duk_context *ctx, void *udata) { + duk_ret_t rc; + + (void) udata; + + prep(ctx); + + rc = duk_get_prop_literal(ctx, 234, "foo"); + printf("obj.foo -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} + +/* duk_get_prop_literal(), DUK_INVALID_INDEX */ +static duk_ret_t test_getpropliteral_c(duk_context *ctx, void *udata) { + duk_ret_t rc; + + (void) udata; + + prep(ctx); + + rc = duk_get_prop_literal(ctx, DUK_INVALID_INDEX, "foo"); + printf("obj.foo -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1)); + duk_pop(ctx); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} + /* duk_get_prop_heapptr(), success cases */ static duk_ret_t test_getpropheapptr_a(duk_context *ctx, void *udata) { duk_ret_t rc; @@ -549,6 +644,10 @@ void test(duk_context *ctx) { TEST_SAFE_CALL(test_getproplstring_b); TEST_SAFE_CALL(test_getproplstring_c); + TEST_SAFE_CALL(test_getpropliteral_a); + TEST_SAFE_CALL(test_getpropliteral_b); + TEST_SAFE_CALL(test_getpropliteral_c); + TEST_SAFE_CALL(test_getpropheapptr_a); TEST_SAFE_CALL(test_getpropheapptr_b); TEST_SAFE_CALL(test_getpropheapptr_c); diff --git a/tests/api/test-has-prop.c b/tests/api/test-has-prop.c index 05bb346f..37fa7d24 100644 --- a/tests/api/test-has-prop.c +++ b/tests/api/test-has-prop.c @@ -50,6 +50,19 @@ final top: 3 ==> rc=1, result='RangeError: invalid stack index 234' *** test_hasproplstring_c (duk_safe_call) ==> rc=1, result='RangeError: invalid stack index -2147483648' +*** test_haspropliteral_a (duk_safe_call) +obj.foo -> rc=1 +obj.nonexistent -> rc=0 +obj['123'] -> rc=1 +arr.nonexistent -> rc=0 +arr['2'] -> rc=1 +arr.length -> rc=1 +final top: 3 +==> rc=0, result='undefined' +*** test_haspropliteral_b (duk_safe_call) +==> rc=1, result='RangeError: invalid stack index 234' +*** test_haspropliteral_c (duk_safe_call) +==> rc=1, result='RangeError: invalid stack index -2147483648' *** test_haspropheapptr_a (duk_safe_call) obj.foo -> rc=1 obj.nonexistent -> rc=0 @@ -349,6 +362,65 @@ static duk_ret_t test_hasproplstring_c(duk_context *ctx, void *udata) { return 0; } +/* duk_has_prop_literal(), success cases */ +static duk_ret_t test_haspropliteral_a(duk_context *ctx, void *udata) { + duk_ret_t rc; + + (void) udata; + + prep(ctx); + + rc = duk_has_prop_literal(ctx, 0, "foo"); + printf("obj.foo -> rc=%d\n", (int) rc); + + rc = duk_has_prop_literal(ctx, 0, "nonexistent"); + printf("obj.nonexistent -> rc=%d\n", (int) rc); + + rc = duk_has_prop_literal(ctx, 0, "123"); + printf("obj['123'] -> rc=%d\n", (int) rc); + + rc = duk_has_prop_literal(ctx, 1, "nonexistent"); + printf("arr.nonexistent -> rc=%d\n", (int) rc); + + rc = duk_has_prop_literal(ctx, 1, "2"); + printf("arr['2'] -> rc=%d\n", (int) rc); + + rc = duk_has_prop_literal(ctx, 1, "length"); + printf("arr.length -> rc=%d\n", (int) rc); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} + +/* duk_has_prop_literal(), invalid index */ +static duk_ret_t test_haspropliteral_b(duk_context *ctx, void *udata) { + duk_ret_t rc; + + (void) udata; + + prep(ctx); + + rc = duk_has_prop_literal(ctx, 234, "foo"); + printf("obj.foo -> rc=%d\n", (int) rc); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} + +/* duk_has_prop_literal(), DUK_INVALID_INDEX */ +static duk_ret_t test_haspropliteral_c(duk_context *ctx, void *udata) { + duk_ret_t rc; + + (void) udata; + + prep(ctx); + + rc = duk_has_prop_literal(ctx, DUK_INVALID_INDEX, "foo"); + printf("obj.foo -> rc=%d\n", (int) rc); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} /* duk_has_prop_heapptr(), success cases */ static duk_ret_t test_haspropheapptr_a(duk_context *ctx, void *udata) { duk_ret_t rc; @@ -454,6 +526,10 @@ void test(duk_context *ctx) { TEST_SAFE_CALL(test_hasproplstring_b); TEST_SAFE_CALL(test_hasproplstring_c); + TEST_SAFE_CALL(test_haspropliteral_a); + TEST_SAFE_CALL(test_haspropliteral_b); + TEST_SAFE_CALL(test_haspropliteral_c); + TEST_SAFE_CALL(test_haspropheapptr_a); TEST_SAFE_CALL(test_haspropheapptr_b); TEST_SAFE_CALL(test_haspropheapptr_c); diff --git a/tests/api/test-put-global-heapptr.c b/tests/api/test-put-global-heapptr.c new file mode 100644 index 00000000..a6772788 --- /dev/null +++ b/tests/api/test-put-global-heapptr.c @@ -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); +} diff --git a/tests/api/test-put-global-literal.c b/tests/api/test-put-global-literal.c new file mode 100644 index 00000000..81e90f78 --- /dev/null +++ b/tests/api/test-put-global-literal.c @@ -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); +} diff --git a/tests/api/test-put-prop.c b/tests/api/test-put-prop.c index 575894f0..19e9afa4 100644 --- a/tests/api/test-put-prop.c +++ b/tests/api/test-put-prop.c @@ -108,11 +108,11 @@ eval: top after eval: 1 ==> rc=1, result='TypeError: not extensible' *** test_putprop_shorthand_a_safecall (duk_safe_call) -{"2001":234,"foo":123,"bar":123,"nul\u0000key":345,"heapptr":456,"stringCoerced":567,"undefined":678} +{"2001":234,"foo":123,"bar":123,"nul\u0000key":345,"heapptr":456,"stringCoerced":567,"undefined":678,"litkey":789} final top: 1 ==> rc=0, result='undefined' *** test_putprop_shorthand_a (duk_pcall) -{"2001":234,"foo":123,"bar":123,"nul\u0000key":345,"heapptr":456,"stringCoerced":567,"undefined":678} +{"2001":234,"foo":123,"bar":123,"nul\u0000key":345,"heapptr":456,"stringCoerced":567,"undefined":678,"litkey":789} final top: 1 ==> rc=0, result='undefined' *** test_putprop_invalid_index1 (duk_safe_call) @@ -127,6 +127,10 @@ final top: 1 ==> rc=1, result='RangeError: invalid stack index -2147483648' *** test_putprop_lstring_invalid_index2 (duk_safe_call) ==> rc=1, result='RangeError: invalid stack index -2147483648' +*** test_putprop_literal_invalid_index1 (duk_safe_call) +==> rc=1, result='RangeError: invalid stack index -2147483648' +*** test_putprop_literal_invalid_index2 (duk_safe_call) +==> rc=1, result='RangeError: invalid stack index -2147483648' *** test_putprop_index_invalid_index1 (duk_safe_call) ==> rc=1, result='RangeError: invalid stack index 345' *** test_putprop_index_invalid_index2 (duk_safe_call) @@ -406,6 +410,9 @@ static duk_ret_t test_putprop_shorthand_a(duk_context *ctx) { duk_push_uint(ctx, 678); duk_put_prop_heapptr(ctx, -2, NULL); + duk_push_uint(ctx, 789); + duk_put_prop_literal(ctx, -2, "litkey"); + duk_json_encode(ctx, -1); printf("%s\n", duk_to_string(ctx, -1)); @@ -479,6 +486,26 @@ static duk_ret_t test_putprop_lstring_invalid_index2(duk_context *ctx, void *uda return 0; } +static duk_ret_t test_putprop_literal_invalid_index1(duk_context *ctx, void *udata) { + (void) udata; + + duk_push_uint(ctx, 123); + duk_put_prop_literal(ctx, 123, "foo"); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} + +static duk_ret_t test_putprop_literal_invalid_index2(duk_context *ctx, void *udata) { + (void) udata; + + duk_push_uint(ctx, 123); + duk_put_prop_literal(ctx, DUK_INVALID_INDEX, "foo"); + + printf("final top: %ld\n", (long) duk_get_top(ctx)); + return 0; +} + static duk_ret_t test_putprop_index_invalid_index1(duk_context *ctx, void *udata) { (void) udata; @@ -552,6 +579,8 @@ void test(duk_context *ctx) { TEST_SAFE_CALL(test_putprop_string_invalid_index2); TEST_SAFE_CALL(test_putprop_lstring_invalid_index1); TEST_SAFE_CALL(test_putprop_lstring_invalid_index2); + TEST_SAFE_CALL(test_putprop_literal_invalid_index1); + TEST_SAFE_CALL(test_putprop_literal_invalid_index2); TEST_SAFE_CALL(test_putprop_index_invalid_index1); TEST_SAFE_CALL(test_putprop_index_invalid_index2); TEST_SAFE_CALL(test_putprop_heapptr_invalid_index1);