Skip to content

Commit

Permalink
Add bigint support on JS value conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
adamscott committed Jul 3, 2024
1 parent 25de53e commit ee27590
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions platform/web/js/libs/library_godot_javascript_singleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ const GodotJSWrapper = {
case 0:
return null;
case 1:
return !!GodotRuntime.getHeapValue(val, 'i64');
case 2:
return GodotRuntime.getHeapValue(val, 'i64');
return Boolean(GodotRuntime.getHeapValue(val, 'i64'));
case 2: {
// `heap_value` may be a bigint.
const heap_value = GodotRuntime.getHeapValue(val, 'i64');
return heap_value >= Number.MIN_SAFE_INTEGER && heap_value <= Number.MAX_SAFE_INTEGER
? Number(heap_value)
: heap_value;
}
case 3:
return GodotRuntime.getHeapValue(val, 'double');
return Number(GodotRuntime.getHeapValue(val, 'double'));
case 4:
return GodotRuntime.parseString(GodotRuntime.getHeapValue(val, '*'));
case 24: // OBJECT
Expand All @@ -110,6 +115,9 @@ const GodotJSWrapper = {
}
GodotRuntime.setHeapValue(p_exchange, p_val, 'double');
return 3; // FLOAT
} else if (type === 'bigint') {
GodotRuntime.setHeapValue(p_exchange, p_val, 'i64');
return 2; // INT
} else if (type === 'string') {
const c_str = GodotRuntime.allocString(p_val);
GodotRuntime.setHeapValue(p_exchange, c_str, '*');
Expand Down

0 comments on commit ee27590

Please sign in to comment.