Skip to content

Commit 4160295

Browse files
Add additional tests
1 parent 8210f62 commit 4160295

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/es12/optional-calls.js

+2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ const tests = [
142142
const obj = {
143143
fn: () => 42,
144144
};
145+
assert.areEqual(42, eval("obj.fn?.()"));
145146
assert.areEqual(42, eval("obj?.fn?.()"));
147+
assert.areEqual(42, eval("obj?.fn()"));
146148
},
147149
},
148150
{

test/es12/optional-chaining.js

+20
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ const tests = [
9696
body() {
9797
assert.areEqual(0, ""?.length, "Expected empty string length");
9898
}
99+
},
100+
{
101+
name: "Unused opt-chain result should not crash jit",
102+
body() {
103+
assert.areEqual(undefined, eval(`boo?.();`));
104+
assert.areEqual("result", eval(`boo?.(); "result"`));
105+
}
106+
},
107+
{
108+
name: "Return register works with opt-chain",
109+
body() {
110+
function shouldReturnUndefined() {
111+
return boo?.();
112+
}
113+
function shouldReturn2() {
114+
return "12"?.length;
115+
}
116+
assert.areEqual(undefined, shouldReturnUndefined());
117+
assert.areEqual(undefined, shouldReturn2());
118+
}
99119
}
100120
];
101121

0 commit comments

Comments
 (0)