Skip to content

Commit 52eaefe

Browse files
committed
[GR-4767] Unable to see block scope frame on stack.
PullRequest: js/1996
2 parents 691f1fb + dab4719 commit 52eaefe

54 files changed

Lines changed: 1667 additions & 1194 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

graal-js/ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ local common = import '../common.jsonnet';
4040
['mvn', '-Dgraalvm.version=GATE', 'package'],
4141
['mvn', '-Dgraalvm.version=GATE', 'exec:exec'],
4242
],
43-
timelimit: '10:00',
43+
timelimit: '15:00',
4444
},
4545

4646
local webassemblyTest = {

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/Parser.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,6 @@ private ParserContextFunctionNode createParserContextFunctionNode(final IdentNod
676676
if (parentFunction == null) {
677677
flags |= FunctionNode.IS_PROGRAM;
678678
flags |= FunctionNode.IS_ANONYMOUS;
679-
} else {
680-
lc.setCurrentFunctionFlag(FunctionNode.HAS_CLOSURES);
681679
}
682680

683681
final Scope parentScope = lc.getCurrentScope();
@@ -1864,6 +1862,9 @@ private PropertyNode createDefaultClassConstructor(int classLineNumber, long cla
18641862
function.setInternalName(CONSTRUCTOR_NAME);
18651863
}
18661864

1865+
// currently required for all functions, including synthetic ones.
1866+
lc.setCurrentFunctionFlag(FunctionNode.HAS_CLOSURES);
1867+
18671868
PropertyNode constructor = new PropertyNode(classToken, ctorFinish, new IdentNode(identToken, ctorFinish, CONSTRUCTOR_NAME),
18681869
createFunctionNode(function, classToken, className, classLineNumber, body),
18691870
null, null, false, false, false, false);
@@ -1976,6 +1977,9 @@ private Pair<FunctionNode, Boolean> fieldInitializer(int lineNumber, long fieldT
19761977
}
19771978
}
19781979

1980+
// currently required for all functions, including synthetic ones.
1981+
lc.setCurrentFunctionFlag(FunctionNode.HAS_CLOSURES);
1982+
19791983
final List<Statement> statements = Collections.singletonList(new ReturnNode(lineNumber, fieldToken, finish, initializer));
19801984
Block bodyBlock = new Block(fieldToken, finish, Block.IS_BODY | Block.IS_SYNTHETIC, body.getScope(), statements);
19811985
return Pair.create(createFunctionNode(function, fieldToken, null, lineNumber, bodyBlock), isAnonymousFunctionDefinition);

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/ParserContextFunctionNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ public void propagateFlagsToParent(ParserContextFunctionNode parent) {
590590
parent.setFlag(FunctionNode.USES_THIS);
591591
}
592592
}
593+
parent.setFlag(FunctionNode.HAS_CLOSURES);
593594
}
594595

595596
private static int calculateLength(final List<IdentNode> parameters) {

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/ir/ClassNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -223,7 +223,7 @@ public void toString(StringBuilder sb, boolean printType) {
223223
ident.toString(sb, printType);
224224
}
225225
if (classHeritage != null) {
226-
sb.append(" extends");
226+
sb.append(" extends ");
227227
classHeritage.toString(sb, printType);
228228
}
229229
sb.append(" {");

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/ir/Scope.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public final class Scope {
8383
protected List<Map.Entry<VarNode, Scope>> hoistableBlockFunctionDeclarations;
8484

8585
private int blockScopedOrRedeclaredSymbols;
86-
private int declaredNames;
8786
private boolean closed;
8887

8988
private Scope(Scope parent, int type, int flags) {
@@ -205,9 +204,6 @@ public Symbol putSymbol(final Symbol symbol) {
205204
if (symbol.isBlockScoped() || symbol.isVarRedeclaredHere()) {
206205
blockScopedOrRedeclaredSymbols++;
207206
}
208-
if (symbol.isBlockScoped() || (symbol.isVar() && !symbol.isParam())) {
209-
declaredNames++;
210-
}
211207
return null;
212208
}
213209

@@ -216,7 +212,7 @@ public boolean hasBlockScopedOrRedeclaredSymbols() {
216212
}
217213

218214
public boolean hasDeclarations() {
219-
return declaredNames != 0;
215+
return !symbols.isEmpty();
220216
}
221217

222218
/**

graal-js/src/com.oracle.truffle.js.parser/src/com/oracle/truffle/js/parser/GraalJSEvaluator.java

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import com.oracle.truffle.api.frame.FrameSlot;
7272
import com.oracle.truffle.api.frame.MaterializedFrame;
7373
import com.oracle.truffle.api.frame.VirtualFrame;
74+
import com.oracle.truffle.api.interop.NodeLibrary;
75+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
7476
import com.oracle.truffle.api.nodes.DirectCallNode;
7577
import com.oracle.truffle.api.nodes.Node;
7678
import com.oracle.truffle.api.nodes.RootNode;
@@ -83,6 +85,7 @@
8385
import com.oracle.truffle.js.nodes.NodeFactory;
8486
import com.oracle.truffle.js.nodes.ScriptNode;
8587
import com.oracle.truffle.js.nodes.access.PropertyGetNode;
88+
import com.oracle.truffle.js.nodes.access.PropertySetNode;
8689
import com.oracle.truffle.js.nodes.arguments.AccessIndexedArgumentNode;
8790
import com.oracle.truffle.js.nodes.control.TryCatchNode;
8891
import com.oracle.truffle.js.nodes.function.EvalNode;
@@ -96,6 +99,7 @@
9699
import com.oracle.truffle.js.runtime.Errors;
97100
import com.oracle.truffle.js.runtime.GraalJSException;
98101
import com.oracle.truffle.js.runtime.JSArguments;
102+
import com.oracle.truffle.js.runtime.JSConfig;
99103
import com.oracle.truffle.js.runtime.JSContext;
100104
import com.oracle.truffle.js.runtime.JSException;
101105
import com.oracle.truffle.js.runtime.JSFrameUtil;
@@ -187,21 +191,6 @@ public ScriptNode parseDirectEval(JSContext context, Node lastNode, Source sourc
187191
return parseEval(context, lastNode, source, directEval.env.isStrictMode(), directEval);
188192
}
189193

190-
private static JavaScriptNode parseInlineScript(JSContext context, Source source, Environment env, boolean isStrict) {
191-
ScriptNode script = JavaScriptTranslator.translateInlineScript(NodeFactory.getInstance(context), context, env, source, isStrict);
192-
RootCallTarget callTarget = script.getCallTarget();
193-
JSFunctionData functionData = script.getFunctionData();
194-
return new JavaScriptNode() {
195-
@Child DirectCallNode callNode = DirectCallNode.create(callTarget);
196-
197-
@Override
198-
public Object execute(VirtualFrame frame) {
199-
DynamicObject closure = JSFunction.create(getRealm(), functionData, frame.materialize());
200-
return callNode.call(JSArguments.createZeroArg(JSFrameUtil.getThisObj(frame), closure));
201-
}
202-
};
203-
}
204-
205194
@TruffleBoundary(transferToInterpreterOnException = false)
206195
private static ScriptNode parseEval(JSContext context, Node lastNode, Source source, boolean isStrict, DirectEvalContext directEval) {
207196
context.checkEvalAllowed();
@@ -980,8 +969,37 @@ public ScriptNode parseScript(JSContext context, Source source, SnapshotProvider
980969

981970
@Override
982971
public JavaScriptNode parseInlineScript(JSContext context, Source source, MaterializedFrame lexicalContextFrame, boolean isStrict, Node locationNode) {
983-
Environment env = new DebugEnvironment(null, NodeFactory.getInstance(context), context, locationNode, lexicalContextFrame);
984-
return parseInlineScript(context, source, env, isStrict);
972+
Environment env;
973+
Object scope;
974+
try {
975+
scope = NodeLibrary.getUncached().getScope(locationNode, lexicalContextFrame, true);
976+
env = new DebugEnvironment(null, NodeFactory.getInstance(context), context, scope);
977+
} catch (UnsupportedMessageException e) {
978+
scope = null;
979+
env = null;
980+
}
981+
ScriptNode script = JavaScriptTranslator.translateInlineScript(NodeFactory.getInstance(context), context, env, source, isStrict);
982+
return createInlineScriptCallNode(context, script.getFunctionData(), script.getCallTarget(), locationNode);
983+
}
984+
985+
private static JavaScriptNode createInlineScriptCallNode(JSContext context, JSFunctionData functionData, RootCallTarget callTarget, Node locationNode) {
986+
return new JavaScriptNode() {
987+
@Child private DirectCallNode callNode = DirectCallNode.create(callTarget);
988+
@Child private PropertySetNode setScopeNode = PropertySetNode.createSetHidden(JSFunction.DEBUG_SCOPE_ID, context);
989+
@Child private NodeLibrary nodeLibrary = NodeLibrary.getFactory().createDispatched(JSConfig.InteropLibraryLimit);
990+
991+
@Override
992+
public Object execute(VirtualFrame frame) {
993+
DynamicObject closure = JSFunction.create(getRealm(), functionData);
994+
try {
995+
Object scope = nodeLibrary.getScope(locationNode, frame, true);
996+
setScopeNode.setValue(closure, scope);
997+
} catch (UnsupportedMessageException e) {
998+
// ignore
999+
}
1000+
return callNode.call(JSArguments.createZeroArg(JSFrameUtil.getThisObj(frame), closure));
1001+
}
1002+
};
9851003
}
9861004

9871005
@Override

0 commit comments

Comments
 (0)