bun-polyfills: bun:jsc tweaks

This commit is contained in:
jhmaster2000
2023-12-02 02:29:54 -03:00
parent 62cdc58acf
commit 989a670682
2 changed files with 12 additions and 6 deletions

View File

@@ -7,10 +7,13 @@ const STUB = () => void 0;
function jscSerialize(value: any, options?: { binaryType: 'nodebuffer'; }): Buffer;
function jscSerialize(value: any, options?: { binaryType?: 'arraybuffer'; }): SharedArrayBuffer;
function jscSerialize(value: any, options?: { binaryType?: string }): Buffer | SharedArrayBuffer {
const serialized = v8.serialize(value);
function jscSerialize(value: any, options?: { binaryType?: string; }): Buffer | SharedArrayBuffer {
const serialized = v8.serialize(value instanceof SharedArrayBuffer ? new Uint8Array(value) : value);
if (options?.binaryType === 'nodebuffer') return serialized;
else return new SharedArrayBuffer(serialized.byteLength);
const sab = new SharedArrayBuffer(serialized.byteLength);
const sabView = new Uint8Array(sab);
sabView.set(serialized);
return sab;
}
// TODO: Investigate ways of making these the actual JSC serialization format (probably Bun WASM)
// TODO: whilst this works for common use-cases like Node <-> Node it still does not make it
@@ -102,9 +105,7 @@ export const reoptimizationRetryCount = ((...args) => args.length ? 0 : void 0 a
export const profile = (() => {
throw new NotImplementedError('jsc.profile is not polyfillable', STUB, true);
}) satisfies typeof jsc.profile;
export const optimizeNextInvocation = (() => {
throw new NotImplementedError('jsc.optimizeNextInvocation is not polyfillable', STUB, true);
}) satisfies typeof jsc.optimizeNextInvocation;
export const optimizeNextInvocation = STUB satisfies typeof jsc.optimizeNextInvocation; // no-op
export { setRandomSeed, getRandomSeed } from '../global/mathrandom.js';

View File

@@ -2,4 +2,9 @@
import '../../../test/js/bun/console/console-iterator.test.ts';
import '../../../test/js/bun/dns/resolve-dns.test.ts';
import '../../../test/js/bun/ffi/ffi.test.js';
// http
// io
import '../../../test/js/bun/jsc/bun-jsc.test.js';
// ...
import '../../../test/js/bun/sqlite/sqlite.test.ts';
// ...