optional chaining fixes (github issue #103)

This commit is contained in:
Fabrice Bellard
2024-01-09 19:15:40 +01:00
parent e1e65aca91
commit f25e5d4094
4 changed files with 137 additions and 9 deletions

View File

@@ -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();