Truly independent web browser
LibJS: Mark the callee of a call of async that is not an arrow function
Shannon Boothcf1ee9e014d2
diff --git a/Libraries/LibJS/Parser/Rust/src/expr.rs b/Libraries/LibJS/Parser/Rust/src/expr.rsindex 9a71d856e15..b706549bf55 100644--- a/Libraries/LibJS/Parser/Rust/src/expr.rs+++ b/Libraries/LibJS/Parser/Rust/src/expr.rs@@ -685,6 +685,15 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {self.close_scope();let list = self.finish_list(mark);self.note_use(N_ASYNC);++ // 13.3.6.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-function-calls-runtime-semantics-evaluation+ // CallExpression : CoverCallExpressionAndAsyncArrowHead+ // 4. Let ref be ? Evaluation of memberExpr.+ // 9. Return ? EvaluateCall(func, ref, args, tailCall).+ // NB: Marks async as the callee, so that EvaluateCall gets the this value from ref.+ if self.marks {+ self.mark_node(base as usize, tag::MARK_CALLEE, 0, params_start);+ }let call_tag = if self.marks && in_array {tag::CALL_ARRAY} else {diff --git a/Tests/LibJS/Runtime/with-basic.js b/Tests/LibJS/Runtime/with-basic.jsindex f01a0175fed..42edc0e2b79 100644--- a/Tests/LibJS/Runtime/with-basic.js+++ b/Tests/LibJS/Runtime/with-basic.js@@ -161,3 +161,29 @@ test("with statement updates empty abrupt completions to undefined", () => {expect(eval("8; do { 9; with ({}) { 10; continue; } 11; } while (false);")).toBe(10);expect(eval("12; do { 13; with ({}) { continue; } 14; } while (false);")).toBeUndefined();});++test("a call of a function named async gets the object of the with statement as this value", () => {+ const object = {+ async() {+ return this === object;+ },+ other() {+ return this === object;+ },+ };+ with (object) {+ const result = async();+ expect(result).toBeTrue();+ expect([async(), other(), async(...[]), async(1, 2)]).toEqual([true, true, true, true]);+ expect((() => async())()).toBeTrue();+ expect(eval("async()")).toBeTrue();+ }++ function async() {+ "use strict";+ return this;+ }+ expect(async()).toBeUndefined();+ const arrow = async () => 1;+ expect(arrow()).toBeInstanceOf(Promise);+});