Skip to content

Commit 1c4af1b

Browse files
committed
Refactoring: Remove VirtualFrame parameter from CreateObjectNode.
Move prototype expression node to ObjectLiteralNode instead.
1 parent 194fbc5 commit 1c4af1b

13 files changed

+171
-183
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/AtomicsBuiltins.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -117,7 +117,7 @@
117117
import com.oracle.truffle.js.runtime.builtins.JSArrayBufferView;
118118
import com.oracle.truffle.js.runtime.builtins.JSSharedArrayBuffer;
119119
import com.oracle.truffle.js.runtime.builtins.JSTypedArrayObject;
120-
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
120+
import com.oracle.truffle.js.runtime.objects.JSObject;
121121
import com.oracle.truffle.js.runtime.objects.PromiseCapabilityRecord;
122122
import com.oracle.truffle.js.runtime.objects.Undefined;
123123

@@ -1155,20 +1155,21 @@ protected Object doWait(VirtualFrame frame, Object maybeTarget, Object index, Ob
11551155
t = Math.max(q, 0);
11561156
}
11571157

1158-
JSAgent agent = getRealm().getAgent();
1158+
JSRealm realm = getRealm();
1159+
JSAgent agent = realm.getAgent();
11591160
if (!isAsync && !agent.canBlock()) {
11601161
errorBranch.enter();
11611162
throw createTypeErrorUnsupported();
11621163
}
11631164
JSAgentWaiterListEntry wl = SharedMemorySync.getWaiterList(getContext(), target, i);
11641165

11651166
PromiseCapabilityRecord promiseCapability = null;
1166-
JSDynamicObject resultObject = null;
1167+
JSObject resultObject = null;
11671168

11681169
if (isAsyncProfile.profile(isAsync)) {
11691170
getContext().signalAsyncWaiterRecordUsage();
11701171
promiseCapability = newPromiseCapability();
1171-
resultObject = ordinaryObjectCreate(frame);
1172+
resultObject = ordinaryObjectCreate(realm);
11721173
}
11731174

11741175
wl.enterCriticalSection();
@@ -1238,12 +1239,12 @@ private PromiseCapabilityRecord newPromiseCapability() {
12381239
return newPromiseCapabilityNode.executeDefault();
12391240
}
12401241

1241-
private JSDynamicObject ordinaryObjectCreate(VirtualFrame frame) {
1242+
private JSObject ordinaryObjectCreate(JSRealm realm) {
12421243
if (objectCreateNode == null) {
12431244
CompilerDirectives.transferToInterpreterAndInvalidate();
12441245
objectCreateNode = insert(CreateObjectNode.create(getContext()));
12451246
}
1246-
return objectCreateNode.execute(frame);
1247+
return objectCreateNode.execute(realm);
12471248
}
12481249
}
12491250

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/OperatorsBuiltins.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ public OperatorsNode(JSContext context, JSBuiltin builtin) {
149149
}
150150

151151
@Specialization
152-
protected JSFunctionObject doOperators(VirtualFrame frame, Object table, Object... extraTables) {
153-
JSDynamicObject prototype = createPrototypeNode.execute(frame);
152+
protected JSFunctionObject doOperators(Object table, Object[] extraTables) {
153+
JSRealm realm = getRealm();
154+
JSObject prototype = createPrototypeNode.execute(realm);
154155
OperatorSet operatorSet = constructOperatorSetNode.execute(table, extraTables);
155156
JSFunctionData constructorFunctionData = getContext().getOrCreateBuiltinFunctionData(
156157
JSContext.BuiltinFunctionKey.OperatorsConstructor, OperatorsNode::createConstructorImpl);
157-
JSFunctionObject constructor = JSFunction.create(getRealm(), constructorFunctionData);
158+
JSFunctionObject constructor = JSFunction.create(realm, constructorFunctionData);
158159
JSFunction.setClassPrototype(constructor, prototype);
159160
setConstructorNode.executeVoid(prototype, constructor);
160161
setOperatorDefinitionsNode.setValue(constructor, operatorSet);

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/PromiseFunctionBuiltins.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -44,7 +44,6 @@
4444
import com.oracle.truffle.api.dsl.Cached;
4545
import com.oracle.truffle.api.dsl.Specialization;
4646
import com.oracle.truffle.api.exception.AbstractTruffleException;
47-
import com.oracle.truffle.api.frame.VirtualFrame;
4847
import com.oracle.truffle.js.builtins.PromiseFunctionBuiltinsFactory.PromiseCombinatorNodeGen;
4948
import com.oracle.truffle.js.builtins.PromiseFunctionBuiltinsFactory.PromiseTryNodeGen;
5049
import com.oracle.truffle.js.builtins.PromiseFunctionBuiltinsFactory.RejectNodeGen;
@@ -71,6 +70,7 @@
7170
import com.oracle.truffle.js.runtime.JSArguments;
7271
import com.oracle.truffle.js.runtime.JSConfig;
7372
import com.oracle.truffle.js.runtime.JSContext;
73+
import com.oracle.truffle.js.runtime.JSRealm;
7474
import com.oracle.truffle.js.runtime.JSRuntime;
7575
import com.oracle.truffle.js.runtime.Strings;
7676
import com.oracle.truffle.js.runtime.builtins.BuiltinEnum;
@@ -286,9 +286,10 @@ protected WithResolversNode(JSContext context, JSBuiltin builtin) {
286286
}
287287

288288
@Specialization
289-
protected JSObject withResolvers(VirtualFrame frame, Object thiz) {
289+
protected JSObject withResolvers(Object thiz) {
290+
JSRealm realm = getRealm();
290291
PromiseCapabilityRecord promiseCapability = newPromiseCapabilityNode.execute(thiz);
291-
JSObject obj = createObjectNode.execute(frame);
292+
JSObject obj = createObjectNode.execute(realm);
292293
definePromisePropertyNode.executeVoid(obj, promiseCapability.getPromise());
293294
defineResolvePropertyNode.executeVoid(obj, promiseCapability.getResolve());
294295
defineRejectPropertyNode.executeVoid(obj, promiseCapability.getReject());

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/ProxyFunctionBuiltins.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -57,13 +57,16 @@
5757
import com.oracle.truffle.js.runtime.JSContext;
5858
import com.oracle.truffle.js.runtime.JSContext.BuiltinFunctionKey;
5959
import com.oracle.truffle.js.runtime.JSFrameUtil;
60+
import com.oracle.truffle.js.runtime.JSRealm;
6061
import com.oracle.truffle.js.runtime.JavaScriptRootNode;
6162
import com.oracle.truffle.js.runtime.Strings;
6263
import com.oracle.truffle.js.runtime.builtins.JSFunction;
6364
import com.oracle.truffle.js.runtime.builtins.JSFunctionData;
65+
import com.oracle.truffle.js.runtime.builtins.JSFunctionObject;
6466
import com.oracle.truffle.js.runtime.builtins.JSProxy;
6567
import com.oracle.truffle.js.runtime.builtins.JSProxyObject;
6668
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
69+
import com.oracle.truffle.js.runtime.objects.JSObject;
6770
import com.oracle.truffle.js.runtime.objects.Null;
6871
import com.oracle.truffle.js.runtime.objects.Undefined;
6972

@@ -96,14 +99,15 @@ public RevocableNode(JSContext context, JSBuiltin builtin) {
9699
}
97100

98101
@Specialization
99-
protected Object doDefault(VirtualFrame frame, Object target, Object handler) {
102+
protected Object doDefault(Object target, Object handler) {
100103
JSDynamicObject proxy = proxyCreateNode.execute(Undefined.instance, target, handler);
101104

102105
JSFunctionData revokerFunctionData = getContext().getOrCreateBuiltinFunctionData(BuiltinFunctionKey.ProxyRevokerFunction, c -> createProxyRevokerFunctionImpl(c));
103-
JSDynamicObject revoker = JSFunction.create(getRealm(), revokerFunctionData);
106+
JSRealm realm = getRealm();
107+
JSFunctionObject revoker = JSFunction.create(realm, revokerFunctionData);
104108
setRevocableProxySlotNode.setValue(revoker, proxy);
105109

106-
JSDynamicObject result = createObjectNode.execute(frame);
110+
JSObject result = createObjectNode.execute(realm);
107111
createProxyPropertyNode.executeVoid(result, proxy);
108112
createRevokePropertyNode.executeVoid(result, revoker);
109113
return result;
@@ -118,7 +122,7 @@ private static JSFunctionData createProxyRevokerFunctionImpl(JSContext context)
118122

119123
@Override
120124
public Object execute(VirtualFrame frame) {
121-
JSDynamicObject functionObject = JSFrameUtil.getFunctionObject(frame);
125+
JSFunctionObject functionObject = JSFrameUtil.getFunctionObject(frame);
122126
Object revocableProxy = getRevocableProxyNode.getValue(functionObject);
123127
if (revocableProxy == Null.instance) {
124128
return Undefined.instance;

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/decorators/ApplyDecoratorsToClassDefinitionNode.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, 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
@@ -40,21 +40,21 @@
4040
*/
4141
package com.oracle.truffle.js.decorators;
4242

43-
import com.oracle.truffle.api.frame.VirtualFrame;
4443
import com.oracle.truffle.api.nodes.ExplodeLoop;
45-
import com.oracle.truffle.api.nodes.Node;
4644
import com.oracle.truffle.api.profiles.BranchProfile;
4745
import com.oracle.truffle.js.decorators.CreateDecoratorContextObjectNode.DecorationState;
46+
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
4847
import com.oracle.truffle.js.nodes.function.JSFunctionCallNode;
4948
import com.oracle.truffle.js.nodes.unary.IsCallableNode;
5049
import com.oracle.truffle.js.runtime.Errors;
5150
import com.oracle.truffle.js.runtime.JSArguments;
5251
import com.oracle.truffle.js.runtime.JSContext;
52+
import com.oracle.truffle.js.runtime.JSRealm;
5353
import com.oracle.truffle.js.runtime.objects.JSObject;
5454
import com.oracle.truffle.js.runtime.objects.Undefined;
5555
import com.oracle.truffle.js.runtime.util.SimpleArrayList;
5656

57-
public class ApplyDecoratorsToClassDefinitionNode extends Node {
57+
public class ApplyDecoratorsToClassDefinitionNode extends JavaScriptBaseNode {
5858

5959
@Child private JSFunctionCallNode callNode;
6060
@Child private IsCallableNode isCallableNode;
@@ -73,11 +73,12 @@ public static ApplyDecoratorsToClassDefinitionNode create(JSContext context) {
7373
}
7474

7575
@ExplodeLoop
76-
public Object executeDecorators(VirtualFrame frame, Object className, JSObject constructor, Object[] decorators, SimpleArrayList<Object> extraInitializers) {
76+
public Object executeDecorators(Object className, JSObject constructor, Object[] decorators, SimpleArrayList<Object> extraInitializers) {
7777
Object classDef = constructor;
78+
JSRealm realm = getRealm();
7879
for (Object decorator : decorators) {
7980
DecorationState state = new DecorationState();
80-
JSObject contextObj = createDecoratorContextObject.evaluateClass(frame, className, extraInitializers, state);
81+
JSObject contextObj = createDecoratorContextObject.evaluateClass(realm, className, extraInitializers, state);
8182
Object newDef = callNode.executeCall(JSArguments.create(Undefined.instance, decorator, classDef, contextObj));
8283
state.finished = true;
8384
if (isCallableNode.executeBoolean(newDef)) {

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/decorators/ApplyDecoratorsToElementDefinition.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -49,6 +49,7 @@
4949
import com.oracle.truffle.api.nodes.Node;
5050
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
5151
import com.oracle.truffle.js.decorators.CreateDecoratorContextObjectNode.DecorationState;
52+
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
5253
import com.oracle.truffle.js.nodes.access.CreateDataPropertyNode;
5354
import com.oracle.truffle.js.nodes.access.CreateObjectNode;
5455
import com.oracle.truffle.js.nodes.access.IsObjectNode;
@@ -61,14 +62,15 @@
6162
import com.oracle.truffle.js.runtime.Errors;
6263
import com.oracle.truffle.js.runtime.JSArguments;
6364
import com.oracle.truffle.js.runtime.JSContext;
65+
import com.oracle.truffle.js.runtime.JSRealm;
6466
import com.oracle.truffle.js.runtime.Strings;
6567
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
6668
import com.oracle.truffle.js.runtime.objects.JSObject;
6769
import com.oracle.truffle.js.runtime.objects.Undefined;
6870
import 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

Comments
 (0)