11/*
2- * Copyright (c) 2022, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2022, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * The Universal Permissive License (UPL), Version 1.0
4949import com .oracle .truffle .api .nodes .Node ;
5050import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
5151import com .oracle .truffle .js .decorators .CreateDecoratorContextObjectNode .DecorationState ;
52+ import com .oracle .truffle .js .nodes .JavaScriptBaseNode ;
5253import com .oracle .truffle .js .nodes .access .CreateDataPropertyNode ;
5354import com .oracle .truffle .js .nodes .access .CreateObjectNode ;
5455import com .oracle .truffle .js .nodes .access .IsObjectNode ;
6162import com .oracle .truffle .js .runtime .Errors ;
6263import com .oracle .truffle .js .runtime .JSArguments ;
6364import com .oracle .truffle .js .runtime .JSContext ;
65+ import com .oracle .truffle .js .runtime .JSRealm ;
6466import com .oracle .truffle .js .runtime .Strings ;
6567import com .oracle .truffle .js .runtime .objects .JSDynamicObject ;
6668import com .oracle .truffle .js .runtime .objects .JSObject ;
6769import com .oracle .truffle .js .runtime .objects .Undefined ;
6870import com .oracle .truffle .js .runtime .util .SimpleArrayList ;
6971
7072@ ImportStatic ({Strings .class })
71- public abstract class ApplyDecoratorsToElementDefinition extends Node {
73+ public abstract class ApplyDecoratorsToElementDefinition extends JavaScriptBaseNode {
7274
7375 protected final JSContext context ;
7476 @ Child CreateDecoratorContextObjectNode createDecoratorContextNode ;
@@ -98,9 +100,10 @@ protected void decorateField(VirtualFrame frame, @SuppressWarnings("unused") JSD
98100 @ Shared @ Cached ("createCall()" ) JSFunctionCallNode callNode ,
99101 @ Shared @ Cached IsCallableNode isCallableNode ,
100102 @ Shared @ Cached InlinedBranchProfile errorBranch ) {
103+ JSRealm realm = getRealm ();
101104 for (Object decorator : record .getDecorators ()) {
102105 Object value = Undefined .instance ;
103- Object newValue = executeDecoratorWithContext (frame , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
106+ Object newValue = executeDecoratorWithContext (frame , realm , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
104107 if (isCallableNode .executeBoolean (newValue )) {
105108 record .addInitializer (newValue );
106109 } else {
@@ -116,9 +119,10 @@ protected void decorateMethod(VirtualFrame frame, @SuppressWarnings("unused") JS
116119 @ Shared @ Cached IsCallableNode isCallableNode ,
117120 @ Shared @ Cached InlinedBranchProfile errorBranch ,
118121 @ Shared @ Cached SetFunctionNameNode setFunctionName ) {
122+ JSRealm realm = getRealm ();
119123 for (Object decorator : record .getDecorators ()) {
120124 Object value = record .getValue ();
121- Object newValue = executeDecoratorWithContext (frame , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
125+ Object newValue = executeDecoratorWithContext (frame , realm , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
122126 if (isCallableNode .executeBoolean (newValue )) {
123127 setFunctionName .execute (newValue , record .getKey ());
124128 record .setValue (newValue );
@@ -137,10 +141,11 @@ protected void decorateGetterSetter(VirtualFrame frame, @SuppressWarnings("unuse
137141 @ Shared @ Cached IsCallableNode isCallableNode ,
138142 @ Shared @ Cached InlinedBranchProfile errorBranch ,
139143 @ Shared @ Cached SetFunctionNameNode setFunctionName ) {
144+ JSRealm realm = getRealm ();
140145 for (Object decorator : record .getDecorators ()) {
141146 boolean isGetter = record .isGetter ();
142147 Object value = isGetter ? record .getGetter () : record .getSetter ();
143- Object newValue = executeDecoratorWithContext (frame , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
148+ Object newValue = executeDecoratorWithContext (frame , realm , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
144149 if (isCallableNode .executeBoolean (newValue )) {
145150 setFunctionName .execute (newValue , record .getKey (), isGetter ? Strings .GET : Strings .SET );
146151 if (isGetter ) {
@@ -169,11 +174,12 @@ protected void decorateAuto(VirtualFrame frame, @SuppressWarnings("unused") JSDy
169174 @ Cached ("create(context, SET)" ) CreateDataPropertyNode createSetDataPropertyNode ,
170175 @ Cached IsObjectNode isObjectNode ,
171176 @ Shared @ Cached InlinedBranchProfile errorBranch ) {
177+ JSRealm realm = getRealm ();
172178 for (Object decorator : record .getDecorators ()) {
173- JSObject value = createObjectNode .execute (frame );
179+ JSObject value = createObjectNode .execute (realm );
174180 createGetDataPropertyNode .executeVoid (value , Strings .GET , record .getGetter ());
175181 createSetDataPropertyNode .executeVoid (value , Strings .SET , record .getSetter ());
176- Object newValue = executeDecoratorWithContext (frame , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
182+ Object newValue = executeDecoratorWithContext (frame , realm , record , value , extraInitializers , decorator , createDecoratorContextNode , callNode );
177183 if (isObjectNode .executeBoolean (newValue )) {
178184 Object newGetter = getGetterNode .getValue (newValue );
179185 if (isCallableNode .executeBoolean (newGetter )) {
@@ -200,10 +206,10 @@ protected void decorateAuto(VirtualFrame frame, @SuppressWarnings("unused") JSDy
200206 record .cleanDecorator ();
201207 }
202208
203- private static Object executeDecoratorWithContext (VirtualFrame frame , ClassElementDefinitionRecord record , Object value , SimpleArrayList <Object > extraInitializers , Object decorator ,
209+ private static Object executeDecoratorWithContext (VirtualFrame frame , JSRealm realm , ClassElementDefinitionRecord record , Object value , SimpleArrayList <Object > extraInitializers , Object decorator ,
204210 CreateDecoratorContextObjectNode createDecoratorContextNode , JSFunctionCallNode callNode ) {
205211 DecorationState state = new DecorationState ();
206- JSObject decoratorContext = createDecoratorContextNode .executeContext (frame , record , extraInitializers , state );
212+ JSObject decoratorContext = createDecoratorContextNode .executeContext (frame , realm , record , extraInitializers , state );
207213 Object newValue = callNode .executeCall (JSArguments .create (Undefined .instance , decorator , value , decoratorContext ));
208214 state .finished = true ;
209215 return newValue ;
0 commit comments