Skip to content

Commit 9084904

Browse files
committed
[GR-27438] Fixes of issues discovered by instrumented external test-suites.
PullRequest: js/1755
2 parents 8baec29 + c2348f3 commit 9084904

File tree

11 files changed

+45
-171
lines changed

11 files changed

+45
-171
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import org.junit.Test;
4444

45-
import com.oracle.truffle.js.nodes.instrumentation.JSTags.BinaryOperationTag;
4645
import com.oracle.truffle.js.nodes.instrumentation.JSTags.ControlFlowBranchTag;
4746
import com.oracle.truffle.js.nodes.instrumentation.JSTags.FunctionCallTag;
4847
import com.oracle.truffle.js.nodes.instrumentation.JSTags.LiteralTag;
@@ -128,25 +127,25 @@ public void incDecVar() {
128127
@Test
129128
public void incLocal() {
130129
evalAllTags("function foo(a) { var x = a++; return x; }; foo(42);");
131-
assertAllLocalOperationsPost("+", 43, 42);
130+
assertAllLocalOperationsPost("++", 43, 42);
132131
}
133132

134133
@Test
135134
public void decLocal() {
136135
evalAllTags("function foo(a) { var x = a--; return x; }; foo(42);");
137-
assertAllLocalOperationsPost("-", 41, 42);
136+
assertAllLocalOperationsPost("--", 41, 42);
138137
}
139138

140139
@Test
141140
public void incLocalPre() {
142141
evalAllTags("function foo(a) { var x = ++a; return x; }; foo(42);");
143-
assertAllLocalOperationsPost("+", 43, 43);
142+
assertAllLocalOperationsPost("++", 43, 43);
144143
}
145144

146145
@Test
147146
public void decLocalPre() {
148147
evalAllTags("function foo(a) { var x = --a; return x; }; foo(42);");
149-
assertAllLocalOperationsPost("-", 41, 41);
148+
assertAllLocalOperationsPost("--", 41, 41);
150149
}
151150

152151
private void assertAllLocalOperationsPost(String operator, int valueSet, int exprReturns) {
@@ -179,14 +178,12 @@ private void assertAllLocalOperationsPost(String operator, int valueSet, int exp
179178
enter(WriteVariableTag.class, (e4, p4) -> {
180179
assertAttribute(e4, NAME, "a");
181180
// De-sugared to a = a + 1;
182-
enter(BinaryOperationTag.class, (e5, p5) -> {
181+
enter(UnaryOperationTag.class, (e5, p5) -> {
183182
assertAttribute(e5, OPERATOR, operator);
184183
enter(ReadVariableTag.class, (e6, p6) -> {
185184
assertAttribute(e6, NAME, "a");
186185
}).exit(assertReturnValue(42));
187186
p5.input(42);
188-
enter(LiteralTag.class).exit(assertReturnValue(1));
189-
p5.input(1);
190187
}).exit();
191188
// Write to 'a' sets new value
192189
p4.input(valueSet);

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/JSNodeUtil.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,22 @@ public static JavaScriptNode getWrappedNode(JavaScriptNode node) {
160160
WrapperNode wrapper = (WrapperNode) node;
161161
// JavaScriptNode wrappers have a JavaScriptNode as delegate
162162
unwrapped = (JavaScriptNode) wrapper.getDelegateNode();
163-
} else if (node instanceof GlobalScopeVarWrapperNode) {
164-
unwrapped = ((GlobalScopeVarWrapperNode) node).getDelegateNode();
165-
} else if (node instanceof JSInputGeneratingNodeWrapper) {
166-
unwrapped = ((JSInputGeneratingNodeWrapper) node).getDelegateNode();
167-
} else if (node instanceof JSTaggedExecutionNode) {
168-
unwrapped = ((JSTaggedExecutionNode) node).getDelegateNode();
169-
} else if (node instanceof JSTargetableWrapperNode) {
170-
unwrapped = ((JSTargetableWrapperNode) node).getDelegate();
163+
}
164+
if (unwrapped instanceof JSInputGeneratingNodeWrapper) {
165+
unwrapped = ((JSInputGeneratingNodeWrapper) unwrapped).getDelegateNode();
166+
}
167+
if (unwrapped instanceof JSTaggedExecutionNode) {
168+
unwrapped = ((JSTaggedExecutionNode) unwrapped).getDelegateNode();
169+
}
170+
if (unwrapped instanceof GlobalScopeVarWrapperNode) {
171+
unwrapped = ((GlobalScopeVarWrapperNode) unwrapped).getDelegateNode();
172+
}
173+
if (unwrapped instanceof JSTargetableWrapperNode) {
174+
unwrapped = ((JSTargetableWrapperNode) unwrapped).getDelegate();
175+
}
176+
if (unwrapped instanceof WrapperNode) {
177+
WrapperNode wrapper = (WrapperNode) unwrapped;
178+
unwrapped = (JavaScriptNode) wrapper.getDelegateNode();
171179
}
172180
assert !isWrapperNode(unwrapped);
173181
return unwrapped;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import com.oracle.truffle.api.frame.VirtualFrame;
4747
import com.oracle.truffle.api.instrumentation.Tag;
48+
import com.oracle.truffle.js.nodes.JSNodeUtil;
4849
import com.oracle.truffle.js.nodes.JavaScriptNode;
4950
import com.oracle.truffle.js.nodes.ReadNode;
5051
import com.oracle.truffle.js.runtime.Errors;
@@ -96,7 +97,7 @@ public Object execute(VirtualFrame frame) {
9697
Object dynamicScope = dynamicScopeNode.execute(frame);
9798
if (scopeHasBinding.execute(dynamicScope)) {
9899
if (isWrite()) {
99-
Object value = ((WriteNode) defaultDelegate).getRhs().execute(frame);
100+
Object value = getRhs().execute(frame);
100101
((WritePropertyNode) scopeAccessNode).executeWithValue(dynamicScope, value);
101102
return value;
102103
} else {
@@ -114,7 +115,7 @@ public Object executeWrite(VirtualFrame frame, Object value) {
114115

115116
@Override
116117
public JavaScriptNode getRhs() {
117-
return ((WriteNode) defaultDelegate).getRhs();
118+
return ((WriteNode) JSNodeUtil.getWrappedNode(defaultDelegate)).getRhs();
118119
}
119120

120121
@Override

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.oracle.truffle.api.instrumentation.GenerateWrapper;
4545
import com.oracle.truffle.api.instrumentation.ProbeNode;
4646
import com.oracle.truffle.api.nodes.UnexpectedResultException;
47+
import com.oracle.truffle.js.nodes.JSNodeUtil;
4748
import com.oracle.truffle.js.nodes.JavaScriptNode;
4849
import com.oracle.truffle.js.runtime.Errors;
4950

@@ -84,7 +85,8 @@ public JavaScriptNode getTarget() {
8485
throw Errors.notImplemented("getTarget");
8586
}
8687

87-
public static Object evaluateReceiver(JavaScriptNode targetNode, VirtualFrame frame, Object targetValue) {
88+
public static Object evaluateReceiver(JavaScriptNode target, VirtualFrame frame, Object targetValue) {
89+
JavaScriptNode targetNode = JSNodeUtil.getWrappedNode(target);
8890
if (!(targetNode instanceof SuperPropertyReferenceNode)) {
8991
return targetValue;
9092
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ abstract class LocalVarOpMaterializedNode extends LocalVarIncNode {
205205
convertOld = cloneUninitialized(JSWriteFrameSlotNode.create(frameSlot, scopeFrameNode, convert, frameDescriptor, hasTemporalDeadZone), materializedTags);
206206

207207
JavaScriptNode readTmp = JSReadFrameSlotNode.create(frameSlot, scopeFrameNode, hasTemporalDeadZone);
208-
JavaScriptNode one = JSConstantNode.createInt(1);
208+
JavaScriptNode one = JSConstantNode.createConstantNumericUnit();
209209
JavaScriptNode opNode;
210210
if (from.op instanceof DecOp) {
211211
opNode = JSSubtractNode.create(readTmp, one);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.oracle.truffle.api.object.Property;
5959
import com.oracle.truffle.api.object.Shape;
6060
import com.oracle.truffle.js.nodes.JSGuards;
61+
import com.oracle.truffle.js.nodes.JSNodeUtil;
6162
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
6263
import com.oracle.truffle.js.nodes.JavaScriptNode;
6364
import com.oracle.truffle.js.nodes.cast.JSToObjectNode;
@@ -507,8 +508,9 @@ public final void executeVoid(VirtualFrame frame, DynamicObject receiver, Dynami
507508
}
508509
Object key = executeKey(frame);
509510
Object value;
510-
if (isAnonymousFunctionDefinition && valueNode instanceof ClassDefinitionNode) {
511-
value = ((ClassDefinitionNode) valueNode).executeWithClassName(frame, key);
511+
JavaScriptNode unwrappedValueNode;
512+
if (isAnonymousFunctionDefinition && (unwrappedValueNode = JSNodeUtil.getWrappedNode(valueNode)) instanceof ClassDefinitionNode) {
513+
value = ((ClassDefinitionNode) unwrappedValueNode).executeWithClassName(frame, key);
512514
} else {
513515
value = executeWithHomeObject(valueNode, frame, homeObject);
514516
if (setFunctionName != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public InstrumentableNode materializeInstrumentableNodes(Set<Class<? extends Tag
101101
// this node is already materialized
102102
return this;
103103
}
104-
JavaScriptNode clonedTarget = JSTaggedExecutionNode.createForInput(target, this, materializedTags);
104+
JavaScriptNode clonedTarget = JSTaggedExecutionNode.createForInput(target, target.hasSourceSection() ? target : this, materializedTags);
105105
if (clonedTarget == target) {
106106
return this;
107107
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/function/JSFunctionCallNode.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.oracle.truffle.api.profiles.ValueProfile;
7575
import com.oracle.truffle.js.lang.JavaScriptLanguage;
7676
import com.oracle.truffle.js.nodes.JSGuards;
77+
import com.oracle.truffle.js.nodes.JSNodeUtil;
7778
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
7879
import com.oracle.truffle.js.nodes.JavaScriptNode;
7980
import com.oracle.truffle.js.nodes.access.JSConstantNode.JSConstantUndefinedNode;
@@ -84,7 +85,6 @@
8485
import com.oracle.truffle.js.nodes.access.SuperPropertyReferenceNode;
8586
import com.oracle.truffle.js.nodes.instrumentation.JSInputGeneratingNodeWrapper;
8687
import com.oracle.truffle.js.nodes.instrumentation.JSMaterializedInvokeTargetableNode;
87-
import com.oracle.truffle.js.nodes.instrumentation.JSTaggedExecutionNode;
8888
import com.oracle.truffle.js.nodes.instrumentation.JSTags;
8989
import com.oracle.truffle.js.nodes.instrumentation.JSTags.FunctionCallTag;
9090
import com.oracle.truffle.js.nodes.instrumentation.JSTags.ReadElementTag;
@@ -445,19 +445,7 @@ public NodeCost getCost() {
445445
public abstract JavaScriptNode getTarget();
446446

447447
protected final Object evaluateReceiver(VirtualFrame frame, Object target) {
448-
Node targetNode = getTarget();
449-
/*
450-
* SuperPropertyReferenceNode's instrumentation wrapper is an instance of
451-
* SuperPropertyReferenceNode. So, normally we wouldn't need to unwrap it. However, it can
452-
* be wrapped by JSTaggedExecutionNode and that could be wrapped by an instrumentation
453-
* wrapper. If that's the case, we have to unwrap twice.
454-
*/
455-
if (targetNode instanceof WrapperNode) {
456-
targetNode = ((WrapperNode) targetNode).getDelegateNode();
457-
}
458-
if (targetNode instanceof JSTaggedExecutionNode) {
459-
targetNode = ((JSTaggedExecutionNode) targetNode).getDelegateNode();
460-
}
448+
JavaScriptNode targetNode = JSNodeUtil.getWrappedNode(getTarget());
461449
if (targetNode instanceof SuperPropertyReferenceNode) {
462450
return ((SuperPropertyReferenceNode) targetNode).evaluateTarget(frame);
463451
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/objects/JSLazyString.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ public static CharSequence createLazyInt(CharSequence left, int right) {
145145
if (left.length() == 0) {
146146
return String.valueOf(right); // bailout
147147
}
148-
return new JSLazyString(left, new JSLazyIntWrapper(right));
148+
JSLazyString result = new JSLazyString(left, new JSLazyIntWrapper(right));
149+
if (result.length() > JavaScriptLanguage.getCurrentJSRealm().getContext().getStringLengthLimit()) {
150+
throw Errors.createRangeErrorInvalidStringLength();
151+
}
152+
return result;
149153
}
150154

151155
/**
@@ -159,7 +163,11 @@ public static CharSequence createLazyInt(int left, CharSequence right) {
159163
if (right.length() == 0) {
160164
return String.valueOf(left); // bailout
161165
}
162-
return new JSLazyString(new JSLazyIntWrapper(left), right);
166+
JSLazyString result = new JSLazyString(new JSLazyIntWrapper(left), right);
167+
if (result.length() > JavaScriptLanguage.getCurrentJSRealm().getContext().getStringLengthLimit()) {
168+
throw Errors.createRangeErrorInvalidStringLength();
169+
}
170+
return result;
163171
}
164172

165173
private CharSequence left;

graal-js/test/test262.json

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -221,30 +221,6 @@
221221
"filePath" : "built-ins/Atomics/xor/non-shared-bufferdata.js",
222222
"status" : "FAIL",
223223
"comment" : "GR-25372: Atomics methods should work with (non-shared) ArrayBuffers"
224-
}, {
225-
"filePath" : "built-ins/BigInt/prototype/toString/a-z.js",
226-
"status" : "PASS",
227-
"statusOverrides" : {
228-
"INSTRUMENT" : "FAIL"
229-
}
230-
}, {
231-
"filePath" : "built-ins/Promise/all/invoke-resolve-get-once-multiple-calls.js",
232-
"status" : "PASS",
233-
"statusOverrides" : {
234-
"INSTRUMENT" : "FAIL"
235-
}
236-
}, {
237-
"filePath" : "built-ins/Promise/allSettled/invoke-resolve-get-once-multiple-calls.js",
238-
"status" : "PASS",
239-
"statusOverrides" : {
240-
"INSTRUMENT" : "FAIL"
241-
}
242-
}, {
243-
"filePath" : "built-ins/Promise/race/invoke-resolve-get-once-multiple-calls.js",
244-
"status" : "PASS",
245-
"statusOverrides" : {
246-
"INSTRUMENT" : "FAIL"
247-
}
248224
}, {
249225
"filePath" : "built-ins/RegExp/named-groups/non-unicode-property-names-valid.js",
250226
"status" : "FAIL",
@@ -1868,61 +1844,13 @@
18681844
}, {
18691845
"filePath" : "built-ins/String/prototype/toLowerCase/special_casing_conditional.js",
18701846
"status" : "FAIL"
1871-
}, {
1872-
"filePath" : "built-ins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js",
1873-
"status" : "PASS",
1874-
"statusOverrides" : {
1875-
"INSTRUMENT" : "FAIL"
1876-
}
1877-
}, {
1878-
"filePath" : "built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js",
1879-
"status" : "PASS",
1880-
"statusOverrides" : {
1881-
"INSTRUMENT" : "FAIL"
1882-
}
1883-
}, {
1884-
"filePath" : "built-ins/TypedArray/prototype/filter/BigInt/callbackfn-set-value-during-iteration.js",
1885-
"status" : "PASS",
1886-
"statusOverrides" : {
1887-
"INSTRUMENT" : "FAIL"
1888-
}
1889-
}, {
1890-
"filePath" : "built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js",
1891-
"status" : "PASS",
1892-
"statusOverrides" : {
1893-
"INSTRUMENT" : "FAIL"
1894-
}
1895-
}, {
1896-
"filePath" : "built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js",
1897-
"status" : "PASS",
1898-
"statusOverrides" : {
1899-
"INSTRUMENT" : "FAIL"
1900-
}
1901-
}, {
1902-
"filePath" : "built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-set-value-during-iteration.js",
1903-
"status" : "PASS",
1904-
"statusOverrides" : {
1905-
"INSTRUMENT" : "FAIL"
1906-
}
1907-
}, {
1908-
"filePath" : "built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js",
1909-
"status" : "PASS",
1910-
"statusOverrides" : {
1911-
"INSTRUMENT" : "FAIL"
1912-
}
19131847
}, {
19141848
"filePath" : "built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js",
19151849
"status" : "PASS",
19161850
"statusOverrides" : {
19171851
"BIG_ENDIAN" : "FAIL"
19181852
},
19191853
"comment" : "Incorrect test (assumes little endian platform), see https://github.com/tc39/test262/issues/757"
1920-
}, {
1921-
"filePath" : "built-ins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js",
1922-
"status" : "PASS",
1923-
"statusOverrides" : {
1924-
"INSTRUMENT" : "FAIL"
1925-
}
19261854
}, {
19271855
"filePath" : "intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js",
19281856
"status" : "FAIL",
@@ -1999,24 +1927,6 @@
19991927
"filePath" : "language/expressions/dynamic-import/usage-from-eval.js",
20001928
"status" : "FAIL",
20011929
"comment" : "TODO: evaluate (Test262 tests update 2018-10-29)"
2002-
}, {
2003-
"filePath" : "language/expressions/super/prop-dot-cls-ref-this.js",
2004-
"status" : "PASS",
2005-
"statusOverrides" : {
2006-
"INSTRUMENT" : "FAIL"
2007-
}
2008-
}, {
2009-
"filePath" : "language/expressions/super/prop-dot-obj-ref-this.js",
2010-
"status" : "PASS",
2011-
"statusOverrides" : {
2012-
"INSTRUMENT" : "FAIL"
2013-
}
2014-
}, {
2015-
"filePath" : "language/global-code/script-decl-lex.js",
2016-
"status" : "PASS",
2017-
"statusOverrides" : {
2018-
"INSTRUMENT" : "FAIL"
2019-
}
20201930
}, {
20211931
"filePath" : "language/statements/class/accessor-name-inst-computed-yield-expr.js",
20221932
"status" : "FAIL",

0 commit comments

Comments
 (0)