This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize a fast path for instanceof binary expressions (#2506)
Summary: Release notes: none Looking through our internal bundles and there are frequent cases where `instanceof` is used where the left-hand side is a primitive and the right-hand side is an abstract value. In the case where the left-hand side is a primitive and the right-hand side is a simple object, the instanceof binary expression should always return `false`. Pull Request resolved: #2506 Differential Revision: D9567344 Pulled By: trueadm fbshipit-source-id: 7333f3b81627657c184c77d4cfffd4511bee0cbf
- Loading branch information
1 parent
dfa38c2
commit f062f34
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// does not contain:instanceof | ||
|
||
function fn(a) { | ||
var x = Object.assign(a); | ||
|
||
if (global.__makeSimple) { | ||
__makeSimple(x); | ||
} | ||
if (undefined instanceof x) { | ||
return "impossible"; | ||
} | ||
if (null instanceof x) { | ||
return "also impossible"; | ||
} | ||
if (false instanceof x) { | ||
return "also impossible 2"; | ||
} | ||
if (true instanceof x) { | ||
return "also impossible 3"; | ||
} | ||
if (0 instanceof x) { | ||
return "also impossible 4"; | ||
} | ||
if (1 instanceof x) { | ||
return "also impossible 5"; | ||
} | ||
if ("" instanceof x) { | ||
return "also impossible 6"; | ||
} | ||
} | ||
|
||
this.__optimize && __optimize(fn); | ||
|
||
inspect = function() { | ||
return fn(Object); | ||
}; |