Skip to content

Commit

Permalink
[GR-44414] Fix Nashorn test failing in shared-engine mode (24.0).
Browse files Browse the repository at this point in the history
PullRequest: js/3022
  • Loading branch information
woess committed Jan 9, 2024
2 parents e69e1fa + cb9a478 commit 159292d
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 155 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -44,10 +44,16 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
import com.oracle.truffle.api.strings.TruffleString;
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateGetDateNodeGen;
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateGetDayNodeGen;
Expand Down Expand Up @@ -80,6 +86,7 @@
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateToStringNodeGen;
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateToTimeStringNodeGen;
import com.oracle.truffle.js.builtins.DatePrototypeBuiltinsFactory.JSDateValueOfNodeGen;
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
import com.oracle.truffle.js.nodes.access.IsObjectNode;
import com.oracle.truffle.js.nodes.access.PropertyGetNode;
import com.oracle.truffle.js.nodes.cast.JSToNumberNode;
Expand Down Expand Up @@ -900,34 +907,49 @@ private JSFunctionCallNode getCallToISOStringFnNode() {

public abstract static class JSDateToPrimitiveNode extends JSBuiltinNode {

@Child private OrdinaryToPrimitiveNode ordinaryToPrimitiveHintNumber;
@Child private OrdinaryToPrimitiveNode ordinaryToPrimitiveHintString;

public JSDateToPrimitiveNode(JSContext context, JSBuiltin builtin) {
super(context, builtin);
}

@Specialization
protected final Object toPrimitive(Object obj, Object hint,
@Cached IsObjectNode isObjectNode,
@Cached InlinedConditionProfile isHintNumber,
@Cached InlinedConditionProfile isHintStringOrDefault) {
if (!isObjectNode.executeBoolean(obj)) {
@Cached DateToPrimitiveHelperNode dateToPrimitiveHelper,
@Cached InlinedBranchProfile errorBranch) {
if (isObjectNode.executeBoolean(obj)) {
return dateToPrimitiveHelper.execute(this, obj, hint);
} else {
errorBranch.enter(this);
throw Errors.createTypeErrorNotAnObject(obj);
}
if (isHintNumber.profile(this, Strings.HINT_NUMBER.equals(hint))) {
if (ordinaryToPrimitiveHintNumber == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
ordinaryToPrimitiveHintNumber = insert(OrdinaryToPrimitiveNode.createHintNumber());
}
}

@GenerateInline
@GenerateCached(false)
@ImportStatic(Strings.class)
abstract static class DateToPrimitiveHelperNode extends JavaScriptBaseNode {

abstract Object execute(Node node, Object obj, Object hint);

@SuppressWarnings("unused")
@Specialization(guards = {"equals(strEqual, HINT_NUMBER, hint)"})
static Object toPrimitiveHintNumber(Object obj, TruffleString hint,
@Cached @Shared TruffleString.EqualNode strEqual,
@Cached("createHintNumber()") OrdinaryToPrimitiveNode ordinaryToPrimitiveHintNumber) {
return ordinaryToPrimitiveHintNumber.execute(obj);
} else if (isHintStringOrDefault.profile(this, Strings.HINT_STRING.equals(hint) || Strings.HINT_DEFAULT.equals(hint))) {
if (ordinaryToPrimitiveHintString == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
ordinaryToPrimitiveHintString = insert(OrdinaryToPrimitiveNode.createHintString());
}
}

@SuppressWarnings("unused")
@Specialization(guards = {"equals(strEqual, HINT_STRING, hint) || equals(strEqual, HINT_DEFAULT, hint)"})
static Object toPrimitiveHintStringOrDefault(Object obj, TruffleString hint,
@Cached @Shared TruffleString.EqualNode strEqual,
@Cached("createHintString()") OrdinaryToPrimitiveNode ordinaryToPrimitiveHintString) {
return ordinaryToPrimitiveHintString.execute(obj);
} else {
}

@Fallback
static Object invalidHint(@SuppressWarnings("unused") Object obj, Object hint) {
assert !(Strings.HINT_STRING.equals(hint) || Strings.HINT_NUMBER.equals(hint) || Strings.HINT_DEFAULT.equals(hint)) : hint;
throw Errors.createTypeError("invalid hint");
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -334,15 +334,15 @@ protected boolean hasProperty(Object thisObj, HasPropertyCacheNode root) {
* @param property The particular entry of the property being accessed.
*/
@Override
protected HasCacheNode createCachedPropertyNode(Property property, Object thisObj, int depth, Object value, HasCacheNode currentHead) {
protected HasCacheNode createCachedPropertyNode(Property property, Object thisObj, JSDynamicObject proto, int depth, Object value, HasCacheNode currentHead) {
assert !isOwnProperty() || depth == 0;
ReceiverCheckNode check;
if (JSDynamicObject.isJSDynamicObject(thisObj)) {
JSDynamicObject thisJSObj = (JSDynamicObject) thisObj;
Shape cacheShape = thisJSObj.getShape();
check = createShapeCheckNode(cacheShape, thisJSObj, depth, false, false);
check = createShapeCheckNode(cacheShape, thisJSObj, proto, depth, false, false);
} else {
check = createPrimitiveReceiverCheck(thisObj, depth);
check = createPrimitiveReceiverCheck(thisObj, proto, depth);
}
if (hasOwnProperty && JSProperty.isModuleNamespaceExport(property)) {
return new ModuleNamespaceHasOwnPropertyNode(check, property);
Expand All @@ -351,32 +351,32 @@ protected HasCacheNode createCachedPropertyNode(Property property, Object thisOb
}

@Override
protected HasCacheNode createUndefinedPropertyNode(Object thisObj, Object store, int depth, Object value) {
HasCacheNode specialized = createJavaPropertyNodeMaybe(thisObj, depth);
protected HasCacheNode createUndefinedPropertyNode(Object thisObj, Object store, JSDynamicObject proto, int depth, Object value) {
HasCacheNode specialized = createJavaPropertyNodeMaybe(thisObj, proto, depth);
if (specialized != null) {
return specialized;
}
if (JSDynamicObject.isJSDynamicObject(thisObj)) {
JSDynamicObject thisJSObj = (JSDynamicObject) thisObj;
Shape cacheShape = thisJSObj.getShape();
if (JSAdapter.isJSAdapter(store)) {
return new JSAdapterHasPropertyCacheNode(key, createJSClassCheck(thisObj, depth));
return new JSAdapterHasPropertyCacheNode(key, createJSClassCheck(thisObj, proto, depth));
} else if (JSProxy.isJSProxy(store)) {
return new JSProxyDispatcherPropertyHasNode(context, key, createJSClassCheck(thisObj, depth), isOwnProperty());
return new JSProxyDispatcherPropertyHasNode(context, key, createJSClassCheck(thisObj, proto, depth), isOwnProperty());
} else {
return new AbsentHasPropertyCacheNode(createShapeCheckNode(cacheShape, thisJSObj, depth, false, false));
return new AbsentHasPropertyCacheNode(createShapeCheckNode(cacheShape, thisJSObj, proto, depth, false, false));
}
} else {
return new AbsentHasPropertyCacheNode(new InstanceofCheckNode(thisObj.getClass()));
}
}

@Override
protected HasCacheNode createJavaPropertyNodeMaybe(Object thisObj, int depth) {
protected HasCacheNode createJavaPropertyNodeMaybe(Object thisObj, JSDynamicObject proto, int depth) {
if (JavaPackage.isJavaPackage(thisObj)) {
return new PresentHasPropertyCacheNode(createJSClassCheck(thisObj, depth));
return new PresentHasPropertyCacheNode(createJSClassCheck(thisObj, proto, depth));
} else if (JavaImporter.isJavaImporter(thisObj)) {
return new UnspecializedHasPropertyCacheNode(createJSClassCheck(thisObj, depth));
return new UnspecializedHasPropertyCacheNode(createJSClassCheck(thisObj, proto, depth));
}
return null;
}
Expand Down

0 comments on commit 159292d

Please sign in to comment.