MCPcopy Index your code
hub / github.com/nodejs/node / toBuffer

Method toBuffer

test/fixtures/wpt/wasm/jsapi/wasm-module-builder.js:1196–1583  ·  view source on GitHub ↗
(debug = false)

Source from the content-addressed store, hash-verified

1194 }
1195
1196 toBuffer(debug = false) {
1197 let binary = new Binary;
1198 let wasm = this;
1199
1200 // Add header
1201 binary.emit_header();
1202
1203 // Add type section
1204 if (wasm.types.length > 0) {
1205 if (debug) print('emitting types @ ' + binary.length);
1206 binary.emit_section(kTypeSectionCode, section => {
1207 let length_with_groups = wasm.types.length;
1208 for (let group of wasm.rec_groups) {
1209 length_with_groups -= group.size - 1;
1210 }
1211 section.emit_u32v(length_with_groups);
1212
1213 let rec_group_index = 0;
1214
1215 for (let i = 0; i < wasm.types.length; i++) {
1216 if (rec_group_index < wasm.rec_groups.length &&
1217 wasm.rec_groups[rec_group_index].start == i) {
1218 section.emit_u8(kWasmRecursiveTypeGroupForm);
1219 section.emit_u32v(wasm.rec_groups[rec_group_index].size);
1220 rec_group_index++;
1221 }
1222
1223 let type = wasm.types[i];
1224 if (type.supertype != kNoSuperType) {
1225 section.emit_u8(type.is_final ? kWasmSubtypeFinalForm
1226 : kWasmSubtypeForm);
1227 section.emit_u8(1); // supertype count
1228 section.emit_u32v(type.supertype);
1229 } else if (!type.is_final) {
1230 section.emit_u8(kWasmSubtypeForm);
1231 section.emit_u8(0); // no supertypes
1232 }
1233 if (type instanceof WasmStruct) {
1234 section.emit_u8(kWasmStructTypeForm);
1235 section.emit_u32v(type.fields.length);
1236 for (let field of type.fields) {
1237 section.emit_type(field.type);
1238 section.emit_u8(field.mutability ? 1 : 0);
1239 }
1240 } else if (type instanceof WasmArray) {
1241 section.emit_u8(kWasmArrayTypeForm);
1242 section.emit_type(type.type);
1243 section.emit_u8(type.mutability ? 1 : 0);
1244 } else {
1245 section.emit_u8(kWasmFunctionTypeForm);
1246 section.emit_u32v(type.params.length);
1247 for (let param of type.params) {
1248 section.emit_type(param);
1249 }
1250 section.emit_u32v(type.results.length);
1251 for (let result of type.results) {
1252 section.emit_type(result);
1253 }

Callers 15

toArrayMethod · 0.95
asyncInstantiateMethod · 0.95
toModuleMethod · 0.95
call_laterFunction · 0.95
getExportsFunction · 0.95
test-ffi-memory.jsFile · 0.45
prototypes.any.jsFile · 0.45

Calls 14

emit_headerMethod · 0.95
emit_sectionMethod · 0.95
emit_u32vMethod · 0.95
emit_typeMethod · 0.95
resetMethod · 0.95
emit_bytesMethod · 0.95
trunc_bufferMethod · 0.95
someMethod · 0.80
printFunction · 0.50
emit_u8Method · 0.45
emit_stringMethod · 0.45
emit_init_exprMethod · 0.45

Tested by

no test coverage detected