Skip to content

Commit d2115b8

Browse files
committed
Added missing handling of NumberFormatExceptions in DebugPrimitiveValue.
Corrected documentation. DebugArrayDisplayValue and DebugObjectDisplayValue now share ExportMessage implementation.
1 parent 97647c6 commit d2115b8

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/debugging/parser/DebugData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ public int asI32OrDefault(int attribute) {
131131
* Converts the underlying attribute value to an integer. Interprets byte and short encodings as
132132
* unsigned integer values.
133133
*
134-
* @return the integer value or {@link DebugUtil#DEFAULT_I32}, if the attribute does not exist
135-
* or the value does not fit into an integer.
134+
* @return the integer value or the given default value, if the attribute does not exist or the
135+
* value does not fit into an integer.
136136
*/
137137
public int asU32OrDefault(int attribute, int defaultValue) {
138138
final int index = attributeIndex(attribute);

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/debugging/representation/DebugArrayDisplayValue.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public long getArraySize() {
108108
}
109109

110110
@ExportMessage
111+
@ExportMessage(name = "isArrayElementModifiable")
111112
@TruffleBoundary
112113
public boolean isArrayElementReadable(long index) {
113114
// TODO Limit the number of displayed values to 255 until GR-62691 is implemented
@@ -129,12 +130,6 @@ public Object readArrayElement(long index) throws InvalidArrayIndexException {
129130
return resolveDebugObject(object, context, location);
130131
}
131132

132-
@ExportMessage
133-
@TruffleBoundary
134-
public boolean isArrayElementModifiable(long index) {
135-
return isArrayElementReadable(index);
136-
}
137-
138133
@ExportMessage
139134
@TruffleBoundary
140135
public boolean isArrayElementInsertable(@SuppressWarnings("unused") long index) {
@@ -144,7 +139,7 @@ public boolean isArrayElementInsertable(@SuppressWarnings("unused") long index)
144139
@ExportMessage(limit = "5")
145140
@TruffleBoundary
146141
public void writeArrayElement(long index, Object value, @CachedLibrary("value") InteropLibrary lib) throws InvalidArrayIndexException {
147-
if (!isArrayElementModifiable(index)) {
142+
if (!isArrayElementReadable(index)) {
148143
throw InvalidArrayIndexException.create(index);
149144
}
150145
final int offset = indexOffset + (int) index;

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/debugging/representation/DebugObjectDisplayValue.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,16 @@ Object getMembers(@SuppressWarnings("unused") boolean includeInternal) {
139139
}
140140

141141
@ExportMessage
142+
@ExportMessage(name = "isMemberModifiable")
142143
@TruffleBoundary
143144
boolean isMemberReadable(String member) {
144145
return members.containsKey(member);
145146
}
146147

147-
@ExportMessage
148-
@TruffleBoundary
149-
boolean isMemberModifiable(String member) {
150-
return members.containsKey(member);
151-
}
152-
153148
@ExportMessage(limit = "5")
154149
@TruffleBoundary
155150
void writeMember(String member, Object value, @CachedLibrary("value") InteropLibrary lib) throws UnknownIdentifierException {
156-
if (!isMemberModifiable(member)) {
151+
if (!isMemberReadable(member)) {
157152
throw UnknownIdentifierException.create(member);
158153
}
159154
final DebugObject memberObject = members.get(member);

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/debugging/representation/DebugPrimitiveValue.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4747
import com.oracle.truffle.api.interop.InteropLibrary;
4848
import com.oracle.truffle.api.interop.TruffleObject;
49+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
4950
import com.oracle.truffle.api.library.ExportLibrary;
5051
import com.oracle.truffle.api.library.ExportMessage;
5152

@@ -97,7 +98,11 @@ public boolean fitsInByte() {
9798
@TruffleBoundary
9899
@ExportMessage
99100
public byte asByte() {
100-
return Byte.parseByte(expression);
101+
try {
102+
return Byte.parseByte(expression);
103+
} catch (NumberFormatException e) {
104+
return 0;
105+
}
101106
}
102107

103108
@TruffleBoundary
@@ -114,7 +119,11 @@ public boolean fitsInShort() {
114119
@TruffleBoundary
115120
@ExportMessage
116121
public short asShort() {
117-
return Short.parseShort(expression);
122+
try {
123+
return Short.parseShort(expression);
124+
} catch (NumberFormatException e) {
125+
return 0;
126+
}
118127
}
119128

120129
@TruffleBoundary
@@ -131,7 +140,11 @@ public boolean fitsInInt() {
131140
@TruffleBoundary
132141
@ExportMessage
133142
public int asInt() {
134-
return Integer.parseInt(expression);
143+
try {
144+
return Integer.parseInt(expression);
145+
} catch (NumberFormatException e) {
146+
return 0;
147+
}
135148
}
136149

137150
@TruffleBoundary
@@ -148,7 +161,11 @@ public boolean fitsInLong() {
148161
@TruffleBoundary
149162
@ExportMessage
150163
public long asLong() {
151-
return Long.parseLong(expression);
164+
try {
165+
return Long.parseLong(expression);
166+
} catch (NumberFormatException e) {
167+
return 0L;
168+
}
152169
}
153170

154171
@TruffleBoundary
@@ -165,7 +182,11 @@ public boolean fitsInFloat() {
165182
@TruffleBoundary
166183
@ExportMessage
167184
public float asFloat() {
168-
return Float.parseFloat(expression);
185+
try {
186+
return Float.parseFloat(expression);
187+
} catch (NumberFormatException e) {
188+
return 0f;
189+
}
169190
}
170191

171192
@TruffleBoundary
@@ -182,7 +203,11 @@ public boolean fitsInDouble() {
182203
@TruffleBoundary
183204
@ExportMessage
184205
public double asDouble() {
185-
return Double.parseDouble(expression);
206+
try {
207+
return Double.parseDouble(expression);
208+
} catch (NumberFormatException e) {
209+
return 0d;
210+
}
186211
}
187212

188213
@TruffleBoundary
@@ -193,8 +218,8 @@ public boolean fitsInBigInteger() {
193218

194219
@TruffleBoundary
195220
@ExportMessage
196-
public BigInteger asBigInteger() {
197-
throw new UnsupportedOperationException();
221+
public BigInteger asBigInteger() throws UnsupportedMessageException {
222+
throw UnsupportedMessageException.create();
198223
}
199224

200225
@TruffleBoundary

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/nodes/WasmFunctionBaseNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
/**
4949
* Intermediate node to support instrumentation. Due to caching, instrumented nodes cannot replace
50-
* themselves at {@link WasmFixedMemoryImplFunctionNode}. Therefore, this intermediate not is
50+
* themselves at {@link WasmFixedMemoryImplFunctionNode}. Therefore, this intermediate node is
5151
* needed.
5252
*/
5353
public final class WasmFunctionBaseNode extends Node {

0 commit comments

Comments
 (0)