-
Couldn't load subscription status.
- Fork 5.2k
[browser][coreCLR] TypeScript host skeleton #119866
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
47a0b01
rebase
pavelsavara 32680f9
more
pavelsavara b4d1f97
fix
pavelsavara 1b932b5
more
pavelsavara 1cf1e51
Update src/native/corehost/browserhost/loader/run.ts
pavelsavara 828f9e9
feedback
pavelsavara 8b0301c
more sharing by table/index
pavelsavara 4af1ad6
fix
pavelsavara 12619cf
fix
pavelsavara ac5aa58
comment
pavelsavara 3fa7292
feedback: dotnet prefix
pavelsavara c456f3d
feedback about names in dotnetUpdateModuleInternals()
pavelsavara 549a859
ecma feedback
pavelsavara 7e2b052
feedback about rollup config flags
pavelsavara 7258af3
todo feedback in memory
pavelsavara bd33d27
ExceptionHandling.RaiseAppDomainUnhandledExceptionEvent
pavelsavara ddbfa3e
todo fetchWasm feedback
pavelsavara df9f8c2
missing config feedback
pavelsavara d197301
DotnetHostBuilder todo feedback
pavelsavara d82c891
cwraps todo
pavelsavara 3779a39
isConfigReady feedback
pavelsavara 5c7e603
Merge branch 'main' into browser_host_ts
pavelsavara 84589d5
WASM-TODO
pavelsavara 9d02e42
fix type names
pavelsavara 8496bc2
Merge branch 'main' into browser_host_ts
pavelsavara 46e640a
isConfigReady feedback
pavelsavara 3944860
Merge branch 'main' into browser_host_ts
pavelsavara 246530b
fix dotnet.boot.js
pavelsavara 5bd6b41
ENVIRONMENT_IS_* feedback
pavelsavara faa1d42
fix
pavelsavara ba46624
_zero_region feedback
pavelsavara 8f60c56
tabulateLoaderExports feedback
pavelsavara a59a4c5
DOTNET: feedback
pavelsavara 9e058b4
CoreCLRInitialized feedback
pavelsavara 0b0e5b6
crossLink feedback
pavelsavara 53b7025
feedback: remove exports, keep IIFE
pavelsavara 43bfcd7
exchange feedback
pavelsavara c1613ef
feedback: document the JS symbol exchange
pavelsavara 773b59e
- added new emscripten JS module libSystem.Browser.Utils.js
pavelsavara 702a096
fix
pavelsavara fe9fc87
Merge branch 'main' into browser_host_ts
pavelsavara f106a71
cleanup
pavelsavara 42c0ba7
lint, minor fixes
pavelsavara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| export * from "../../libs/Common/JavaScript/cross-module"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| import { } from "../../../libs/Common/JavaScript/cross-linked"; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| import type { CharPtr, VoidPtr, VoidPtrPtr } from "./types"; | ||
| import { } from "./cross-linked"; // ensure ambient symbols are declared | ||
|
|
||
| const loadedAssemblies : Map<string, { ptr: number, length: number }> = new Map(); | ||
|
|
||
| export function registerDllBytes(bytes: Uint8Array, asset: { name: string }) { | ||
| const sp = Module.stackSave(); | ||
| try { | ||
| const sizeOfPtr = 4; | ||
| const ptrPtr = Module.stackAlloc(sizeOfPtr); | ||
| if (Module._posix_memalign(ptrPtr as any, 16, bytes.length)) { | ||
| throw new Error("posix_memalign failed"); | ||
| } | ||
|
|
||
| const ptr = Module.HEAPU32[ptrPtr as any >>> 2]; | ||
| Module.HEAPU8.set(bytes, ptr); | ||
| loadedAssemblies.set(asset.name, { ptr, length: bytes.length }); | ||
| } finally { | ||
| Module.stackRestore(sp); | ||
| } | ||
| } | ||
|
|
||
| // bool BrowserHost_ExternalAssemblyProbe(const char* pathPtr, /*out*/ void **outDataStartPtr, /*out*/ int64_t* outSize); | ||
| export function BrowserHost_ExternalAssemblyProbe(pathPtr:CharPtr, outDataStartPtr:VoidPtrPtr, outSize:VoidPtr) { | ||
| const path = Module.UTF8ToString(pathPtr); | ||
| const assembly = loadedAssemblies.get(path); | ||
| if (assembly) { | ||
| Module.HEAPU32[outDataStartPtr as any >>> 2] = assembly.ptr; | ||
| // int64_t target | ||
| Module.HEAPU32[outSize as any >>> 2] = assembly.length; | ||
| Module.HEAPU32[((outSize as any) + 4) >>> 2] = 0; | ||
| return true; | ||
| } | ||
| Module.HEAPU32[outDataStartPtr as any >>> 2] = 0; | ||
| Module.HEAPU32[outSize as any >>> 2] = 0; | ||
| Module.HEAPU32[((outSize as any) + 4) >>> 2] = 0; | ||
| return false; | ||
| } | ||
|
|
||
| export function BrowserHost_ResolveMain(exitCode:number) { | ||
| dotnetLoaderExports.resolveRunMainPromise(exitCode); | ||
| } | ||
|
|
||
| export function BrowserHost_RejectMain(reason:any) { | ||
| dotnetLoaderExports.rejectRunMainPromise(reason); | ||
| } | ||
|
|
||
| // WASM-TODO: take ideas from Mono | ||
| // - second call to exit should be silent | ||
| // - second call to exit not override the first exit code | ||
| // - improve reason extraction | ||
| // - install global handler for unhandled exceptions and promise rejections | ||
| // - raise ExceptionHandling.RaiseAppDomainUnhandledExceptionEvent() | ||
| export function exit(exit_code: number, reason: any): void { | ||
| const reasonStr = reason ? (reason.stack ? reason.stack || reason.message : reason.toString()) : ""; | ||
| if (exit_code !== 0) { | ||
| dotnetLogger.error(`Exit with code ${exit_code} ${reason ? "and reason: " + reasonStr : ""}`); | ||
| } | ||
| if (dotnetJSEngine.IS_NODE) { | ||
| (globalThis as any).process.exit(exit_code); | ||
| } | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export async function runMain(mainAssemblyName?: string, args?: string[]): Promise<number> { | ||
pavelsavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // int BrowserHost_ExecuteAssembly(char * assemblyPath) | ||
| const res = Module.ccall("BrowserHost_ExecuteAssembly", "number", ["string"], [mainAssemblyName]) as number; | ||
| if (res != 0) { | ||
| const reason = new Error("Failed to execute assembly"); | ||
| exit(res, reason); | ||
| throw reason; | ||
| } | ||
|
|
||
| return dotnetLoaderExports.getRunMainPromise(); | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export async function runMainAndExit(mainAssemblyName?: string, args?: string[]): Promise<number> { | ||
| try { | ||
| await runMain(mainAssemblyName, args); | ||
| } catch (error) { | ||
| exit(1, error); | ||
| throw error; | ||
| } | ||
| exit(0, null); | ||
| return 0; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export function setEnvironmentVariable(name: string, value: string): void { | ||
| throw new Error("Not implemented"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| import type { InternalExchange, BrowserHostExports, RuntimeAPI, BrowserHostExportsTable } from "./types"; | ||
| import { InternalExchangeIndex } from "./types"; | ||
| import { } from "./cross-linked"; // ensure ambient symbols are declared | ||
|
|
||
| import { exit, runMain, runMainAndExit, setEnvironmentVariable, registerDllBytes } from "./host"; | ||
| import { | ||
| setHeapB32, setHeapB8, setHeapU8, setHeapU16, setHeapU32, setHeapI8, setHeapI16, setHeapI32, setHeapI52, setHeapU52, setHeapI64Big, setHeapF32, setHeapF64, | ||
| getHeapB32, getHeapB8, getHeapU8, getHeapU16, getHeapU32, getHeapI8, getHeapI16, getHeapI32, getHeapI52, getHeapU52, getHeapI64Big, getHeapF32, getHeapF64, | ||
| localHeapViewI8, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewU8, localHeapViewU16, localHeapViewU32, localHeapViewF32, localHeapViewF64, | ||
| isSharedArrayBuffer, | ||
| } from "./memory"; | ||
|
|
||
| export function dotnetInitializeModule(internals: InternalExchange): void { | ||
| const runtimeApiLocal: Partial<RuntimeAPI> = { | ||
| runMain, | ||
| runMainAndExit, | ||
| setEnvironmentVariable, | ||
| exit, | ||
| setHeapB32, setHeapB8, setHeapU8, setHeapU16, setHeapU32, setHeapI8, setHeapI16, setHeapI32, setHeapI52, setHeapU52, setHeapI64Big, setHeapF32, setHeapF64, | ||
| getHeapB32, getHeapB8, getHeapU8, getHeapU16, getHeapU32, getHeapI8, getHeapI16, getHeapI32, getHeapI52, getHeapU52, getHeapI64Big, getHeapF32, getHeapF64, | ||
| localHeapViewI8, localHeapViewI16, localHeapViewI32, localHeapViewI64Big, localHeapViewU8, localHeapViewU16, localHeapViewU32, localHeapViewF32, localHeapViewF64, | ||
| }; | ||
|
|
||
| const hostNativeExportsLocal: BrowserHostExports = { | ||
| registerDllBytes, | ||
| isSharedArrayBuffer | ||
| }; | ||
| dotnetSetInternals(internals); | ||
| Object.assign(internals[InternalExchangeIndex.RuntimeAPI], runtimeApiLocal); | ||
| internals[InternalExchangeIndex.BrowserHostExportsTable] = tabulateBrowserHostExports(hostNativeExportsLocal); | ||
| const updates = internals[InternalExchangeIndex.InternalUpdatesCallbacks]; | ||
| if (!updates.includes(dotnetUpdateModuleInternals)) updates.push(dotnetUpdateModuleInternals); | ||
| dotnetUpdateAllInternals(); | ||
pavelsavara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function tabulateBrowserHostExports(map:BrowserHostExports):BrowserHostExportsTable { | ||
| // keep in sync with dotnetUpdateModuleInternals() | ||
| return [ | ||
| map.registerDllBytes, | ||
| map.isSharedArrayBuffer, | ||
| ]; | ||
| } | ||
| } | ||
|
|
||
| export { BrowserHost_ExternalAssemblyProbe, BrowserHost_ResolveMain, BrowserHost_RejectMain } from "./host"; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.