Skip to content
Permalink
Browse files Browse the repository at this point in the history
Handle typeof applied to empty in InstSimplify
Summary:
Do not simplify `typeof` if it is applied to an invalid type. This
handles a case like the one in the added test, where `typeof` is called
on a literal empty in unreachable code.

Reviewed By: kodafb

Differential Revision: D31000173

fbshipit-source-id: 2d7f69cbcc9c1bb0a916585c07171089444c85dc
  • Loading branch information
neildhar authored and facebook-github-bot committed Oct 13, 2021
1 parent 435972c commit 55e1b23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/IR/IREval.cpp
Expand Up @@ -107,7 +107,7 @@ Literal *hermes::evalUnaryOperator(
case ValueKind::LiteralStringKind:
return builder.getLiteralString("string");
default:
llvm_unreachable("Invalid literal kind.");
break;
}
break;

Expand Down
5 changes: 5 additions & 0 deletions test/hermes/tdz-check.js
Expand Up @@ -45,3 +45,8 @@ test(() => {
return x;
});
//CHECK-NEXT: caught ReferenceError: accessing an uninitialized variable

test(() => {
const foo = print(foo, typeof foo)
});
//CHECK-NEXT: caught ReferenceError: accessing an uninitialized variable

0 comments on commit 55e1b23

Please sign in to comment.