5454import com .oracle .truffle .js .builtins .ErrorPrototypeBuiltinsFactory .ErrorPrototypeToStringNodeGen ;
5555import com .oracle .truffle .js .builtins .ErrorPrototypeBuiltinsFactory .ForeignErrorPrototypeCauseNodeGen ;
5656import com .oracle .truffle .js .builtins .ErrorPrototypeBuiltinsFactory .ForeignErrorPrototypeMessageNodeGen ;
57+ import com .oracle .truffle .js .builtins .ErrorPrototypeBuiltinsFactory .ForeignErrorPrototypeNameNodeGen ;
5758import com .oracle .truffle .js .builtins .ErrorPrototypeBuiltinsFactory .ForeignErrorPrototypeStackNodeGen ;
5859import com .oracle .truffle .js .nodes .access .IsObjectNode ;
5960import com .oracle .truffle .js .nodes .access .PropertyGetNode ;
@@ -157,11 +158,11 @@ protected Object toStringObject(Object errorObj,
157158 if (Strings .length (strMessage ) == 0 ) {
158159 return strName ;
159160 }
160- return toStringIntl (strName , strMessage );
161+ return concatNameAndMessage (strName , strMessage );
161162 }
162163
163164 @ TruffleBoundary
164- private static Object toStringIntl (TruffleString strName , TruffleString strMessage ) {
165+ private static Object concatNameAndMessage (TruffleString strName , TruffleString strMessage ) {
165166 return Strings .concatAll (strName , Strings .COLON_SPACE , strMessage );
166167 }
167168
@@ -207,6 +208,7 @@ protected ForeignErrorPrototypeBuiltins() {
207208 public enum ForeignError implements BuiltinEnum <ForeignError > {
208209 cause (0 ),
209210 message (0 ),
211+ name (0 ),
210212 stack (0 );
211213
212214 private final int length ;
@@ -233,6 +235,8 @@ protected Object createNode(JSContext context, JSBuiltin builtin, boolean constr
233235 return ForeignErrorPrototypeCauseNodeGen .create (context , builtin , args ().withThis ().createArgumentNodes (context ));
234236 case message :
235237 return ForeignErrorPrototypeMessageNodeGen .create (context , builtin , args ().withThis ().createArgumentNodes (context ));
238+ case name :
239+ return ForeignErrorPrototypeNameNodeGen .create (context , builtin , args ().withThis ().createArgumentNodes (context ));
236240 case stack :
237241 return ForeignErrorPrototypeStackNodeGen .create (context , builtin , args ().withThis ().createArgumentNodes (context ));
238242 }
@@ -266,6 +270,31 @@ protected Object getMessage(Object error,
266270
267271 }
268272
273+ @ ImportStatic (JSConfig .class )
274+ public abstract static class ForeignErrorPrototypeNameNode extends JSBuiltinNode {
275+
276+ public ForeignErrorPrototypeNameNode (JSContext context , JSBuiltin builtin ) {
277+ super (context , builtin );
278+ }
279+
280+ @ Specialization (limit = "InteropLibraryLimit" )
281+ protected Object getName (Object error ,
282+ @ CachedLibrary ("error" ) InteropLibrary interop ,
283+ @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interopMeta ,
284+ @ Cached ImportValueNode importNode ) {
285+ try {
286+ if (interop .isException (error ) && interop .hasMetaObject (error )) {
287+ return importNode .executeWithTarget (interopMeta .getMetaQualifiedName (interop .getMetaObject (error )));
288+ }
289+ } catch (UnsupportedMessageException e ) {
290+ // Interop contract violation
291+ assert false : e ;
292+ }
293+ return Strings .UC_ERROR ;
294+ }
295+
296+ }
297+
269298 @ ImportStatic (JSConfig .class )
270299 public abstract static class ForeignErrorPrototypeStackNode extends JSBuiltinNode {
271300
0 commit comments