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

Fixed a problem with super and nested lambdas #1838

Merged
merged 1 commit into from
Feb 20, 2025
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
4 changes: 4 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,10 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl
cx, frame.scope, frame.fnOrScript, indexReg);
if (fn.idata.itsFunctionType == FunctionNode.ARROW_FUNCTION) {
Scriptable homeObject = getCurrentFrameHomeObject(frame);
if (fn.idata.itsNeedsActivation) {
fn.setHomeObject(homeObject);
}

stack[++stackTop] =
new ArrowFunction(
cx, frame.scope, fn, frame.thisObj, homeObject);
Expand Down
32 changes: 32 additions & 0 deletions rhino/src/test/java/org/mozilla/javascript/SuperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,38 @@ void doublyNestedLambdaCaptureSuper() {

Utils.assertWithAllModes_ES6("object", script);
}

@Test
void mixedCompileInterpret() {
String script =
""
+ "var proto = {\n"
+ " x: 'proto',\n"
+ " f() {\n"
+ " return this.x;\n"
+ " }\n"
+ "};\n"
+ "var object = {\n"
+ " x: 'object',\n"
+ " f() {\n"
+ " return () => { return super.f(); };\n"
+ " }\n"
+ "};\n"
+ "Object.setPrototypeOf(object, proto);\n";
String script2 = "object.f()();";

try (Context cx = Context.enter()) {
cx.setLanguageVersion(Context.VERSION_ES6);
ScriptableObject scope = cx.initStandardObjects();

cx.setInterpretedMode(true);
cx.evaluateString(scope, script, "test", 1, null);

cx.setInterpretedMode(false);
Object res = cx.evaluateString(scope, script2, "test", 1, null);
assertEquals("object", res);
}
}
}

/**
Expand Down