mirror of
https://github.com/bellard/quickjs.git
synced 2025-09-30 15:04:24 +03:00
optional chaining fixes (github issue #103)
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user