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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen 2019-01-02 16:12:39 +01:00
parent b91093f0e5
commit 47a9eea8c8
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 12 additions and 1 deletions

View File

@ -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();
}

View File

@ -4,6 +4,7 @@
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');
@ -11,6 +12,8 @@ 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);
}