Skip to content
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

[wasm] rationalize internal exports #60075

Merged
merged 6 commits into from
Oct 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<PlatformManifestFileEntry Include="icudt_optimal.dat" IsNative="true" />
<PlatformManifestFileEntry Include="icudt_optimal_no_CJK.dat" IsNative="true" />
<PlatformManifestFileEntry Include="runtime.iffe.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.d.ts" IsNative="true" />
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
<PlatformManifestFileEntry Include="library-dotnet.js" IsNative="true" />
<PlatformManifestFileEntry Include="pal_random.js" IsNative="true" />
<PlatformManifestFileEntry Include="corebindings.c" IsNative="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static void StopProfile()
{
}

// Called by the AOT profiler to save profile data into Module.aot_profile_data
// Called by the AOT profiler to save profile data into INTERNAL.aot_profile_data
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static unsafe void DumpAotProfileData(ref byte buf, int len, string extraArg)
{
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/Native/Unix/System.Native/pal_random.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

var DotNetEntropyLib = {
const DotNetEntropyLib = {
$DOTNETENTROPY: {
// batchedQuotaMax is the max number of bytes as specified by the api spec.
// If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
Expand All @@ -10,13 +10,13 @@ var DotNetEntropyLib = {
getBatchedRandomValues: function (buffer, bufferLength) {
// for modern web browsers
// map the work array to the memory buffer passed with the length
for (var i = 0; i < bufferLength; i += this.batchedQuotaMax) {
var view = new Uint8Array(Module.HEAPU8.buffer, buffer + i, Math.min(bufferLength - i, this.batchedQuotaMax));
for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) {
const view = new Uint8Array(Module.HEAPU8.buffer, buffer + i, Math.min(bufferLength - i, this.batchedQuotaMax));
crypto.getRandomValues(view)
}
}
},
dotnet_browser_entropy : function (buffer, bufferLength) {
dotnet_browser_entropy: function (buffer, bufferLength) {
// check that we have crypto available
if (typeof crypto === 'object' && typeof crypto['getRandomValues'] === 'function') {
DOTNETENTROPY.getBatchedRandomValues(buffer, bufferLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public static void BindStaticMethod()
{
HelperMarshal._intValue = 0;
Runtime.InvokeJS(@$"
var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
invoke_int (200);
");

Expand All @@ -295,7 +295,7 @@ public static void BindIntPtrStaticMethod()
{
HelperMarshal._intPtrValue = IntPtr.Zero;
Runtime.InvokeJS(@$"
var invoke_int_ptr = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeIntPtr"");
var invoke_int_ptr = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeIntPtr"");
invoke_int_ptr (42);
");
Assert.Equal(42, (int)HelperMarshal._intPtrValue);
Expand All @@ -306,7 +306,7 @@ public static void MarshalIntPtrToJS()
{
HelperMarshal._marshaledIntPtrValue = IntPtr.Zero;
Runtime.InvokeJS(@$"
var invokeMarshalIntPtr = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeMarshalIntPtr"");
var invokeMarshalIntPtr = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeMarshalIntPtr"");
var r = invokeMarshalIntPtr ();

if (r != 42) throw `Invalid int_ptr value`;
Expand All @@ -319,7 +319,7 @@ public static void InvokeStaticMethod()
{
HelperMarshal._intValue = 0;
Runtime.InvokeJS(@$"
Module.mono_call_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"", [ 300 ]);
INTERNAL.call_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"", [ 300 ]);
");

Assert.Equal(300, HelperMarshal._intValue);
Expand All @@ -330,7 +330,7 @@ public static void ResolveMethod()
{
HelperMarshal._intValue = 0;
Runtime.InvokeJS(@$"
var invoke_int = Module.mono_method_resolve (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_method_resolve (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
App.call_test_method (""InvokeInt"", [ invoke_int ]);
");

Expand Down Expand Up @@ -629,7 +629,7 @@ public static void BoundStaticMethodMissingArgs()

HelperMarshal._intValue = 1;
Runtime.InvokeJS(@$"
var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
invoke_int ();
");
Assert.Equal(0, HelperMarshal._intValue);
Expand All @@ -640,7 +640,7 @@ public static void BoundStaticMethodExtraArgs()
{
HelperMarshal._intValue = 0;
Runtime.InvokeJS(@$"
var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
invoke_int (200, 400);
");
Assert.Equal(200, HelperMarshal._intValue);
Expand All @@ -654,13 +654,13 @@ public static void BoundStaticMethodArgumentTypeCoercion()

HelperMarshal._intValue = 0;
Runtime.InvokeJS(@$"
var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
invoke_int (""200"");
");
Assert.Equal(200, HelperMarshal._intValue);

Runtime.InvokeJS(@$"
var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
invoke_int (400.5);
");
Assert.Equal(400, HelperMarshal._intValue);
Expand All @@ -671,14 +671,14 @@ public static void BoundStaticMethodUnpleasantArgumentTypeCoercion()
{
HelperMarshal._intValue = 100;
Runtime.InvokeJS(@$"
var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
invoke_int (""hello"");
");
Assert.Equal(0, HelperMarshal._intValue);

// In this case at the very least, the leading "7" is not turned into the number 7
Runtime.InvokeJS(@$"
var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"");
invoke_int (""7apples"");
");
Assert.Equal(0, HelperMarshal._intValue);
Expand All @@ -689,7 +689,7 @@ public static void PassUintArgument()
{
HelperMarshal._uintValue = 0;
Runtime.InvokeJS(@$"
var invoke_uint = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt"");
var invoke_uint = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt"");
invoke_uint (0xFFFFFFFE);
");

Expand All @@ -702,9 +702,9 @@ public static void ReturnUintEnum ()
HelperMarshal._uintValue = 0;
HelperMarshal._enumValue = TestEnum.BigValue;
Runtime.InvokeJS(@$"
var get_value = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetEnumValue"");
var get_value = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetEnumValue"");
var e = get_value ();
var invoke_uint = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt"");
var invoke_uint = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt"");
invoke_uint (e);
");
Assert.Equal((uint)TestEnum.BigValue, HelperMarshal._uintValue);
Expand All @@ -715,7 +715,7 @@ public static void PassUintEnumByValue ()
{
HelperMarshal._enumValue = TestEnum.Zero;
Runtime.InvokeJS(@$"
var set_enum = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j"");
var set_enum = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j"");
set_enum (0xFFFFFFFE);
");
Assert.Equal(TestEnum.BigValue, HelperMarshal._enumValue);
Expand All @@ -728,7 +728,7 @@ public static void PassUintEnumByValueMasqueradingAsInt ()
// HACK: We're explicitly telling the bindings layer to pass an int here, not an enum
// Because we know the enum is : uint, this is compatible, so it works.
Runtime.InvokeJS(@$"
var set_enum = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""i"");
var set_enum = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""i"");
set_enum (0xFFFFFFFE);
");
Assert.Equal(TestEnum.BigValue, HelperMarshal._enumValue);
Expand All @@ -740,7 +740,7 @@ public static void PassUintEnumByNameIsNotImplemented ()
HelperMarshal._enumValue = TestEnum.Zero;
var exc = Assert.Throws<JSException>( () =>
Runtime.InvokeJS(@$"
var set_enum = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j"");
var set_enum = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j"");
set_enum (""BigValue"");
")
);
Expand All @@ -752,7 +752,7 @@ public static void CannotUnboxUint64 ()
{
var exc = Assert.Throws<JSException>( () =>
Runtime.InvokeJS(@$"
var get_u64 = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetUInt64"", """");
var get_u64 = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetUInt64"", """");
var u64 = get_u64();
")
);
Expand Down Expand Up @@ -806,7 +806,7 @@ public static void ManuallyInternString()
{
HelperMarshal._stringResource = HelperMarshal._stringResource2 = null;
Runtime.InvokeJS(@"
var sym = BINDING.mono_intern_string(""interned string 3"");
var sym = INTERNAL.mono_intern_string(""interned string 3"");
App.call_test_method (""InvokeString"", [ sym ], ""s"");
App.call_test_method (""InvokeString2"", [ sym ], ""s"");
");
Expand All @@ -823,7 +823,7 @@ public static void LargeStringsAreNotAutomaticallyLocatedInInternTable()
var s = ""long interned string"";
for (var i = 0; i < 1024; i++)
s += String(i % 10);
var sym = BINDING.mono_intern_string(s);
var sym = INTERNAL.mono_intern_string(s);
App.call_test_method (""InvokeString"", [ sym ], ""S"");
App.call_test_method (""InvokeString2"", [ sym ], ""s"");
");
Expand All @@ -837,7 +837,7 @@ public static void CanInternVeryManyStrings()
HelperMarshal._stringResource = null;
Runtime.InvokeJS(@"
for (var i = 0; i < 10240; i++)
BINDING.mono_intern_string('s' + i);
INTERNAL.mono_intern_string('s' + i);
App.call_test_method (""InvokeString"", [ 's5000' ], ""S"");
");
Assert.Equal("s5000", HelperMarshal._stringResource);
Expand All @@ -864,8 +864,8 @@ public static void InternedStringReturnValuesWork()
HelperMarshal._stringResource = HelperMarshal._stringResource2 = null;
var fqn = "[System.Private.Runtime.InteropServices.JavaScript.Tests]System.Runtime.InteropServices.JavaScript.Tests.HelperMarshal:StoreArgumentAndReturnLiteral";
Runtime.InvokeJS(
$"var a = BINDING.bind_static_method('{fqn}')('test');\r\n" +
$"var b = BINDING.bind_static_method('{fqn}')(a);\r\n" +
$"var a = INTERNAL.mono_bind_static_method('{fqn}')('test');\r\n" +
$"var b = INTERNAL.mono_bind_static_method('{fqn}')(a);\r\n" +
"App.call_test_method ('InvokeString2', [ b ]);"
);
Assert.Equal("s: 1 length: 1", HelperMarshal._stringResource);
Expand Down
10 changes: 5 additions & 5 deletions src/mono/mono/component/mini-wasm-debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void wasm_debugger_log (int level, const gchar *format, ...)
var message = Module.UTF8ToString ($1);
var namespace = "Debugger.Debug";

if (MONO["logging"] && MONO.logging["debugger"]) {
MONO.logging.debugger (level, message);
if (INTERNAL["logging"] && INTERNAL.logging["debugger"]) {
INTERNAL.logging.debugger (level, message);
return;
}

Expand Down Expand Up @@ -375,7 +375,7 @@ mono_wasm_send_dbg_command_with_parms (int id, MdbgProtCommandSet command_set, i
m_dbgprot_buffer_add_data (&bufWithParms, data, size);
if (!write_value_to_buffer(&bufWithParms, valtype, newvalue)) {
EM_ASM ({
MONO.mono_wasm_add_dbg_command_received ($0, $1, $2, $3);
INTERNAL.mono_wasm_add_dbg_command_received ($0, $1, $2, $3);
}, 0, id, 0, 0);
return TRUE;
}
Expand Down Expand Up @@ -403,7 +403,7 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command,
else
error = mono_process_dbg_packet (id, command_set, command, &no_reply, data, data + size, &buf);
EM_ASM ({
MONO.mono_wasm_add_dbg_command_received ($0, $1, $2, $3);
INTERNAL.mono_wasm_add_dbg_command_received ($0, $1, $2, $3);
}, error == MDBGPROT_ERR_NONE, id, buf.buf, buf.p-buf.buf);

buffer_free (&buf);
Expand All @@ -414,7 +414,7 @@ static gboolean
receive_debugger_agent_message (void *data, int len)
{
EM_ASM ({
MONO.mono_wasm_add_dbg_command_received (1, -1, $0, $1);
INTERNAL.mono_wasm_add_dbg_command_received (1, -1, $0, $1);
}, data, len);
mono_wasm_save_thread_context();
mono_wasm_fire_debugger_agent_message ();
Expand Down
6 changes: 3 additions & 3 deletions src/mono/sample/mbr/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ <h3 id="header">Wasm Browser Sample</h3>
init: function () {
var outElement = document.getElementById("out");
document.getElementById("update").addEventListener("click", function () {
BINDING.call_static_method("[WasmDelta] Sample.Test:Update", []);
INTERNAL.call_static_method("[WasmDelta] Sample.Test:Update", []);
console.log ("applied update");
var ret = BINDING.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []);
var ret = INTERNAL.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []);
outElement.innerHTML = ret;
})
var ret = BINDING.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []);
var ret = INTERNAL.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []);
outElement.innerHTML = ret;
console.log ("ready");
},
Expand Down
20 changes: 10 additions & 10 deletions src/mono/sample/mbr/browser/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
// The .NET Foundation licenses this file to you under the MIT license.

"use strict";
var Module = {
var Module = {
config: null,

preInit: async function() {
await MONO.mono_wasm_load_config("./mono-config.json"); // sets Module.config implicitly
preInit: async function () {
await MONO.mono_wasm_load_config("./mono-config.json"); // sets MONO.config implicitly
},

// Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
if (!Module.config || Module.config.error) {
if (!MONO.config || MONO.config.error) {
console.log("An error occured while loading the config file");
return;
}

Module.config.loaded_cb = function () {
App.init ();
MONO.config.loaded_cb = function () {
App.init();
};
Module.config.environment_variables = {
MONO.config.environment_variables = {
"DOTNET_MODIFIABLE_ASSEMBLIES": "debug"
};
Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
MONO.config.fetch_file_cb = function (asset) {
return fetch(asset, { credentials: 'same-origin' });
}

MONO.mono_load_runtime_and_bcl_args (Module.config);
MONO.mono_load_runtime_and_bcl_args(MONO.config);
},
};
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/browser-bench/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h3 id="header">Wasm Browser Sample - Simple Benchmark</h3>
};

function yieldBench () {
let promise = BINDING.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:RunBenchmark", []);
let promise = INTERNAL.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:RunBenchmark", []);
promise.then(ret => {
document.getElementById("out").innerHTML += ret;
if (ret.length > 0) {
Expand All @@ -52,7 +52,7 @@ <h3 id="header">Wasm Browser Sample - Simple Benchmark</h3>
var App = {
init: function () {
if (tasks != '')
BINDING.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:SetTasks", tasks);
INTERNAL.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:SetTasks", tasks);
yieldBench ();
}
};
Expand Down
Loading