Skip to content

Commit 159292d

Browse files
committed
[GR-44414] Fix Nashorn test failing in shared-engine mode (24.0).
PullRequest: js/3022
2 parents e69e1fa + cb9a478 commit 159292d

File tree

11 files changed

+259
-155
lines changed

11 files changed

+259
-155
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/DatePrototypeBuiltins.java

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -44,10 +44,16 @@
4444

4545
import com.oracle.truffle.api.CompilerDirectives;
4646
import com.oracle.truffle.api.dsl.Cached;
47+
import com.oracle.truffle.api.dsl.Cached.Shared;
48+
import com.oracle.truffle.api.dsl.Fallback;
49+
import com.oracle.truffle.api.dsl.GenerateCached;
50+
import com.oracle.truffle.api.dsl.GenerateInline;
51+
import com.oracle.truffle.api.dsl.ImportStatic;
4752
import com.oracle.truffle.api.dsl.Specialization;
4853
import com.oracle.truffle.api.interop.InteropLibrary;
54+
import com.oracle.truffle.api.nodes.Node;
4955
import com.oracle.truffle.api.profiles.ConditionProfile;
50-
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
56+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
5157
import com.oracle.truffle.api.strings.TruffleString;
5258
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateGetDateNodeGen;
5359
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateGetDayNodeGen;
@@ -80,6 +86,7 @@
8086
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateToStringNodeGen;
8187
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateToTimeStringNodeGen;
8288
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateValueOfNodeGen;
89+
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
8390
import com.oracle.truffle.js.nodes.access.IsObjectNode;
8491
import com.oracle.truffle.js.nodes.access.PropertyGetNode;
8592
import com.oracle.truffle.js.nodes.cast.JSToNumberNode;
@@ -900,34 +907,49 @@ private JSFunctionCallNode getCallToISOStringFnNode() {
900907

901908
public abstract static class JSDateToPrimitiveNode extends JSBuiltinNode {
902909

903-
@Child private OrdinaryToPrimitiveNode ordinaryToPrimitiveHintNumber;
904-
@Child private OrdinaryToPrimitiveNode ordinaryToPrimitiveHintString;
905-
906910
public JSDateToPrimitiveNode(JSContext context, JSBuiltin builtin) {
907911
super(context, builtin);
908912
}
909913

910914
@Specialization
911915
protected final Object toPrimitive(Object obj, Object hint,
912916
@Cached IsObjectNode isObjectNode,
913-
@Cached InlinedConditionProfile isHintNumber,
914-
@Cached InlinedConditionProfile isHintStringOrDefault) {
915-
if (!isObjectNode.executeBoolean(obj)) {
917+
@Cached DateToPrimitiveHelperNode dateToPrimitiveHelper,
918+
@Cached InlinedBranchProfile errorBranch) {
919+
if (isObjectNode.executeBoolean(obj)) {
920+
return dateToPrimitiveHelper.execute(this, obj, hint);
921+
} else {
922+
errorBranch.enter(this);
916923
throw Errors.createTypeErrorNotAnObject(obj);
917924
}
918-
if (isHintNumber.profile(this, Strings.HINT_NUMBER.equals(hint))) {
919-
if (ordinaryToPrimitiveHintNumber == null) {
920-
CompilerDirectives.transferToInterpreterAndInvalidate();
921-
ordinaryToPrimitiveHintNumber = insert(OrdinaryToPrimitiveNode.createHintNumber());
922-
}
925+
}
926+
927+
@GenerateInline
928+
@GenerateCached(false)
929+
@ImportStatic(Strings.class)
930+
abstract static class DateToPrimitiveHelperNode extends JavaScriptBaseNode {
931+
932+
abstract Object execute(Node node, Object obj, Object hint);
933+
934+
@SuppressWarnings("unused")
935+
@Specialization(guards = {"equals(strEqual, HINT_NUMBER, hint)"})
936+
static Object toPrimitiveHintNumber(Object obj, TruffleString hint,
937+
@Cached @Shared TruffleString.EqualNode strEqual,
938+
@Cached("createHintNumber()") OrdinaryToPrimitiveNode ordinaryToPrimitiveHintNumber) {
923939
return ordinaryToPrimitiveHintNumber.execute(obj);
924-
} else if (isHintStringOrDefault.profile(this, Strings.HINT_STRING.equals(hint) || Strings.HINT_DEFAULT.equals(hint))) {
925-
if (ordinaryToPrimitiveHintString == null) {
926-
CompilerDirectives.transferToInterpreterAndInvalidate();
927-
ordinaryToPrimitiveHintString = insert(OrdinaryToPrimitiveNode.createHintString());
928-
}
940+
}
941+
942+
@SuppressWarnings("unused")
943+
@Specialization(guards = {"equals(strEqual, HINT_STRING, hint) || equals(strEqual, HINT_DEFAULT, hint)"})
944+
static Object toPrimitiveHintStringOrDefault(Object obj, TruffleString hint,
945+
@Cached @Shared TruffleString.EqualNode strEqual,
946+
@Cached("createHintString()") OrdinaryToPrimitiveNode ordinaryToPrimitiveHintString) {
929947
return ordinaryToPrimitiveHintString.execute(obj);
930-
} else {
948+
}
949+
950+
@Fallback
951+
static Object invalidHint(@SuppressWarnings("unused") Object obj, Object hint) {
952+
assert !(Strings.HINT_STRING.equals(hint) || Strings.HINT_NUMBER.equals(hint) || Strings.HINT_DEFAULT.equals(hint)) : hint;
931953
throw Errors.createTypeError("invalid hint");
932954
}
933955
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/HasPropertyCacheNode.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -334,15 +334,15 @@ protected boolean hasProperty(Object thisObj, HasPropertyCacheNode root) {
334334
* @param property The particular entry of the property being accessed.
335335
*/
336336
@Override
337-
protected HasCacheNode createCachedPropertyNode(Property property, Object thisObj, int depth, Object value, HasCacheNode currentHead) {
337+
protected HasCacheNode createCachedPropertyNode(Property property, Object thisObj, JSDynamicObject proto, int depth, Object value, HasCacheNode currentHead) {
338338
assert !isOwnProperty() || depth == 0;
339339
ReceiverCheckNode check;
340340
if (JSDynamicObject.isJSDynamicObject(thisObj)) {
341341
JSDynamicObject thisJSObj = (JSDynamicObject) thisObj;
342342
Shape cacheShape = thisJSObj.getShape();
343-
check = createShapeCheckNode(cacheShape, thisJSObj, depth, false, false);
343+
check = createShapeCheckNode(cacheShape, thisJSObj, proto, depth, false, false);
344344
} else {
345-
check = createPrimitiveReceiverCheck(thisObj, depth);
345+
check = createPrimitiveReceiverCheck(thisObj, proto, depth);
346346
}
347347
if (hasOwnProperty && JSProperty.isModuleNamespaceExport(property)) {
348348
return new ModuleNamespaceHasOwnPropertyNode(check, property);
@@ -351,32 +351,32 @@ protected HasCacheNode createCachedPropertyNode(Property property, Object thisOb
351351
}
352352

353353
@Override
354-
protected HasCacheNode createUndefinedPropertyNode(Object thisObj, Object store, int depth, Object value) {
355-
HasCacheNode specialized = createJavaPropertyNodeMaybe(thisObj, depth);
354+
protected HasCacheNode createUndefinedPropertyNode(Object thisObj, Object store, JSDynamicObject proto, int depth, Object value) {
355+
HasCacheNode specialized = createJavaPropertyNodeMaybe(thisObj, proto, depth);
356356
if (specialized != null) {
357357
return specialized;
358358
}
359359
if (JSDynamicObject.isJSDynamicObject(thisObj)) {
360360
JSDynamicObject thisJSObj = (JSDynamicObject) thisObj;
361361
Shape cacheShape = thisJSObj.getShape();
362362
if (JSAdapter.isJSAdapter(store)) {
363-
return new JSAdapterHasPropertyCacheNode(key, createJSClassCheck(thisObj, depth));
363+
return new JSAdapterHasPropertyCacheNode(key, createJSClassCheck(thisObj, proto, depth));
364364
} else if (JSProxy.isJSProxy(store)) {
365-
return new JSProxyDispatcherPropertyHasNode(context, key, createJSClassCheck(thisObj, depth), isOwnProperty());
365+
return new JSProxyDispatcherPropertyHasNode(context, key, createJSClassCheck(thisObj, proto, depth), isOwnProperty());
366366
} else {
367-
return new AbsentHasPropertyCacheNode(createShapeCheckNode(cacheShape, thisJSObj, depth, false, false));
367+
return new AbsentHasPropertyCacheNode(createShapeCheckNode(cacheShape, thisJSObj, proto, depth, false, false));
368368
}
369369
} else {
370370
return new AbsentHasPropertyCacheNode(new InstanceofCheckNode(thisObj.getClass()));
371371
}
372372
}
373373

374374
@Override
375-
protected HasCacheNode createJavaPropertyNodeMaybe(Object thisObj, int depth) {
375+
protected HasCacheNode createJavaPropertyNodeMaybe(Object thisObj, JSDynamicObject proto, int depth) {
376376
if (JavaPackage.isJavaPackage(thisObj)) {
377-
return new PresentHasPropertyCacheNode(createJSClassCheck(thisObj, depth));
377+
return new PresentHasPropertyCacheNode(createJSClassCheck(thisObj, proto, depth));
378378
} else if (JavaImporter.isJavaImporter(thisObj)) {
379-
return new UnspecializedHasPropertyCacheNode(createJSClassCheck(thisObj, depth));
379+
return new UnspecializedHasPropertyCacheNode(createJSClassCheck(thisObj, proto, depth));
380380
}
381381
return null;
382382
}

0 commit comments

Comments
 (0)