Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,32 @@
"@babel/node": "^7.27.1",
"@babel/preset-env": "^7.27.2",
"@babel/preset-typescript": "^7.27.1",
"@changesets/cli": "^2.29.3",
"@changesets/cli": "^2.29.4",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^16.0.1",
"@types/benchmark": "^2.1.5",
"@types/jest": "^29.5.14",
"@types/node": "^22.15.17",
"assemblyscript": "^0.27.27",
"babel-loader": "^9.1.3",
"assemblyscript": "^0.27.36",
"babel-loader": "^9.2.1",
"benchmark": "^2.1.4",
"concurrently": "^9.1.2",
"core-js": "^3.37.0",
"core-js": "^3.42.0",
"dts-bundle-generator": "^9.5.1",
"expose-gc": "^1.0.0",
"gh-pages": "^6.1.1",
"html-webpack-plugin": "^5.6.0",
"gh-pages": "^6.3.0",
"html-webpack-plugin": "^5.6.3",
"husky": "^9.1.7",
"jest": "^29.7.0",
"oxlint": "^0.16.9",
"oxlint": "^0.16.10",
"prettier": "^3.5.3",
"rimraf": "^6.0.1",
"rollup": "^4.40.2",
"rollup-plugin-terser": "^7.0.2",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typedoc": "^0.28.4",
"typedoc-plugin-markdown": "^4.0.1",
"typescript": "^5.4.5",
"typescript": "^5.8.3",
"webpack": "^5.99.8",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.1",
Expand Down
8 changes: 6 additions & 2 deletions src/allocator/functional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export function allocatorInit(
/**
* For testing purposes
*/
export function listAllAllocatedPointers(allocatorState: AllocatorState) {
export function listAllAllocatedPointers(allocatorState: AllocatorState): {
blockPointer: number;
pointer: number;
size: number;
}[] {
const pointers: Array<{
blockPointer: number;
pointer: number;
Expand Down Expand Up @@ -480,7 +484,7 @@ export function stats(
/**
* To be used after ArrayBuffer change
*/
export function setEnd(allocatorState: AllocatorState, newEnd: number) {
export function setEnd(allocatorState: AllocatorState, newEnd: number): void {
set_end(allocatorState.state, newEnd);
}

Expand Down
23 changes: 17 additions & 6 deletions src/internal/BaseProxyTrap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { ExternalArgs, GlobalCarrier, InternalAPI } from "./interfaces";
import { incrementRefCount } from "./store";
import { WrapperDestroyed } from "./exceptions";
import { INTERNAL_API_SYMBOL } from "./symbols";

// See https://github.com/microsoft/TypeScript/issues/61892#issuecomment-2989433469
// oxlint-disable-next-line no-unsafe-declaration-merging
export interface BaseProxyTrap {
[INTERNAL_API_SYMBOL](): InternalAPI;
}

export abstract class BaseProxyTrap implements InternalAPI {
constructor(
Expand All @@ -9,29 +16,33 @@ export abstract class BaseProxyTrap implements InternalAPI {
protected _entryPointer: number
) {
incrementRefCount(this.carrier.heap, this.entryPointer);
// See https://github.com/microsoft/TypeScript/issues/61892#issuecomment-2989433469
this[INTERNAL_API_SYMBOL] = () => {
return this;
};
}

public destroy() {
public destroy(): void {
this._entryPointer = 0;
}

public getCarrier() {
public getCarrier(): GlobalCarrier {
return this.carrier;
}

public replaceCarrierContent(newCarrierContent: GlobalCarrier) {
public replaceCarrierContent(newCarrierContent: GlobalCarrier): void {
Object.assign(this.carrier, newCarrierContent);
}

public getEntryPointer() {
public getEntryPointer(): number {
return this.entryPointer;
}

public getExternalArgs() {
public getExternalArgs(): ExternalArgs {
return this.externalArgs;
}

protected get entryPointer() {
protected get entryPointer(): number {
if (this._entryPointer === 0) {
throw new WrapperDestroyed();
}
Expand Down
12 changes: 6 additions & 6 deletions src/internal/TransactionalAllocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TransactionalAllocator implements FunctionalAllocatorWrapper {
protected transactionAddresses: number[];
protected allocatorState: AllocatorState;

static load(ab: ArrayBuffer | SharedArrayBuffer) {
static load(ab: ArrayBuffer | SharedArrayBuffer): TransactionalAllocator {
const state = loadAllocator(ab, MEM_POOL_START);

return new TransactionalAllocator(state);
Expand Down Expand Up @@ -140,7 +140,7 @@ export class TransactionalAllocator implements FunctionalAllocatorWrapper {
return listFreeBlocks(this.allocatorState);
}

public setNewEnd(newEnd: number) {
public setNewEnd(newEnd: number): void {
setEnd(this.allocatorState, newEnd);
}

Expand All @@ -162,7 +162,7 @@ export class TransactionalAllocator implements FunctionalAllocatorWrapper {
return address;
}

public transaction<T>(cmd: () => T) {
public transaction<T>(cmd: () => T): T {
this.startTransaction();
try {
return cmd();
Expand All @@ -171,16 +171,16 @@ export class TransactionalAllocator implements FunctionalAllocatorWrapper {
}
}

protected startTransaction() {
protected startTransaction(): void {
this.inTransaction = true;
}

protected endTransaction() {
protected endTransaction(): void {
this.inTransaction = false;
this.transactionAddresses = [];
}

protected rollbackTransaction() {
protected rollbackTransaction(): void {
const { transactionAddresses } = this;
this.transactionAddresses = [];
this.inTransaction = false;
Expand Down
28 changes: 16 additions & 12 deletions src/internal/WeakValueMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class WeakValueMap<K, V> implements Map<K, V> {
);
}

set(key: K, value: V) {
set(key: K, value: V): this {
const existingRef = this.map.get(key);
if (existingRef) this.group.unregister(existingRef);
const newRef = new WeakRef(value);
Expand All @@ -64,7 +64,7 @@ export class WeakValueMap<K, V> implements Map<K, V> {
return this;
}

has(key: K) {
has(key: K): boolean {
const w = this.map.get(key);
if (w === undefined) {
return false;
Expand All @@ -77,7 +77,7 @@ export class WeakValueMap<K, V> implements Map<K, V> {
return true;
}

get(key: K) {
get(key: K): V | undefined {
const w = this.map.get(key);
if (w === undefined) {
return undefined;
Expand All @@ -91,7 +91,7 @@ export class WeakValueMap<K, V> implements Map<K, V> {
return v;
}

delete(key: K) {
delete(key: K): boolean {
const w = this.map.get(key);
if (w) {
this.map.delete(key);
Expand All @@ -101,20 +101,21 @@ export class WeakValueMap<K, V> implements Map<K, V> {
return false;
}

clear() {
clear(): void {
for (const w of this.map.values()) {
this.group.unregister(w);
}
this.map.clear();
}

*[Symbol.iterator](type?: typeof KEYS | typeof VALUES | typeof KEYS_VALUES) {
*[Symbol.iterator](type?: typeof KEYS | typeof VALUES | typeof KEYS_VALUES): MapIterator<[K, V]> {
for (const [key, weak] of this.map) {
const v = weak.deref();
if (v === undefined) {
this.map.delete(key);
this.group.unregister(weak);
} else if (type === KEYS) {
// @ts-expect-error ts 5.8 migration
yield key;
} else if (type === VALUES) {
yield v;
Expand All @@ -124,32 +125,35 @@ export class WeakValueMap<K, V> implements Map<K, V> {
}
}

keys() {
keys(): MapIterator<K> {
// @ts-expect-error ts 5.8 migration
return this[Symbol.iterator](KEYS);
}

values() {
values(): MapIterator<V> {
// @ts-expect-error ts 5.8 migration
return this[Symbol.iterator](VALUES);
}

entries() {
entries(): MapIterator<[K, V]> {
return this[Symbol.iterator](KEYS_VALUES);
}

forEach(
callbackfn: (value: V, key: K, map: Map<K, V>) => void,
thisArg?: any
) {
): void {
for (const [key, value] of this) {
// @ts-expect-error ts 5.8 migration
callbackfn.call(thisArg, key, value, this);
}
}

public get size() {
public get size(): number {
return this.map.size;
}

public get [Symbol.toStringTag]() {
public get [Symbol.toStringTag](): string {
return this.map[Symbol.toStringTag];
}
}
11 changes: 6 additions & 5 deletions src/internal/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ObjectBufferSettings,
GlobalCarrier,
MemoryStats,
ExternalArgs,
} from "./interfaces";
import {
arrayBufferCopyTo,
Expand Down Expand Up @@ -101,7 +102,7 @@ export function createObjectBuffer<T = any>(
export function unstable_resizeObjectBuffer(
objectBuffer: unknown,
newSize: number
) {
): ArrayBuffer {
if (newSize < memoryStats(objectBuffer).top) {
throw new OutOfMemoryError();
}
Expand Down Expand Up @@ -180,7 +181,7 @@ export function loadObjectBuffer<T = any>(
export function unstable_replaceUnderlyingArrayBuffer(
objectBuffer: unknown,
newArrayBuffer: ArrayBuffer | SharedArrayBuffer
) {
): void {
const allocator = TransactionalAllocator.load(newArrayBuffer);
const carrier: GlobalCarrier = { allocator, heap: allocator.getHeap() };

Expand Down Expand Up @@ -216,11 +217,11 @@ export { reclaim, queueReclaim } from "./reclaim";
export function updateObjectBufferSettings(
objectBuffer: unknown,
options: ObjectBufferSettings
) {
): void {
Object.assign(getInternalAPI(objectBuffer).getExternalArgs(), options);
}

export function readObjectBufferSettings(objectBuffer: unknown) {
export function readObjectBufferSettings(objectBuffer: unknown): ExternalArgs {
return getInternalAPI(objectBuffer).getExternalArgs();
}

Expand All @@ -233,6 +234,6 @@ export function readObjectBufferSettings(objectBuffer: unknown) {
* because It's only safe to call it when you have a lock/similar (As any other operation)
* And FinalizationRegistry might run when ever
*/
export function processQueuedReclaims(objectBuffer: unknown) {
export function processQueuedReclaims(objectBuffer: unknown): void {
freeNoLongerUsedAddresses(getInternalAPI(objectBuffer).getCarrier());
}
18 changes: 9 additions & 9 deletions src/internal/arrayHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function arrayGetPointerToIndex(
carrier: GlobalCarrier,
pointerToArrayEntry: number,
indexToGet: number
) {
): number {
// out of bound
invariant(
indexToGet <= array_length_get(carrier.heap, pointerToArrayEntry),
Expand All @@ -36,7 +36,7 @@ export function arrayGetValuePointerInIndex(
carrier: GlobalCarrier,
pointerToArrayEntry: number,
indexToGet: number
) {
): number {
return carrier.heap.u32[
arrayGetPointerToIndex(carrier, pointerToArrayEntry, indexToGet) /
Uint32Array.BYTES_PER_ELEMENT
Expand All @@ -48,7 +48,7 @@ export function getFinalValueAtArrayIndex(
globalCarrier: GlobalCarrier,
pointerToArrayEntry: number,
indexToGet: number
) {
): any {
const pointer = arrayGetValuePointerInIndex(
globalCarrier,
pointerToArrayEntry,
Expand All @@ -63,7 +63,7 @@ export function setValuePointerAtArrayIndex(
pointerToArrayEntry: number,
indexToSet: number,
pointerToEntry: number
) {
): void {
const pointer = arrayGetPointerToIndex(
carrier,
pointerToArrayEntry,
Expand All @@ -79,7 +79,7 @@ export function setValueAtArrayIndex(
pointerToArrayEntry: number,
indexToSet: number,
value: unknown
) {
): void {
const refedPointers: number[] = [];

const newValuePointer = saveValueIterativeReturnPointer(
Expand Down Expand Up @@ -124,7 +124,7 @@ export function extendArrayIfNeeded(
carrier: GlobalCarrier,
pointerToArrayEntry: number,
wishedLength: number
) {
): void {
if (wishedLength > array_length_get(carrier.heap, pointerToArrayEntry)) {
if (
wishedLength >
Expand All @@ -150,7 +150,7 @@ export function shrinkArray(
heap: Heap,
pointerToArrayEntry: number,
wishedLength: number
) {
): void {
array_length_set(heap, pointerToArrayEntry, wishedLength);
}

Expand Down Expand Up @@ -192,7 +192,7 @@ export function arraySort(
carrier: GlobalCarrier,
pointerToArrayEntry: number,
sortComparator: (a: any, b: any) => 1 | -1 | 0 = defaultCompareFunction
) {
): void {
const arrayDataSpace = array_dataspacePointer_get(
carrier.heap,
pointerToArrayEntry
Expand Down Expand Up @@ -265,7 +265,7 @@ function toString(obj: any) {
export function arrayReverse(
carrier: GlobalCarrier,
pointerToArrayEntry: number
) {
): void {
for (
let i = 0;
i < Math.floor(array_length_get(carrier.heap, pointerToArrayEntry) / 2);
Expand Down
Loading
Loading