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

Method toBuffer

deps/v8/test/mjsunit/wasm/wasm-module-builder.js:1881–2379  ·  view source on GitHub ↗
(debug = false)

Source from the content-addressed store, hash-verified

1879 }
1880
1881 toBuffer(debug = false) {
1882 let binary = new Binary;
1883 let wasm = this;
1884
1885 // Add header.
1886 binary.emit_header();
1887
1888 // Add type section.
1889 if (wasm.types.length > 0) {
1890 if (debug) print('emitting types @ ' + binary.length);
1891 binary.emit_section(kTypeSectionCode, section => {
1892 let length_with_groups = wasm.types.length;
1893 for (let group of wasm.rec_groups) {
1894 length_with_groups -= group.size - 1;
1895 }
1896 section.emit_u32v(length_with_groups);
1897
1898 let rec_group_index = 0;
1899
1900 for (let i = 0; i < wasm.types.length; i++) {
1901 if (rec_group_index < wasm.rec_groups.length &&
1902 wasm.rec_groups[rec_group_index].start == i) {
1903 section.emit_u8(kWasmRecursiveTypeGroupForm);
1904 section.emit_u32v(wasm.rec_groups[rec_group_index].size);
1905 rec_group_index++;
1906 }
1907
1908 let type = wasm.types[i];
1909 if (type.supertype != kNoSuperType) {
1910 section.emit_u8(type.is_final ? kWasmSubtypeFinalForm
1911 : kWasmSubtypeForm);
1912 section.emit_u8(1); // supertype count
1913 section.emit_u32v(type.supertype);
1914 } else if (!type.is_final) {
1915 section.emit_u8(kWasmSubtypeForm);
1916 section.emit_u8(0); // no supertypes
1917 }
1918 if (type.is_shared) section.emit_u8(kWasmSharedTypeForm);
1919 if (type.describes !== undefined) {
1920 section.emit_u8(kWasmDescribesTypeForm);
1921 section.emit_u32v(type.describes);
1922 }
1923 if (type.descriptor !== undefined) {
1924 section.emit_u8(kWasmDescriptorTypeForm);
1925 section.emit_u32v(type.descriptor);
1926 }
1927 if (type instanceof WasmStruct) {
1928 section.emit_u8(kWasmStructTypeForm);
1929 section.emit_u32v(type.fields.length);
1930 for (let field of type.fields) {
1931 section.emit_type(field.type);
1932 section.emit_u8(field.mutability ? 1 : 0);
1933 }
1934 } else if (type instanceof WasmArray) {
1935 section.emit_u8(kWasmArrayTypeForm);
1936 section.emit_type(type.type);
1937 section.emit_u8(type.mutability ? 1 : 0);
1938 } else if (type instanceof WasmCont) {

Callers 3

toArrayMethod · 0.95
asyncInstantiateMethod · 0.95
toModuleMethod · 0.95

Calls 15

emit_headerMethod · 0.95
emit_sectionMethod · 0.95
emit_bytesMethod · 0.95
trunc_bufferMethod · 0.95
wasmUnsignedLebFunction · 0.85
is_activeMethod · 0.80
is_passiveMethod · 0.80
someMethod · 0.80
forEachMethod · 0.65
mapMethod · 0.65
printFunction · 0.50

Tested by

no test coverage detected