Skip to content

src: support V8 experimental shared values in messaging

This adds the missing integration support for the V8 experimental shared structs feature (--harmony-struct). There is no observable difference to node if --harmony-struct is not passed. The flag is false by default.

This experimental feature is for proving out shared memory in JS. The standards side is tracked by https://github.com/tc39/proposal-structs, though the current experiment, for the sake of ease of experimentation, does not include syntax. The features in experiment is documented here.

I also intentionally did not add any tests because the features are experimental and volatile. Here is an illustrative example though:

'use strict';
const { Worker, isMainThread, parentPort } = require('worker_threads');

if (isMainThread) {
  let Box = new SharedStructType(['payload']);
  let b = new Box();
  b.payload = "hello shared memory world";

  let worker = new Worker(__filename);
  worker.on('message', (message) => {
    console.log(b.payload);
    console.log(message === b);
  });

  worker.postMessage(b);
} else {
  parentPort.on('message', (message) => {
    // Simple echo.
    parentPort.postMessage(message);
  });
}

Merge request reports

Loading