Skip to content

Commit 7f78137

Browse files
committed
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>
1 parent f6e341a commit 7f78137

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/node_serdes.cc

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ DeserializerContext::DeserializerContext(Environment* env,
283283
length_(Buffer::Length(buffer)),
284284
deserializer_(env->isolate(), data_, length_, this) {
285285
object()->Set(env->context(), env->buffer_string(), buffer).FromJust();
286+
deserializer_.SetExpectInlineWasm(true);
286287

287288
MakeWeak();
288289
}

test/parallel/test-v8-serdes.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
const { internalBinding } = require('internal/test/binding');
66
const common = require('../common');
7+
const fixtures = require('../common/fixtures');
78
const assert = require('assert');
89
const v8 = require('v8');
910
const os = require('os');
1011

1112
const circular = {};
1213
circular.circular = circular;
1314

15+
const wasmModule = new WebAssembly.Module(fixtures.readSync('test.wasm'));
16+
1417
const objects = [
1518
{ foo: 'bar' },
1619
{ bar: 'baz' },
@@ -20,7 +23,8 @@ const objects = [
2023
undefined,
2124
null,
2225
42,
23-
circular
26+
circular,
27+
wasmModule
2428
];
2529

2630
const hostObject = new (internalBinding('js_stream').JSStream)();
@@ -230,3 +234,9 @@ const deserializerTypeError =
230234
/^TypeError: buffer must be a TypedArray or a DataView$/,
231235
);
232236
}
237+
238+
{
239+
const deserializedWasmModule = v8.deserialize(v8.serialize(wasmModule));
240+
const instance = new WebAssembly.Instance(deserializedWasmModule);
241+
assert.strictEqual(instance.exports.addTwo(10, 20), 30);
242+
}

0 commit comments

Comments
 (0)