File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ const tests = [
112112 } ,
113113 {
114114 name : "Optional call of root function" ,
115- body ( ) {
115+ body ( ) {
116116 assert . areEqual ( 42 , eval ?. ( "42" ) ) ;
117117
118118 globalThis . doNotUseThisBadGlobalFunction = ( ) => 42 ;
@@ -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 {
Original file line number Diff line number Diff 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 simpleObj . null ?. ( ) ;
112+ }
113+ function shouldReturn2 ( ) {
114+ return "12" ?. length ;
115+ }
116+ assert . areEqual ( undefined , shouldReturnUndefined ( ) ) ;
117+ assert . areEqual ( 2 , shouldReturn2 ( ) ) ;
118+ }
99119 }
100120] ;
101121
You can’t perform that action at this time.
0 commit comments