Skip to content

Commit 052710d

Browse files
Fix issues after merge.
1 parent 2821014 commit 052710d

File tree

6 files changed

+126
-3
lines changed

6 files changed

+126
-3
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ public enum Constructor implements BuiltinEnum<Constructor> {
331331
JavaImporter(1),
332332

333333
// Record and Tuple proposal
334+
Record(0),
334335
Tuple(0);
335336

336337
private final int length;
@@ -630,6 +631,8 @@ protected Object createNode(JSContext context, JSBuiltin builtin, boolean constr
630631
? ConstructWebAssemblyTableNodeGen.create(context, builtin, true, args().newTarget().fixedArgs(1).createArgumentNodes(context))
631632
: ConstructWebAssemblyTableNodeGen.create(context, builtin, false, args().function().fixedArgs(1).createArgumentNodes(context)))
632633
: createCallRequiresNew(context, builtin);
634+
case Record:
635+
throw new RuntimeException("TODO"); // TODO
633636
case Tuple:
634637
return construct ? ConstructTupleNodeGen.create(context, builtin, args().createArgumentNodes(context))
635638
: CallTupleNodeGen.create(context, builtin, args().varArgs().createArgumentNodes(context));
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.truffle.js.builtins;
42+
43+
import com.oracle.truffle.js.nodes.function.JSBuiltin;
44+
import com.oracle.truffle.js.runtime.JSContext;
45+
import com.oracle.truffle.js.runtime.builtins.BuiltinEnum;
46+
import com.oracle.truffle.js.runtime.builtins.JSRecord;
47+
48+
/**
49+
* Contains builtins for Record function.
50+
*/
51+
public final class RecordFunctionBuiltins extends JSBuiltinsContainer.SwitchEnum<RecordFunctionBuiltins.RecordFunction> {
52+
53+
public static final JSBuiltinsContainer BUILTINS = new RecordFunctionBuiltins();
54+
55+
protected RecordFunctionBuiltins() {
56+
super(JSRecord.CLASS_NAME, RecordFunction.class);
57+
}
58+
59+
public enum RecordFunction implements BuiltinEnum<RecordFunction> {
60+
;
61+
62+
private final int length;
63+
64+
RecordFunction(int length) {
65+
this.length = length;
66+
}
67+
68+
@Override
69+
public int getLength() {
70+
return length;
71+
}
72+
}
73+
74+
@Override
75+
protected Object createNode(JSContext context, JSBuiltin builtin, boolean construct, boolean newTarget, RecordFunction builtinEnum) {
76+
switch (builtinEnum) {
77+
// TODO
78+
}
79+
return null;
80+
}
81+
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/ReadElementNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,11 @@ protected Object executeWithTargetAndIndexUnchecked(Object target, Object index,
15991599

16001600
@Override
16011601
protected Object executeWithTargetAndIndexUnchecked(Object target, int index, Object receiver, Object defaultValue, ReadElementNode root) {
1602+
return executeWithTargetAndIndexUnchecked(target, (long)index, receiver, defaultValue, root);
1603+
}
1604+
1605+
@Override
1606+
protected Object executeWithTargetAndIndexUnchecked(Object target, long index, Object receiver, Object defaultValue, ReadElementNode root) {
16021607
Tuple tuple = (Tuple) target;
16031608
return JSObject.getOrDefault(JSTuple.create(root.context, tuple), index, receiver, defaultValue, jsclassProfile, root);
16041609
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/control/DeletePropertyNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.oracle.truffle.api.interop.UnsupportedMessageException;
5858
import com.oracle.truffle.api.library.CachedLibrary;
5959
import com.oracle.truffle.api.nodes.NodeInfo;
60+
import com.oracle.truffle.api.object.DynamicObject;
6061
import com.oracle.truffle.api.object.DynamicObjectLibrary;
6162
import com.oracle.truffle.api.object.Property;
6263
import com.oracle.truffle.api.profiles.ConditionProfile;

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/JSRealm.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.SplittableRandom;
5656
import java.util.WeakHashMap;
5757

58+
import com.oracle.truffle.js.runtime.builtins.JSRecord;
5859
import org.graalvm.collections.Pair;
5960
import org.graalvm.home.HomeFinder;
6061
import org.graalvm.options.OptionValues;
@@ -379,6 +380,8 @@ public class JSRealm {
379380
private final DynamicObject foreignIterablePrototype;
380381

381382
/** Record and Tuple support. */
383+
private final DynamicObject recordConstructor;
384+
private final DynamicObject recordPrototype;
382385
private final DynamicObject tupleConstructor;
383386
private final DynamicObject tuplePrototype;
384387

@@ -763,10 +766,15 @@ public JSRealm(JSContext context, TruffleLanguage.Env env) {
763766
// TODO: Associate with the correct ECMAScript Version
764767
boolean es13 = context.getContextOptions().getEcmaScriptVersion() >= JSConfig.ECMAScript2022;
765768
if (es13) {
769+
ctor = JSRecord.createConstructor(this);
770+
this.recordConstructor = ctor.getFunctionObject();
771+
this.recordPrototype = ctor.getPrototype();
766772
ctor = JSTuple.createConstructor(this);
767773
this.tupleConstructor = ctor.getFunctionObject();
768774
this.tuplePrototype = ctor.getPrototype();
769775
} else {
776+
this.recordConstructor = null;
777+
this.recordPrototype = null;
770778
this.tupleConstructor = null;
771779
this.tuplePrototype= null;
772780
}
@@ -2468,6 +2476,14 @@ public DynamicObject getForeignIterablePrototype() {
24682476
return foreignIterablePrototype;
24692477
}
24702478

2479+
public DynamicObject getRecordConstructor() {
2480+
return recordConstructor;
2481+
}
2482+
2483+
public DynamicObject getRecordPrototype() {
2484+
return recordPrototype;
2485+
}
2486+
24712487
public DynamicObject getTupleConstructor() {
24722488
return tupleConstructor;
24732489
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/builtins/JSRecord.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@
4343
import com.oracle.truffle.api.nodes.Node;
4444
import com.oracle.truffle.api.object.DynamicObject;
4545
import com.oracle.truffle.api.object.Shape;
46+
import com.oracle.truffle.js.builtins.RecordFunctionBuiltins;
4647
import com.oracle.truffle.js.runtime.JSContext;
4748
import com.oracle.truffle.js.runtime.JSRealm;
4849
import com.oracle.truffle.js.runtime.JSRuntime;
4950
import com.oracle.truffle.js.runtime.Record;
5051
import com.oracle.truffle.js.runtime.Symbol;
52+
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
53+
import com.oracle.truffle.js.runtime.objects.JSObject;
5154
import com.oracle.truffle.js.runtime.objects.JSObjectUtil;
5255
import com.oracle.truffle.js.runtime.objects.JSShape;
5356
import com.oracle.truffle.js.runtime.objects.PropertyDescriptor;
@@ -112,8 +115,11 @@ public DynamicObject createPrototype(JSRealm realm, DynamicObject constructor) {
112115

113116
@Override
114117
public DynamicObject getIntrinsicDefaultProto(JSRealm realm) {
115-
// TODO: return realm.getRecordPrototype();
116-
return null;
118+
return realm.getRecordPrototype();
119+
}
120+
121+
public static JSConstructor createConstructor(JSRealm realm) {
122+
return INSTANCE.createConstructorAndPrototype(realm, RecordFunctionBuiltins.BUILTINS);
117123
}
118124

119125
/**
@@ -126,9 +132,20 @@ public DynamicObject getIntrinsicDefaultProto(JSRealm realm) {
126132
*/
127133
@Override
128134
public Shape makeInitialShape(JSContext context, DynamicObject prototype) {
129-
return JSShape.newBuilder(context, INSTANCE, prototype)
135+
Shape initialShape = Shape.newBuilder()
136+
.layout(JSShape.getLayout(INSTANCE))
137+
.dynamicType(INSTANCE)
138+
.addConstantProperty(JSObject.HIDDEN_PROTO, prototype, 0)
130139
.shapeFlags(JSShape.NOT_EXTENSIBLE_FLAG)
131140
.build();
141+
142+
assert !JSShape.isExtensible(initialShape);
143+
return initialShape;
144+
145+
// TODO: remove commented out code below
146+
// return JSShape.newBuilder(context, INSTANCE, prototype)
147+
// .shapeFlags(JSShape.NOT_EXTENSIBLE_FLAG)
148+
// .build();
132149
}
133150

134151
/**

0 commit comments

Comments
 (0)