mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
1fde98bb4f
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>
28 lines
663 B
JavaScript
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);
|
|
}
|