4343import com .oracle .truffle .api .CallTarget ;
4444import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
4545import com .oracle .truffle .api .RootCallTarget ;
46- import com .oracle .truffle .api .dsl .Bind ;
4746import com .oracle .truffle .api .dsl .Cached ;
48- import com .oracle .truffle .api .dsl .Idempotent ;
47+ import com .oracle .truffle .api .dsl .Cached . Exclusive ;
4948import com .oracle .truffle .api .dsl .Cached .Shared ;
49+ import com .oracle .truffle .api .dsl .Idempotent ;
50+ import com .oracle .truffle .api .dsl .ImportStatic ;
5051import com .oracle .truffle .api .dsl .NeverDefault ;
5152import com .oracle .truffle .api .dsl .Specialization ;
5253import com .oracle .truffle .api .interop .InteropLibrary ;
5354import com .oracle .truffle .api .interop .UnsupportedMessageException ;
5455import com .oracle .truffle .api .library .CachedLibrary ;
55- import com .oracle .truffle .api .nodes .Node ;
5656import com .oracle .truffle .api .nodes .RootNode ;
5757import com .oracle .truffle .api .object .DynamicObjectLibrary ;
5858import com .oracle .truffle .api .profiles .ConditionProfile ;
@@ -300,11 +300,11 @@ public JSBindNode(JSContext context, JSBuiltin builtin) {
300300 }
301301
302302 @ Specialization
303- protected JSDynamicObject bindJSFunction (JSFunctionObject thisFnObj , Object thisArg , Object [] args ,
303+ protected final JSDynamicObject bindJSFunction (JSFunctionObject thisFnObj , Object thisArg , Object [] args ,
304304 @ Cached @ Shared GetPrototypeNode getPrototypeNode ,
305305 @ Cached ("create(getContext())" ) @ Shared CopyFunctionNameAndLengthNode copyNameAndLengthNode ,
306306 @ Cached @ Shared ("isConstructorProf" ) InlinedConditionProfile isConstructorProfile ,
307- @ Cached InlinedConditionProfile isAsyncProfile ,
307+ @ Cached @ Exclusive InlinedConditionProfile isAsyncProfile ,
308308 @ Cached @ Shared ("setProtoProf" ) InlinedConditionProfile setProtoProfile ) {
309309 JSDynamicObject proto = getPrototypeNode .execute (thisFnObj );
310310
@@ -316,20 +316,19 @@ protected JSDynamicObject bindJSFunction(JSFunctionObject thisFnObj, Object this
316316 return boundFunction ;
317317 }
318318
319- @ Specialization (guards = {"!isJSFunction(thisObj)" , "isCallableNode.executeBoolean(thisObj)" })
320- protected JSDynamicObject bindOther (Object thisObj , Object thisArg , Object [] args ,
321- @ Bind ("this" ) Node node ,
319+ @ Specialization (guards = {"!isJSFunction(thisObj)" , "isCallableNode.executeBoolean(thisObj)" }, limit = "1" )
320+ protected final JSDynamicObject bindOther (Object thisObj , Object thisArg , Object [] args ,
322321 @ SuppressWarnings ("unused" ) @ Cached @ Shared IsCallableNode isCallableNode ,
323322 @ Cached @ Shared GetPrototypeNode getPrototypeNode ,
324323 @ Cached ForeignObjectPrototypeNode foreignPrototypeNode ,
325324 @ Cached IsConstructorNode isConstructorNode ,
326325 @ Cached ("create(getContext())" ) @ Shared CopyFunctionNameAndLengthNode copyNameAndLengthNode ,
327- @ Cached InlinedConditionProfile isProxyProfile ,
326+ @ Cached @ Exclusive InlinedConditionProfile isProxyProfile ,
328327 @ Cached @ Shared ("isConstructorProf" ) InlinedConditionProfile isConstructorProfile ,
329328 @ Cached @ Shared ("setProtoProf" ) InlinedConditionProfile setProtoProfile ) {
330329 JSRealm realm = JSRuntime .getFunctionRealm (thisObj , JSRealm .get (this ));
331330 JSDynamicObject proto ;
332- if (isProxyProfile .profile (node , JSProxy .isJSProxy (thisObj ))) {
331+ if (isProxyProfile .profile (this , JSProxy .isJSProxy (thisObj ))) {
333332 proto = getPrototypeNode .execute (thisObj );
334333 } else {
335334 assert JSRuntime .isCallableForeign (thisObj );
@@ -341,12 +340,12 @@ protected JSDynamicObject bindOther(Object thisObj, Object thisArg, Object[] arg
341340 }
342341
343342 JSContext context = getContext ();
344- boolean constructor = isConstructorProfile .profile (node , isConstructorNode .executeBoolean (thisObj ));
343+ boolean constructor = isConstructorProfile .profile (this , isConstructorNode .executeBoolean (thisObj ));
345344 JSFunctionData boundFunctionData = context .getBoundFunctionData (constructor , false );
346345 JSFunctionObject boundFunction = JSFunction .createBound (context , realm , boundFunctionData , thisObj , thisArg , args );
347346
348347 boolean needSetProto = proto != realm .getFunctionPrototype ();
349- if (setProtoProfile .profile (node , needSetProto )) {
348+ if (setProtoProfile .profile (this , needSetProto )) {
350349 JSObject .setPrototype (boundFunction , proto );
351350 }
352351
@@ -356,13 +355,14 @@ protected JSDynamicObject bindOther(Object thisObj, Object thisArg, Object[] arg
356355 }
357356
358357 @ SuppressWarnings ("unused" )
359- @ Specialization (guards = {"!isCallableNode.executeBoolean(thisObj)" })
360- protected JSDynamicObject bindError (Object thisObj , Object thisArg , Object [] arg ,
358+ @ Specialization (guards = {"!isCallableNode.executeBoolean(thisObj)" }, limit = "1" )
359+ protected static JSDynamicObject bindError (Object thisObj , Object thisArg , Object [] arg ,
361360 @ SuppressWarnings ("unused" ) @ Cached @ Shared IsCallableNode isCallableNode ) {
362361 throw Errors .createTypeErrorNotAFunction (thisObj );
363362 }
364363 }
365364
365+ @ ImportStatic (JSConfig .class )
366366 public abstract static class JSFunctionToStringNode extends JSBuiltinNode {
367367
368368 public JSFunctionToStringNode (JSContext context , JSBuiltin builtin ) {
@@ -397,28 +397,29 @@ private static TruffleString getNameIntl(TruffleString name) {
397397 @ SuppressWarnings ("unused" )
398398 @ Specialization (guards = {"isES2019OrLater()" , "!isJSFunction(fnObj)" , "isCallable.executeBoolean(fnObj)" }, limit = "1" )
399399 protected TruffleString toStringCallable (Object fnObj ,
400- @ Cached @ Shared ("isCallable" ) IsCallableNode isCallable ,
401- @ CachedLibrary ("fnObj" ) InteropLibrary interop ) {
402- if (interop .hasExecutableName (fnObj )) {
403- try {
404- Object name = interop .getExecutableName (fnObj );
405- return getNameIntl (InteropLibrary .getUncached ().asTruffleString (name ));
406- } catch (UnsupportedMessageException e ) {
400+ @ Cached @ Shared IsCallableNode isCallable ,
401+ @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
402+ @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interopStr ,
403+ @ Cached TruffleString .SwitchEncodingNode switchEncoding ) {
404+ try {
405+ Object name = null ;
406+ if (interop .hasExecutableName (fnObj )) {
407+ name = interop .getExecutableName (fnObj );
408+ } else if (interop .isMetaObject (fnObj )) {
409+ name = interop .getMetaSimpleName (fnObj );
407410 }
408- } else if (interop .isMetaObject (fnObj )) {
409- try {
410- Object name = interop .getMetaSimpleName (fnObj );
411- return getNameIntl (InteropLibrary .getUncached ().asTruffleString (name ));
412- } catch (UnsupportedMessageException e ) {
411+ if (name != null ) {
412+ return getNameIntl (Strings .interopAsTruffleString (name , interopStr , switchEncoding ));
413413 }
414+ } catch (UnsupportedMessageException e ) {
414415 }
415416 return Strings .FUNCTION_NATIVE_CODE ;
416417 }
417418
418419 @ SuppressWarnings ("unused" )
419420 @ Specialization (guards = {"isES2019OrLater()" , "!isCallable.executeBoolean(fnObj)" }, limit = "1" )
420421 protected TruffleString toStringNotCallable (Object fnObj ,
421- @ Cached @ Shared ( "isCallable" ) IsCallableNode isCallable ) {
422+ @ Cached @ Shared IsCallableNode isCallable ) {
422423 throw Errors .createTypeErrorNotAFunction (fnObj );
423424 }
424425
@@ -445,7 +446,7 @@ private static TruffleString toStringDefaultTarget(JSDynamicObject fnObj) {
445446 if (ssect == null || !ssect .isAvailable () || ssect .getSource ().isInternal ()) {
446447 result = Strings .concatAll (Strings .FUNCTION_SPC , JSFunction .getName (fnObj ), Strings .FUNCTION_NATIVE_CODE_BODY );
447448 } else {
448- result = Strings .fromCharSequence (ssect .getCharacters ());
449+ result = Strings .fromJavaString (ssect .getCharacters (). toString ());
449450 }
450451 return result ;
451452 }
0 commit comments