Skip to content

Commit

Permalink
v8: enable inline WASM in serialization API
Browse files Browse the repository at this point in the history
Since the API we expose through the `v8` module is Buffer-based,
we cannot transfer WASM modules directly. Instead, we enable
the V8-provided inline WASM (de)serialization for WASM modules.

PR-URL: nodejs#25313
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
Anna Henningsen authored and refack committed Jan 10, 2019
1 parent ca027b7 commit 2d3415a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/node_serdes.cc
Expand Up @@ -282,6 +282,7 @@ DeserializerContext::DeserializerContext(Environment* env,
length_(Buffer::Length(buffer)),
deserializer_(env->isolate(), data_, length_, this) {
object()->Set(env->context(), env->buffer_string(), buffer).FromJust();
deserializer_.SetExpectInlineWasm(true);

MakeWeak();
}
Expand Down
12 changes: 11 additions & 1 deletion test/parallel/test-v8-serdes.js
Expand Up @@ -4,13 +4,16 @@

const { internalBinding } = require('internal/test/binding');
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const v8 = require('v8');
const os = require('os');

const circular = {};
circular.circular = circular;

const wasmModule = new WebAssembly.Module(fixtures.readSync('test.wasm'));

const objects = [
{ foo: 'bar' },
{ bar: 'baz' },
Expand All @@ -20,7 +23,8 @@ const objects = [
undefined,
null,
42,
circular
circular,
wasmModule
];

const hostObject = new (internalBinding('js_stream').JSStream)();
Expand Down Expand Up @@ -230,3 +234,9 @@ const deserializerTypeError =
/^TypeError: buffer must be a TypedArray or a DataView$/,
);
}

{
const deserializedWasmModule = v8.deserialize(v8.serialize(wasmModule));
const instance = new WebAssembly.Instance(deserializedWasmModule);
assert.strictEqual(instance.exports.addTwo(10, 20), 30);
}

0 comments on commit 2d3415a

Please sign in to comment.