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:
parent
b91093f0e5
commit
47a9eea8c8
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user