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

[browser] threads & js cleanup #86278

Merged
merged 10 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
small tweaks
  • Loading branch information
pavelsavara committed May 24, 2023
commit a4e69619d2cbc6055c163f27dc534a6cce422dee
10 changes: 10 additions & 0 deletions src/mono/wasm/runtime/invoke-cs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";

import MonoWasmThreads from "consts:monoWasmThreads";
import { Module, runtimeHelpers } from "./globals";
import { bind_arg_marshal_to_cs } from "./marshal-to-cs";
Expand Down Expand Up @@ -86,6 +88,13 @@ export function mono_wasm_bind_cs_function(fully_qualified_name: MonoStringRef,
bound_fn = bind_fn(closure);
}

// this is just to make debugging easier.
// It's not CSP compliant and possibly not performant, that's why it's only enabled in debug builds
// in Release configuration, it would be a trimmed by rollup
if (BuildConfiguration === "Debug") {
bound_fn = new Function("fn", "return (function JSExport_" + methodname + "(){ return fn.apply(this, arguments)});")(bound_fn);
}

(<any>bound_fn)[bound_cs_function_symbol] = true;

_walk_exports_to_set_function(assembly, namespace, classname, methodname, signature_hash, bound_fn);
Expand Down Expand Up @@ -235,6 +244,7 @@ type BindingClosure = {
}

export function invoke_method_and_handle_exception(method: MonoMethod, args: JSMarshalerArguments): void {
assert_synchronization_context();
const fail = cwraps.mono_wasm_invoke_method_bound(method, args);
if (fail) throw new Error("ERR24: Unexpected error: " + string_decoder.copy(fail));
if (is_args_exception(args)) {
Expand Down
9 changes: 9 additions & 0 deletions src/mono/wasm/runtime/invoke-js.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import BuildConfiguration from "consts:configuration";

import { marshal_exception_to_cs, bind_arg_marshal_to_cs } from "./marshal-to-cs";
import { get_signature_argument_count, bound_js_function_symbol, get_sig, get_signature_version, get_signature_type, imported_js_function_symbol } from "./marshal";
import { setI32_unchecked } from "./memory";
Expand Down Expand Up @@ -83,6 +85,13 @@ export function mono_wasm_bind_js_function(function_name: MonoStringRef, module_
bound_fn = bind_fn(closure);
}

// this is just to make debugging easier.
// It's not CSP compliant and possibly not performant, that's why it's only enabled in debug builds
// in Release configuration, it would be a trimmed by rollup
if (BuildConfiguration === "Debug") {
bound_fn = new Function("fn", "return (function JSImport_" + js_function_name.replaceAll(".", "_") + "(){ return fn.apply(this, arguments)});")(bound_fn);
}

(<any>bound_fn)[imported_js_function_symbol] = true;
const fn_handle = fn_wrapper_by_fn_handle.length;
fn_wrapper_by_fn_handle.push(bound_fn);
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/loader/worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MonoConfig } from "../types";
import { MonoConfigInternal } from "../types/internal";
import { deep_merge_config } from "./config";
import { deep_merge_config, normalizeConfig } from "./config";
import { ENVIRONMENT_IS_WEB, loaderHelpers } from "./globals";
import { mono_log_debug } from "./logging";

Expand Down Expand Up @@ -30,6 +30,7 @@ function onMonoConfigReceived(config: MonoConfigInternal): void {
}

deep_merge_config(loaderHelpers.config, config);
normalizeConfig();
mono_log_debug("mono config received");
workerMonoConfigReceived = true;
loaderHelpers.afterConfigLoaded.promise_control.resolve(loaderHelpers.config);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ export function bindings_init(): void {
try {
const mark = startMeasure();
init_managed_exports();
if (WasmEnableLegacyJsInterop && !disableLegacyJsInterop) {
if (WasmEnableLegacyJsInterop && !disableLegacyJsInterop && !ENVIRONMENT_IS_PTHREAD) {
init_legacy_exports();
}
if (MonoWasmThreads && !ENVIRONMENT_IS_PTHREAD) {
Expand Down