Skip to content
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
2 changes: 2 additions & 0 deletions src/mono/browser/runtime/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
jiterpreter-opcodes.ts
jiterpreter-tables.ts
dotnet.d.ts
diagnostics-mock.d.ts
13 changes: 12 additions & 1 deletion src/mono/browser/runtime/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
"es6/*.js",
"jiterpreter-opcodes.ts",
"jiterpreter-tables.ts",
"dotnet.d.ts",
"diagnostics-mock.d.ts",
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
Expand All @@ -48,6 +50,15 @@ module.exports = {
"semi": [
"error",
"always"
]
],
"brace-style": ["error"],
"eol-last": ["error"],
"space-before-blocks": ["error"],
"semi-spacing": ["error", { "before": false, "after": true }],
"no-trailing-spaces": ["error"],
"object-curly-spacing": ["error", "always"],
"array-bracket-spacing": ["error"],
"space-infix-ops": ["error"],
"space-before-function-paren": ["error", "always"],
}
};
21 changes: 9 additions & 12 deletions src/mono/browser/runtime/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { VoidPtr } from "./types/emscripten";
import { setSegmentationRulesFromJson } from "./hybrid-globalization/grapheme-segmenter";

// this need to be run only after onRuntimeInitialized event, when the memory is ready
export function instantiate_asset(asset: AssetEntry, url: string, bytes: Uint8Array): void {
export function instantiate_asset (asset: AssetEntry, url: string, bytes: Uint8Array): void {
mono_log_debug(`Loaded:${asset.name} as ${asset.behavior} size ${bytes.length} from ${url}`);
const mark = startMeasure();

Expand Down Expand Up @@ -82,22 +82,19 @@ export function instantiate_asset(asset: AssetEntry, url: string, bytes: Uint8Ar
const index = loaderHelpers._loaded_files.findIndex(element => element.file == virtualName);
loaderHelpers._loaded_files.splice(index, 1);
}
}
else if (asset.behavior === "pdb") {
} else if (asset.behavior === "pdb") {
cwraps.mono_wasm_add_assembly(virtualName, offset!, bytes.length);
}
else if (asset.behavior === "icu") {
} else if (asset.behavior === "icu") {
if (!mono_wasm_load_icu_data(offset!))
Module.err(`Error loading ICU asset ${asset.name}`);
}
else if (asset.behavior === "resource") {
} else if (asset.behavior === "resource") {
cwraps.mono_wasm_add_satellite_assembly(virtualName, asset.culture || "", offset!, bytes.length);
}
endMeasure(mark, MeasuredBlock.instantiateAsset, asset.name);
++loaderHelpers.actual_instantiated_assets_count;
}

export async function instantiate_symbols_asset(pendingAsset: AssetEntryInternal): Promise<void> {
export async function instantiate_symbols_asset (pendingAsset: AssetEntryInternal): Promise<void> {
try {
const response = await pendingAsset.pendingDownloadInternal!.response;
const text = await response.text();
Expand All @@ -107,7 +104,7 @@ export async function instantiate_symbols_asset(pendingAsset: AssetEntryInternal
}
}

export async function instantiate_segmentation_rules_asset(pendingAsset: AssetEntryInternal): Promise<void> {
export async function instantiate_segmentation_rules_asset (pendingAsset: AssetEntryInternal): Promise<void> {
try {
const response = await pendingAsset.pendingDownloadInternal!.response;
const json = await response.json();
Expand All @@ -117,7 +114,7 @@ export async function instantiate_segmentation_rules_asset(pendingAsset: AssetEn
}
}

export async function wait_for_all_assets() {
export async function wait_for_all_assets () {
// wait for all assets in memory
await runtimeHelpers.allAssetsInMemory.promise;
if (runtimeHelpers.config.assets) {
Expand All @@ -129,6 +126,6 @@ export async function wait_for_all_assets() {
}

// Used by the debugger to enumerate loaded dlls and pdbs
export function mono_wasm_get_loaded_files(): string[] {
export function mono_wasm_get_loaded_files (): string[] {
return loaderHelpers.loadedFiles;
}
}
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// https://github.com/sq/JSIL/blob/1d57d5427c87ab92ffa3ca4b82429cd7509796ba/JSIL.Libraries/Includes/Bootstrap/Core/Classes/System.Convert.js#L149
// Thanks to Katelyn Gadd @kg

export function toBase64StringImpl(inArray: Uint8Array, offset?: number, length?: number) : string{
export function toBase64StringImpl (inArray: Uint8Array, offset?: number, length?: number) : string {
const reader = _makeByteReader(inArray, offset, length);
let result = "";
let ch1: number | null = 0, ch2: number | null = 0, ch3: number | null = 0;
Expand Down Expand Up @@ -76,7 +76,7 @@ const _base64Table = [
"+", "/"
];

function _makeByteReader(bytes: Uint8Array, index?: number, count?: number): {
function _makeByteReader (bytes: Uint8Array, index?: number, count?: number): {
read: () => number | null
} {
let position = (typeof (index) === "number") ? index : 0;
Expand Down
36 changes: 17 additions & 19 deletions src/mono/browser/runtime/cancelable-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ import { invoke_later_when_on_ui_thread_async } from "./invoke-js";

export const _are_promises_supported = ((typeof Promise === "object") || (typeof Promise === "function")) && (typeof Promise.resolve === "function");

export function isThenable(js_obj: any): boolean {
export function isThenable (js_obj: any): boolean {
// When using an external Promise library like Bluebird the Promise.resolve may not be sufficient
// to identify the object as a Promise.
return Promise.resolve(js_obj) === js_obj ||
((typeof js_obj === "object" || typeof js_obj === "function") && typeof js_obj.then === "function");
}

export function wrap_as_cancelable_promise<T>(fn: () => Promise<T>): ControllablePromise<T> {
export function wrap_as_cancelable_promise<T> (fn: () => Promise<T>): ControllablePromise<T> {
const { promise, promise_control } = createPromiseController<T>();
const inner = fn();
inner.then((data) => promise_control.resolve(data)).catch((reason) => promise_control.reject(reason));
return promise;
}

export function wrap_as_cancelable<T>(inner: Promise<T>): ControllablePromise<T> {
export function wrap_as_cancelable<T> (inner: Promise<T>): ControllablePromise<T> {
const { promise, promise_control } = createPromiseController<T>();
inner.then((data) => promise_control.resolve(data)).catch((reason) => promise_control.reject(reason));
return promise;
}

export function mono_wasm_cancel_promise(task_holder_gc_handle: GCHandle): void {
// cancelation should not arrive earlier than the promise created by marshaling in mono_wasm_invoke_jsimport_MT
export function mono_wasm_cancel_promise (task_holder_gc_handle: GCHandle): void {
// cancelation should not arrive earlier than the promise created by marshaling in mono_wasm_invoke_jsimport_MT
invoke_later_when_on_ui_thread_async(() => mono_wasm_cancel_promise_impl(task_holder_gc_handle));
}

export function mono_wasm_cancel_promise_impl(task_holder_gc_handle: GCHandle): void {
export function mono_wasm_cancel_promise_impl (task_holder_gc_handle: GCHandle): void {
if (!loaderHelpers.is_runtime_running()) {
mono_log_debug("This promise can't be canceled, mono runtime already exited.");
return;
Expand All @@ -63,15 +63,15 @@ export class PromiseHolder extends ManagedObject {
public isPostponed = false;
public data: any = null;
public reason: any = undefined;
public constructor(public promise: Promise<any>,
public constructor (public promise: Promise<any>,
private gc_handle: GCHandle,
private promiseHolderPtr: number, // could be null for GCV_handle
private promiseHolderPtr: number, // could be null for GCV_handle
private res_converter?: MarshalerToCs) {
super();
}

// returns false if the promise is being canceled by another thread in managed code
setIsResolving(): boolean {
setIsResolving (): boolean {
if (!WasmEnableThreads || this.promiseHolderPtr === 0) {
return true;
}
Expand All @@ -82,7 +82,7 @@ export class PromiseHolder extends ManagedObject {
return false;
}

resolve(data: any) {
resolve (data: any) {
if (!loaderHelpers.is_runtime_running()) {
mono_log_debug("This promise resolution can't be propagated to managed code, mono runtime already exited.");
return;
Expand All @@ -106,7 +106,7 @@ export class PromiseHolder extends ManagedObject {
this.complete_task_wrapper(data, null);
}

reject(reason: any) {
reject (reason: any) {
if (!loaderHelpers.is_runtime_running()) {
mono_log_debug("This promise rejection can't be propagated to managed code, mono runtime already exited.");
return;
Expand All @@ -131,7 +131,7 @@ export class PromiseHolder extends ManagedObject {
this.complete_task_wrapper(null, reason);
}

cancel() {
cancel () {
if (!loaderHelpers.is_runtime_running()) {
mono_log_debug("This promise cancelation can't be propagated to managed code, mono runtime already exited.");
return;
Expand All @@ -141,7 +141,7 @@ export class PromiseHolder extends ManagedObject {

if (this.isPostponed) {
// there was racing resolve/reject which was postponed, to retain valid GCHandle
// in this case we just finish the original resolve/reject
// in this case we just finish the original resolve/reject
// and we need to use the postponed data/reason
this.isResolved = true;
if (this.reason !== undefined) {
Expand All @@ -162,7 +162,7 @@ export class PromiseHolder extends ManagedObject {
}

// we can do this just once, because it will be dispose the GCHandle
complete_task_wrapper(data: any, reason: any) {
complete_task_wrapper (data: any, reason: any) {
try {
mono_assert(!this.isPosted, "Promise is already posted to managed.");
this.isPosted = true;
Expand All @@ -175,14 +175,12 @@ export class PromiseHolder extends ManagedObject {
// order of operations with teardown_managed_proxy matters
// so that managed user code running in the continuation could allocate the same GCHandle number and the local registry would be already ok with that
complete_task(this.gc_handle, reason, data, this.res_converter || marshal_cs_object_to_cs);
}
catch (ex) {
} catch (ex) {
try {
loaderHelpers.mono_exit(1, ex);
}
catch (ex2) {
} catch (ex2) {
// there is no point to propagate the exception into the unhandled promise rejection
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isSharedArrayBuffer, localHeapViewU8 } from "./memory";
// https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
const batchedQuotaMax = 65536;

export function mono_wasm_browser_entropy(bufferPtr: number, bufferLength: number): number {
export function mono_wasm_browser_entropy (bufferPtr: number, bufferLength: number): number {
if (!globalThis.crypto || !globalThis.crypto.getRandomValues) {
return -1;
}
Expand Down
12 changes: 6 additions & 6 deletions src/mono/browser/runtime/cuint64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/// and 'import type { CUInt64 } from './cuint64';
export type CUInt64 = readonly [number, number];

export function toBigInt(x: CUInt64): bigint {
export function toBigInt (x: CUInt64): bigint {
return BigInt(x[0]) | BigInt(x[1]) << BigInt(32);
}

export function fromBigInt(x: bigint): CUInt64 {
export function fromBigInt (x: bigint): CUInt64 {
if (x < BigInt(0))
throw new Error(`${x} is not a valid 64 bit integer`);
if (x > BigInt(0xFFFFFFFFFFFFFFFF))
Expand All @@ -20,11 +20,11 @@ export function fromBigInt(x: bigint): CUInt64 {
return [low, high];
}

export function dangerousToNumber(x: CUInt64): number {
export function dangerousToNumber (x: CUInt64): number {
return x[0] | x[1] << 32;
}

export function fromNumber(x: number): CUInt64 {
export function fromNumber (x: number): CUInt64 {
if (x < 0)
throw new Error(`${x} is not a valid 64 bit integer`);
if ((x >> 32) > 0xFFFFFFFF)
Expand All @@ -34,11 +34,11 @@ export function fromNumber(x: number): CUInt64 {
return [x & 0xFFFFFFFF, x >> 32];
}

export function pack32(lo: number, hi: number): CUInt64 {
export function pack32 (lo: number, hi: number): CUInt64 {
return [lo, hi];
}

export function unpack32(x: CUInt64): [number, number] {
export function unpack32 (x: CUInt64): [number, number] {
return [x[0], x[1]];
}

Expand Down
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/cwraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const enum I52Error {

const fastCwrapTypes = ["void", "number", null];

function cwrap(name: string, returnType: string | null, argTypes: string[] | undefined, opts: any): Function {
function cwrap (name: string, returnType: string | null, argTypes: string[] | undefined, opts: any): Function {
// Attempt to bypass emscripten's generated wrapper if it is safe to do so
let fce =
// Special cwrap options disable the fast path
Expand Down Expand Up @@ -314,7 +314,7 @@ function cwrap(name: string, returnType: string | null, argTypes: string[] | und
return fce;
}

export function init_c_exports(): void {
export function init_c_exports (): void {
const fns = [...fn_signatures];
for (const sig of fns) {
const wf: any = wrapped_c_functions;
Expand Down
Loading