11/*
2- * Copyright (c) 2018, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * The Universal Permissive License (UPL), Version 1.0
6767import com .oracle .truffle .js .nodes .access .GetMethodNode ;
6868import com .oracle .truffle .js .nodes .access .GetPrototypeNode ;
6969import com .oracle .truffle .js .nodes .access .IsJSObjectNode ;
70+ import com .oracle .truffle .js .nodes .access .IsObjectNode ;
7071import com .oracle .truffle .js .nodes .access .PropertyGetNode ;
7172import com .oracle .truffle .js .nodes .binary .InstanceofNodeGen .IsBoundFunctionCacheNodeGen ;
7273import com .oracle .truffle .js .nodes .binary .InstanceofNodeGen .OrdinaryHasInstanceNodeGen ;
@@ -249,18 +250,22 @@ protected boolean doIsBound(Object obj, JSDynamicObject check,
249250
250251 @ Specialization (guards = {"!isJSObject(left)" , "isForeignObject(left)" , "isJSFunction(right)" , "!isBoundFunction(right)" })
251252 protected boolean doForeignObject (@ SuppressWarnings ("unused" ) Object left , @ SuppressWarnings ("unused" ) JSDynamicObject right ,
253+ @ Cached @ Shared IsObjectNode isAnyObjectNode ,
252254 @ Cached @ Shared ("foreignPrototypeNode" ) ForeignObjectPrototypeNode getForeignPrototypeNode ,
253255 @ Cached @ Shared ("invalidPrototypeBranch" ) InlinedBranchProfile invalidPrototypeBranch ,
254256 @ Cached ("create(context)" ) @ Shared ("ordinaryHasInstance" ) OrdinaryHasInstanceNode ordinaryHasInstanceNode ) {
255257 if (context .isOptionForeignObjectPrototype ()) {
256- return foreignObjectIntl (left , right , getForeignPrototypeNode , invalidPrototypeBranch , ordinaryHasInstanceNode );
258+ return foreignObjectIntl (left , right , isAnyObjectNode , getForeignPrototypeNode , invalidPrototypeBranch , ordinaryHasInstanceNode );
257259 } else {
258260 return false ;
259261 }
260262 }
261263
262- private boolean foreignObjectIntl (Object left , JSDynamicObject right , ForeignObjectPrototypeNode getForeignPrototypeNode , InlinedBranchProfile invalidPrototypeBranch ,
263- OrdinaryHasInstanceNode ordinaryHasInstanceNode ) {
264+ private boolean foreignObjectIntl (Object left , JSDynamicObject right , IsObjectNode isObjectNode , ForeignObjectPrototypeNode getForeignPrototypeNode ,
265+ InlinedBranchProfile invalidPrototypeBranch , OrdinaryHasInstanceNode ordinaryHasInstanceNode ) {
266+ if (!isObjectNode .executeBoolean (left )) {
267+ return false ;
268+ }
264269 Object rightProto = getConstructorPrototype (right , invalidPrototypeBranch );
265270 Object foreignProto = getForeignPrototypeNode .execute (left );
266271 if (foreignProto == rightProto ) {
@@ -276,10 +281,11 @@ protected boolean doNotAnObject(@SuppressWarnings("unused") Object left, @Suppre
276281
277282 @ Specialization (guards = {"!isJSObject(left)" , "isForeignObject(left)" , "isJSProxy(right)" , "isCallableProxy(right)" })
278283 protected boolean doNotAnObjectProxyForeign (@ SuppressWarnings ("unused" ) Object left , @ SuppressWarnings ("unused" ) JSDynamicObject right ,
284+ @ Cached @ Shared IsObjectNode isAnyObjectNode ,
279285 @ Cached @ Shared ("foreignPrototypeNode" ) ForeignObjectPrototypeNode getForeignPrototypeNode ,
280286 @ Cached @ Shared ("invalidPrototypeBranch" ) InlinedBranchProfile invalidPrototypeBranch ,
281287 @ Cached ("create(context)" ) @ Shared ("ordinaryHasInstance" ) OrdinaryHasInstanceNode ordinaryHasInstanceNode ) {
282- return doForeignObject (left , right , getForeignPrototypeNode , invalidPrototypeBranch , ordinaryHasInstanceNode );
288+ return doForeignObject (left , right , isAnyObjectNode , getForeignPrototypeNode , invalidPrototypeBranch , ordinaryHasInstanceNode );
283289 }
284290
285291 @ Specialization (guards = {"!isJSObject(left)" , "!isForeignObject(left)" , "isJSProxy(right)" , "isCallableProxy(right)" })
0 commit comments