4343import com .oracle .truffle .api .CompilerDirectives ;
4444import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
4545import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
46- import com .oracle .truffle .api .RootCallTarget ;
4746import com .oracle .truffle .api .dsl .Cached ;
4847import com .oracle .truffle .api .dsl .Specialization ;
4948import com .oracle .truffle .api .dsl .Cached .Shared ;
5049import com .oracle .truffle .api .instrumentation .Tag ;
5150import com .oracle .truffle .api .interop .InteropLibrary ;
5251import com .oracle .truffle .api .interop .UnsupportedMessageException ;
5352import com .oracle .truffle .api .library .CachedLibrary ;
54- import com .oracle .truffle .api .nodes .RootNode ;
5553import com .oracle .truffle .api .object .DynamicObject ;
5654import com .oracle .truffle .api .object .Shape ;
5755import com .oracle .truffle .api .profiles .BranchProfile ;
5856import com .oracle .truffle .api .profiles .ConditionProfile ;
59- import com .oracle .truffle .api .source .SourceSection ;
6057import com .oracle .truffle .js .nodes .JavaScriptBaseNode ;
6158import com .oracle .truffle .js .nodes .JavaScriptNode ;
6259import com .oracle .truffle .js .nodes .access .GetMethodNode ;
6764import com .oracle .truffle .js .nodes .binary .InstanceofNodeGen .OrdinaryHasInstanceNodeGen ;
6865import com .oracle .truffle .js .nodes .cast .JSToBooleanNode ;
6966import com .oracle .truffle .js .nodes .function .JSFunctionCallNode ;
67+ import com .oracle .truffle .js .runtime .BigInt ;
7068import com .oracle .truffle .js .runtime .Errors ;
7169import com .oracle .truffle .js .runtime .JSArguments ;
7270import com .oracle .truffle .js .runtime .JSContext ;
@@ -151,12 +149,42 @@ private static boolean isCallable(DynamicObject target, BranchProfile proxyBranc
151149 }
152150
153151 @ Specialization (guards = {"isNullOrUndefined(target)" })
154- protected boolean doInvalidTarget (@ SuppressWarnings ("unused" ) Object obj , Object target ) {
152+ protected boolean doNullOrUndefinedTarget (@ SuppressWarnings ("unused" ) Object obj , DynamicObject target ) {
155153 throw Errors .createTypeErrorInvalidInstanceofTarget (target , this );
156154 }
157155
158- @ Specialization (guards = {"!isJSType(target)" }, limit = "3" )
159- protected boolean doForeignTarget (@ SuppressWarnings ("unused" ) Object instance , Object target ,
156+ @ Specialization ()
157+ protected boolean doStringTarget (@ SuppressWarnings ("unused" ) Object obj , String target ) {
158+ throw Errors .createTypeErrorInvalidInstanceofTarget (target , this );
159+ }
160+
161+ @ Specialization ()
162+ protected boolean doDoubleTarget (@ SuppressWarnings ("unused" ) Object obj , double target ) {
163+ throw Errors .createTypeErrorInvalidInstanceofTarget (target , this );
164+ }
165+
166+ @ Specialization ()
167+ protected boolean doBooleanTarget (@ SuppressWarnings ("unused" ) Object obj , boolean target ) {
168+ throw Errors .createTypeErrorInvalidInstanceofTarget (target , this );
169+ }
170+
171+ @ Specialization ()
172+ protected boolean doBigIntTarget (@ SuppressWarnings ("unused" ) Object obj , BigInt target ) {
173+ throw Errors .createTypeErrorInvalidInstanceofTarget (target , this );
174+ }
175+
176+ @ Specialization ()
177+ protected boolean doSymbolTarget (@ SuppressWarnings ("unused" ) Object obj , Symbol target ) {
178+ throw Errors .createTypeErrorInvalidInstanceofTarget (target , this );
179+ }
180+
181+ @ Specialization (guards = {"isForeignObject(target)" , "isJSType(instance)" })
182+ protected boolean doForeignTargetJSType (@ SuppressWarnings ("unused" ) DynamicObject instance , @ SuppressWarnings ("unused" ) Object target ) {
183+ return false ;
184+ }
185+
186+ @ Specialization (guards = {"isForeignObject(target)" , "!isJSType(instance)" }, limit = "3" )
187+ protected boolean doForeignTargetOther (Object instance , Object target ,
160188 @ CachedLibrary ("target" ) InteropLibrary interop ) {
161189 try {
162190 return interop .isMetaInstance (target , instance );
@@ -165,15 +193,6 @@ protected boolean doForeignTarget(@SuppressWarnings("unused") Object instance, O
165193 }
166194 }
167195
168- @ TruffleBoundary
169- private static String functionToString (DynamicObject fnObj ) {
170- assert JSFunction .isJSFunction (fnObj );
171- RootCallTarget dct = (RootCallTarget ) JSFunction .getCallTarget (fnObj );
172- RootNode rn = dct .getRootNode ();
173- SourceSection ssect = rn .getSourceSection ();
174- return ((ssect == null || !ssect .isAvailable ()) ? "function " + JSFunction .getName (fnObj ) + "() { [native code] }" : ssect .getCharacters ().toString ());
175- }
176-
177196 @ Override
178197 protected JavaScriptNode copyUninitialized (Set <Class <? extends Tag >> materializedTags ) {
179198 return InstanceofNodeGen .create (context , cloneUninitialized (getLeft (), materializedTags ), cloneUninitialized (getRight (), materializedTags ));
0 commit comments