Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { BINDINGType, MONOType } from 'dotnet/dotnet-legacy';
export let BINDING: BINDINGType = undefined as any;
export let MONO: MONOType = undefined as any;
export let Module: DotnetModuleConfig & EmscriptenModule = undefined as any;
let MONO_INTERNAL: any = undefined as any;

const uint64HighOrderShift = Math.pow(2, 32);
const maxSafeNumberHighPart = Math.pow(2, 21) - 1; // The high-order int32 from Number.MAX_SAFE_INTEGER
Expand Down Expand Up @@ -146,7 +147,7 @@ export const monoPlatform: Platform = {

beginHeapLock: function beginHeapLock() {
assertHeapIsNotLocked();
currentHeapLock = new MonoHeapLock();
currentHeapLock = MonoHeapLock.create();
return currentHeapLock;
},

Expand Down Expand Up @@ -358,10 +359,11 @@ async function createRuntimeInstance(resourceLoader: WebAssemblyResourceLoader):
(dotnet as any).withModuleConfig(moduleConfig);

const runtime = await dotnet.create();
const { MONO: mono, BINDING: binding, Module: module, setModuleImports } = runtime;
const { MONO: mono, BINDING: binding, Module: module, setModuleImports, INTERNAL: mono_internal } = runtime;
Module = module;
BINDING = binding;
MONO = mono;
MONO_INTERNAL = mono_internal;

Blazor._internal.dotNetCriticalError = printErr;
Blazor._internal.loadLazyAssembly = (assemblyNameToLoad) => loadLazyAssembly(resourceLoader, assemblyNameToLoad);
Expand Down Expand Up @@ -554,6 +556,8 @@ class MonoHeapLock implements HeapLock {
throw new Error('Trying to release a lock which isn\'t current');
}

MONO_INTERNAL.mono_wasm_gc_unlock();

currentHeapLock = null;

while (this.postReleaseActions?.length) {
Expand All @@ -566,4 +570,9 @@ class MonoHeapLock implements HeapLock {
assertHeapIsNotLocked();
}
}

static create(): MonoHeapLock {
MONO_INTERNAL.mono_wasm_gc_lock();
return new MonoHeapLock();
}
}