Skip to content

Commit dab5509

Browse files
committed
Return properties names as an interop array object.
1 parent b9b2be6 commit dab5509

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/main/java/org/truffleruby/cext/ValueWrapper.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected boolean hasMembers() {
131131

132132
@ExportMessage
133133
protected Object getMembers(boolean includeInternal) {
134-
return new String[]{ "value" };
134+
return new ValueWrapperPropertyList();
135135
}
136136

137137
@ExportMessage
@@ -150,29 +150,33 @@ protected static Object readMember(ValueWrapper wrapper, String member,
150150
}
151151
}
152152

153-
@ExportMessage
154-
protected static boolean hasArrayElements(ValueWrapper wrapper) {
155-
return true;
156-
}
153+
@ExportLibrary(InteropLibrary.class)
154+
public static class ValueWrapperPropertyList implements TruffleObject {
157155

158-
@ExportMessage
159-
protected static long getArraySize(ValueWrapper wrapper) {
160-
return 1;
161-
}
156+
@ExportMessage
157+
protected static boolean hasArrayElements(ValueWrapperPropertyList wrapper) {
158+
return true;
159+
}
162160

163-
@ExportMessage
164-
protected static Object readArrayElement(ValueWrapper wrapper, long index,
165-
@Cached @Exclusive BranchProfile errorProfile) throws InvalidArrayIndexException {
166-
if (index == 0L) {
167-
return wrapper.object;
168-
} else {
169-
errorProfile.enter();
170-
throw InvalidArrayIndexException.create(index);
161+
@ExportMessage
162+
protected static long getArraySize(ValueWrapperPropertyList wrapper) {
163+
return 1;
171164
}
172-
}
173165

174-
@ExportMessage
175-
protected static boolean isArrayElementReadable(ValueWrapper wrapper, long index) {
176-
return index == 0L;
166+
@ExportMessage
167+
protected static Object readArrayElement(ValueWrapperPropertyList list, long index,
168+
@Cached @Exclusive BranchProfile errorProfile) throws InvalidArrayIndexException {
169+
if (index == 0L) {
170+
return "value";
171+
} else {
172+
errorProfile.enter();
173+
throw InvalidArrayIndexException.create(index);
174+
}
175+
}
176+
177+
@ExportMessage
178+
protected static boolean isArrayElementReadable(ValueWrapperPropertyList wrapper, long index) {
179+
return index == 0L;
180+
}
177181
}
178182
}

0 commit comments

Comments
 (0)