aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-07-16 21:15:24 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-16 21:15:24 -0700
commit209dc981c0ef52de5c80eab5d24ec8a8eba765e8 (patch)
treec3d203d03d109161bcaf25558c05fda49c5e864e /src/js
parent7fc392b182fa45d1fa33e654c2b4d1f1022a1ac3 (diff)
downloadbun-209dc981c0ef52de5c80eab5d24ec8a8eba765e8.tar.gz
bun-209dc981c0ef52de5c80eab5d24ec8a8eba765e8.tar.zst
bun-209dc981c0ef52de5c80eab5d24ec8a8eba765e8.zip
Implement Workers (#3645)
* copy files * format * options * Introduce `Worker`, `onmessage`, `onerror`, and `postMessage` globals * Stub `Worker.prototype.ref` & `Worker.prototype.unref` * Update web_worker.zig * Worker works * Add "mini" mode * add wakeup * Partially fix the keep-alive issue * clean up refer behavior * Implement `serialize` & `deserialize` in `bun:jsc` & add polyfill for `node:v8` * Types & docs * Update globals.d.ts * Add mutex * Fixes --------- Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/js')
-rw-r--r--src/js/bun/jsc.ts2
-rw-r--r--src/js/node/v8.ts9
-rw-r--r--src/js/out/modules/bun/jsc.js4
-rw-r--r--src/js/out/modules/node/v8.js9
4 files changed, 15 insertions, 9 deletions
diff --git a/src/js/bun/jsc.ts b/src/js/bun/jsc.ts
index 154e7345c..8063da948 100644
--- a/src/js/bun/jsc.ts
+++ b/src/js/bun/jsc.ts
@@ -34,3 +34,5 @@ export const profile = jsc.profile;
export default jsc;
export const setTimeZone = jsc.setTimeZone;
export const setTimezone = setTimeZone;
+export const serialize = jsc.serialize;
+export const deserialize = jsc.deserialize;
diff --git a/src/js/node/v8.ts b/src/js/node/v8.ts
index 3018c34e6..b043e10fe 100644
--- a/src/js/node/v8.ts
+++ b/src/js/node/v8.ts
@@ -1,6 +1,7 @@
// Hardcoded module "node:v8"
// This is a stub! None of this is actually implemented yet.
import { hideFromStack, throwNotImplemented } from "../shared";
+import { serialize as jscSerialize, deserialize as jscDeserialize } from "bun:jsc";
function notimpl(message) {
throwNotImplemented("node:v8 " + message);
@@ -42,8 +43,8 @@ function getHeapCodeStatistics() {
function setFlagsFromString() {
notimpl("setFlagsFromString");
}
-function deserialize() {
- notimpl("deserialize");
+function deserialize(value) {
+ return jscDeserialize(value);
}
function takeCoverage() {
notimpl("takeCoverage");
@@ -51,8 +52,8 @@ function takeCoverage() {
function stopCoverage() {
notimpl("stopCoverage");
}
-function serialize() {
- notimpl("serialize");
+function serialize(arg1) {
+ return jscSerialize(arg1, { binaryType: "nodebuffer" });
}
function writeHeapSnapshot() {
notimpl("writeHeapSnapshot");
diff --git a/src/js/out/modules/bun/jsc.js b/src/js/out/modules/bun/jsc.js
index df89b2584..45fb51bdd 100644
--- a/src/js/out/modules/bun/jsc.js
+++ b/src/js/out/modules/bun/jsc.js
@@ -1,4 +1,4 @@
-var jsc = globalThis[Symbol.for("Bun.lazy")]("bun:jsc"), callerSourceOrigin = jsc.callerSourceOrigin, jscDescribe = jsc.describe, jscDescribeArray = jsc.describeArray, describe = jscDescribe, describeArray = jscDescribeArray, drainMicrotasks = jsc.drainMicrotasks, edenGC = jsc.edenGC, fullGC = jsc.fullGC, gcAndSweep = jsc.gcAndSweep, getRandomSeed = jsc.getRandomSeed, heapSize = jsc.heapSize, heapStats = jsc.heapStats, startSamplingProfiler = jsc.startSamplingProfiler, samplingProfilerStackTraces = jsc.samplingProfilerStackTraces, isRope = jsc.isRope, memoryUsage = jsc.memoryUsage, noInline = jsc.noInline, noFTL = jsc.noFTL, noOSRExitFuzzing = jsc.noOSRExitFuzzing, numberOfDFGCompiles = jsc.numberOfDFGCompiles, optimizeNextInvocation = jsc.optimizeNextInvocation, releaseWeakRefs = jsc.releaseWeakRefs, reoptimizationRetryCount = jsc.reoptimizationRetryCount, setRandomSeed = jsc.setRandomSeed, startRemoteDebugger = jsc.startRemoteDebugger, totalCompileTime = jsc.totalCompileTime, getProtectedObjects = jsc.getProtectedObjects, generateHeapSnapshotForDebugging = jsc.generateHeapSnapshotForDebugging, profile = jsc.profile, jsc_default = jsc, setTimeZone = jsc.setTimeZone, setTimezone = setTimeZone;
+var jsc = globalThis[Symbol.for("Bun.lazy")]("bun:jsc"), callerSourceOrigin = jsc.callerSourceOrigin, jscDescribe = jsc.describe, jscDescribeArray = jsc.describeArray, describe = jscDescribe, describeArray = jscDescribeArray, drainMicrotasks = jsc.drainMicrotasks, edenGC = jsc.edenGC, fullGC = jsc.fullGC, gcAndSweep = jsc.gcAndSweep, getRandomSeed = jsc.getRandomSeed, heapSize = jsc.heapSize, heapStats = jsc.heapStats, startSamplingProfiler = jsc.startSamplingProfiler, samplingProfilerStackTraces = jsc.samplingProfilerStackTraces, isRope = jsc.isRope, memoryUsage = jsc.memoryUsage, noInline = jsc.noInline, noFTL = jsc.noFTL, noOSRExitFuzzing = jsc.noOSRExitFuzzing, numberOfDFGCompiles = jsc.numberOfDFGCompiles, optimizeNextInvocation = jsc.optimizeNextInvocation, releaseWeakRefs = jsc.releaseWeakRefs, reoptimizationRetryCount = jsc.reoptimizationRetryCount, setRandomSeed = jsc.setRandomSeed, startRemoteDebugger = jsc.startRemoteDebugger, totalCompileTime = jsc.totalCompileTime, getProtectedObjects = jsc.getProtectedObjects, generateHeapSnapshotForDebugging = jsc.generateHeapSnapshotForDebugging, profile = jsc.profile, jsc_default = jsc, setTimeZone = jsc.setTimeZone, setTimezone = setTimeZone, serialize = jsc.serialize, deserialize = jsc.deserialize;
export {
totalCompileTime,
startSamplingProfiler,
@@ -6,6 +6,7 @@ export {
setTimezone,
setTimeZone,
setRandomSeed,
+ serialize,
samplingProfilerStackTraces,
reoptimizationRetryCount,
releaseWeakRefs,
@@ -28,6 +29,7 @@ export {
fullGC,
edenGC,
drainMicrotasks,
+ deserialize,
describeArray,
describe,
jsc_default as default,
diff --git a/src/js/out/modules/node/v8.js b/src/js/out/modules/node/v8.js
index eb7a6568b..b2a42e898 100644
--- a/src/js/out/modules/node/v8.js
+++ b/src/js/out/modules/node/v8.js
@@ -17,6 +17,7 @@ class NotImplementedError extends Error {
}
// src/js/node/v8.ts
+import {serialize as jscSerialize, deserialize as jscDeserialize} from "bun:jsc";
var notimpl = function(message) {
throwNotImplemented("node:v8 " + message);
}, cachedDataVersionTag = function() {
@@ -31,14 +32,14 @@ var notimpl = function(message) {
notimpl("getHeapCodeStatistics");
}, setFlagsFromString = function() {
notimpl("setFlagsFromString");
-}, deserialize = function() {
- notimpl("deserialize");
+}, deserialize = function(value) {
+ return jscDeserialize(value);
}, takeCoverage = function() {
notimpl("takeCoverage");
}, stopCoverage = function() {
notimpl("stopCoverage");
-}, serialize = function() {
- notimpl("serialize");
+}, serialize = function(arg1) {
+ return jscSerialize(arg1, { binaryType: "nodebuffer" });
}, writeHeapSnapshot = function() {
notimpl("writeHeapSnapshot");
}, setHeapSnapshotNearHeapLimit = function() {