Skip to content

Commit e8ba715

Browse files
committed
Preserve ~ operator input value for instrumentation.
1 parent f9db3da commit e8ba715

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

graal-js/src/com.oracle.truffle.js.test.instrumentation/src/com/oracle/truffle/js/test/instrumentation/UnaryOperationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ public void voidMethod() {
9393
}
9494

9595
@Test
96-
public void toInt() {
97-
// 'true' is converted to '1' before the binary operation.
98-
assertBasicUnaryOperation("var x = true; var b = ~x;", true, 1, -2, "~");
96+
public void bitwiseNot() {
97+
assertBasicUnaryOperation("var x = true; var b = ~x;", true, true, -2, "~");
9998
}
10099

101100
@Test

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/unary/JSComplementNode.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import com.oracle.truffle.api.dsl.Cached;
4646
import com.oracle.truffle.api.dsl.Specialization;
47+
import com.oracle.truffle.api.frame.VirtualFrame;
4748
import com.oracle.truffle.api.instrumentation.InstrumentableNode;
4849
import com.oracle.truffle.api.instrumentation.Tag;
4950
import com.oracle.truffle.api.nodes.NodeInfo;
@@ -54,6 +55,7 @@
5455
import com.oracle.truffle.js.nodes.instrumentation.JSInputGeneratingNodeWrapper;
5556
import com.oracle.truffle.js.nodes.instrumentation.JSTags.UnaryOperationTag;
5657
import com.oracle.truffle.js.runtime.BigInt;
58+
import com.oracle.truffle.js.runtime.SafeInteger;
5759

5860
@NodeInfo(shortName = "~")
5961
public abstract class JSComplementNode extends JSUnaryNode {
@@ -64,7 +66,7 @@ protected JSComplementNode(JavaScriptNode operand) {
6466

6567
public static JSComplementNode create(JavaScriptNode operand) {
6668
Truncatable.truncate(operand);
67-
return JSComplementNodeGen.create(JSToNumericNode.create(operand));
69+
return JSComplementNodeGen.create(operand);
6870
}
6971

7072
@Override
@@ -91,10 +93,14 @@ protected int doInteger(int a) {
9193
return ~a;
9294
}
9395

96+
@Specialization
97+
protected int doSafeInteger(SafeInteger a) {
98+
return ~a.intValue();
99+
}
100+
94101
@Specialization
95102
protected int doDouble(double a,
96103
@Cached("create()") JSToInt32Node toInt32Node) {
97-
98104
return doInteger(toInt32Node.executeInt(a));
99105
}
100106

@@ -103,6 +109,18 @@ protected BigInt doBigInt(BigInt a) {
103109
return a.not();
104110
}
105111

112+
@Specialization(replaces = {"doInteger", "doSafeInteger", "doDouble", "doBigInt"})
113+
protected Object doGeneric(VirtualFrame frame, Object value,
114+
@Cached JSToNumericNode toNumericNode,
115+
@Cached("createInner()") JSComplementNode recursive) {
116+
Object number = toNumericNode.execute(value);
117+
return recursive.execute(frame, number);
118+
}
119+
120+
static JSComplementNode createInner() {
121+
return JSComplementNodeGen.create(null);
122+
}
123+
106124
@Override
107125
public boolean isResultAlwaysOfType(Class<?> clazz) {
108126
return clazz == Number.class;

0 commit comments

Comments
 (0)