From cbc0f9fd974de2e2435ac98dd83c4b2ad96f75c1 Mon Sep 17 00:00:00 2001 From: Dan Minor Date: Thu, 14 Dec 2023 17:58:45 +0000 Subject: [PATCH] Bug 1800724 - Use DecoratorEmitter::emitCallExtraInitializers in BytecodeEmitter; r=arai Differential Revision: https://phabricator.services.mozilla.com/D195924 --- js/src/frontend/BytecodeEmitter.cpp | 5 +++++ js/src/frontend/DecoratorEmitter.cpp | 13 ++++++++----- js/src/jit-test/tests/decorators/addInitializer.js | 6 +++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index e957c7dabed3..28f4681d9e3f 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -10755,6 +10755,11 @@ bool BytecodeEmitter::emitInitializeInstanceMembers( return false; } // 5. Return unused. + + if (!de.emitCallExtraInitializers(TaggedParserAtomIndex::WellKnown:: + dot_instanceExtraInitializers_())) { + return false; + } #endif } return true; diff --git a/js/src/frontend/DecoratorEmitter.cpp b/js/src/frontend/DecoratorEmitter.cpp index 2e1f6c0ffb83..77492706b984 100644 --- a/js/src/frontend/DecoratorEmitter.cpp +++ b/js/src/frontend/DecoratorEmitter.cpp @@ -812,8 +812,14 @@ bool DecoratorEmitter::emitInitializeFieldOrAccessor() { bool DecoratorEmitter::emitCallExtraInitializers( TaggedParserAtomIndex extraInitializers) { + // Support for static and class extra initializers will be added in + // bug 1868220 and bug 1868221. + MOZ_ASSERT( + extraInitializers == + TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()); + if (!bce_->emitGetName(extraInitializers)) { - // [stack] ARRAY + // [stack] ARRAY return false; } @@ -834,9 +840,6 @@ bool DecoratorEmitter::emitCallExtraInitializers( } InternalWhileEmitter wh(bce_); - // At this point, we have no context to determine offsets in the - // code for this while statement. Ideally, it would correspond to - // the field we're initializing. if (!wh.emitCond()) { // [stack] ARRAY LENGTH INDEX return false; @@ -886,7 +889,7 @@ bool DecoratorEmitter::emitCallExtraInitializers( // Callee is always internal function. if (!bce_->emitCall(JSOp::CallIgnoresRv, 0)) { - // [stack] ARRAY LENGTH INDEX INITIALIZER THIS RVAL + // [stack] ARRAY LENGTH INDEX RVAL return false; } diff --git a/js/src/jit-test/tests/decorators/addInitializer.js b/js/src/jit-test/tests/decorators/addInitializer.js index 22cc1a3ad70d..58b5c32b2d5f 100644 --- a/js/src/jit-test/tests/decorators/addInitializer.js +++ b/js/src/jit-test/tests/decorators/addInitializer.js @@ -1,6 +1,8 @@ // |jit-test| skip-if: !getBuildConfiguration("decorators") load(libdir + "asserts.js"); +let extraInitializerCalled = {}; + function checkDecoratorContext(kind, isPrivate, isStatic, name) { return function (value, context) { if (kind == "field") { @@ -16,7 +18,7 @@ function checkDecoratorContext(kind, isPrivate, isStatic, name) { assertEq(context.static, isStatic); assertEq(context.name, name); assertEq(typeof context.addInitializer, "function"); - context.addInitializer(() => {}); + context.addInitializer(() => {extraInitializerCalled[context.name] = true;}); // return undefined } } @@ -27,3 +29,5 @@ class C { } let c = new C(); +assertEq(extraInitializerCalled["x"], true); +assertEq(extraInitializerCalled["y accessor storage"], true);