<!--<_EmccCFlags Include="-DLINK_ICALLS=1" Condition="'$(WasmLinkIcalls)' == 'true'" />-->
<!--<_EmccCFlags Include="-DENABLE_AOT_PROFILER=1" Condition="$(WasmProfilers.Contains('aot'))" />-->
<!--<_EmccCFlags Include="-DENABLE_BROWSER_PROFILER=1" Condition="$(WasmProfilers.Contains('browser'))" />-->
- <!--<_EmccCFlags Include="-DCORE_BINDINGS" />-->
<!--<_EmccCFlags Include="-DGEN_PINVOKE=1" />-->
<!--<_EmccCFlags Include="-emit-llvm" />-->
add_executable(dotnet driver.c pinvoke.c stubs.c synthetic-pthread.c)
target_include_directories(dotnet PUBLIC ${MONO_INCLUDES} ${MONO_OBJ_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}/include/wasm)
-target_compile_options(dotnet PUBLIC @${NATIVE_BIN_DIR}/src/wasi-default.rsp @${NATIVE_BIN_DIR}/src/wasi-compile.rsp -DCORE_BINDINGS -DGEN_PINVOKE=1)
+target_compile_options(dotnet PUBLIC @${NATIVE_BIN_DIR}/src/wasi-default.rsp @${NATIVE_BIN_DIR}/src/wasi-compile.rsp -DGEN_PINVOKE=1)
set_target_properties(dotnet PROPERTIES COMPILE_FLAGS ${CONFIGURATION_WASICC_FLAGS})
<_EmccCFlags Include="-DLINK_ICALLS=1" Condition="'$(WasmLinkIcalls)' == 'true'" />
<_EmccCFlags Include="-DENABLE_AOT_PROFILER=1" Condition="$(WasmProfilers.Contains('aot'))" />
<_EmccCFlags Include="-DENABLE_BROWSER_PROFILER=1" Condition="$(WasmProfilers.Contains('browser'))" />
- <_EmccCFlags Include="-DCORE_BINDINGS" />
<_EmccCFlags Include="-DGEN_PINVOKE=1" />
<_EmccCFlags Include="-emit-llvm" />
<EmscriptenEnvVars Include="PYTHONPATH=$(EmscriptenPythonToolsPath)" Condition="'$(OS)' == 'Windows_NT'" />
<EmscriptenEnvVars Include="PYTHONHOME=" Condition="'$(OS)' == 'Windows_NT'" />
<EmscriptenEnvVars Include="EM_CACHE=$(WasmCachePath)" Condition="'$(WasmCachePath)' != ''" />
+ <EmscriptenEnvVars Include="WasmEnableLegacyJsInterop=$(WasmEnableLegacyJsInterop)"/>
+ <EmscriptenEnvVars Include="MonoWasmThreads=$(MonoWasmThreads)"/>
</ItemGroup>
<ItemGroup Condition="'$(WasmAllowUndefinedSymbols)' == 'true'">
- $(RunAOTCompilationAfterBuild) - Run AOT compilation even after Build. By default, it is run only for publish.
Defaults to false.
- $(WasmAotProfilePath) - Path to an AOT profile file.
+ - $(WasmEnableLegacyJsInterop) - Include support for legacy JS interop. Defaults to true.
- $(WasmEnableExceptionHandling) - Enable support for the WASM Exception Handling feature.
- $(WasmEnableSIMD) - Enable support for the WASM SIMD feature.
- $(WasmEnableWebcil) - Enable conversion of assembly .dlls to .webcil
<WasmDedup Condition="'$(WasmDedup)' == ''">true</WasmDedup>
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">false</WasmEnableExceptionHandling>
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">true</WasmEnableSIMD>
+ <WasmEnableLegacyJsInterop Condition="'$(WasmEnableLegacyJsInterop)' == ''">true</WasmEnableLegacyJsInterop>
<!--<WasmStripAOTAssemblies Condition="'$(AOTMode)' == 'LLVMOnlyInterp'">false</WasmStripAOTAssemblies>-->
<!--<WasmStripAOTAssemblies Condition="'$(WasmStripAOTAssemblies)' == ''">$(RunAOTCompilation)</WasmStripAOTAssemblies>-->
option(DISABLE_THREADS "defined if the build does NOT support multithreading" ON)
option(DISABLE_WASM_USER_THREADS "defined if the build does not allow user threads to be created in a multithreaded build" OFF)
+option(ENABLE_LEGACY_JS_INTEROP "defined if the build supports legacy JavaScript interop" ON)
set(CMAKE_EXECUTABLE_SUFFIX ".js")
add_executable(dotnet corebindings.c driver.c pinvoke.c)
target_include_directories(dotnet PUBLIC ${MONO_INCLUDES} ${MONO_OBJ_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}/include/wasm)
-target_compile_options(dotnet PUBLIC @${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-compile.rsp -DCORE_BINDINGS -DGEN_PINVOKE=1)
+target_compile_options(dotnet PUBLIC @${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-compile.rsp -DGEN_PINVOKE=1)
set_target_properties(dotnet PROPERTIES COMPILE_FLAGS ${CONFIGURATION_EMCC_FLAGS})
import { mono_wasm_load_icu_data } from "./icu";
import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, ENVIRONMENT_IS_WEB, Module, runtimeHelpers } from "./imports";
import { mono_wasm_load_bytes_into_heap } from "./memory";
-import { MONO } from "./net6-legacy/imports";
import { endMeasure, MeasuredBlock, startMeasure } from "./profiler";
import { createPromiseController, PromiseAndController } from "./promise-controller";
import { delay } from "./promise-utils";
if (runtimeHelpers.config.assets) {
mono_assert(actual_downloaded_assets_count == expected_downloaded_assets_count, () => `Expected ${expected_downloaded_assets_count} assets to be downloaded, but only finished ${actual_downloaded_assets_count}`);
mono_assert(actual_instantiated_assets_count == expected_instantiated_assets_count, () => `Expected ${expected_instantiated_assets_count} assets to be in memory, but only instantiated ${actual_instantiated_assets_count}`);
- loaded_files.forEach(value => MONO.loaded_files.push(value.url));
+ loaded_files.forEach(value => runtimeHelpers.loadedFiles.push(value.url));
if (runtimeHelpers.diagnosticTracing) console.debug("MONO_WASM: all assets are loaded in wasm memory");
}
}
// Used by the debugger to enumerate loaded dlls and pdbs
export function mono_wasm_get_loaded_files(): string[] {
- return MONO.loaded_files;
+ return runtimeHelpers.loadedFiles;
}
#include "gc-common.h"
//JS funcs
+extern void mono_wasm_release_cs_owned_object (int js_handle);
+extern void mono_wasm_bind_js_function(MonoString **function_name, MonoString **module_name, void *signature, int* function_js_handle, int *is_exception, MonoObject **result);
+extern void mono_wasm_invoke_bound_function(int function_js_handle, void *data);
+extern void mono_wasm_invoke_import(int fn_handle, void *data);
+extern void mono_wasm_bind_cs_function(MonoString **fully_qualified_name, int signature_hash, void* signatures, int *is_exception, MonoObject **result);
+extern void mono_wasm_marshal_promise(void *data);
+
+typedef void (*background_job_cb)(void);
+void mono_threads_schedule_background_job (background_job_cb cb);
+
+#ifdef ENABLE_LEGACY_JS_INTEROP
extern void mono_wasm_invoke_js_with_args_ref (int js_handle, MonoString **method, MonoArray **args, int *is_exception, MonoObject **result);
extern void mono_wasm_get_object_property_ref (int js_handle, MonoString **propertyName, int *is_exception, MonoObject **result);
-extern void mono_wasm_get_by_index_ref (int js_handle, int property_index, int *is_exception, MonoObject **result);
extern void mono_wasm_set_object_property_ref (int js_handle, MonoString **propertyName, MonoObject **value, int createIfNotExist, int hasOwnProperty, int *is_exception, MonoObject **result);
+extern void mono_wasm_get_by_index_ref (int js_handle, int property_index, int *is_exception, MonoObject **result);
extern void mono_wasm_set_by_index_ref (int js_handle, int property_index, MonoObject **value, int *is_exception, MonoObject **result);
extern void mono_wasm_get_global_object_ref (MonoString **global_name, int *is_exception, MonoObject **result);
-extern void mono_wasm_release_cs_owned_object (int js_handle);
-extern void mono_wasm_create_cs_owned_object_ref (MonoString **core_name, MonoArray **args, int *is_exception, MonoObject** result);
extern void mono_wasm_typed_array_to_array_ref (int js_handle, int *is_exception, MonoObject **result);
+extern void mono_wasm_create_cs_owned_object_ref (MonoString **core_name, MonoArray **args, int *is_exception, MonoObject** result);
extern void mono_wasm_typed_array_from_ref (int ptr, int begin, int end, int bytes_per_element, int type, int *is_exception, MonoObject** result);
-extern void mono_wasm_bind_js_function(MonoString **function_name, MonoString **module_name, void *signature, int* function_js_handle, int *is_exception, MonoObject **result);
-extern void mono_wasm_invoke_bound_function(int function_js_handle, void *data);
-extern void mono_wasm_invoke_import(int fn_handle, void *data);
-extern void mono_wasm_bind_cs_function(MonoString **fully_qualified_name, int signature_hash, void* signatures, int *is_exception, MonoObject **result);
-extern void mono_wasm_marshal_promise(void *data);
+// Blazor specific custom routines - see dotnet_support.js for backing code
+extern void* mono_wasm_invoke_js_blazor (MonoString **exceptionMessage, void *callInfo, void* arg0, void* arg1, void* arg2);
+#endif /* ENABLE_LEGACY_JS_INTEROP */
-
-void core_initialize_internals (void)
+void bindings_initialize_internals (void)
{
+ mono_add_internal_call ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::ScheduleBackgroundJob", mono_threads_schedule_background_job);
+
mono_add_internal_call ("Interop/Runtime::ReleaseCSOwnedObject", mono_wasm_release_cs_owned_object);
mono_add_internal_call ("Interop/Runtime::BindJSFunction", mono_wasm_bind_js_function);
mono_add_internal_call ("Interop/Runtime::InvokeJSFunction", mono_wasm_invoke_bound_function);
mono_add_internal_call ("Interop/Runtime::MarshalPromise", mono_wasm_marshal_promise);
mono_add_internal_call ("Interop/Runtime::RegisterGCRoot", mono_wasm_register_root);
mono_add_internal_call ("Interop/Runtime::DeregisterGCRoot", mono_wasm_deregister_root);
-
+#ifdef ENABLE_LEGACY_JS_INTEROP
// legacy
mono_add_internal_call ("Interop/Runtime::InvokeJSWithArgsRef", mono_wasm_invoke_js_with_args_ref);
mono_add_internal_call ("Interop/Runtime::GetObjectPropertyRef", mono_wasm_get_object_property_ref);
mono_add_internal_call ("Interop/Runtime::TypedArrayToArrayRef", mono_wasm_typed_array_to_array_ref);
mono_add_internal_call ("Interop/Runtime::CreateCSOwnedObjectRef", mono_wasm_create_cs_owned_object_ref);
mono_add_internal_call ("Interop/Runtime::TypedArrayFromRef", mono_wasm_typed_array_from_ref);
-}
-
-// Int8Array | int8_t | byte or SByte (signed byte)
-// Uint8Array | uint8_t | byte or Byte (unsigned byte)
-// Uint8ClampedArray| uint8_t | byte or Byte (unsigned byte)
-// Int16Array | int16_t | short (signed short)
-// Uint16Array | uint16_t | ushort (unsigned short)
-// Int32Array | int32_t | int (signed integer)
-// Uint32Array | uint32_t | uint (unsigned integer)
-// Float32Array | float | float
-// Float64Array | double | double
-// typed array marshalling
-// Keep in sync with driver.c
-#define MARSHAL_ARRAY_BYTE 10
-#define MARSHAL_ARRAY_UBYTE 11
-#define MARSHAL_ARRAY_UBYTE_C 12 // alias of MARSHAL_ARRAY_UBYTE
-#define MARSHAL_ARRAY_SHORT 13
-#define MARSHAL_ARRAY_USHORT 14
-#define MARSHAL_ARRAY_INT 15
-#define MARSHAL_ARRAY_UINT 16
-#define MARSHAL_ARRAY_FLOAT 17
-#define MARSHAL_ARRAY_DOUBLE 18
-
-EMSCRIPTEN_KEEPALIVE void
-mono_wasm_typed_array_new_ref (char *arr, int length, int size, int type, PPVOLATILE(MonoArray) result)
-{
- MONO_ENTER_GC_UNSAFE;
- MonoClass * typeClass = mono_get_byte_class(); // default is Byte
- switch (type) {
- case MARSHAL_ARRAY_BYTE:
- typeClass = mono_get_sbyte_class();
- break;
- case MARSHAL_ARRAY_SHORT:
- typeClass = mono_get_int16_class();
- break;
- case MARSHAL_ARRAY_USHORT:
- typeClass = mono_get_uint16_class();
- break;
- case MARSHAL_ARRAY_INT:
- typeClass = mono_get_int32_class();
- break;
- case MARSHAL_ARRAY_UINT:
- typeClass = mono_get_uint32_class();
- break;
- case MARSHAL_ARRAY_FLOAT:
- typeClass = mono_get_single_class();
- break;
- case MARSHAL_ARRAY_DOUBLE:
- typeClass = mono_get_double_class();
- break;
- case MARSHAL_ARRAY_UBYTE:
- case MARSHAL_ARRAY_UBYTE_C:
- typeClass = mono_get_byte_class();
- break;
- default:
- printf ("Invalid marshal type %d in mono_wasm_typed_array_new", type);
- abort();
- }
-
- PVOLATILE(MonoArray) buffer;
-
- buffer = mono_array_new (mono_get_root_domain(), typeClass, length);
- memcpy(mono_array_addr_with_size(buffer, sizeof(char), 0), arr, length * size);
- store_volatile((PPVOLATILE(MonoObject))result, (MonoObject *)buffer);
- MONO_EXIT_GC_UNSAFE;
+ // Blazor specific custom routines - see dotnet_support.js for backing code
+ mono_add_internal_call ("WebAssembly.JSInterop.InternalCalls::InvokeJS", mono_wasm_invoke_js_blazor);
+#endif /* ENABLE_LEGACY_JS_INTEROP */
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+import WasmEnableLegacyJsInterop from "consts:WasmEnableLegacyJsInterop";
import {
MonoArray, MonoAssembly, MonoClass,
MonoMethod, MonoObject, MonoString,
type SigLine = [lazy: boolean, name: string, returnType: string | null, argTypes?: string[], opts?: any];
+const legacy_interop_cwraps: SigLine[] = !WasmEnableLegacyJsInterop ? [] : [
+ [true, "mono_wasm_array_get_ref", "void", ["number", "number", "number"]],
+ [true, "mono_wasm_obj_array_new_ref", "void", ["number", "number"]],
+ [true, "mono_wasm_obj_array_set_ref", "void", ["number", "number", "number"]],
+ [true, "mono_wasm_try_unbox_primitive_and_get_type_ref", "number", ["number", "number", "number"]],
+ [true, "mono_wasm_box_primitive_ref", "void", ["number", "number", "number", "number"]],
+ [true, "mono_wasm_string_array_new_ref", "void", ["number", "number"]],
+ [true, "mono_wasm_typed_array_new_ref", "void", ["number", "number", "number", "number", "number"]],
+ [true, "mono_wasm_get_delegate_invoke_ref", "number", ["number"]],
+ [true, "mono_wasm_get_type_name", "string", ["number"]],
+ [true, "mono_wasm_get_type_aqn", "string", ["number"]],
+ [true, "mono_wasm_obj_array_new", "number", ["number"]],
+ [true, "mono_wasm_obj_array_set", "void", ["number", "number", "number"]],
+ [true, "mono_wasm_array_length_ref", "number", ["number"]],
+];
+
// when the method is assigned/cached at usage, instead of being invoked directly from cwraps, it can't be marked lazy, because it would be re-bound on each call
const fn_signatures: SigLine[] = [
// MONO
// BINDING
[true, "mono_wasm_get_corlib", "number", []],
[true, "mono_wasm_assembly_load", "number", ["string"]],
- [true, "mono_wasm_find_corlib_class", "number", ["string", "string"]],
[true, "mono_wasm_assembly_find_class", "number", ["number", "string", "string"]],
[true, "mono_wasm_runtime_run_module_cctor", "void", ["number"]],
- [true, "mono_wasm_find_corlib_type", "number", ["string", "string"]],
- [true, "mono_wasm_assembly_find_type", "number", ["number", "string", "string"]],
[true, "mono_wasm_assembly_find_method", "number", ["number", "string", "number"]],
[false, "mono_wasm_invoke_method_ref", "void", ["number", "number", "number", "number", "number"]],
[true, "mono_wasm_string_from_utf16_ref", "void", ["number", "number", "number"]],
- [true, "mono_wasm_array_length_ref", "number", ["number"]],
- [true, "mono_wasm_array_get_ref", "void", ["number", "number", "number"]],
- [false, "mono_wasm_obj_array_new", "number", ["number"]],
- [false, "mono_wasm_obj_array_new_ref", "void", ["number", "number"]],
- [false, "mono_wasm_obj_array_set", "void", ["number", "number", "number"]],
- [false, "mono_wasm_obj_array_set_ref", "void", ["number", "number", "number"]],
- [true, "mono_wasm_register_bundled_satellite_assemblies", "void", []],
- [false, "mono_wasm_try_unbox_primitive_and_get_type_ref", "number", ["number", "number", "number"]],
- [true, "mono_wasm_box_primitive_ref", "void", ["number", "number", "number", "number"]],
[true, "mono_wasm_intern_string_ref", "void", ["number"]],
[true, "mono_wasm_assembly_get_entry_point", "number", ["number"]],
- [true, "mono_wasm_get_delegate_invoke_ref", "number", ["number"]],
- [true, "mono_wasm_string_array_new_ref", "void", ["number", "number"]],
- [true, "mono_wasm_typed_array_new_ref", "void", ["number", "number", "number", "number", "number"]],
[true, "mono_wasm_class_get_type", "number", ["number"]],
- [true, "mono_wasm_get_type_name", "string", ["number"]],
- [true, "mono_wasm_get_type_aqn", "string", ["number"]],
// MONO.diagnostics
[true, "mono_wasm_event_pipe_enable", "bool", ["string", "number", "number", "string", "bool", "number"]],
[true, "mono_jiterp_debug_count", "number", []],
[true, "mono_jiterp_get_trace_hit_count", "number", ["number"]],
[true, "mono_jiterp_get_polling_required_address", "number", []],
+ ...legacy_interop_cwraps
];
+export interface t_LegacyCwraps {
+ // legacy interop
+ mono_wasm_array_get_ref(array: MonoObjectRef, idx: number, result: MonoObjectRef): void;
+ mono_wasm_obj_array_new_ref(size: number, result: MonoObjectRef): void;
+ mono_wasm_obj_array_set_ref(array: MonoObjectRef, idx: number, obj: MonoObjectRef): void;
+ mono_wasm_try_unbox_primitive_and_get_type_ref(obj: MonoObjectRef, buffer: VoidPtr, buffer_size: number): number;
+ mono_wasm_box_primitive_ref(klass: MonoClass, value: VoidPtr, value_size: number, result: MonoObjectRef): void;
+ mono_wasm_string_array_new_ref(size: number, result: MonoObjectRef): void;
+ mono_wasm_typed_array_new_ref(arr: VoidPtr, length: number, size: number, type: number, result: MonoObjectRef): void;
+ mono_wasm_get_delegate_invoke_ref(delegate: MonoObjectRef): MonoMethod;
+ mono_wasm_get_type_name(ty: MonoType): string;
+ mono_wasm_get_type_aqn(ty: MonoType): string;
+ mono_wasm_obj_array_new(size: number): MonoArray;
+ mono_wasm_obj_array_set(array: MonoArray, idx: number, obj: MonoObject): void;
+ mono_wasm_array_length_ref(array: MonoObjectRef): number;
+}
+
export interface t_Cwraps {
// MONO
mono_wasm_register_root(start: VoidPtr, size: number, name: string): number;
// BINDING
mono_wasm_get_corlib(): MonoAssembly;
mono_wasm_assembly_load(name: string): MonoAssembly;
- mono_wasm_find_corlib_class(namespace: string, name: string): MonoClass;
mono_wasm_assembly_find_class(assembly: MonoAssembly, namespace: string, name: string): MonoClass;
- mono_wasm_find_corlib_type(namespace: string, name: string): MonoType;
- mono_wasm_assembly_find_type(assembly: MonoAssembly, namespace: string, name: string): MonoType;
mono_wasm_assembly_find_method(klass: MonoClass, name: string, args: number): MonoMethod;
mono_wasm_invoke_method_ref(method: MonoMethod, this_arg: MonoObjectRef, params: VoidPtr, out_exc: MonoObjectRef, out_result: MonoObjectRef): void;
mono_wasm_string_from_utf16_ref(str: CharPtr, len: number, result: MonoObjectRef): void;
-
- mono_wasm_array_length_ref(array: MonoObjectRef): number;
- mono_wasm_array_get_ref(array: MonoObjectRef, idx: number, result: MonoObjectRef): void;
- mono_wasm_obj_array_new_ref(size: number, result: MonoObjectRef): void;
- mono_wasm_obj_array_set_ref(array: MonoObjectRef, idx: number, obj: MonoObjectRef): void;
- mono_wasm_register_bundled_satellite_assemblies(): void;
- mono_wasm_try_unbox_primitive_and_get_type_ref(obj: MonoObjectRef, buffer: VoidPtr, buffer_size: number): number;
- mono_wasm_box_primitive_ref(klass: MonoClass, value: VoidPtr, value_size: number, result: MonoObjectRef): void;
- mono_wasm_intern_string_ref(strRef: MonoStringRef): void;
- mono_wasm_assembly_get_entry_point(assembly: MonoAssembly, idx: number): MonoMethod;
- mono_wasm_string_array_new_ref(size: number, result: MonoObjectRef): void;
- mono_wasm_typed_array_new_ref(arr: VoidPtr, length: number, size: number, type: number, result: MonoObjectRef): void;
mono_wasm_class_get_type(klass: MonoClass): MonoType;
- mono_wasm_get_delegate_invoke_ref(delegate: MonoObjectRef): MonoMethod;
- mono_wasm_get_type_name(ty: MonoType): string;
- mono_wasm_get_type_aqn(ty: MonoType): string;
+ mono_wasm_assembly_get_entry_point(assembly: MonoAssembly, idx: number): MonoMethod;
+ mono_wasm_intern_string_ref(strRef: MonoStringRef): void;
- /**
- * @deprecated Not GC or thread safe
- */
- mono_wasm_obj_array_new(size: number): MonoArray;
- /**
- * @deprecated Not GC or thread safe
- */
- mono_wasm_obj_array_set(array: MonoArray, idx: number, obj: MonoObject): void;
// MONO.diagnostics
mono_wasm_event_pipe_enable(outputPath: string | null, stream: VoidPtr, bufferSizeInMB: number, providers: string, rundownRequested: boolean, outSessionId: VoidPtr): boolean;
const wrapped_c_functions: t_Cwraps = <any>{};
export default wrapped_c_functions;
+export const legacy_c_functions: t_LegacyCwraps & t_Cwraps = wrapped_c_functions as any;
// see src/mono/wasm/driver.c I52_ERROR_xxx
export const enum I52Error {
#endif
#include "gc-common.h"
-#ifdef CORE_BINDINGS
-void core_initialize_internals ();
-#endif
-
-extern void mono_wasm_set_entrypoint_breakpoint (const char* assembly_name, int method_token);
+void bindings_initialize_internals ();
-// Blazor specific custom routines - see dotnet_support.js for backing code
-extern void* mono_wasm_invoke_js_blazor (MonoString **exceptionMessage, void *callInfo, void* arg0, void* arg1, void* arg2);
void mono_wasm_enable_debugging (int);
-
-static int _marshal_type_from_mono_type (int mono_type, MonoClass *klass, MonoType *type);
-
-int mono_wasm_register_root (char *start, size_t size, const char *name);
-void mono_wasm_deregister_root (char *addr);
-
void mono_ee_interp_init (const char *opts);
void mono_marshal_ilgen_init (void);
void mono_method_builder_ilgen_init (void);
void mono_sgen_mono_ilgen_init (void);
void mono_icall_table_init (void);
-void mono_aot_register_module (void **aot_info);
char *monoeg_g_getenv(const char *variable);
int monoeg_g_setenv(const char *variable, const char *value, int overwrite);
-int32_t monoeg_g_hasenv(const char *variable);
-void mono_free (void*);
int32_t mini_parse_debug_option (const char *option);
char *mono_method_get_full_name (MonoMethod *method);
-char *mono_method_full_name (MonoMethod *method, int signature);
-extern void mono_wasm_register_timezones_bundle();
+extern void mono_wasm_register_timezones_bundle();
+extern void mono_wasm_set_entrypoint_breakpoint (const char* assembly_name, int method_token);
static void mono_wasm_init_finalizer_thread (void);
+#ifdef ENABLE_LEGACY_JS_INTEROP
+
#define MARSHAL_TYPE_NULL 0
#define MARSHAL_TYPE_INT 1
#define MARSHAL_TYPE_FP64 2
resolved_safehandle_class = 0,
resolved_voidtaskresult_class = 0;
+#endif /* ENABLE_LEGACY_JS_INTEROP */
+
int mono_wasm_enable_gc = 1;
/* Not part of public headers */
return addr;
}
-typedef void (*background_job_cb)(void);
-void mono_threads_schedule_background_job (background_job_cb cb);
-
-void mono_initialize_internals (void)
-{
- // Blazor specific custom routines - see dotnet_support.js for backing code
- mono_add_internal_call ("WebAssembly.JSInterop.InternalCalls::InvokeJS", mono_wasm_invoke_js_blazor);
-
-#ifdef CORE_BINDINGS
- core_initialize_internals();
-#endif
-
- mono_add_internal_call ("System.Runtime.InteropServices.JavaScript.JSSynchronizationContext::ScheduleBackgroundJob", mono_threads_schedule_background_job);
-}
-
-EMSCRIPTEN_KEEPALIVE void
+void
mono_wasm_register_bundled_satellite_assemblies (void)
{
/* In legacy satellite_assembly_count is always false */
mono_trace_set_log_handler (wasm_trace_logger, NULL);
root_domain = mono_jit_init_version ("mono", NULL);
- mono_initialize_internals();
+ bindings_initialize_internals();
mono_thread_set_main (mono_thread_current ());
return result;
}
-EMSCRIPTEN_KEEPALIVE MonoMethod*
-mono_wasm_get_delegate_invoke_ref (MonoObject **delegate)
-{
- MonoMethod * result;
- MONO_ENTER_GC_UNSAFE;
- result = mono_get_delegate_invoke(mono_object_get_class (*delegate));
- MONO_EXIT_GC_UNSAFE;
- return result;
-}
-
-EMSCRIPTEN_KEEPALIVE void
-mono_wasm_box_primitive_ref (MonoClass *klass, void *value, int value_size, PPVOLATILE(MonoObject) result)
-{
- assert (klass);
-
- MONO_ENTER_GC_UNSAFE;
- MonoType *type = mono_class_get_type (klass);
- int alignment;
-
- if (mono_type_size (type, &alignment) <= value_size)
- // TODO: use mono_value_box_checked and propagate error out
- store_volatile(result, mono_value_box (root_domain, klass, value));
-
- MONO_EXIT_GC_UNSAFE;
-}
-
EMSCRIPTEN_KEEPALIVE void
mono_wasm_invoke_method_ref (MonoMethod *method, MonoObject **this_arg_in, void *params[], MonoObject **_out_exc, MonoObject **out_result)
{
MONO_EXIT_GC_UNSAFE;
}
+#ifdef ENABLE_LEGACY_JS_INTEROP
+
static int
class_is_task (MonoClass *klass)
{
}
}
+EMSCRIPTEN_KEEPALIVE void
+mono_wasm_typed_array_new_ref (char *arr, int length, int size, int type, PPVOLATILE(MonoArray) result)
+{
+ MONO_ENTER_GC_UNSAFE;
+ MonoClass * typeClass = mono_get_byte_class(); // default is Byte
+ switch (type) {
+ case MARSHAL_ARRAY_BYTE:
+ typeClass = mono_get_sbyte_class();
+ break;
+ case MARSHAL_ARRAY_SHORT:
+ typeClass = mono_get_int16_class();
+ break;
+ case MARSHAL_ARRAY_USHORT:
+ typeClass = mono_get_uint16_class();
+ break;
+ case MARSHAL_ARRAY_INT:
+ typeClass = mono_get_int32_class();
+ break;
+ case MARSHAL_ARRAY_UINT:
+ typeClass = mono_get_uint32_class();
+ break;
+ case MARSHAL_ARRAY_FLOAT:
+ typeClass = mono_get_single_class();
+ break;
+ case MARSHAL_ARRAY_DOUBLE:
+ typeClass = mono_get_double_class();
+ break;
+ case MARSHAL_ARRAY_UBYTE:
+ case MARSHAL_ARRAY_UBYTE_C:
+ typeClass = mono_get_byte_class();
+ break;
+ default:
+ printf ("Invalid marshal type %d in mono_wasm_typed_array_new", type);
+ abort();
+ }
+
+ PVOLATILE(MonoArray) buffer;
+
+ buffer = mono_array_new (mono_get_root_domain(), typeClass, length);
+ memcpy(mono_array_addr_with_size(buffer, sizeof(char), 0), arr, length * size);
+
+ store_volatile((PPVOLATILE(MonoObject))result, (MonoObject *)buffer);
+ MONO_EXIT_GC_UNSAFE;
+}
+
+EMSCRIPTEN_KEEPALIVE MonoMethod*
+mono_wasm_get_delegate_invoke_ref (MonoObject **delegate)
+{
+ MonoMethod * result;
+ MONO_ENTER_GC_UNSAFE;
+ result = mono_get_delegate_invoke(mono_object_get_class (*delegate));
+ MONO_EXIT_GC_UNSAFE;
+ return result;
+}
+
+EMSCRIPTEN_KEEPALIVE void
+mono_wasm_box_primitive_ref (MonoClass *klass, void *value, int value_size, PPVOLATILE(MonoObject) result)
+{
+ assert (klass);
+
+ MONO_ENTER_GC_UNSAFE;
+ MonoType *type = mono_class_get_type (klass);
+ int alignment;
+
+ if (mono_type_size (type, &alignment) <= value_size)
+ // TODO: use mono_value_box_checked and propagate error out
+ store_volatile(result, mono_value_box (root_domain, klass, value));
+
+ MONO_EXIT_GC_UNSAFE;
+}
+
+EMSCRIPTEN_KEEPALIVE char *
+mono_wasm_get_type_name (MonoType * typePtr) {
+ return mono_type_get_name_full (typePtr, MONO_TYPE_NAME_FORMAT_REFLECTION);
+}
+
+EMSCRIPTEN_KEEPALIVE char *
+mono_wasm_get_type_aqn (MonoType * typePtr) {
+ return mono_type_get_name_full (typePtr, MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED);
+}
+
// This code runs inside a gc unsafe region
static int
_mono_wasm_try_unbox_primitive_and_get_type_ref_impl (PVOLATILE(MonoObject) obj, void *result, int result_capacity) {
MONO_EXIT_GC_UNSAFE;
}
+#endif /* ENABLE_LEGACY_JS_INTEROP */
+
EMSCRIPTEN_KEEPALIVE int
mono_wasm_exec_regression (int verbose_level, char *image)
{
return result;
}
-EMSCRIPTEN_KEEPALIVE char *
-mono_wasm_get_type_name (MonoType * typePtr) {
- return mono_type_get_name_full (typePtr, MONO_TYPE_NAME_FORMAT_REFLECTION);
-}
-
-EMSCRIPTEN_KEEPALIVE char *
-mono_wasm_get_type_aqn (MonoType * typePtr) {
- return mono_type_get_name_full (typePtr, MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED);
-}
-
EMSCRIPTEN_KEEPALIVE void
mono_wasm_write_managed_pointer_unsafe (PPVOLATILE(MonoObject) destination, PVOLATILE(MonoObject) source) {
store_volatile(destination, source);
"use strict";
-#if USE_PTHREADS
-const usePThreads = true;
-const isPThread = `ENVIRONMENT_IS_PTHREAD`;
-#else
-const usePThreads = false;
-const isPThread = `false`;
-#endif
+const monoWasmThreads = process.env.MonoWasmThreads == "true";
+const WasmEnableLegacyJsInterop = process.env.WasmEnableLegacyJsInterop === "true";
+const isPThread = monoWasmThreads ? "ENVIRONMENT_IS_PTHREAD" : "false";
const DotnetSupportLib = {
$DOTNET: {},
// Emscripten's getBinaryPromise is not async for NodeJs, but we would like to have it async, so we replace it.
// We also replace implementation of fetch
$DOTNET__postset: `
-let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
-${usePThreads ? `
+let __dotnet_replacement_PThread = ${monoWasmThreads} ? {} : undefined;
+${monoWasmThreads ? `
__dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
__dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
__dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker;
});
}
var noExitRuntime = __dotnet_replacements.noExitRuntime;
-${usePThreads ? `
+${monoWasmThreads ? `
PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTLS;
PThread.allocateUnusedWorker = __dotnet_replacements.pthreadReplacements.allocateUnusedWorker;
// the methods would be visible to EMCC linker
// --- keep in sync with exports.ts ---
-const linked_functions = [
+let linked_functions = [
// mini-wasm.c
"mono_set_timeout",
"mono_wasm_profiler_leave",
// driver.c
- "mono_wasm_invoke_js_blazor",
"mono_wasm_trace_logger",
"mono_wasm_event_pipe_early_startup_callback",
"mono_jiterp_do_jit_call_indirect",
// corebindings.c
- "mono_wasm_invoke_js_with_args_ref",
- "mono_wasm_get_object_property_ref",
- "mono_wasm_set_object_property_ref",
- "mono_wasm_get_by_index_ref",
- "mono_wasm_set_by_index_ref",
- "mono_wasm_get_global_object_ref",
- "mono_wasm_create_cs_owned_object_ref",
"mono_wasm_release_cs_owned_object",
- "mono_wasm_typed_array_to_array_ref",
- "mono_wasm_typed_array_from_ref",
"mono_wasm_bind_js_function",
"mono_wasm_invoke_bound_function",
"mono_wasm_invoke_import",
// pal_icushim_static.c
"mono_wasm_load_icu_data",
-
- #if USE_PTHREADS
- /// mono-threads-wasm.c
- "mono_wasm_pthread_on_pthread_attached",
- // diagnostics_server.c
- "mono_wasm_diagnostic_server_on_server_thread_created",
- "mono_wasm_diagnostic_server_on_runtime_server_init",
- "mono_wasm_diagnostic_server_stream_signal_work_available",
- #endif
];
+if (monoWasmThreads) {
+ linked_functions = [...linked_functions,
+ /// mono-threads-wasm.c
+ "mono_wasm_pthread_on_pthread_attached",
+ // diagnostics_server.c
+ "mono_wasm_diagnostic_server_on_server_thread_created",
+ "mono_wasm_diagnostic_server_on_runtime_server_init",
+ "mono_wasm_diagnostic_server_stream_signal_work_available",
+ ]
+}
+if (WasmEnableLegacyJsInterop) {
+ linked_functions = [...linked_functions,
+ "mono_wasm_invoke_js_with_args_ref",
+ "mono_wasm_get_object_property_ref",
+ "mono_wasm_set_object_property_ref",
+ "mono_wasm_get_by_index_ref",
+ "mono_wasm_set_by_index_ref",
+ "mono_wasm_get_global_object_ref",
+ "mono_wasm_create_cs_owned_object_ref",
+ "mono_wasm_typed_array_to_array_ref",
+ "mono_wasm_typed_array_from_ref",
+ "mono_wasm_invoke_js_blazor",
+ ]
+}
+
// -- this javascript file is evaluated by emcc during compilation! --
// we generate simple proxy for each exported function so that emcc will include them in the final output
for (let linked_function of linked_functions) {
import { http_wasm_supports_streaming_response, http_wasm_create_abort_controler, http_wasm_abort_request, http_wasm_abort_response, http_wasm_fetch, http_wasm_fetch_bytes, http_wasm_get_response_header_names, http_wasm_get_response_header_values, http_wasm_get_response_bytes, http_wasm_get_response_length, http_wasm_get_streamed_response_bytes } from "./http";
import { exportedRuntimeAPI, Module, runtimeHelpers } from "./imports";
import { get_property, set_property, has_property, get_typeof_property, get_global_this, dynamic_import } from "./invoke-js";
-import { mono_method_resolve } from "./net6-legacy/method-binding";
import { mono_intern_string } from "./strings";
import { mono_wasm_stringify_as_error_with_stack } from "./logging";
import { ws_wasm_create, ws_wasm_open, ws_wasm_send, ws_wasm_receive, ws_wasm_close, ws_wasm_abort } from "./web-socket";
mono_wasm_profiler_init_aot: cwraps.mono_wasm_profiler_init_aot,
mono_wasm_profiler_init_browser: cwraps.mono_wasm_profiler_init_browser,
mono_wasm_exec_regression: cwraps.mono_wasm_exec_regression,
- mono_method_resolve,//MarshalTests.cs
mono_intern_string,// MarshalTests.cs
// with mono_wasm_debugger_log and mono_wasm_trace_logger
// The .NET Foundation licenses this file to you under the MIT license.
import MonoWasmThreads from "consts:monoWasmThreads";
-import { mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause, mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint } from "./debug";
-
+import WasmEnableLegacyJsInterop from "consts:WasmEnableLegacyJsInterop";
+import { mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint, mono_wasm_fire_debugger_agent_message_with_data, mono_wasm_fire_debugger_agent_message_with_data_to_pause } from "./debug";
import { mono_wasm_release_cs_owned_object } from "./gc-handles";
import { mono_wasm_load_icu_data } from "./icu";
import { mono_wasm_bind_cs_function } from "./invoke-cs";
import { mono_interp_tier_prepare_jiterpreter } from "./jiterpreter";
import { mono_interp_jit_wasm_entry_trampoline, mono_interp_record_interp_entry } from "./jiterpreter-interp-entry";
import { mono_interp_jit_wasm_jit_call_trampoline, mono_interp_invoke_wasm_jit_call_trampoline, mono_interp_flush_jitcall_queue, mono_jiterp_do_jit_call_indirect } from "./jiterpreter-jit-call";
-import { mono_wasm_typed_array_from_ref } from "./net6-legacy/buffers";
-import {
- mono_wasm_invoke_js_blazor, mono_wasm_invoke_js_with_args_ref, mono_wasm_get_object_property_ref, mono_wasm_set_object_property_ref,
- mono_wasm_get_by_index_ref, mono_wasm_set_by_index_ref, mono_wasm_get_global_object_ref
-} from "./net6-legacy/method-calls";
import { mono_wasm_marshal_promise } from "./marshal-to-js";
import { mono_wasm_pthread_on_pthread_attached } from "./pthreads/worker";
import { mono_set_timeout, schedule_background_exec } from "./scheduling";
import { mono_wasm_diagnostic_server_on_server_thread_created } from "./diagnostics/server_pthread";
import { mono_wasm_diagnostic_server_on_runtime_server_init, mono_wasm_event_pipe_early_startup_callback } from "./diagnostics";
import { mono_wasm_diagnostic_server_stream_signal_work_available } from "./diagnostics/server_pthread/stream-queue";
-import { mono_wasm_create_cs_owned_object_ref } from "./net6-legacy/cs-to-js";
-import { mono_wasm_typed_array_to_array_ref } from "./net6-legacy/js-to-cs";
import { mono_wasm_trace_logger } from "./logging";
import { mono_wasm_profiler_leave, mono_wasm_profiler_enter } from "./profiler";
+import { mono_wasm_create_cs_owned_object_ref } from "./net6-legacy/cs-to-js";
+import { mono_wasm_typed_array_to_array_ref } from "./net6-legacy/js-to-cs";
+import { mono_wasm_typed_array_from_ref } from "./net6-legacy/buffers";
+import {
+ mono_wasm_invoke_js_blazor, mono_wasm_invoke_js_with_args_ref, mono_wasm_get_object_property_ref, mono_wasm_set_object_property_ref,
+ mono_wasm_get_by_index_ref, mono_wasm_set_by_index_ref, mono_wasm_get_global_object_ref
+} from "./net6-legacy/method-calls";
// the methods would be visible to EMCC linker
// --- keep in sync with dotnet.cjs.lib.js ---
mono_wasm_diagnostic_server_stream_signal_work_available,
};
+const mono_wasm_legacy_interop_exports = !WasmEnableLegacyJsInterop ? undefined : {
+ // corebindings.c
+ mono_wasm_invoke_js_with_args_ref,
+ mono_wasm_get_object_property_ref,
+ mono_wasm_set_object_property_ref,
+ mono_wasm_get_by_index_ref,
+ mono_wasm_set_by_index_ref,
+ mono_wasm_get_global_object_ref,
+ mono_wasm_create_cs_owned_object_ref,
+ mono_wasm_typed_array_to_array_ref,
+ mono_wasm_typed_array_from_ref,
+ mono_wasm_invoke_js_blazor,
+};
+
// the methods would be visible to EMCC linker
// --- keep in sync with dotnet.cjs.lib.js ---
// --- keep in sync with dotnet.es6.lib.js ---
mono_wasm_profiler_leave,
// driver.c
- mono_wasm_invoke_js_blazor,
mono_wasm_trace_logger,
mono_wasm_set_entrypoint_breakpoint,
mono_wasm_event_pipe_early_startup_callback,
// corebindings.c
- mono_wasm_invoke_js_with_args_ref,
- mono_wasm_get_object_property_ref,
- mono_wasm_set_object_property_ref,
- mono_wasm_get_by_index_ref,
- mono_wasm_set_by_index_ref,
- mono_wasm_get_global_object_ref,
- mono_wasm_create_cs_owned_object_ref,
mono_wasm_release_cs_owned_object,
- mono_wasm_typed_array_to_array_ref,
- mono_wasm_typed_array_from_ref,
mono_wasm_bind_js_function,
mono_wasm_invoke_bound_function,
mono_wasm_invoke_import,
// threading exports, if threading is enabled
...mono_wasm_threads_exports,
+ // legacy interop exports, if enabled
+ ...mono_wasm_legacy_interop_exports
};
}
import GitHash from "consts:gitHash";
import MonoWasmThreads from "consts:monoWasmThreads";
import BuildConfiguration from "consts:configuration";
+import WasmEnableLegacyJsInterop from "consts:WasmEnableLegacyJsInterop";
import { ENVIRONMENT_IS_PTHREAD, exportedRuntimeAPI, moduleExports, set_emscripten_entrypoint, set_imports_exports } from "./imports";
import { DotnetModule, is_nullish, EarlyImports, EarlyExports, EarlyReplacements, RuntimeAPI, CreateDotnetRuntimeType } from "./types";
import { configure_emscripten_startup, mono_wasm_pthread_worker_init } from "./startup";
-import { mono_bind_static_method } from "./net6-legacy/method-calls";
import { create_weak_ref } from "./weak-ref";
-import { export_binding_api, export_mono_api } from "./net6-legacy/exports-legacy";
import { export_internal } from "./exports-internal";
import { export_linker } from "./exports-linker";
import { init_polyfills } from "./polyfills";
import { export_api, export_module } from "./export-api";
+
+// legacy
+import { mono_bind_static_method } from "./net6-legacy/method-calls";
+import { export_binding_api, export_internal_api, export_mono_api } from "./net6-legacy/exports-legacy";
import { set_legacy_exports } from "./net6-legacy/imports";
const __initializeImportsAndExports: any = initializeImportsAndExports; // don't want to export the type
// we want to have same instance of MONO, BINDING and Module in dotnet iife
set_imports_exports(imports, exports);
- set_legacy_exports(exports);
+ if (WasmEnableLegacyJsInterop) {
+ set_legacy_exports(exports);
+ }
init_polyfills(replacements);
// here we merge methods from the local objects into exported objects
- Object.assign(exports.mono, export_mono_api());
- Object.assign(exports.binding, export_binding_api());
+ if (WasmEnableLegacyJsInterop) {
+ Object.assign(exports.mono, export_mono_api());
+ Object.assign(exports.binding, export_binding_api());
+ Object.assign(exports.internal, export_internal_api());
+ }
Object.assign(exports.internal, export_internal());
const API = export_api();
__linker_exports = export_linker();
Object.assign(exportedRuntimeAPI, {
- MONO: exports.mono,
- BINDING: exports.binding,
INTERNAL: exports.internal,
IMPORTS: exports.marshaled_imports,
Module: module,
},
...API,
});
+ if (WasmEnableLegacyJsInterop) {
+ Object.assign(exportedRuntimeAPI, {
+ MONO: exports.mono,
+ BINDING: exports.binding,
+ });
+ }
+
Object.assign(callbackAPI, API);
if (exports.module.__undefinedConfig) {
module.disableDotnet6Compatibility = true;
if (imports.isGlobal || !module.disableDotnet6Compatibility) {
Object.assign(module, exportedRuntimeAPI);
- // backward compatibility
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- module.mono_bind_static_method = (fqn: string, signature: string/*ArgsMarshalString*/): Function => {
- console.warn("MONO_WASM: Module.mono_bind_static_method is obsolete, please use [JSExportAttribute] interop instead");
- return mono_bind_static_method(fqn, signature);
- };
+ if (WasmEnableLegacyJsInterop) {
+ // backward compatibility
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore
+ module.mono_bind_static_method = (fqn: string, signature: string/*ArgsMarshalString*/): Function => {
+ console.warn("MONO_WASM: Module.mono_bind_static_method is obsolete, please use [JSExportAttribute] interop instead");
+ return mono_bind_static_method(fqn, signature);
+ };
+ }
const warnWrap = (name: string, provider: () => any) => {
if (typeof globalThisAny[name] !== "undefined") {
/// <reference path="./types/v8.d.ts" />
/// <reference path="./types/node.d.ts" />
-import { CreateDotnetRuntimeType, DotnetModule, RuntimeAPI, EarlyExports, EarlyImports, ModuleAPI, RuntimeHelpers } from "./types";
-import { EmscriptenModule } from "./types/emscripten";
+import type { CreateDotnetRuntimeType, DotnetModule, RuntimeAPI, EarlyExports, EarlyImports, ModuleAPI, RuntimeHelpers } from "./types";
+import type { EmscriptenModule } from "./types/emscripten";
// these are our public API (except internal)
export let Module: EmscriptenModule & DotnetModule;
},
diagnosticTracing: false,
enablePerfMeasure: true,
+ loadedFiles: []
};
export const runtimeHelpers: RuntimeHelpers = initialRuntimeHelpers as any;
// The .NET Foundation licenses this file to you under the MIT license.
import { _are_promises_supported } from "../cancelable-promise";
-import cwraps from "../cwraps";
+import { legacy_c_functions as cwraps } from "../cwraps";
import { mono_wasm_get_jsobj_from_js_handle, _lookup_js_owned_object, setup_managed_proxy, mono_wasm_get_js_handle, teardown_managed_proxy, assert_not_disposed } from "../gc-handles";
import { wrap_error_root, wrap_no_error_root } from "../invoke-js";
import { ManagedObject } from "../marshal";
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-import cwraps from "../cwraps";
+import { legacy_c_functions as cwraps } from "../cwraps";
import { mono_wasm_runtime_ready } from "../debug";
import { mono_wasm_load_icu_data } from "../icu";
import { runtimeHelpers } from "../imports";
import { mono_wasm_load_runtime } from "../startup";
import { BINDINGType, MONOType } from "./export-types";
import { mono_wasm_load_data_archive } from "../assets";
+import { mono_method_resolve } from "./method-binding";
export function export_mono_api(): MONOType {
return {
});
}
+export function export_internal_api(): any {
+ return {
+ mono_method_resolve,//MarshalTests.cs
+ };
+}
+
export function export_binding_api(): BINDINGType {
return {
// legacy BINDING API
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-import { EarlyExports, MonoClass } from "../types";
-import { VoidPtr } from "../types/emscripten";
-import { BINDINGType, MONOType } from "./export-types";
+import type { EarlyExports, MonoClass } from "../types";
+import type { VoidPtr } from "../types/emscripten";
+import type { BINDINGType, MONOType } from "./export-types";
export let MONO: MONOType;
export let BINDING: BINDINGType;
// The .NET Foundation licenses this file to you under the MIT license.
import { isThenable } from "../cancelable-promise";
-import cwraps from "../cwraps";
+import { legacy_c_functions as cwraps } from "../cwraps";
import { js_owned_gc_handle_symbol, assert_not_disposed, cs_owned_js_handle_symbol, mono_wasm_get_js_handle, setup_managed_proxy, mono_wasm_release_cs_owned_object, teardown_managed_proxy, mono_wasm_get_jsobj_from_js_handle } from "../gc-handles";
import { Module } from "../imports";
import { wrap_error_root, wrap_no_error_root } from "../invoke-js";
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-import cwraps from "../cwraps";
+import { legacy_c_functions as cwraps } from "../cwraps";
import { Module } from "../imports";
import { parseFQN } from "../invoke-cs";
import { setI32, setU32, setF32, setF64, setU52, setI52, setB32, setI32_unchecked, setU32_unchecked, _zero_region, _create_temp_frame, getB32, getI32, getU32, getF32, getF64 } from "../memory";
const productVersion = process.env.ProductVersion || "8.0.0-dev";
const nativeBinDir = process.env.NativeBinDir ? process.env.NativeBinDir.replace(/"/g, "") : "bin";
const monoWasmThreads = process.env.MonoWasmThreads === "true" ? true : false;
+const WasmEnableLegacyJsInterop = process.env.WasmEnableLegacyJsInterop !== "false" ? true : false;
const monoDiagnosticsMock = process.env.MonoDiagnosticsMock === "true" ? true : false;
const terserConfig = {
compress: {
include: ["**/*.ts", "../../../../artifacts/bin/native/generated/**/*.ts"]
};
-const outputCodePlugins = [regexReplace(inlineAssert), consts({ productVersion, configuration, monoWasmThreads, monoDiagnosticsMock, gitHash }), typescript(typescriptConfigOptions)];
+const outputCodePlugins = [regexReplace(inlineAssert), consts({ productVersion, configuration, monoWasmThreads, monoDiagnosticsMock, gitHash, WasmEnableLegacyJsInterop }), typescript(typescriptConfigOptions)];
const externalDependencies = [
];
import BuildConfiguration from "consts:configuration";
import MonoWasmThreads from "consts:monoWasmThreads";
+import WasmEnableLegacyJsInterop from "consts:WasmEnableLegacyJsInterop";
import { CharPtrNull, DotnetModule, RuntimeAPI, MonoConfig, MonoConfigInternal } from "./types";
import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, INTERNAL, Module, runtimeHelpers } from "./imports";
import cwraps, { init_c_exports } from "./cwraps";
import { createPromiseController } from "./promise-controller";
import { string_decoder } from "./strings";
import { init_managed_exports } from "./managed-exports";
-import { init_legacy_exports } from "./net6-legacy/corebindings";
import { cwraps_internal } from "./exports-internal";
-import { cwraps_binding_api, cwraps_mono_api } from "./net6-legacy/exports-legacy";
import { CharPtr, InstantiateWasmCallBack, InstantiateWasmSuccessCallback } from "./types/emscripten";
import { instantiate_wasm_asset, mono_download_assets, resolve_asset_path, start_asset_download, wait_for_all_assets } from "./assets";
-import { BINDING, MONO } from "./net6-legacy/imports";
import { readSymbolMapFile } from "./logging";
import { mono_wasm_init_diagnostics } from "./diagnostics";
import { preAllocatePThreadWorkerPool, instantiateWasmPThreadWorkerPool } from "./pthreads/browser";
import { export_linker } from "./exports-linker";
import { endMeasure, MeasuredBlock, startMeasure } from "./profiler";
+// legacy
+import { init_legacy_exports } from "./net6-legacy/corebindings";
+import { cwraps_binding_api, cwraps_mono_api } from "./net6-legacy/exports-legacy";
+import { BINDING, MONO } from "./net6-legacy/imports";
+
let config: MonoConfigInternal = undefined as any;
let configLoaded = false;
export const dotnetReady = createPromiseController<any>();
// init_polyfills() is already called from export.ts
init_c_exports();
cwraps_internal(INTERNAL);
- cwraps_mono_api(MONO);
- cwraps_binding_api(BINDING);
-
+ if (WasmEnableLegacyJsInterop) {
+ cwraps_mono_api(MONO);
+ cwraps_binding_api(BINDING);
+ }
// removeRunDependency triggers the dependenciesFulfilled callback (runCaller) in
// emscripten - on a worker since we don't have any other dependencies that causes run() to get
// called too soon; and then it will get called a second time when dotnet.js calls it directly.
try {
const mark = startMeasure();
init_managed_exports();
- init_legacy_exports();
+ if (WasmEnableLegacyJsInterop) {
+ init_legacy_exports();
+ }
initialize_marshalers_to_js();
initialize_marshalers_to_cs();
runtimeHelpers._i52_error_scratch_buffer = <any>Module._malloc(4);
quit: Function,
locateFile: (path: string, prefix?: string) => string,
javaScriptExports: JavaScriptExports,
+ loadedFiles: string[],
}
export type GlobalizationMode =
/* Support for starting user threads is disabled */
#cmakedefine DISABLE_WASM_USER_THREADS
+/* Support legacy JavaScript interop */
+#cmakedefine ENABLE_LEGACY_JS_INTEROP
+
#endif/*__MONO_WASM_CONFIG_H__*/
<MonoWasmThreadsNoUser Condition="'$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreadsNoUser>
<MonoDiagnosticsMock Condition="'$(MonoDiagnosticsMock)' == '' and '$(Configuration)' == 'Release'">false</MonoDiagnosticsMock>
<MonoDiagnosticsMock Condition="'$(MonoDiagnosticsMock)' == '' and '$(Configuration)' == 'Debug'">true</MonoDiagnosticsMock>
+ <WasmEnableLegacyJsInterop Condition="'$(WasmEnableLegacyJsInterop)' == ''">true</WasmEnableLegacyJsInterop>
</PropertyGroup>
<PropertyGroup>
<CMakeBuildRuntimeConfigureCmd Condition="'$(WasmEnableSIMD)' == 'true' and '$(Configuration)' == 'Release'">$(CMakeBuildRuntimeConfigureCmd) -DWASM_OPT_ADDITIONAL_FLAGS="--enable-simd"</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd Condition="'$(MonoWasmThreadsNoUser)' == 'true'">$(CMakeBuildRuntimeConfigureCmd) -DDISABLE_WASM_USER_THREADS=1</CMakeBuildRuntimeConfigureCmd>
+ <CMakeBuildRuntimeConfigureCmd Condition="'$(WasmEnableLegacyJsInterop)' != 'true'">$(CMakeBuildRuntimeConfigureCmd) -DENABLE_LEGACY_JS_INTEROP=0</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd>$(CMakeBuildRuntimeConfigureCmd) $(CMakeConfigurationEmsdkPath)</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd Condition="'$(OS)' == 'Windows_NT'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" && call "$([MSBuild]::NormalizePath('$(EMSDK_PATH)', 'emsdk_env.bat'))" && $(CMakeBuildRuntimeConfigureCmd)</CMakeBuildRuntimeConfigureCmd>
SkipUnchangedFiles="true" />
<Exec Command="$(CMakeBuildRuntimeConfigureCmd)" WorkingDirectory="$(NativeBinDir)" />
- <Exec Command="$(CMakeBuildRuntimeCmd)" WorkingDirectory="$(NativeBinDir)" />
+ <Exec Command="$(CMakeBuildRuntimeCmd)" WorkingDirectory="$(NativeBinDir)"
+ EnvironmentVariables="WasmEnableLegacyJsInterop=$(WasmEnableLegacyJsInterop);MonoWasmThreads=$(MonoWasmThreads)" />
<ItemGroup>
<IcuDataFiles Include="$(NativeBinDir)*.dat" />
<Target Name="SetMonoRollupEnvironment" DependsOnTargets="GetProductVersions">
<PropertyGroup>
- <MonoRollupEnvironment>Configuration:$(Configuration),NativeBinDir:$(NativeBinDir),ProductVersion:$(ProductVersion),MonoWasmThreads:$(MonoWasmThreads),MonoDiagnosticsMock:$(MonoDiagnosticsMock)</MonoRollupEnvironment>
+ <MonoRollupEnvironment>Configuration:$(Configuration),NativeBinDir:$(NativeBinDir),ProductVersion:$(ProductVersion),MonoWasmThreads:$(MonoWasmThreads),WasmEnableLegacyJsInterop:$(WasmEnableLegacyJsInterop),MonoDiagnosticsMock:$(MonoDiagnosticsMock)</MonoRollupEnvironment>
</PropertyGroup>
<PropertyGroup>