diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2024-01-09 19:15:40 +0100 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2024-01-09 19:15:40 +0100 |
commit | f25e5d4094a11cf098670417e8a16ffb7cbadda0 (patch) | |
tree | 5b88af3b1a3c6023128d89660b4df93e632d7acd /tests | |
parent | e1e65aca9193b8f014bccf88484db4f410a05376 (diff) | |
download | quickjs-f25e5d4094a11cf098670417e8a16ffb7cbadda0.tar.gz quickjs-f25e5d4094a11cf098670417e8a16ffb7cbadda0.zip |
optional chaining fixes (github issue #103)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_language.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_language.js b/tests/test_language.js index 6785416..65dab5f 100644 --- a/tests/test_language.js +++ b/tests/test_language.js @@ -558,6 +558,31 @@ function test_parse_semicolon() } } +/* optional chaining tests not present in test262 */ +function test_optional_chaining() +{ + var a, z; + z = null; + a = { b: { c: 2 } }; + assert(delete z?.b.c, true); + assert(delete a?.b.c, true); + assert(JSON.stringify(a), '{"b":{}}', "optional chaining delete"); + + a = { b: { c: 2 } }; + assert(delete z?.b["c"], true); + assert(delete a?.b["c"], true); + assert(JSON.stringify(a), '{"b":{}}'); + + a = { + b() { return this._b; }, + _b: { c: 42 } + }; + + assert((a?.b)().c, 42); + + assert((a?.["b"])().c, 42); +} + test_op1(); test_cvt(); test_eq(); @@ -578,3 +603,4 @@ test_function_length(); test_argument_scope(); test_function_expr_name(); test_parse_semicolon(); +test_optional_chaining(); |