From cbea881dff7196b22fd5aaf97ac306a9e226ca5d Mon Sep 17 00:00:00 2001 From: Michael Leon Date: Tue, 4 Nov 2025 14:02:40 -0800 Subject: [PATCH] Set home object correctly in object literal accessors Summary: `genFunctionExpression` of an accessor was not setting the home object correctly. Reviewed By: avp Differential Revision: D86118531 fbshipit-source-id: a64afe938d61b7b210cc6eac68a561fc21aaba34 (cherry picked from commit 18a9634659443c92d481efe71b0c2aea9e6c464b) --- lib/IRGen/ESTreeIRGen-expr.cpp | 4 ++-- test/hermes/object-literal-getter-super.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/IRGen/ESTreeIRGen-expr.cpp b/lib/IRGen/ESTreeIRGen-expr.cpp index 073cb38e5a0..4d27ac94007 100644 --- a/lib/IRGen/ESTreeIRGen-expr.cpp +++ b/lib/IRGen/ESTreeIRGen-expr.cpp @@ -1634,7 +1634,7 @@ Value *ESTreeIRGen::genObjectExpr(ESTree::ObjectExpressionNode *Expr) { Builder.createIdentifier("get " + keyStr.str()), /* superClassNode */ nullptr, Function::DefinitionKind::ES5Function, - /* homeObject */ nullptr, + /* homeObject */ capturedObj, /* parentNode */ propValue->getterProp); } @@ -1645,7 +1645,7 @@ Value *ESTreeIRGen::genObjectExpr(ESTree::ObjectExpressionNode *Expr) { Builder.createIdentifier("set " + keyStr.str()), /* superClassNode */ nullptr, Function::DefinitionKind::ES5Function, - /* homeObject */ nullptr, + /* homeObject */ capturedObj, /* parentNode */ propValue->setterProp); } diff --git a/test/hermes/object-literal-getter-super.js b/test/hermes/object-literal-getter-super.js index 5ba94c9a0ba..846fd684f51 100644 --- a/test/hermes/object-literal-getter-super.js +++ b/test/hermes/object-literal-getter-super.js @@ -20,3 +20,19 @@ var object = { Object.setPrototypeOf(object, proto); print(object.a); // CHECK: a proto m + +// Test that accessors without computed names can also refer to super. +(function () { + let v1 = { + get a() { + let x = super.m; + print(x); + } + } + let parent = { m: 12 }; + v1.a; +// CHECK-NEXT: undefined + Object.setPrototypeOf(v1, parent); + v1.a; +// CHECK-NEXT: 12 +})();