Skip to content

Commit

Permalink
feedback from @kg
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Oct 1, 2021
1 parent f48fc92 commit bb623ea
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 28 deletions.
13 changes: 7 additions & 6 deletions src/mono/wasm/runtime/corebindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { JSHandle, GCHandle, MonoObject, t_RuntimeHelpers } from './types';
import { ArgsMarshalString } from './method-binding';
import { _create_primitive_converters } from './method-binding';

const fn_signatures: [csname: string, name: string, signature: ArgsMarshalString][] = [
const fn_signatures: [jsname: string, csname: string, signature: ArgsMarshalString][] = [
["_get_cs_owned_object_by_js_handle", "GetCSOwnedObjectByJSHandle", "ii!"],
["_get_cs_owned_object_js_handle", "GetCSOwnedObjectJSHandle", 'mi'],
["_try_get_cs_owned_object_js_handle", "TryGetCSOwnedObjectJSHandle", "mi"],
Expand All @@ -31,10 +31,10 @@ const fn_signatures: [csname: string, name: string, signature: ArgsMarshalString

export interface t_CSwraps {
// BINDING
_get_cs_owned_object_by_js_handle(jsHandle: JSHandle, shouldAddInflight: number): void;
_get_cs_owned_object_js_handle(jsHandle: JSHandle, shouldAddInflight: number): MonoObject;
_try_get_cs_owned_object_js_handle(obj: MonoObject, shouldAddInflight: number): JSHandle;
_create_cs_owned_proxy(jsHandle: JSHandle, mappedType: number, shouldAddInflight: number): MonoObject;
_get_cs_owned_object_by_js_handle(jsHandle: JSHandle, shouldAddInflight: 0 | 1): void;
_get_cs_owned_object_js_handle(jsHandle: JSHandle, shouldAddInflight: 0 | 1): MonoObject;
_try_get_cs_owned_object_js_handle(obj: MonoObject, shouldAddInflight: 0 | 1): JSHandle;
_create_cs_owned_proxy(jsHandle: JSHandle, mappedType: number, shouldAddInflight: 0 | 1): MonoObject;

_get_js_owned_object_by_gc_handle(gcHandle: GCHandle): MonoObject;
_get_js_owned_object_gc_handle(obj: MonoObject): GCHandle
Expand Down Expand Up @@ -69,7 +69,8 @@ export default wrapped_cs_functions;

export const runtimeHelpers: t_RuntimeHelpers = <any>{
namespace: "System.Runtime.InteropServices.JavaScript",
classname: "Runtime"
classname: "Runtime",
loaded_files: [],
}

let bind_runtime_method: Function
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/cwraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface t_Cwraps {
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_assembly_find_method(klass: MonoClass, name: CharPtr, args: number): MonoMethod;
mono_wasm_assembly_find_method(klass: MonoClass, name: string, args: number): MonoMethod;
mono_wasm_invoke_method(method: MonoMethod, this_arg: MonoObject, params: VoidPtr, out_exc: MonoObject): MonoObject;
mono_wasm_string_get_utf8(str: MonoString): CharPtr;
mono_wasm_string_from_utf16(str: CharPtr, len: number): MonoString;
Expand Down
7 changes: 3 additions & 4 deletions src/mono/wasm/runtime/debug.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { Module, MONO } from './modules'
import { Module } from './modules'
import { toBase64StringImpl, _base64_to_uint8 } from './base64'
import cwraps from './cwraps'
import { runtimeHelpers } from './corebindings';
import { loaded_files } from './startup';

var commands_received: any;
var _call_function_res_cache: any = {}
Expand All @@ -15,7 +14,7 @@ var _debugger_buffer: NativePointer;
var _debugger_heap_bytes: Uint8Array;

export function mono_wasm_runtime_ready() {
runtimeHelpers.mono_wasm_runtime_is_ready = MONO.mono_wasm_runtime_is_ready = true;
runtimeHelpers.mono_wasm_runtime_is_ready = true;

// FIXME: where should this go?
_next_call_function_res_id = 0;
Expand Down Expand Up @@ -112,7 +111,7 @@ export function mono_wasm_raise_debug_event(event: WasmEvent, args = {}) {
// Used by the debugger to enumerate loaded dlls and pdbs
export function mono_wasm_get_loaded_files() {
cwraps.mono_wasm_set_is_debugger_attached(true);
return loaded_files;
return runtimeHelpers.loaded_files;
}

function _create_proxy_from_object_id(objectId: string, details: any) {
Expand Down
25 changes: 18 additions & 7 deletions src/mono/wasm/runtime/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import {
mono_wasm_fire_debugger_agent_message,
} from './debug'
import { setMONO, setBINDING } from './modules'
import { MonoConfig } from './types'
import { MonoConfig, MonoConfigError } from './types'
import {
mono_load_runtime_and_bcl_args, mono_wasm_load_config,
mono_wasm_setenv, mono_wasm_set_runtime_options,
mono_wasm_load_data_archive, mono_wasm_asm_loaded,
mono_bindings_init, loaded_files,
mono_bindings_init,
mono_wasm_invoke_js_blazor, mono_wasm_invoke_js_marshalled, mono_wasm_invoke_js_unmarshalled
} from './startup'
import { mono_set_timeout, schedule_background_exec } from './scheduling'
Expand Down Expand Up @@ -57,12 +57,14 @@ import { runtimeHelpers } from './corebindings'

export let MONO: MONO = <any>{
// current "public" MONO API
loaded_files,
mono_wasm_setenv,
mono_wasm_load_bytes_into_heap,
mono_wasm_load_icu_data,
mono_wasm_runtime_ready,
mono_wasm_load_data_archive,
get loaded_files() {
return runtimeHelpers.loaded_files
},

// EM_JS macro
string_decoder,
Expand All @@ -76,7 +78,6 @@ export let MONO: MONO = <any>{
//mono.mono_wasm_get_icudt_name = mono_wasm_get_icudt_name,

// used in debugger
mono_wasm_runtime_is_ready: runtimeHelpers.mono_wasm_runtime_is_ready,
mono_wasm_get_loaded_files,
mono_wasm_add_dbg_command_received,
mono_wasm_send_dbg_command_with_parms,
Expand All @@ -88,12 +89,17 @@ export let MONO: MONO = <any>{
mono_wasm_debugger_resume,
mono_wasm_detach_debugger,
mono_wasm_raise_debug_event,
get mono_wasm_runtime_is_ready() {
return runtimeHelpers.mono_wasm_runtime_is_ready
},

// used in tests
mono_load_runtime_and_bcl_args,
mono_wasm_load_config,
mono_wasm_set_runtime_options,
// config ,
get config() {
return runtimeHelpers.config
},
}

export let BINDING: BINDING = <any>{
Expand Down Expand Up @@ -134,6 +140,11 @@ export function export_to_emscripten(mono: any, binding: any, dotnet: any, modul
setBINDING(binding, module);

Object.assign(module, _linker_exports);
Object.assign(module, {
get config() {
return runtimeHelpers.config
},
});

// tests
module.mono_call_static_method = call_static_method
Expand Down Expand Up @@ -195,12 +206,12 @@ export const _linker_exports = {
// this represents visibility in the javascript
// like https://github.com/dotnet/aspnetcore/blob/main/src/Components/Web.JS/src/Platform/Mono/MonoTypes.ts
export interface MONO {
loaded_files: string[];
mono_wasm_runtime_ready: typeof mono_wasm_runtime_ready
mono_wasm_setenv: typeof mono_wasm_setenv
mono_wasm_load_data_archive: typeof mono_wasm_load_data_archive;
mono_wasm_load_bytes_into_heap: typeof mono_wasm_load_bytes_into_heap;
mono_wasm_load_icu_data: typeof mono_wasm_load_icu_data;
loaded_files: string[];
}

// this represents visibility in the javascript
Expand All @@ -220,7 +231,7 @@ export interface BINDING {

// how we extended wasm Module
export type t_ModuleExtension = t_Module & {
config?: MonoConfig,
config?: MonoConfig | MonoConfigError,

//tests
mono_call_static_method: typeof call_static_method
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/library-dotnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const linked_functions = [
'mono_wasm_get_icudt_name',
]

// this generates simple adapter during emcc compilation
// -- 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 (var linked_function of linked_functions) {
const fn_template = `return __dotnet_runtime._linker_exports.${linked_function}.apply(__dotnet_runtime, arguments)`;
DotNetSupportLib[linked_function] = new Function(fn_template)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/method-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const _signature_converters = new Map<string, Converter>();

const _method_descriptions = new Map();

export function find_method(klass: MonoClass, name: CharPtr, n: number) {
export function find_method(klass: MonoClass, name: string, n: number) {
var result = cwraps.mono_wasm_assembly_find_method(klass, name, n);
if (result) {
_method_descriptions.set(result, name);
Expand Down
11 changes: 3 additions & 8 deletions src/mono/wasm/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import { runtimeHelpers, set_bind_runtime_method } from './corebindings';
import { bind_runtime_method, get_method, _create_primitive_converters } from './method-binding';
import { conv_string } from './strings';

export const loaded_files: string[] = []


export function mono_wasm_invoke_js_blazor(exceptionMessage: Int32Ptr, callInfo: any, arg0: any, arg1: any, arg2: any) {
try {
var blazorExports = (<any>globalThis).Blazor;
Expand Down Expand Up @@ -275,7 +272,7 @@ function _get_fetch_file_cb_from_args(args: MonoConfig): (asset: string) => Prom
}

function _finalize_startup(args: MonoConfig, ctx: MonoInitContext) {
ctx.loaded_files.forEach(value => loaded_files.push(value.url));
ctx.loaded_files.forEach(value => runtimeHelpers.loaded_files.push(value.url));
if (ctx.tracing) {
console.log("MONO_WASM: loaded_assets: " + JSON.stringify(ctx.loaded_assets));
console.log("MONO_WASM: loaded_files: " + JSON.stringify(ctx.loaded_files));
Expand Down Expand Up @@ -591,13 +588,11 @@ export async function mono_wasm_load_config(configFilePath: string) {
} else { // shell or worker
config = JSON.parse(read(configFilePath)); // read is a v8 debugger command
}
MONO.config = config;
module.config = MONO.config;
runtimeHelpers.config = config
} catch (e) {
const errMessage = "failed to load config file " + configFilePath;
console.error(errMessage)
MONO.config = <any>{ message: errMessage, error: e };
module.config = MONO.config;
runtimeHelpers.config = { message: errMessage, error: e };
} finally {
Module.removeRunDependency(configFilePath);
}
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export type t_RuntimeHelpers = {
_class_boolean: MonoClass;
mono_wasm_runtime_is_ready: boolean;
mono_wasm_bindings_is_ready: boolean;

loaded_files: string[];
config: MonoConfig|MonoConfigError;
}

export const wasm_type_symbol = Symbol.for("wasm type");
Expand Down

0 comments on commit bb623ea

Please sign in to comment.