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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
"source.fixAll.eslint": "explicit"
},
"debug.javascript.usePreviewAutoAttach": true,
"debug.javascript.usePreview": true
"debug.javascript.usePreview": true,
"jest.runMode": "on-demand"
}
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,40 @@
"prettier-check": "prettier --check src"
},
"devDependencies": {
"@babel/cli": "^7.27.2",
"@babel/core": "^7.27.1",
"@babel/node": "^7.27.1",
"@babel/preset-env": "^7.27.2",
"@babel/cli": "^7.28.0",
"@babel/core": "^7.28.0",
"@babel/node": "^7.28.0",
"@babel/preset-env": "^7.28.0",
"@babel/preset-typescript": "^7.27.1",
"@changesets/cli": "^2.29.3",
"@changesets/cli": "^2.29.5",
"@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",
"@types/node": "^22.16.3",
"assemblyscript": "^0.28.3",
"babel-loader": "^9.2.1",
"benchmark": "^2.1.4",
"concurrently": "^9.1.2",
"core-js": "^3.37.0",
"concurrently": "^9.2.0",
"core-js": "^3.44.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",
"prettier": "^3.5.3",
"oxlint": "^1.6.0",
"prettier": "^3.6.2",
"rimraf": "^6.0.1",
"rollup": "^4.40.2",
"rollup": "^4.45.0",
"rollup-plugin-terser": "^7.0.2",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typedoc-plugin-markdown": "^4.0.1",
"typescript": "^5.4.5",
"webpack": "^5.99.8",
"typedoc": "^0.28.7",
"typedoc-plugin-markdown": "^4.7.0",
"typescript": "^5.8.3",
"webpack": "^5.100.1",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.1",
"webpack-dev-server": "^5.2.2",
"worker-loader": "^3.0.8"
},
"files": [
Expand Down
10 changes: 7 additions & 3 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 Expand Up @@ -863,5 +867,5 @@ function blockSelfAddress(dataAddress: number): number {
* @param size - alignment value
*/
export function align(addr: number, size: Pow2): number {
return size--, (addr + size) & ~size;
return (size--, (addr + size) & ~size);
}
66 changes: 66 additions & 0 deletions src/apiTests/Set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,69 @@ describe("Set tests", () => {
`);
});
});

describe("new set methods", () => {
test.failing("union", () => {
const objectBuffer = createObjectBuffer<any>(2048, {});
objectBuffer.setA = new Set([1, 2, 3]);
objectBuffer.setB = new Set([3, 4, 5]);

const result = objectBuffer.setA.union(objectBuffer.setB);
expect([...result]).toMatchInlineSnapshot(`[1, 2, 3, 4, 5]`);
});

test.failing("intersection", () => {
const objectBuffer = createObjectBuffer<any>(2048, {});
objectBuffer.setA = new Set([1, 2, 3]);
objectBuffer.setB = new Set([3, 4, 5]);

const result = objectBuffer.setA.intersection(objectBuffer.setB);
expect([...result]).toMatchInlineSnapshot(`[3]`);
});

test.failing("difference", () => {
const objectBuffer = createObjectBuffer<any>(2048, {});
objectBuffer.setA = new Set([1, 2, 3]);
objectBuffer.setB = new Set([3, 4, 5]);

const result = objectBuffer.setA.difference(objectBuffer.setB);
expect([...result]).toMatchInlineSnapshot(`[1, 2]`);
});

test.failing("symmetricDifference", () => {
const objectBuffer = createObjectBuffer<any>(2048, {});
objectBuffer.setA = new Set([1, 2, 3]);
objectBuffer.setB = new Set([3, 4, 5]);

const result = objectBuffer.setA.symmetricDifference(objectBuffer.setB);
expect([...result]).toMatchInlineSnapshot(`[1, 2, 4, 5]`);
});

test.failing("isSubsetOf", () => {
const objectBuffer = createObjectBuffer<any>(2048, {});
objectBuffer.setA = new Set([1, 2]);
objectBuffer.setB = new Set([1, 2, 3]);

expect(objectBuffer.setA.isSubsetOf(objectBuffer.setB)).toBe(true);
expect(objectBuffer.setB.isSubsetOf(objectBuffer.setA)).toBe(false);
});

test.failing("isSupersetOf", () => {
const objectBuffer = createObjectBuffer<any>(2048, {});
objectBuffer.setA = new Set([1, 2, 3]);
objectBuffer.setB = new Set([1, 2]);

expect(objectBuffer.setA.isSupersetOf(objectBuffer.setB)).toBe(true);
expect(objectBuffer.setB.isSupersetOf(objectBuffer.setA)).toBe(false);
});

test.failing("isDisjointFrom", () => {
const objectBuffer = createObjectBuffer<any>(1024, {});
objectBuffer.setA = new Set([1, 2, 3]);
objectBuffer.setB = new Set([4, 5, 6]);
objectBuffer.setC = new Set([3, 4, 5]);

expect(objectBuffer.setA.isDisjointFrom(objectBuffer.setB)).toBe(true);
expect(objectBuffer.setA.isDisjointFrom(objectBuffer.setC)).toBe(false);
});
});
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
30 changes: 18 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,23 @@ 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 +127,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];
}
}
Loading
Loading