0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-v8-serdes-sharedarraybuffer.js
Anna Henningsen 1fde98bb4f
v8: expose new V8 serialization API
Expose the new serialization API that was added in V8 5.5 to userland.
The JS API is virtually a direct copy of what V8 provides on the
C++ level.

This is useful Node as a possible replacement for some internals
that currently use JSON, like IPC, but is likely to be useful to
general userland code as well.

PR-URL: https://github.com/nodejs/node/pull/11048
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-03-29 05:14:55 +02:00

28 lines
663 B
JavaScript

/*global SharedArrayBuffer*/
'use strict';
// Flags: --harmony-sharedarraybuffer
const common = require('../common');
const assert = require('assert');
const v8 = require('v8');
{
const sab = new SharedArrayBuffer(64);
const uint8array = new Uint8Array(sab);
const ID = 42;
const ser = new v8.Serializer();
ser._getSharedArrayBufferId = common.mustCall(() => ID);
ser.writeHeader();
ser.writeValue(uint8array);
const des = new v8.Deserializer(ser.releaseBuffer());
des.readHeader();
des.transferArrayBuffer(ID, sab);
const value = des.readValue();
assert.strictEqual(value.buffer, sab);
assert.notStrictEqual(value, uint8array);
}