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: #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 8, 2019
1 parent f6e341a commit 7f78137
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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 11 additions & 1 deletion test/parallel/test-v8-serdes.js
Original file line number Diff line number Diff line change
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 7f78137

Please sign in to comment.