diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2022-11-03 03:16:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 03:16:02 +0300 |
commit | 4c3001dca2c75b14cb36995e7537c46826ad558e (patch) | |
tree | 38a82949589b9af110d489605dca4aa0e81ba879 | |
parent | 12a44e9bd6ee39ba9d1c69d19e81776f4d149f79 (diff) |
[release/7.0] [wasm] Add `IMemoryView` as exported type (#77397)
* Add IMemoryView as exported type.
* IMemoryView extends IDisposable.
Co-authored-by: Marek FiĊĦera <mara@neptuo.com>
-rw-r--r-- | src/mono/wasm/runtime/dotnet.d.ts | 26 | ||||
-rw-r--r-- | src/mono/wasm/runtime/export-types.ts | 3 | ||||
-rw-r--r-- | src/mono/wasm/runtime/marshal.ts | 6 |
3 files changed, 30 insertions, 5 deletions
diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index a65ce52c7de..66b7dd2ebb7 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -236,6 +236,30 @@ declare type ModuleAPI = { declare function createDotnetRuntime(moduleFactory: DotnetModuleConfig | ((api: RuntimeAPI) => DotnetModuleConfig)): Promise<RuntimeAPI>; declare type CreateDotnetRuntimeType = typeof createDotnetRuntime; +interface IDisposable { + dispose(): void; + get isDisposed(): boolean; +} +interface IMemoryView extends IDisposable { + /** + * copies elements from provided source to the wasm memory. + * target has to have the elements of the same type as the underlying C# array. + * same as TypedArray.set() + */ + set(source: TypedArray, targetOffset?: number): void; + /** + * copies elements from wasm memory to provided target. + * target has to have the elements of the same type as the underlying C# array. + */ + copyTo(target: TypedArray, sourceOffset?: number): void; + /** + * same as TypedArray.slice() + */ + slice(start?: number, end?: number): TypedArray; + get length(): number; + get byteLength(): number; +} + declare global { function getDotnetRuntime(runtimeId: number): RuntimeAPI | undefined; } @@ -243,4 +267,4 @@ declare global { declare const dotnet: ModuleAPI["dotnet"]; declare const exit: ModuleAPI["exit"]; -export { CreateDotnetRuntimeType, DotnetModuleConfig, EmscriptenModule, ModuleAPI, MonoConfig, RuntimeAPI, createDotnetRuntime as default, dotnet, exit }; +export { CreateDotnetRuntimeType, DotnetModuleConfig, EmscriptenModule, IMemoryView, ModuleAPI, MonoConfig, RuntimeAPI, createDotnetRuntime as default, dotnet, exit }; diff --git a/src/mono/wasm/runtime/export-types.ts b/src/mono/wasm/runtime/export-types.ts index ea27e07e62a..a1ad9df1e8b 100644 --- a/src/mono/wasm/runtime/export-types.ts +++ b/src/mono/wasm/runtime/export-types.ts @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +import { IMemoryView } from "./marshal"; import { createDotnetRuntime, CreateDotnetRuntimeType, DotnetModuleConfig, RuntimeAPI, MonoConfig, ModuleAPI } from "./types"; import { EmscriptenModule } from "./types/emscripten"; @@ -21,6 +22,6 @@ declare const exit: ModuleAPI["exit"]; export { EmscriptenModule, - RuntimeAPI, ModuleAPI, DotnetModuleConfig, CreateDotnetRuntimeType, MonoConfig, + RuntimeAPI, ModuleAPI, DotnetModuleConfig, CreateDotnetRuntimeType, MonoConfig, IMemoryView, dotnet, exit }; diff --git a/src/mono/wasm/runtime/marshal.ts b/src/mono/wasm/runtime/marshal.ts index f20a620c5fb..c03ef13aea7 100644 --- a/src/mono/wasm/runtime/marshal.ts +++ b/src/mono/wasm/runtime/marshal.ts @@ -376,7 +376,7 @@ export const enum MemoryViewType { Double = 2, } -abstract class MemoryView implements IMemoryView, IDisposable { +abstract class MemoryView implements IMemoryView { protected constructor(public _pointer: VoidPtr, public _length: number, public _viewType: MemoryViewType) { } @@ -432,7 +432,7 @@ abstract class MemoryView implements IMemoryView, IDisposable { } } -export interface IMemoryView { +export interface IMemoryView extends IDisposable { /** * copies elements from provided source to the wasm memory. * target has to have the elements of the same type as the underlying C# array. @@ -453,7 +453,7 @@ export interface IMemoryView { get byteLength(): number; } -export class Span extends MemoryView implements IDisposable { +export class Span extends MemoryView { private is_disposed = false; public constructor(pointer: VoidPtr, length: number, viewType: MemoryViewType) { super(pointer, length, viewType); |