Skip to content

Commit cc28732

Browse files
Remove use of legacy interop preventing CSP compliance in Blazor WebAssembly (#48182)
1 parent 8489285 commit cc28732

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { WebAssemblyResourceLoader, LoadingResource } from '../WebAssemblyResour
1111
import { Platform, System_Array, Pointer, System_Object, System_String, HeapLock, PlatformApi } from '../Platform';
1212
import { WebAssemblyBootResourceType, WebAssemblyStartOptions } from '../WebAssemblyStartOptions';
1313
import { Blazor } from '../../GlobalExports';
14-
import { DotnetModuleConfig, EmscriptenModule, MonoConfig, ModuleAPI, BootJsonData, ICUDataMode } from 'dotnet';
14+
import { DotnetModuleConfig, EmscriptenModule, MonoConfig, ModuleAPI, BootJsonData, ICUDataMode, RuntimeAPI } from 'dotnet';
1515
import { BINDINGType, MONOType } from 'dotnet/dotnet-legacy';
1616
import { WebAssemblyComponentDescriptor, discoverComponents, discoverPersistedState } from '../../Services/ComponentDescriptorDiscovery';
1717
import { attachRootComponentToElement, attachRootComponentToLogicalElement } from '../../Rendering/Renderer';
@@ -24,6 +24,7 @@ export let BINDING: BINDINGType = undefined as any;
2424
export let MONO: MONOType = undefined as any;
2525
export let Module: DotnetModuleConfig & EmscriptenModule = undefined as any;
2626
let MONO_INTERNAL: any = undefined as any;
27+
let runtime: RuntimeAPI = undefined as any;
2728

2829
const uint64HighOrderShift = Math.pow(2, 32);
2930
const maxSafeNumberHighPart = Math.pow(2, 21) - 1; // The high-order int32 from Number.MAX_SAFE_INTEGER
@@ -62,10 +63,8 @@ export const monoPlatform: Platform = {
6263
},
6364

6465
callEntryPoint: async function callEntryPoint(assemblyName: string): Promise<any> {
65-
const emptyArray = [[]];
66-
6766
try {
68-
await BINDING.call_assembly_entry_point(assemblyName, emptyArray, 'm');
67+
await runtime.runMain(assemblyName, []);
6968
} catch (error) {
7069
console.error(error);
7170
showErrorNotification();
@@ -131,18 +130,7 @@ export const monoPlatform: Platform = {
131130
return unboxedValue;
132131
}
133132

134-
let decodedString: string | null | undefined;
135-
if (currentHeapLock) {
136-
decodedString = currentHeapLock.stringCache.get(fieldValue);
137-
if (decodedString === undefined) {
138-
decodedString = BINDING.conv_string(fieldValue as any as System_String);
139-
currentHeapLock.stringCache.set(fieldValue, decodedString);
140-
}
141-
} else {
142-
decodedString = BINDING.conv_string(fieldValue as any as System_String);
143-
}
144-
145-
return decodedString;
133+
return BINDING.conv_string(fieldValue as any as System_String);
146134
},
147135

148136
readStructField: function readStructField<T extends Pointer>(baseAddress: Pointer, fieldOffset?: number): T {
@@ -321,7 +309,7 @@ async function createRuntimeInstance(options: Partial<WebAssemblyStartOptions>):
321309

322310
anyDotnet.withStartupOptions(options).withModuleConfig(moduleConfig);
323311

324-
const runtime = await dotnet.create();
312+
runtime = await dotnet.create();
325313
const { MONO: mono, BINDING: binding, Module: module, setModuleImports, INTERNAL: mono_internal } = runtime;
326314
Module = module;
327315
BINDING = binding;
@@ -472,9 +460,6 @@ function assertHeapIsNotLocked() {
472460
}
473461

474462
class MonoHeapLock implements HeapLock {
475-
// Within a given heap lock, it's safe to cache decoded strings since the memory can't change
476-
stringCache = new Map<number, string | null>();
477-
478463
// eslint-disable-next-line @typescript-eslint/ban-types
479464
private postReleaseActions?: Function[];
480465

0 commit comments

Comments
 (0)