Skip to content

[release/7.0] [wasm] Add IMemoryView as exported type #77397

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 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
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
26 changes: 25 additions & 1 deletion src/mono/wasm/runtime/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,35 @@ 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;
}

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 };
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/export-types.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -21,6 +22,6 @@ declare const exit: ModuleAPI["exit"];

export {
EmscriptenModule,
RuntimeAPI, ModuleAPI, DotnetModuleConfig, CreateDotnetRuntimeType, MonoConfig,
RuntimeAPI, ModuleAPI, DotnetModuleConfig, CreateDotnetRuntimeType, MonoConfig, IMemoryView,
dotnet, exit
};
6 changes: 3 additions & 3 deletions src/mono/wasm/runtime/marshal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down