summaryrefslogtreecommitdiff
path: root/tests/test_language.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_language.js')
-rw-r--r--tests/test_language.js26
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();