Skip to content

Commit

Permalink
Add global structuredClone()
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Mar 21, 2024
1 parent d19bcf5 commit 5a90255
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bare-os": "^2.0.0",
"bare-path": "^2.0.0",
"bare-repl": "^1.0.0",
"bare-structured-clone": "^1.0.1",
"bare-structured-clone": "^1.0.2",
"bare-timers": "^2.0.0",
"bare-tty": "^3.0.0",
"bare-url": "^1.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ global.queueMicrotask = function queueMicrotask (fn) {
.catch(err => setImmediate(() => { throw err }))
}

/**
* https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
*/

global.structuredClone = require('bare-structured-clone')

/**
* Thanks to Node.js, it is customary for the buffer API to be available
* globally and many of the core modules in Bare also assume this.
Expand Down
6 changes: 3 additions & 3 deletions src/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ module.exports = exports = class Thread {
const serialized = structuredClone.serialize(data)

const state = { start: 0, end: 0, buffer: null }

structuredClone.preencode(state, serialized)

state.buffer = Buffer.allocUnsafe(state.end)
structuredClone.encode(state, serialized)
state.buffer = data = Buffer.allocUnsafe(state.end)

data = state.buffer
structuredClone.encode(state, serialized)
}

this._handle = bare.setupThread(filename, source, data, stackSize)
Expand Down

0 comments on commit 5a90255

Please sign in to comment.