In the browser there are WHATWG Transferable Streams which provides a means to read and write to different context using WHATWG Streams, for example using the readable and writable pairs of a TransformStream. Effectively meaning it's possible to communicate between an iframe and a window or a window and a window, or a Worklet and a Worker, etc.
There is also WebAssembly.Memory, which provides a means to read and write to the same linear memory object between different contexts.
In Node.js there is --import flag to preload modules; in Bun there is the -r option to preload modules, which effectively provides a means to set objects and definitions of objects globally before the main module loads. For example, let's say we wanted to define Node.js' fs.readSync function onto Node.js' process.stdin, in preprocess-module.js
import process from "node:process";
import { readSync } from "node:fs";
process.stdin.readSync = readSync;
export {};
node --import preprocess.module module.ts
Re
> I've tried overwriting one context's global `Object`
That can be potentially disasterous since Object itself is writable, we can do
Object = 1;
in one context and Object.assign() would throw in the nth context.