-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Fix JS<->WASM string marshaling crash #42486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ var BindingSupportLib = { | |
| this.find_method = Module.cwrap ('mono_wasm_assembly_find_method', 'number', ['number', 'string', 'number']); | ||
| this.invoke_method = Module.cwrap ('mono_wasm_invoke_method', 'number', ['number', 'number', 'number', 'number']); | ||
| this.mono_string_get_utf8 = Module.cwrap ('mono_wasm_string_get_utf8', 'number', ['number']); | ||
| this.js_string_to_mono_string = Module.cwrap ('mono_wasm_string_from_js', 'number', ['string']); | ||
| this.mono_wasm_string_from_utf16 = Module.cwrap ('mono_wasm_string_from_utf16', 'number', ['number', 'number']); | ||
| this.mono_get_obj_type = Module.cwrap ('mono_wasm_get_obj_type', 'number', ['number']); | ||
| this.mono_unbox_int = Module.cwrap ('mono_unbox_int', 'number', ['number']); | ||
| this.mono_unbox_float = Module.cwrap ('mono_wasm_unbox_float', 'number', ['number']); | ||
|
|
@@ -141,6 +141,17 @@ var BindingSupportLib = { | |
| return this.call_method (this.is_simple_array, null, "mi", [ ele ]); | ||
| }, | ||
|
|
||
| js_string_to_mono_string: function (string) { | ||
| var buffer = Module._malloc ((string.length + 1) * 2); | ||
| var buffer16 = (buffer / 2) | 0; | ||
| for (var i = 0; i < string.length; i++) | ||
| Module.HEAP16[buffer16 + i] = string.charCodeAt (i); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Is this file intended to follow Mono conventions? If so, space before the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, though I don't know if we follow that convention for the JS. I can make it match.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll correct this in the larger bindings optimization PR, didn't want to let a formatting change delay the merge on this one
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string[i] in JS returns a single-character string |
||
| Module.HEAP16[buffer16 + string.length] = 0; | ||
| var result = this.mono_wasm_string_from_utf16 (buffer, string.length); | ||
| Module._free (buffer); | ||
| return result; | ||
| }, | ||
|
|
||
| mono_array_to_js_array: function (mono_array) { | ||
| if (mono_array === 0) | ||
| return null; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.