Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/mono/wasm/runtime/binding_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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;
Comment thread
CoffeeFlux marked this conversation as resolved.
for (var i = 0; i < string.length; i++)
Module.HEAP16[buffer16 + i] = string.charCodeAt (i);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 [ here and the next line.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't string[i] access generally faster than charCodeAt ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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;
Expand Down
11 changes: 11 additions & 0 deletions src/mono/wasm/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,17 @@ mono_wasm_string_from_js (const char *str)
return NULL;
}

EMSCRIPTEN_KEEPALIVE MonoString *
mono_wasm_string_from_utf16 (const mono_unichar2 * chars, int length)
{
assert (length >= 0);
Comment thread
CoffeeFlux marked this conversation as resolved.

if (chars)
return mono_string_new_utf16 (root_domain, chars, length);
else
return NULL;
}

static int
class_is_task (MonoClass *klass)
{
Expand Down