Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peel known functions in interpreter so they don't break continuations #1510

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions rhino/src/main/java/org/mozilla/javascript/ArrowFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public ArrowFunction(

@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
Scriptable callThis = boundThis != null ? boundThis : ScriptRuntime.getTopCallScope(cx);
return targetFunction.call(cx, scope, callThis, args);
return targetFunction.call(cx, scope, getCallThis(cx), args);
}

@Override
Expand Down Expand Up @@ -74,6 +73,14 @@ String decompile(int indent, int flags) {
return super.decompile(indent, flags);
}

Scriptable getCallThis(Context cx) {
return boundThis != null ? boundThis : ScriptRuntime.getTopCallScope(cx);
}

Callable getTargetFunction() {
return targetFunction;
}

static boolean equalObjectGraphs(ArrowFunction f1, ArrowFunction f2, EqualObjectGraphs eq) {
return eq.equalGraphs(f1.boundThis, f2.boundThis)
&& eq.equalGraphs(f1.targetFunction, f2.targetFunction);
Expand Down
28 changes: 20 additions & 8 deletions rhino/src/main/java/org/mozilla/javascript/BoundFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ public BoundFunction(

@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] extraArgs) {
Scriptable callThis = boundThis;
if (callThis == null && ScriptRuntime.hasTopCall(cx)) {
callThis = ScriptRuntime.getTopCallScope(cx);
}
if (callThis == null) {
callThis = getTopLevelScope(scope);
}
return targetFunction.call(cx, scope, callThis, concat(boundArgs, extraArgs));
return targetFunction.call(cx, scope, getCallThis(cx, scope), concat(boundArgs, extraArgs));
}

@Override
Expand Down Expand Up @@ -98,6 +91,25 @@ private static Object[] concat(Object[] first, Object[] second) {
return args;
}

Callable getTargetFunction() {
return targetFunction;
}

Object[] getBoundArgs() {
return boundArgs;
}

Scriptable getCallThis(Context cx, Scriptable scope) {
Scriptable callThis = boundThis;
if (callThis == null && ScriptRuntime.hasTopCall(cx)) {
callThis = ScriptRuntime.getTopCallScope(cx);
}
if (callThis == null) {
callThis = getTopLevelScope(scope);
}
return callThis;
}

static boolean equalObjectGraphs(BoundFunction f1, BoundFunction f2, EqualObjectGraphs eq) {
return eq.equalGraphs(f1.boundThis, f2.boundThis)
&& eq.equalGraphs(f1.targetFunction, f2.targetFunction)
Expand Down
Loading
Loading