MCPcopy Create free account
hub / github.com/nodejs/node / defaultFor

Method defaultFor

deps/v8/test/mjsunit/wasm/wasm-module-builder.js:1581–1604  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

1579 nextTypeIndex() { return this.types.length; }
1580
1581 static defaultFor(type) {
1582 switch (type) {
1583 case kWasmI32:
1584 return wasmI32Const(0);
1585 case kWasmI64:
1586 return wasmI64Const(0);
1587 case kWasmF32:
1588 return wasmF32Const(0.0);
1589 case kWasmF64:
1590 return wasmF64Const(0.0);
1591 case kWasmS128:
1592 return [kSimdPrefix, kExprS128Const, ...(new Array(16).fill(0))];
1593 case kWasmStringViewIter:
1594 case kWasmStringViewWtf8:
1595 case kWasmStringViewWtf16:
1596 throw new Error("String views are non-defaultable");
1597 default:
1598 if ((typeof type) != 'number' && type.opcode != kWasmRefNull) {
1599 throw new Error("Non-defaultable type");
1600 }
1601 let heap_type = (typeof type) == 'number' ? type : type.heap_type;
1602 return [kExprRefNull, ...wasmSignedLeb(heap_type, kMaxVarInt32Size)];
1603 }
1604 }
1605
1606 addGlobal(type, mutable, shared, init) {
1607 if (init === undefined) init = WasmModuleBuilder.defaultFor(type);

Callers 2

addGlobalMethod · 0.45
regress-1403398.jsFile · 0.45

Calls 6

wasmI64ConstFunction · 0.85
fillMethod · 0.80
wasmI32ConstFunction · 0.70
wasmF32ConstFunction · 0.70
wasmF64ConstFunction · 0.70
wasmSignedLebFunction · 0.70

Tested by

no test coverage detected