Skip to content

Commit 5a59512

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Handle null as a switch statement case value.
Bug: 51527 Change-Id: I6203c9aa668689bb44800082864174b9fb215289 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310500 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent a282120 commit 5a59512

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/compiler/lib/src/ssa/codegen.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,18 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
817817
// omit the code for it.
818818
if (successor.isLive) {
819819
do {
820-
visit(inputs[inputIndex]);
820+
final input = inputs[inputIndex];
821+
visit(input);
821822
currentContainer = js.Block.empty();
822823
cases.add(js.Case(pop(), currentContainer));
824+
if (input is HConstant && input.constant is NullConstantValue) {
825+
// JavaScript case expressions match on `===`, which means that the
826+
// just emitted `case null:` will not catch `undefined`.
827+
// Add `case void 0:` to catch `undefined`.
828+
currentContainer = js.Block.empty();
829+
cases.add(
830+
js.Case(js.Prefix('void', js.number(0)), currentContainer));
831+
}
823832
inputIndex++;
824833
} while ((successors[inputIndex - 1] == successor) &&
825834
(inputIndex < inputs.length));

0 commit comments

Comments
 (0)