Skip to content

Commit 6ebd8ec

Browse files
committed
more
1 parent 86c5d89 commit 6ebd8ec

File tree

16 files changed

+101
-45
lines changed

16 files changed

+101
-45
lines changed

src/coreclr/vm/wasm/callhelpers.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,27 @@ extern "C" void SystemJS_ExecuteTimerCallback()
785785
Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler();
786786
}
787787

788+
static MethodDesc* MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_IntPtr_RetVoid = nullptr;
789+
static void Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace(void* arg0)
790+
{
791+
int64_t args[1] =
792+
{
793+
(int64_t)arg0
794+
};
795+
796+
// Lazy lookup of MethodDesc for the function export scenario.
797+
if (!MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_IntPtr_RetVoid)
798+
{
799+
LookupMethodByName("System.Runtime.InteropServices.JavaScript.JavaScriptExports, System.Runtime.InteropServices.JavaScript, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "GetManagedStackTrace", &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_IntPtr_RetVoid);
800+
}
801+
ExecuteInterpretedMethodFromUnmanaged(MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_IntPtr_RetVoid, (int8_t*)args, sizeof(args), nullptr);
802+
}
803+
804+
extern "C" void SystemInteropJS_GetManagedStackTrace(void* arg0)
805+
{
806+
Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace(arg0);
807+
}
808+
788809
extern const ReverseThunkMapEntry g_ReverseThunks[] =
789810
{
790811
{ 100678287, { &MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler } },

src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/JavaScriptExports.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
229229
}
230230
}
231231

232+
[UnmanagedCallersOnly(EntryPoint = "SystemInteropJS_GetManagedStackTrace")]
232233
// the marshaled signature is: string GetManagedStackTrace(GCHandle exception)
233234
public static void GetManagedStackTrace(JSMarshalerArgument* arguments_buffer)
234235
{

src/native/libs/Common/JavaScript/cross-module/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function dotnetUpdateInternalsSubscriber() {
142142
// keep in sync with interopJavaScriptExportsToTable()
143143
function interopJavaScriptExportsFromTable(table: InteropJavaScriptExportsTable, interop: InteropJavaScriptExports): void {
144144
const interopLocal: InteropJavaScriptExports = {
145+
SystemInteropJS_GetManagedStackTrace: table[0],
145146
};
146147
Object.assign(interop, interopLocal);
147148
}

src/native/libs/Common/JavaScript/types/exchange.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ export type BrowserHostExportsTable = [
7575
]
7676

7777
export type InteropJavaScriptExports = {
78+
SystemInteropJS_GetManagedStackTrace: typeof _SystemInteropJS_GetManagedStackTrace,
7879
}
7980

8081
export type InteropJavaScriptExportsTable = [
82+
typeof _SystemInteropJS_GetManagedStackTrace,
8183
]
8284

8385
export type NativeBrowserExports = {

src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/cancelable-promise.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
import { ManagedObject } from "./marshaled-types";
55
import { ControllablePromise, GCHandle, MarshalerToCs } from "./types";
6-
import { completeTask, isRuntimeRunning } from "./utils";
6+
import { isRuntimeRunning } from "./utils";
77
import { lookupJsOwnedObject, teardownManagedProxy } from "./gc-handles";
88
import { marshalCsObjectToCs } from "./marshal-to-cs";
9+
import { completeTask } from "./managed-exports";
910

1011
const promiseHolderSymbol = Symbol.for("wasm promise_holder");
1112

src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/gc-handles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { dotnetAssert, dotnetLogger } from "./cross-module";
77

88
import type { GCHandle, JSHandle, WeakRefInternal } from "./types";
99
import { GCHandleNull } from "./types";
10-
import { assertJsInterop, isRuntimeRunning, releaseJsOwnedObjectByGcHandle } from "./utils";
10+
import { assertJsInterop, isRuntimeRunning } from "./utils";
1111
import { useWeakRef, createStrongRef, createWeakRef } from "./weak-ref";
1212
import { jsImportWrapperByFnHandle } from "./invoke-js";
1313
import { boundCsFunctionSymbol, importedJsFunctionSymbol, proxyDebugSymbol } from "./marshal";
1414
import { exportsByAssembly } from "./invoke-cs";
15+
import { releaseJsOwnedObjectByGcHandle } from "./managed-exports";
1516

1617
const useFinalizationRegistry = typeof globalThis.FinalizationRegistry === "function";
1718
let jsOwnedObjectRegistry: FinalizationRegistry<any>;

src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/invoke-cs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
import { assertJsInterop, bindAssemblyExports } from "./utils";
4+
import { bindAssemblyExports } from "./managed-exports";
5+
import { assertJsInterop } from "./utils";
56

67
export const exportsByAssembly: Map<string, any> = new Map();
78

src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/invoke-js.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import BuildConfiguration from "consts:configuration";
55

6-
import { dotnetBrowserUtilsExports, dotnetApi, dotnetAssert, dotnetLogger, VoidPtrNull } from "./cross-module";
6+
import { dotnetBrowserUtilsExports, dotnetApi, dotnetAssert, dotnetLogger, VoidPtrNull, Module } from "./cross-module";
77

88
import type { BindingClosure, BoundMarshalerToJs, JSFnHandle, JSFunctionSignature, JSHandle, JSMarshalerArguments, VoidPtr, WrappedJSFunction } from "./types";
99
import { MarshalerType, MeasuredBlock } from "./types";
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
import { dotnetInteropJSExports, Module } from "./cross-module";
5+
import { allocStackFrame, getArg, setArgType, setGcHandle as setGcHandle } from "./marshal";
6+
import { marshalStringToJs } from "./marshal-to-js";
7+
import { MarshalerType, type GCHandle, type MarshalerToCs, type MarshalerToJs } from "./types";
8+
import { assertRuntimeRunning, isRuntimeRunning } from "./utils";
9+
10+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11+
export function releaseJsOwnedObjectByGcHandle(gcHandle: GCHandle) {
12+
// TODO-WASM
13+
}
14+
15+
export function getManagedStackTrace(exceptionGCHandle: GCHandle): string {
16+
assertRuntimeRunning();
17+
const sp = Module.stackSave();
18+
try {
19+
const size = 3;
20+
const args = allocStackFrame(size);
21+
22+
const arg1 = getArg(args, 2);
23+
setArgType(arg1, MarshalerType.Exception);
24+
setGcHandle(arg1, exceptionGCHandle);
25+
26+
dotnetInteropJSExports.SystemInteropJS_GetManagedStackTrace(args);
27+
28+
const res = getArg(args, 1);
29+
return marshalStringToJs(res)!;
30+
} finally {
31+
if (isRuntimeRunning()) Module.stackRestore(sp);
32+
}
33+
}
34+
35+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
36+
export function callDelegate(callbackGcHandle: GCHandle, arg1Js: any, arg2Js: any, arg3Js: any, resConverter?: MarshalerToJs, arg1Converter?: MarshalerToCs, arg2Converter?: MarshalerToCs, arg3Converter?: MarshalerToCs) {
37+
}
38+
39+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
40+
export function completeTask(holder_gc_handle: GCHandle, error?: any, data?: any, res_converter?: MarshalerToCs) {
41+
42+
}
43+
44+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
45+
export function bindAssemblyExports(assemblyName: string): Promise<void> {
46+
// TODO-WASM
47+
return Promise.resolve();
48+
}

src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/marshal-to-js.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { GCHandleNull, JavaScriptMarshalerArgSize, MarshalerType } from "./types
1010
import { arrayElementSize, csToJsMarshalers, getArg, getArgBool, getArgDate, getArgElementType, getArgF32, getArgF64, getArgGcHandle, getArgI16, getArgI32, getArgI52, getArgI64Big, getArgIntptr, getArgJsHandle, getArgLength, getArgType, getArgU16, getArgU8, getSignatureArg1Type, getSignatureArg2Type, getSignatureArg3Type, getSignatureResType, proxyDebugSymbol, setArgType, setJsHandle } from "./marshal";
1111
import { getMarshalerToCsByType, jsinteropDoc, marshalExceptionToCs } from "./marshal-to-cs";
1212
import { lookupJsOwnedObject, getJsHandleFromJSObject, getJSObjectFromJSHandle, registerWithJsvHandle, releaseCSOwnedObject, setupManagedProxy, teardownManagedProxy } from "./gc-handles";
13-
import { assertRuntimeRunning, callDelegate, fixupPointer, isRuntimeRunning } from "./utils";
13+
import { assertRuntimeRunning, fixupPointer, isRuntimeRunning } from "./utils";
1414
import { ArraySegment, ManagedError, ManagedObject, MemoryViewType, Span } from "./marshaled-types";
15+
import { callDelegate } from "./managed-exports";
1516

1617
export function initializeMarshalersToJs(): void {
1718
if (csToJsMarshalers.size == 0) {

0 commit comments

Comments
 (0)