File tree Expand file tree Collapse file tree 3 files changed +25
-6
lines changed
oxc_ecmascript/src/constant_evaluation
oxc_minifier/src/peephole Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -350,9 +350,25 @@ fn binary_operation_evaluate_value_to<'a>(
350350 if left_ty. is_undetermined ( ) {
351351 return None ;
352352 }
353- return Some ( ConstantValue :: Boolean (
354- name == "Object" && left. value_type ( ctx) . is_object ( ) ,
355- ) ) ;
353+ if name == "Object" {
354+ if !left_ty. is_object ( ) {
355+ return Some ( ConstantValue :: Boolean ( false ) ) ;
356+ }
357+ if matches ! (
358+ left,
359+ Expression :: ArrayExpression ( _)
360+ | Expression :: RegExpLiteral ( _)
361+ | Expression :: FunctionExpression ( _)
362+ | Expression :: ArrowFunctionExpression ( _)
363+ | Expression :: ClassExpression ( _)
364+ ) | matches ! ( left, Expression :: ObjectExpression ( obj_expr) if obj_expr. properties. is_empty( ) )
365+ {
366+ return Some ( ConstantValue :: Boolean ( true ) ) ;
367+ }
368+ // NOTE: `{ __proto__: null } instanceof Object` is false
369+ return None ;
370+ }
371+ return Some ( ConstantValue :: Boolean ( false ) ) ;
356372 }
357373 }
358374 None
Original file line number Diff line number Diff line change @@ -1819,6 +1819,11 @@ mod test {
18191819 fn test_fold_instance_of_additional ( ) {
18201820 fold ( "(typeof {}) instanceof Object" , "!1" ) ;
18211821 fold ( "(+{}) instanceof Number" , "!1" ) ;
1822+ fold_same ( "({ __proto__: null }) instanceof Object" ) ;
1823+ fold ( "/foo/ instanceof Object" , "!0" ) ;
1824+ fold ( "(() => {}) instanceof Object" , "!0" ) ;
1825+ fold ( "(function(){}) instanceof Object" , "!0" ) ;
1826+ fold ( "(class{}) instanceof Object" , "!0" ) ;
18221827 }
18231828
18241829 #[ test]
Original file line number Diff line number Diff line change @@ -2,9 +2,7 @@ commit: 17ac85ca
22
33minifier_node_compat Summary :
44AST Parsed : 938 / 938 (100.00 % )
5- Positive Passed : 929 / 938 (99.04 % )
6- execution_result : tasks / coverage / ES2015 / annex b ›__proto__ in object literals ›basic support
7-
5+ Positive Passed : 930 / 938 (99.15 % )
86execution_result : tasks / coverage / ES2015 / built - ins ›Proxy ›" getOwnPropertyDescriptor" handler invariants
97
108execution_result : tasks / coverage / ES2015 / misc ›Proxy , internal ' get' calls ›HasBinding
You can’t perform that action at this time.
0 commit comments