Skip to content
Permalink
Browse files

v8: enable inline WASM in serialization API

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: #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...
addaleax committed Jan 2, 2019
1 parent f6e341a commit 7f78137c37c92783082b451238920383667269ab
Showing with 12 additions and 1 deletion.
  1. +1 −0 src/node_serdes.cc
  2. +11 −1 test/parallel/test-v8-serdes.js
@@ -283,6 +283,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();
}
@@ -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' },
@@ -20,7 +23,8 @@ const objects = [
undefined,
null,
42,
circular
circular,
wasmModule
];

const hostObject = new (internalBinding('js_stream').JSStream)();
@@ -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 7f78137

Please sign in to comment.
You can’t perform that action at this time.