summaryrefslogtreecommitdiffstats
path: root/platform/web/js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/web/js')
-rw-r--r--platform/web/js/libs/library_godot_javascript_singleton.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/platform/web/js/libs/library_godot_javascript_singleton.js b/platform/web/js/libs/library_godot_javascript_singleton.js
index 6bb69bca95..3ff6abba60 100644
--- a/platform/web/js/libs/library_godot_javascript_singleton.js
+++ b/platform/web/js/libs/library_godot_javascript_singleton.js
@@ -127,6 +127,10 @@ const GodotJSWrapper = {
GodotRuntime.setHeapValue(p_exchange, id, 'i64');
return 24; // OBJECT
},
+
+ isBuffer: function (obj) {
+ return obj instanceof ArrayBuffer || ArrayBuffer.isView(obj);
+ },
},
godot_js_wrapper_interface_get__proxy: 'sync',
@@ -303,6 +307,34 @@ const GodotJSWrapper = {
return -1;
}
},
+
+ godot_js_wrapper_object_is_buffer__proxy: 'sync',
+ godot_js_wrapper_object_is_buffer__sig: 'ii',
+ godot_js_wrapper_object_is_buffer: function (p_id) {
+ const obj = GodotJSWrapper.get_proxied_value(p_id);
+ return GodotJSWrapper.isBuffer(obj)
+ ? 1
+ : 0;
+ },
+
+ godot_js_wrapper_object_transfer_buffer__proxy: 'sync',
+ godot_js_wrapper_object_transfer_buffer__sig: 'viiii',
+ godot_js_wrapper_object_transfer_buffer: function (p_id, p_byte_arr, p_byte_arr_write, p_callback) {
+ let obj = GodotJSWrapper.get_proxied_value(p_id);
+ if (!GodotJSWrapper.isBuffer(obj)) {
+ return;
+ }
+
+ if (ArrayBuffer.isView(obj) && !(obj instanceof Uint8Array)) {
+ obj = new Uint8Array(obj.buffer);
+ } else if (obj instanceof ArrayBuffer) {
+ obj = new Uint8Array(obj);
+ }
+
+ const resizePackedByteArrayAndOpenWrite = GodotRuntime.get_func(p_callback);
+ const bytesPtr = resizePackedByteArrayAndOpenWrite(p_byte_arr, p_byte_arr_write, obj.length);
+ HEAPU8.set(obj, bytesPtr);
+ },
};
autoAddDeps(GodotJSWrapper, '$GodotJSWrapper');