Skip to content

Instantly share code, notes, and snippets.

@lewing
Created November 13, 2020 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewing/0cc29d338d8cc1f2239f31bb1f36360b to your computer and use it in GitHub Desktop.
Save lewing/0cc29d338d8cc1f2239f31bb1f36360b to your computer and use it in GitHub Desktop.
diff --git a/src/mono/wasm/runtime/binding_support.js b/src/mono/wasm/runtime/binding_support.js
index 7c088060e23..6f9133cadc8 100644
--- a/src/mono/wasm/runtime/binding_support.js
+++ b/src/mono/wasm/runtime/binding_support.js
@@ -280,11 +280,11 @@ var BindingSupportLib = {
return interned_instance;
var result = MONO.string_decoder.copy (mono_obj);
- if (interned) {
+ if (result.interned || interned) {
// This string is interned on the managed side but we didn't have it in our cache.
- this._store_string_in_intern_table (result, mono_obj, false);
+ this._store_string_in_intern_table (result.value, mono_obj, false);
}
- return result;
+ return result.value;
},
is_nested_array: function (ele) {
diff --git a/src/mono/wasm/runtime/dotnet_support.js b/src/mono/wasm/runtime/dotnet_support.js
index c780db55dbe..794900640a1 100644
--- a/src/mono/wasm/runtime/dotnet_support.js
+++ b/src/mono/wasm/runtime/dotnet_support.js
@@ -4,7 +4,7 @@
var DotNetSupportLib = {
$DOTNET: {
conv_string: function (mono_obj) {
- return MONO.string_decoder.copy (mono_obj);
+ return MONO.string_decoder.copy (mono_obj).value;
}
},
mono_wasm_invoke_js_blazor: function(exceptionMessage, callInfo, arg0, arg1, arg2) {
diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c
index d1680e62235..5ff922dfaaa 100644
--- a/src/mono/wasm/runtime/driver.c
+++ b/src/mono/wasm/runtime/driver.c
@@ -694,11 +694,11 @@ mono_wasm_string_get_utf8 (MonoString *str)
return mono_string_to_utf8 (str); //XXX JS is responsible for freeing this
}
-EMSCRIPTEN_KEEPALIVE void
+EMSCRIPTEN_KEEPALIVE int
mono_wasm_string_convert (MonoString *str)
{
if (str == NULL)
- return;
+ return 0;
mono_unichar2 *native_val = mono_string_chars (str);
int native_len = mono_string_length (str) * 2;
@@ -706,6 +706,8 @@ mono_wasm_string_convert (MonoString *str)
EM_ASM ({
MONO.string_decoder.decode($0, $0 + $1, true);
}, (int)native_val, native_len);
+
+ return mono_string_is_interned (str);
}
EMSCRIPTEN_KEEPALIVE MonoString *
diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js
index fc212721460..a2a4df03c22 100644
--- a/src/mono/wasm/runtime/library_mono.js
+++ b/src/mono/wasm/runtime/library_mono.js
@@ -488,15 +488,16 @@ var MonoSupportLib = {
string_decoder: {
copy: function (mono_string) {
if (mono_string == 0)
- return null;
+ return { value: null, interned: false };
if (!this.mono_wasm_string_convert)
- this.mono_wasm_string_convert = Module.cwrap ("mono_wasm_string_convert", null, ['number']);
+ this.mono_wasm_string_convert = Module.cwrap ("mono_wasm_string_convert", 'number', ['number']);
+
+ var interned = this.mono_wasm_string_convert (mono_string);
- this.mono_wasm_string_convert (mono_string);
var result = this.result;
this.result = undefined;
- return result;
+ return { value: result, interned: interned };
},
decode: function (start, end, save) {
if (!MONO.mono_text_decoder) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment