From e921029ad72dc5d39d0c4733b9f0950d62b46aed Mon Sep 17 00:00:00 2001 From: GulgDev Date: Wed, 16 Apr 2025 12:46:18 +0500 Subject: [PATCH 1/6] Add expression info tests --- test/binaryen.js/expressions.js | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index 544f2b97806..df3be3df452 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -7,6 +7,11 @@ function assertDeepEqual(x, y) { } } +function assertInfoEqual(wrapper, info) { + for (let i in info) + assertDeepEqual(typeof wrapper[i] === "function" ? wrapper[i]() : wrapper[i], info[i]); +} + console.log("# Expression"); (function testWrapper() { var theExpression = binaryen.Block(42); // works without new @@ -27,6 +32,7 @@ console.log("# Block"); const theBlock = binaryen.Block(module.block(null, [])); assert(theBlock instanceof binaryen.Block); assert(theBlock instanceof binaryen.Expression); + assertInfoEqual(theBlock, binaryen.getExpressionInfo(theBlock)); assert(theBlock.id === binaryen.BlockId); assert(theBlock.name === null); assert(theBlock.type === binaryen.none); @@ -91,6 +97,7 @@ console.log("# If"); const theIf = binaryen.If(module.if(condition, ifTrue, ifFalse)); assert(theIf instanceof binaryen.If); assert(theIf instanceof binaryen.Expression); + assertInfoEqual(theIf, binaryen.getExpressionInfo(theIf)); assert(theIf.id === binaryen.IfId); assert(theIf.condition === condition); assert(theIf.ifTrue === ifTrue); @@ -133,6 +140,7 @@ console.log("# Loop"); const theLoop = binaryen.Loop(module.loop(name, body)); assert(theLoop instanceof binaryen.Loop); assert(theLoop instanceof binaryen.Expression); + assertInfoEqual(theLoop, binaryen.getExpressionInfo(theLoop)); assert(theLoop.id === binaryen.LoopId); assert(theLoop.name === name); assert(theLoop.body === body); @@ -165,6 +173,7 @@ console.log("# Break"); const theBreak = binaryen.Break(module.br(name, condition, value)); assert(theBreak instanceof binaryen.Break); assert(theBreak instanceof binaryen.Expression); + assertInfoEqual(theBreak, binaryen.getExpressionInfo(theBreak)); assert(theBreak.name === name); assert(theBreak.condition === condition); assert(theBreak.value === value); @@ -199,6 +208,7 @@ console.log("# Switch"); const theSwitch = binaryen.Switch(module.switch(names, defaultName, condition, value)); assert(theSwitch instanceof binaryen.Switch); assert(theSwitch instanceof binaryen.Expression); + assertInfoEqual(theSwitch, binaryen.getExpressionInfo(theSwitch)); assert(theSwitch.numNames === 2); assertDeepEqual(theSwitch.names, names); assert(theSwitch.defaultName === defaultName); @@ -249,6 +259,7 @@ console.log("# Call"); const theCall = binaryen.Call(module.call(target, operands, binaryen.i32)); assert(theCall instanceof binaryen.Call); assert(theCall instanceof binaryen.Expression); + assertInfoEqual(theCall, binaryen.getExpressionInfo(theCall)); assert(theCall.target === target); assertDeepEqual(theCall.operands, operands); assertDeepEqual(theCall.getOperands(), operands); @@ -306,6 +317,7 @@ console.log("# CallIndirect"); const theCallIndirect = binaryen.CallIndirect(module.call_indirect(table, target, operands, params, results)); assert(theCallIndirect instanceof binaryen.CallIndirect); assert(theCallIndirect instanceof binaryen.Expression); + assertInfoEqual(theCallIndirect, binaryen.getExpressionInfo(theCallIndirect)); assert(theCallIndirect.table === table); assert(theCallIndirect.target === target); assertDeepEqual(theCallIndirect.operands, operands); @@ -363,6 +375,7 @@ console.log("# LocalGet"); const theLocalGet = binaryen.LocalGet(module.local.get(index, type)); assert(theLocalGet instanceof binaryen.LocalGet); assert(theLocalGet instanceof binaryen.Expression); + assertInfoEqual(theLocalGet, binaryen.getExpressionInfo(theLocalGet)); assert(theLocalGet.index === index); assert(theLocalGet.type === type); @@ -391,6 +404,7 @@ console.log("# LocalSet"); const theLocalSet = binaryen.LocalSet(module.local.set(index, value)); assert(theLocalSet instanceof binaryen.LocalSet); assert(theLocalSet instanceof binaryen.Expression); + assertInfoEqual(theLocalSet, binaryen.getExpressionInfo(theLocalSet)); assert(theLocalSet.index === index); assert(theLocalSet.value === value); assert(theLocalSet.tee === false); @@ -425,6 +439,7 @@ console.log("# GlobalGet"); const theGlobalGet = binaryen.GlobalGet(module.global.get(name, type)); assert(theGlobalGet instanceof binaryen.GlobalGet); assert(theGlobalGet instanceof binaryen.Expression); + assertInfoEqual(theGlobalGet, binaryen.getExpressionInfo(theGlobalGet)); assert(theGlobalGet.name === name); assert(theGlobalGet.type === type); @@ -453,6 +468,7 @@ console.log("# GlobalSet"); const theGlobalSet = binaryen.GlobalSet(module.global.set(name, value)); assert(theGlobalSet instanceof binaryen.GlobalSet); assert(theGlobalSet instanceof binaryen.Expression); + assertInfoEqual(theGlobalSet, binaryen.getExpressionInfo(theGlobalSet)); assert(theGlobalSet.name === name); assert(theGlobalSet.value === value); assert(theGlobalSet.type == binaryen.none); @@ -481,6 +497,7 @@ console.log("# MemorySize"); const theMemorySize = binaryen.MemorySize(module.memory.size()); assert(theMemorySize instanceof binaryen.MemorySize); assert(theMemorySize instanceof binaryen.Expression); + assertInfoEqual(theMemorySize, binaryen.getExpressionInfo(theMemorySize)); assert(theMemorySize.type === type); theMemorySize.finalize(); @@ -504,6 +521,7 @@ console.log("# MemoryGrow"); const theMemoryGrow = binaryen.MemoryGrow(module.memory.grow(delta)); assert(theMemoryGrow instanceof binaryen.MemoryGrow); assert(theMemoryGrow instanceof binaryen.Expression); + assertInfoEqual(theMemoryGrow, binaryen.getExpressionInfo(theMemoryGrow)); assert(theMemoryGrow.delta === delta); assert(theMemoryGrow.type === type); @@ -532,6 +550,7 @@ console.log("# Load"); const theLoad = binaryen.Load(module.i32.load(offset, align, ptr)); assert(theLoad instanceof binaryen.Load); assert(theLoad instanceof binaryen.Expression); + assertInfoEqual(theLoad, binaryen.getExpressionInfo(theLoad)); assert(theLoad.offset === offset); assert(theLoad.align === align); assert(theLoad.ptr === ptr); @@ -579,6 +598,7 @@ console.log("# Store"); const theStore = binaryen.Store(module.i32.store(offset, align, ptr, value)); assert(theStore instanceof binaryen.Store); assert(theStore instanceof binaryen.Expression); + assertInfoEqual(theStore, binaryen.getExpressionInfo(theStore)); assert(theStore.offset === offset); assert(theStore.align === align); assert(theStore.ptr === ptr); @@ -627,6 +647,7 @@ console.log("# Const"); assert(theConst.valueI32 === 1); theConst.valueI32 = 2; assert(theConst.valueI32 === 2); + assert(theConst.valueI32 === binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.i32); theConst.valueI64Low = 3; @@ -634,21 +655,26 @@ console.log("# Const"); theConst.valueI64High = 4; assert(theConst.valueI64High === 4); theConst.finalize(); + assert(theConst.valueI64Low === binaryen.getExpressionInfo(theConst).value.low); + assert(theConst.valueI64High === binaryen.getExpressionInfo(theConst).value.high); assert(theConst.type == binaryen.i64); theConst.valueF32 = 5; assert(theConst.valueF32 === 5); theConst.finalize(); + assert(theConst.valueF32 === binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.f32); theConst.valueF64 = 6; assert(theConst.valueF64 === 6); theConst.finalize(); + assert(theConst.valueF64 === binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.f64); theConst.valueV128 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; assertDeepEqual(theConst.valueV128, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); theConst.finalize(); + assertDeepEqual(theConst.valueV128, binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.v128); console.log(theConst.toText()); @@ -670,6 +696,7 @@ console.log("# Unary"); const theUnary = binaryen.Unary(module.i32.eqz(value)); assert(theUnary instanceof binaryen.Unary); assert(theUnary instanceof binaryen.Expression); + assertInfoEqual(theUnary, binaryen.getExpressionInfo(theUnary)); assert(theUnary.op === op); assert(theUnary.value === value); assert(theUnary.type === binaryen.i32); @@ -702,6 +729,7 @@ console.log("# Binary"); const theBinary = binaryen.Binary(module.i32.add(left, right)); assert(theBinary instanceof binaryen.Binary); assert(theBinary instanceof binaryen.Expression); + assertInfoEqual(theBinary, binaryen.getExpressionInfo(theBinary)); assert(theBinary.op === op); assert(theBinary.left === left); assert(theBinary.right === right); @@ -737,6 +765,7 @@ console.log("# Select"); const theSelect = binaryen.Select(module.select(condition, ifTrue, ifFalse)); assert(theSelect.ifTrue === ifTrue); assert(theSelect instanceof binaryen.Select); assert(theSelect instanceof binaryen.Expression); + assertInfoEqual(theSelect, binaryen.getExpressionInfo(theSelect)); assert(theSelect.condition === condition); assert(theSelect.ifTrue === ifTrue); assert(theSelect.ifFalse === ifFalse); @@ -769,6 +798,7 @@ console.log("# Drop"); const theDrop = binaryen.Drop(module.drop(value)); assert(theDrop instanceof binaryen.Drop); assert(theDrop instanceof binaryen.Expression); + assertInfoEqual(theDrop, binaryen.getExpressionInfo(theDrop)); assert(theDrop.value === value); assert(theDrop.type === binaryen.none); @@ -796,6 +826,7 @@ console.log("# Return"); const theReturn = binaryen.Return(module.return(value)); assert(theReturn instanceof binaryen.Return); assert(theReturn instanceof binaryen.Expression); + assertInfoEqual(theReturn, binaryen.getExpressionInfo(theReturn)); assert(theReturn.value === value); assert(theReturn.type === binaryen.unreachable); @@ -827,6 +858,7 @@ console.log("# AtomicRMW"); const theAtomicRMW = binaryen.AtomicRMW(module.i32.atomic.rmw.add(offset, ptr, value)); assert(theAtomicRMW instanceof binaryen.AtomicRMW); assert(theAtomicRMW instanceof binaryen.Expression); + assertInfoEqual(theAtomicRMW, binaryen.getExpressionInfo(theAtomicRMW)); assert(theAtomicRMW.op === op); assert(theAtomicRMW.bytes === 4); assert(theAtomicRMW.offset === offset); @@ -870,6 +902,7 @@ console.log("# AtomicCmpxchg"); const theAtomicCmpxchg = binaryen.AtomicCmpxchg(module.i32.atomic.rmw.cmpxchg(offset, ptr, expected, replacement)); assert(theAtomicCmpxchg instanceof binaryen.AtomicCmpxchg); assert(theAtomicCmpxchg instanceof binaryen.Expression); + assertInfoEqual(theAtomicCmpxchg, binaryen.getExpressionInfo(theAtomicCmpxchg)); assert(theAtomicCmpxchg.bytes === 4); assert(theAtomicCmpxchg.offset === offset); assert(theAtomicCmpxchg.ptr === ptr); @@ -912,6 +945,7 @@ console.log("# AtomicWait"); const theAtomicWait = binaryen.AtomicWait(module.memory.atomic.wait32(ptr, expected, timeout)); assert(theAtomicWait instanceof binaryen.AtomicWait); assert(theAtomicWait instanceof binaryen.Expression); + assertInfoEqual(theAtomicWait, binaryen.getExpressionInfo(theAtomicWait)); assert(theAtomicWait.ptr === ptr); assert(theAtomicWait.expected === expected); assert(theAtomicWait.expectedType === binaryen.i32); @@ -950,6 +984,7 @@ console.log("# AtomicNotify"); const theAtomicNotify = binaryen.AtomicNotify(module.memory.atomic.notify(ptr, notifyCount)); assert(theAtomicNotify instanceof binaryen.AtomicNotify); assert(theAtomicNotify instanceof binaryen.Expression); + assertInfoEqual(theAtomicNotify, binaryen.getExpressionInfo(theAtomicNotify)); assert(theAtomicNotify.ptr === ptr); assert(theAtomicNotify.notifyCount === notifyCount); assert(theAtomicNotify.type === binaryen.i32); @@ -979,6 +1014,7 @@ console.log("# AtomicFence"); const theAtomicFence = binaryen.AtomicFence(module.atomic.fence()); assert(theAtomicFence instanceof binaryen.AtomicFence); assert(theAtomicFence instanceof binaryen.Expression); + assertInfoEqual(theAtomicFence, binaryen.getExpressionInfo(theAtomicFence)); assert(theAtomicFence.order === 0); // reserved, not yet used assert(theAtomicFence.type === binaryen.none); @@ -1008,6 +1044,7 @@ console.log("# SIMDExtract"); const theSIMDExtract = binaryen.SIMDExtract(module.i8x16.extract_lane_s(vec, index)); assert(theSIMDExtract instanceof binaryen.SIMDExtract); assert(theSIMDExtract instanceof binaryen.Expression); + assertInfoEqual(theSIMDExtract, binaryen.getExpressionInfo(theSIMDExtract)); assert(theSIMDExtract.op === op); assert(theSIMDExtract.vec === vec); assert(theSIMDExtract.index === index); @@ -1044,6 +1081,7 @@ console.log("# SIMDReplace"); const theSIMDReplace = binaryen.SIMDReplace(module.i8x16.replace_lane(vec, index, value)); assert(theSIMDReplace instanceof binaryen.SIMDReplace); assert(theSIMDReplace instanceof binaryen.Expression); + assertInfoEqual(theSIMDReplace, binaryen.getExpressionInfo(theSIMDReplace)); assert(theSIMDReplace.op === op); assert(theSIMDReplace.vec === vec); assert(theSIMDReplace.index === index); @@ -1082,6 +1120,7 @@ console.log("# SIMDShuffle"); const theSIMDShuffle = binaryen.SIMDShuffle(module.i8x16.shuffle(left, right, mask)); assert(theSIMDShuffle instanceof binaryen.SIMDShuffle); assert(theSIMDShuffle instanceof binaryen.Expression); + assertInfoEqual(theSIMDShuffle, binaryen.getExpressionInfo(theSIMDShuffle)); assert(theSIMDShuffle.left === left); assert(theSIMDShuffle.right === right); assertDeepEqual(theSIMDShuffle.mask, mask); @@ -1118,6 +1157,7 @@ console.log("# SIMDTernary"); const theSIMDTernary = binaryen.SIMDTernary(module.v128.bitselect(a, b, c)); assert(theSIMDTernary instanceof binaryen.SIMDTernary); assert(theSIMDTernary instanceof binaryen.Expression); + assertInfoEqual(theSIMDTernary, binaryen.getExpressionInfo(theSIMDTernary)); assert(theSIMDTernary.op === op); assert(theSIMDTernary.a === a); assert(theSIMDTernary.b === b); @@ -1144,6 +1184,7 @@ console.log("# SIMDShift"); const theSIMDShift = binaryen.SIMDShift(module.i8x16.shl(vec, shift)); assert(theSIMDShift instanceof binaryen.SIMDShift); assert(theSIMDShift instanceof binaryen.Expression); + assertInfoEqual(theSIMDShift, binaryen.getExpressionInfo(theSIMDShift)); assert(theSIMDShift.op === op); assert(theSIMDShift.vec === vec); assert(theSIMDShift.shift === shift); @@ -1181,6 +1222,7 @@ console.log("# SIMDLoad"); const theSIMDLoad = binaryen.SIMDLoad(module.v128.load8x8_s(offset, align, ptr)); assert(theSIMDLoad instanceof binaryen.SIMDLoad); assert(theSIMDLoad instanceof binaryen.Expression); + assertInfoEqual(theSIMDLoad, binaryen.getExpressionInfo(theSIMDLoad)); assert(theSIMDLoad.offset === offset); assert(theSIMDLoad.align === align); assert(theSIMDLoad.ptr === ptr); @@ -1222,6 +1264,7 @@ console.log("# SIMDLoadStoreLane"); const theSIMDLoadStoreLane = binaryen.SIMDLoadStoreLane(module.v128.load8_lane(offset, align, index, ptr, vec)); assert(theSIMDLoadStoreLane instanceof binaryen.SIMDLoadStoreLane); assert(theSIMDLoadStoreLane instanceof binaryen.Expression); + assertInfoEqual(theSIMDLoadStoreLane, binaryen.getExpressionInfo(theSIMDLoadStoreLane)); assert(theSIMDLoadStoreLane.op === op); assert(theSIMDLoadStoreLane.offset === offset); assert(theSIMDLoadStoreLane.align === align); @@ -1283,6 +1326,7 @@ console.log("# MemoryInit"); const theMemoryInit = binaryen.MemoryInit(module.memory.init(segment, dest, offset, size)); assert(theMemoryInit instanceof binaryen.MemoryInit); assert(theMemoryInit instanceof binaryen.Expression); + assertInfoEqual(theMemoryInit, binaryen.getExpressionInfo(theMemoryInit)); assert(theMemoryInit.segment === segment); assert(theMemoryInit.dest === dest); assert(theMemoryInit.offset === offset); @@ -1319,6 +1363,7 @@ console.log("# DataDrop"); const theDataDrop = binaryen.DataDrop(module.data.drop(segment)); assert(theDataDrop instanceof binaryen.DataDrop); assert(theDataDrop instanceof binaryen.Expression); + assertInfoEqual(theDataDrop, binaryen.getExpressionInfo(theDataDrop)); assert(theDataDrop.segment === segment); assert(theDataDrop.type === binaryen.none); @@ -1349,6 +1394,7 @@ console.log("# MemoryCopy"); const theMemoryCopy = binaryen.MemoryCopy(module.memory.copy(dest, source, size)); assert(theMemoryCopy instanceof binaryen.MemoryCopy); assert(theMemoryCopy instanceof binaryen.Expression); + assertInfoEqual(theMemoryCopy, binaryen.getExpressionInfo(theMemoryCopy)); assert(theMemoryCopy.dest === dest); assert(theMemoryCopy.source === source); assert(theMemoryCopy.size === size); @@ -1385,6 +1431,7 @@ console.log("# MemoryFill"); const theMemoryFill = binaryen.MemoryFill(module.memory.fill(dest, value, size)); assert(theMemoryFill instanceof binaryen.MemoryFill); assert(theMemoryFill instanceof binaryen.Expression); + assertInfoEqual(theMemoryFill, binaryen.getExpressionInfo(theMemoryFill)); assert(theMemoryFill.dest === dest); assert(theMemoryFill.value === value); assert(theMemoryFill.size === size); @@ -1418,6 +1465,7 @@ console.log("# RefIsNull"); const theRefIsNull = binaryen.RefIsNull(module.ref.is_null(value)); assert(theRefIsNull instanceof binaryen.RefIsNull); assert(theRefIsNull instanceof binaryen.Expression); + assertInfoEqual(theRefIsNull, binaryen.getExpressionInfo(theRefIsNull)); assert(theRefIsNull.value === value); assert(theRefIsNull.type === binaryen.i32); @@ -1447,6 +1495,7 @@ console.log("# RefAs"); const theRefAs = binaryen.RefAs(module.ref.as_non_null(value)); assert(theRefAs instanceof binaryen.RefAs); assert(theRefAs instanceof binaryen.Expression); + assertInfoEqual(theRefAs, binaryen.getExpressionInfo(theRefAs)); assert(theRefAs.op === op); assert(theRefAs.value === value); assert(theRefAs.type !== binaryen.i32); // TODO: === (ref any) @@ -1482,6 +1531,7 @@ console.log("# RefFunc"); const theRefFunc = binaryen.RefFunc(module.ref.func(func, type)); assert(theRefFunc instanceof binaryen.RefFunc); assert(theRefFunc instanceof binaryen.Expression); + assertInfoEqual(theRefFunc, binaryen.getExpressionInfo(theRefFunc)); assert(theRefFunc.func === func); assert(theRefFunc.type === type); @@ -1509,6 +1559,7 @@ console.log("# RefEq"); const theRefEq = binaryen.RefEq(module.ref.eq(left, right)); assert(theRefEq instanceof binaryen.RefEq); assert(theRefEq instanceof binaryen.Expression); + assertInfoEqual(theRefEq, binaryen.getExpressionInfo(theRefEq)); assert(theRefEq.left === left); assert(theRefEq.right === right); assert(theRefEq.type === binaryen.i32); @@ -1540,6 +1591,7 @@ console.log("# RefTest"); const theRefTest = binaryen.RefTest(module.ref.test(ref, castType)); assert(theRefTest instanceof binaryen.RefTest); assert(theRefTest instanceof binaryen.Expression); + assertInfoEqual(theRefTest, binaryen.getExpressionInfo(theRefTest)); assert(theRefTest.ref === ref); assert(theRefTest.castType === castType); assert(theRefTest.type === binaryen.i32); @@ -1571,6 +1623,7 @@ console.log("# RefCast"); const theRefCast = binaryen.RefCast(module.ref.cast(ref, type)); assert(theRefCast instanceof binaryen.RefCast); assert(theRefCast instanceof binaryen.Expression); + assertInfoEqual(theRefCast, binaryen.getExpressionInfo(theRefCast)); assert(theRefCast.ref === ref); assert(theRefCast.type === type); @@ -1601,6 +1654,7 @@ console.log("# BrOn"); const theBrOn = binaryen.BrOn(module.br_on_null(name, ref)); assert(theBrOn instanceof binaryen.BrOn); assert(theBrOn instanceof binaryen.Expression); + assertInfoEqual(theBrOn, binaryen.getExpressionInfo(theBrOn)); assert(theBrOn.name === name); assert(theBrOn.ref === ref); assert(theBrOn.op === op); @@ -1653,6 +1707,7 @@ console.log("# StructNew"); const theStructNew = binaryen.StructNew(module.struct.new(operands, type)); assert(theStructNew instanceof binaryen.StructNew); assert(theStructNew instanceof binaryen.Expression); + assertInfoEqual(theStructNew, binaryen.getExpressionInfo(theStructNew)); assertDeepEqual(theStructNew.operands, operands); assertDeepEqual(theStructNew.getOperands(), operands); assert(theStructNew.type === type); @@ -1709,6 +1764,7 @@ console.log("# StructGet"); const theStructGet = binaryen.StructGet(module.struct.get(index, ref, type, signed)); assert(theStructGet instanceof binaryen.StructGet); assert(theStructGet instanceof binaryen.Expression); + assertInfoEqual(theStructGet, binaryen.getExpressionInfo(theStructGet)); assert(theStructGet.index === index); assert(theStructGet.ref === ref); assert(theStructGet.signed === signed); @@ -1757,6 +1813,7 @@ console.log("# StructSet"); const theStructSet = binaryen.StructSet(module.struct.set(index, ref, value)); assert(theStructSet instanceof binaryen.StructSet); assert(theStructSet instanceof binaryen.Expression); + assertInfoEqual(theStructSet, binaryen.getExpressionInfo(theStructSet)); assert(theStructSet.index === index); assert(theStructSet.ref === ref); assert(theStructSet.value === value); @@ -1800,6 +1857,7 @@ console.log("# ArrayNew"); const theArrayNew = binaryen.ArrayNew(module.array.new(type, size, init)); assert(theArrayNew instanceof binaryen.ArrayNew); assert(theArrayNew instanceof binaryen.Expression); + assertInfoEqual(theArrayNew, binaryen.getExpressionInfo(theArrayNew)); assert(theArrayNew.size === size); assert(theArrayNew.init === init); assert(theArrayNew.type === type); @@ -1842,6 +1900,7 @@ console.log("# ArrayNewFixed"); const theArrayNewFixed = binaryen.ArrayNewFixed(module.array.new_fixed(type, values)); assert(theArrayNewFixed instanceof binaryen.ArrayNewFixed); assert(theArrayNewFixed instanceof binaryen.Expression); + assertInfoEqual(theArrayNewFixed, binaryen.getExpressionInfo(theArrayNewFixed)); assertDeepEqual(theArrayNewFixed.values, values); assertDeepEqual(theArrayNewFixed.getValues(), values); assert(theArrayNewFixed.type === type); @@ -1893,6 +1952,7 @@ console.log("# ArrayNewData"); const theArrayNewData = binaryen.ArrayNewData(module.array.new_data(type, segment, offset, size)); assert(theArrayNewData instanceof binaryen.ArrayNewData); assert(theArrayNewData instanceof binaryen.Expression); + assertInfoEqual(theArrayNewData, binaryen.getExpressionInfo(theArrayNewData)); assert(theArrayNewData.segment === segment); assert(theArrayNewData.offset === offset); assert(theArrayNewData.size === size); @@ -1937,6 +1997,7 @@ console.log("# ArrayNewElem"); const theArrayNewElem = binaryen.ArrayNewElem(module.array.new_elem(type, segment, offset, size)); assert(theArrayNewElem instanceof binaryen.ArrayNewElem); assert(theArrayNewElem instanceof binaryen.Expression); + assertInfoEqual(theArrayNewElem, binaryen.getExpressionInfo(theArrayNewElem)); assert(theArrayNewElem.segment === segment); assert(theArrayNewElem.offset === offset); assert(theArrayNewElem.size === size); @@ -1981,6 +2042,7 @@ console.log("# ArrayGet"); const theArrayGet = binaryen.ArrayGet(module.array.get(ref, index, type, signed)); assert(theArrayGet instanceof binaryen.ArrayGet); assert(theArrayGet instanceof binaryen.Expression); + assertInfoEqual(theArrayGet, binaryen.getExpressionInfo(theArrayGet)); assert(theArrayGet.ref === ref); assert(theArrayGet.index === index); assert(theArrayGet.signed === signed); @@ -2024,6 +2086,7 @@ console.log("# ArraySet"); const theArraySet = binaryen.ArraySet(module.array.set(ref, index, value)); assert(theArraySet instanceof binaryen.ArraySet); assert(theArraySet instanceof binaryen.Expression); + assertInfoEqual(theArraySet, binaryen.getExpressionInfo(theArraySet)); assert(theArraySet.ref === ref); assert(theArraySet.index === index); assert(theArraySet.value === value); @@ -2065,6 +2128,7 @@ console.log("# ArrayLen"); const theArrayLen = binaryen.ArrayLen(module.array.len(ref)); assert(theArrayLen instanceof binaryen.ArrayLen); assert(theArrayLen instanceof binaryen.Expression); + assertInfoEqual(theArrayLen, binaryen.getExpressionInfo(theArrayLen)); assert(theArrayLen.ref === ref); assert(theArrayLen.type === binaryen.i32); @@ -2103,6 +2167,7 @@ console.log("# ArrayFill"); const theArrayFill = binaryen.ArrayFill(module.array.fill(ref, index, value, size)); assert(theArrayFill instanceof binaryen.ArrayFill); assert(theArrayFill instanceof binaryen.Expression); + assertInfoEqual(theArrayFill, binaryen.getExpressionInfo(theArrayFill)); assert(theArrayFill.ref === ref); assert(theArrayFill.index === index); assert(theArrayFill.value === value); @@ -2151,6 +2216,7 @@ console.log("# ArrayCopy"); const theArrayCopy = binaryen.ArrayCopy(module.array.copy(destRef, destIndex, srcRef, srcIndex, length)); assert(theArrayCopy instanceof binaryen.ArrayCopy); assert(theArrayCopy instanceof binaryen.Expression); + assertInfoEqual(theArrayCopy, binaryen.getExpressionInfo(theArrayCopy)); assert(theArrayCopy.destRef === destRef); assert(theArrayCopy.destIndex === destIndex); assert(theArrayCopy.srcRef === srcRef); @@ -2202,6 +2268,7 @@ console.log("# ArrayInitData"); const theArrayInitData = binaryen.ArrayInitData(module.array.init_data(segment, ref, index, offset, size)); assert(theArrayInitData instanceof binaryen.ArrayInitData); assert(theArrayInitData instanceof binaryen.Expression); + assertInfoEqual(theArrayInitData, binaryen.getExpressionInfo(theArrayInitData)); assert(theArrayInitData.segment === segment); assert(theArrayInitData.ref === ref); assert(theArrayInitData.index === index); @@ -2253,6 +2320,7 @@ console.log("# ArrayInitElem"); const theArrayInitElem = binaryen.ArrayInitElem(module.array.init_elem(segment, ref, index, offset, size)); assert(theArrayInitElem instanceof binaryen.ArrayInitElem); assert(theArrayInitElem instanceof binaryen.Expression); + assertInfoEqual(theArrayInitElem, binaryen.getExpressionInfo(theArrayInitElem)); assert(theArrayInitElem.segment === segment); assert(theArrayInitElem.ref === ref); assert(theArrayInitElem.index === index); @@ -2299,6 +2367,7 @@ console.log("# Try"); const theTry = binaryen.Try(module.try('', body, ["tag1"], catchBodies, '')); assert(theTry instanceof binaryen.Try); assert(theTry instanceof binaryen.Expression); + assertInfoEqual(theTry, binaryen.getExpressionInfo(theTry)); assert(theTry.body === body); assertDeepEqual(theTry.catchBodies, catchBodies); assert(theTry.type === binaryen.i32); @@ -2373,6 +2442,7 @@ console.log("# Throw"); const theThrow = binaryen.Throw(module.throw(tag, operands)); assert(theThrow instanceof binaryen.Throw); assert(theThrow instanceof binaryen.Expression); + assertInfoEqual(theThrow, binaryen.getExpressionInfo(theThrow)); assert(theThrow.tag === tag); assertDeepEqual(theThrow.operands, operands); assert(theThrow.type === binaryen.unreachable); @@ -2415,6 +2485,7 @@ console.log("# Rethrow"); const theRethrow = binaryen.Rethrow(module.rethrow("l0")); assert(theRethrow instanceof binaryen.Rethrow); assert(theRethrow instanceof binaryen.Expression); + assertInfoEqual(theRethrow, binaryen.getExpressionInfo(theRethrow)); assert(theRethrow.target === "l0"); assert(theRethrow.type === binaryen.unreachable); @@ -2446,6 +2517,7 @@ console.log("# TupleMake"); const theTupleMake = binaryen.TupleMake(module.tuple.make(operands)); assert(theTupleMake instanceof binaryen.TupleMake); assert(theTupleMake instanceof binaryen.Expression); + assertInfoEqual(theTupleMake, binaryen.getExpressionInfo(theTupleMake)); assertDeepEqual(theTupleMake.operands, operands); assert(theTupleMake.type === type); @@ -2490,6 +2562,7 @@ console.log("# TupleExtract"); const theTupleExtract = binaryen.TupleExtract(module.tuple.extract(tuple, index)); assert(theTupleExtract instanceof binaryen.TupleExtract); assert(theTupleExtract instanceof binaryen.Expression); + assertInfoEqual(theTupleExtract, binaryen.getExpressionInfo(theTupleExtract)); assert(theTupleExtract.tuple === tuple); assert(theTupleExtract.index === index); assert(theTupleExtract.type === binaryen.i32); @@ -2523,6 +2596,7 @@ console.log("# RefI31"); const theRefI31 = binaryen.RefI31(module.ref.i31(value)); assert(theRefI31 instanceof binaryen.RefI31); assert(theRefI31 instanceof binaryen.Expression); + assertInfoEqual(theRefI31, binaryen.getExpressionInfo(theRefI31)); assert(theRefI31.value === value); // assert(theRefI31.type === binaryen.?); // TODO: (ref i31) @@ -2547,6 +2621,7 @@ console.log("# I31Get"); const theI31Get = binaryen.I31Get(module.i31.get_s(i31)); assert(theI31Get instanceof binaryen.I31Get); assert(theI31Get instanceof binaryen.Expression); + assertInfoEqual(theI31Get, binaryen.getExpressionInfo(theI31Get)); assert(theI31Get.i31 === i31); assert(theI31Get.signed === true); assert(theI31Get.type === binaryen.i32); From 2b85d67ce34f63caf1b090de3051323393a72c1d Mon Sep 17 00:00:00 2001 From: GulgDev Date: Wed, 16 Apr 2025 21:10:31 +0500 Subject: [PATCH 2/6] Add missing expression ids to `getExpressionInfo` & fix existing --- src/js/binaryen.js-post.js | 144 ++++++++++++++++++++- test/binaryen.js/exception-handling.js.txt | 4 +- 2 files changed, 141 insertions(+), 7 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 5521cc6cca8..37ae0505883 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3058,7 +3058,7 @@ Module['getExpressionType'] = function(expr) { Module['getExpressionInfo'] = function(expr) { const id = Module['_BinaryenExpressionGetId'](expr); const type = Module['_BinaryenExpressionGetType'](expr); - switch (id) { // TODO: GC instructions + switch (id) { case Module['BlockId']: return { 'id': id, @@ -3113,7 +3113,7 @@ Module['getExpressionInfo'] = function(expr) { 'type': type, 'isReturn': Boolean(Module['_BinaryenCallIndirectIsReturn'](expr)), 'target': Module['_BinaryenCallIndirectGetTarget'](expr), - 'table': Module['_BinaryenCallIndirectGetTable'](expr), + 'table': UTF8ToString(Module['_BinaryenCallIndirectGetTable'](expr)), 'operands': getAllNested(expr, Module['_BinaryenCallIndirectGetNumOperands'], Module['_BinaryenCallIndirectGetOperandAt']) }; case Module['LocalGetId']: @@ -3446,17 +3446,151 @@ Module['getExpressionInfo'] = function(expr) { 'left': Module['_BinaryenRefEqGetLeft'](expr), 'right': Module['_BinaryenRefEqGetRight'](expr) }; + case Module['RefTestId']: + return { + 'id': id, + 'type': type, + 'ref': Module['_BinaryenRefTestGetRef'](expr), + 'castType': Module['_BinaryenRefTestGetCastType'](expr) + }; + case Module['RefCastId']: + return { + 'id': id, + 'type': type, + 'ref': Module['_BinaryenRefCastGetRef'](expr) + }; + case Module['BrOnId']: + return { + 'id': id, + 'type': type, + 'op': Module['_BinaryenBrOnGetOp'](expr), + 'name': UTF8ToString(Module['_BinaryenBrOnGetName'](expr)), + 'ref': Module['_BinaryenBrOnGetRef'](expr), + 'castType': Module['_BinaryenBrOnGetCastType'](expr) + }; + case Module['StructNewId']: + return { + 'id': id, + 'type': type, + 'operands': getAllNested(expr, Module['_BinaryenStructNewGetNumOperands'], Module['_BinaryenStructNewGetOperandAt']), + }; + case Module['StructGetId']: + return { + 'id': id, + 'type': type, + 'index': Module['_BinaryenStructGetGetIndex'](expr), + 'ref': Module['_BinaryenStructGetGetRef'](expr), + 'isSigned': Boolean(Module['_BinaryenStructGetIsSigned'](expr)) + }; + case Module['StructSetId']: + return { + 'id': id, + 'type': type, + 'index': Module['_BinaryenStructSetGetIndex'](expr), + 'ref': Module['_BinaryenStructSetGetRef'](expr), + 'value': Module['_BinaryenStructSetGetValue'](expr) + }; + case Module['ArrayNewId']: + return { + 'id': id, + 'type': type, + 'getInit': Module['_BinaryenArrayNewGetInit'](expr), + 'getSize': Module['_BinaryenArrayNewGetSize'](expr) + }; + case Module['ArrayNewFixedId']: + return { + 'id': id, + 'type': type, + 'values': getAllNested(expr, Module['_BinaryenArrayNewFixedGetNumValues'], Module['_BinaryenArrayNewFixedGetValueAt']) + }; + case Module['ArrayNewDataId']: + return { + 'id': id, + 'type': type, + 'segment': UTF8ToString(Module['_BinaryenArrayNewDataGetSegment'](expr)), + 'offset': Module['_BinaryenArrayNewDataGetOffset'](expr), + 'size': Module['_BinaryenArrayNewDataGetSize'](expr) + }; + case Module['ArrayNewElemId']: + return { + 'id': id, + 'type': type, + 'segment': UTF8ToString(Module['_BinaryenArrayNewElemGetSegment'](expr)), + 'offset': Module['_BinaryenArrayNewElemGetOffset'](expr), + 'size': Module['_BinaryenArrayNewElemGetSize'](expr) + }; + case Module['ArrayGetId']: + return { + 'id': id, + 'type': type, + 'ref': Module['_BinaryenArrayGetGetRef'](expr), + 'index': Module['_BinaryenArrayGetGetIndex'](expr), + 'isSigned': Boolean(Module['_BinaryenArrayGetIsSigned'](expr)) + }; + case Module['ArraySetId']: + return { + 'id': id, + 'type': type, + 'ref': Module['_BinaryenArraySetGetRef'](expr), + 'index': Module['_BinaryenArraySetGetIndex'](expr), + 'value': Module['_BinaryenArraySetGetValue'](expr) + }; + case Module['ArrayLenId']: + return { + 'id': id, + 'type': type, + 'ref': Module['_BinaryenArrayLenGetRef'](expr) + }; + case Module['ArrayFillId']: + return { + 'id': id, + 'type': type, + 'ref': Module['_BinaryenArrayFillGetRef'](expr), + 'index': Module['_BinaryenArrayFillGetIndex'](expr), + 'value': Module['_BinaryenArrayFillGetValue'](expr), + 'size': Module['_BinaryenArrayFillGetSize'](expr) + }; + case Module['ArrayCopyId']: + return { + 'id': id, + 'type': type, + 'destRef': Module['_BinaryenArrayCopyGetDestRef'](expr), + 'destIndex': Module['_BinaryenArrayCopyGetDestIndex'](expr), + 'srcRef': Module['_BinaryenArrayCopyGetSrcRef'](expr), + 'srcIndex': Module['_BinaryenArrayCopyGetSrcIndex'](expr), + 'length': Module['_BinaryenArrayCopyGetLength'](expr) + }; + case Module['ArrayInitDataId']: + return { + 'id': id, + 'type': type, + 'segment': UTF8ToString(Module['_BinaryenArrayInitDataGetSegment'](expr)), + 'ref': Module['_BinaryenArrayInitDataGetRef'](expr), + 'index': Module['_BinaryenArrayInitDataGetIndex'](expr), + 'offset': Module['_BinaryenArrayInitDataGetOffset'](expr), + 'size': Module['_BinaryenArrayInitDataGetSize'](expr) + }; + case Module['ArrayInitElemId']: + return { + 'id': id, + 'type': type, + 'segment': UTF8ToString(Module['_BinaryenArrayInitElemGetSegment'](expr)), + 'ref': Module['_BinaryenArrayInitElemGetRef'](expr), + 'index': Module['_BinaryenArrayInitElemGetIndex'](expr), + 'offset': Module['_BinaryenArrayInitElemGetOffset'](expr), + 'size': Module['_BinaryenArrayInitElemGetSize'](expr) + }; case Module['TryId']: return { 'id': id, 'type': type, 'name': UTF8ToString(Module['_BinaryenTryGetName'](expr)), 'body': Module['_BinaryenTryGetBody'](expr), - 'catchTags': getAllNested(expr, Module['_BinaryenTryGetNumCatchTags'], Module['_BinaryenTryGetCatchTagAt']), + 'catchTags': getAllNested(expr, Module['_BinaryenTryGetNumCatchTags'], Module['_BinaryenTryGetCatchTagAt']).map(p => UTF8ToString(p)), 'catchBodies': getAllNested(expr, Module['_BinaryenTryGetNumCatchBodies'], Module['_BinaryenTryGetCatchBodyAt']), - 'hasCatchAll': Module['_BinaryenTryHasCatchAll'](expr), + 'hasCatchAll': Boolean(Module['_BinaryenTryHasCatchAll'](expr)), 'delegateTarget': UTF8ToString(Module['_BinaryenTryGetDelegateTarget'](expr)), - 'isDelegate': Module['_BinaryenTryIsDelegate'](expr) + 'isDelegate': Boolean(Module['_BinaryenTryIsDelegate'](expr)) }; case Module['ThrowId']: return { diff --git a/test/binaryen.js/exception-handling.js.txt b/test/binaryen.js/exception-handling.js.txt index 6be0eb40a58..7e2e875749a 100644 --- a/test/binaryen.js/exception-handling.js.txt +++ b/test/binaryen.js/exception-handling.js.txt @@ -36,5 +36,5 @@ getExpressionInfo(throw) = {"id":54,"type":1,"tag":"e"} getExpressionInfo(rethrow) = {"id":55,"type":1,"target":"l0"} -getExpressionInfo(try_catch) = {"id":52,"type":1,"name":"l0","hasCatchAll":0,"delegateTarget":"","isDelegate":0} -getExpressionInfo(try_delegate) = {"id":52,"type":0,"name":"try_outer","hasCatchAll":1,"delegateTarget":"","isDelegate":0} +getExpressionInfo(try_catch) = {"id":52,"type":1,"name":"l0","hasCatchAll":false,"delegateTarget":"","isDelegate":false} +getExpressionInfo(try_delegate) = {"id":52,"type":0,"name":"try_outer","hasCatchAll":true,"delegateTarget":"","isDelegate":false} From b627969321eaa86d5b4cca05ceabe009d79e647f Mon Sep 17 00:00:00 2001 From: GulgDev Date: Thu, 17 Apr 2025 21:13:02 +0500 Subject: [PATCH 3/6] Replace `assertInfoEqual` with explicit property checks and fix inconsistencies in `getExpressionInfo` --- src/js/binaryen.js-post.js | 45 +- test/binaryen.js/exception-handling.js.txt | 4 +- test/binaryen.js/expressions.js | 908 +++++++++++++++++++-- 3 files changed, 865 insertions(+), 92 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 37ae0505883..4695a5a4d85 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3059,13 +3059,15 @@ Module['getExpressionInfo'] = function(expr) { const id = Module['_BinaryenExpressionGetId'](expr); const type = Module['_BinaryenExpressionGetType'](expr); switch (id) { - case Module['BlockId']: + case Module['BlockId']: { + const name = Module['_BinaryenBlockGetName'](expr); return { 'id': id, 'type': type, - 'name': UTF8ToString(Module['_BinaryenBlockGetName'](expr)), + 'name': name ? UTF8ToString(name) : null, 'children': getAllNested(expr, Module['_BinaryenBlockGetNumChildren'], Module['_BinaryenBlockGetChildAt']) }; + } case Module['IfId']: return { 'id': id, @@ -3074,21 +3076,25 @@ Module['getExpressionInfo'] = function(expr) { 'ifTrue': Module['_BinaryenIfGetIfTrue'](expr), 'ifFalse': Module['_BinaryenIfGetIfFalse'](expr) }; - case Module['LoopId']: + case Module['LoopId']: { + const name = Module['_BinaryenLoopGetName'](expr); return { 'id': id, 'type': type, - 'name': UTF8ToString(Module['_BinaryenLoopGetName'](expr)), + 'name': name ? UTF8ToString(name) : null, 'body': Module['_BinaryenLoopGetBody'](expr) }; - case Module['BreakId']: + } + case Module['BreakId']: { + const name = Module['_BinaryenBreakGetName'](expr); return { 'id': id, 'type': type, - 'name': UTF8ToString(Module['_BinaryenBreakGetName'](expr)), + 'name': name ? UTF8ToString(name) : null, 'condition': Module['_BinaryenBreakGetCondition'](expr), 'value': Module['_BinaryenBreakGetValue'](expr) }; + } case Module['SwitchId']: return { 'id': id, @@ -3114,7 +3120,9 @@ Module['getExpressionInfo'] = function(expr) { 'isReturn': Boolean(Module['_BinaryenCallIndirectIsReturn'](expr)), 'target': Module['_BinaryenCallIndirectGetTarget'](expr), 'table': UTF8ToString(Module['_BinaryenCallIndirectGetTable'](expr)), - 'operands': getAllNested(expr, Module['_BinaryenCallIndirectGetNumOperands'], Module['_BinaryenCallIndirectGetOperandAt']) + 'operands': getAllNested(expr, Module['_BinaryenCallIndirectGetNumOperands'], Module['_BinaryenCallIndirectGetOperandAt']), + 'params': Module['_BinaryenCallIndirectGetParams'](expr), + 'results': Module['_BinaryenCallIndirectGetResults'](expr) }; case Module['LocalGetId']: return { @@ -3192,7 +3200,8 @@ Module['getExpressionInfo'] = function(expr) { 'bytes': Module['_BinaryenStoreGetBytes'](expr), 'align': Module['_BinaryenStoreGetAlign'](expr), 'ptr': Module['_BinaryenStoreGetPtr'](expr), - 'value': Module['_BinaryenStoreGetValue'](expr) + 'value': Module['_BinaryenStoreGetValue'](expr), + 'valueType': Module['_BinaryenStoreGetValueType'](expr) }; case Module['ConstId']: { let value; @@ -3386,11 +3395,13 @@ Module['getExpressionInfo'] = function(expr) { 'align': Module['_BinaryenSIMDLoadStoreLaneGetAlign'](expr), 'index': Module['_BinaryenSIMDLoadStoreLaneGetIndex'](expr), 'ptr': Module['_BinaryenSIMDLoadStoreLaneGetPtr'](expr), - 'vec': Module['_BinaryenSIMDLoadStoreLaneGetVec'](expr) + 'vec': Module['_BinaryenSIMDLoadStoreLaneGetVec'](expr), + 'isStore': Boolean(Module['_BinaryenSIMDLoadStoreLaneIsStore'](expr)) }; case Module['MemoryInitId']: return { 'id': id, + 'type': type, 'segment': UTF8ToString(Module['_BinaryenMemoryInitGetSegment'](expr)), 'dest': Module['_BinaryenMemoryInitGetDest'](expr), 'offset': Module['_BinaryenMemoryInitGetOffset'](expr), @@ -3399,11 +3410,13 @@ Module['getExpressionInfo'] = function(expr) { case Module['DataDropId']: return { 'id': id, + 'type': type, 'segment': UTF8ToString(Module['_BinaryenDataDropGetSegment'](expr)), }; case Module['MemoryCopyId']: return { 'id': id, + 'type': type, 'dest': Module['_BinaryenMemoryCopyGetDest'](expr), 'source': Module['_BinaryenMemoryCopyGetSource'](expr), 'size': Module['_BinaryenMemoryCopyGetSize'](expr) @@ -3411,6 +3424,7 @@ Module['getExpressionInfo'] = function(expr) { case Module['MemoryFillId']: return { 'id': id, + 'type': type, 'dest': Module['_BinaryenMemoryFillGetDest'](expr), 'value': Module['_BinaryenMemoryFillGetValue'](expr), 'size': Module['_BinaryenMemoryFillGetSize'](expr) @@ -3494,8 +3508,8 @@ Module['getExpressionInfo'] = function(expr) { return { 'id': id, 'type': type, - 'getInit': Module['_BinaryenArrayNewGetInit'](expr), - 'getSize': Module['_BinaryenArrayNewGetSize'](expr) + 'init': Module['_BinaryenArrayNewGetInit'](expr), + 'size': Module['_BinaryenArrayNewGetSize'](expr) }; case Module['ArrayNewFixedId']: return { @@ -3580,18 +3594,21 @@ Module['getExpressionInfo'] = function(expr) { 'offset': Module['_BinaryenArrayInitElemGetOffset'](expr), 'size': Module['_BinaryenArrayInitElemGetSize'](expr) }; - case Module['TryId']: + case Module['TryId']: { + const name = Module['_BinaryenTryGetName'](expr); + const delegateTarget = Module['_BinaryenTryGetDelegateTarget'](expr); return { 'id': id, 'type': type, - 'name': UTF8ToString(Module['_BinaryenTryGetName'](expr)), + 'name': name ? UTF8ToString(name) : null, 'body': Module['_BinaryenTryGetBody'](expr), 'catchTags': getAllNested(expr, Module['_BinaryenTryGetNumCatchTags'], Module['_BinaryenTryGetCatchTagAt']).map(p => UTF8ToString(p)), 'catchBodies': getAllNested(expr, Module['_BinaryenTryGetNumCatchBodies'], Module['_BinaryenTryGetCatchBodyAt']), 'hasCatchAll': Boolean(Module['_BinaryenTryHasCatchAll'](expr)), - 'delegateTarget': UTF8ToString(Module['_BinaryenTryGetDelegateTarget'](expr)), + 'delegateTarget': delegateTarget ? UTF8ToString(delegateTarget) : null, 'isDelegate': Boolean(Module['_BinaryenTryIsDelegate'](expr)) }; + } case Module['ThrowId']: return { 'id': id, diff --git a/test/binaryen.js/exception-handling.js.txt b/test/binaryen.js/exception-handling.js.txt index 7e2e875749a..992fbb4c479 100644 --- a/test/binaryen.js/exception-handling.js.txt +++ b/test/binaryen.js/exception-handling.js.txt @@ -36,5 +36,5 @@ getExpressionInfo(throw) = {"id":54,"type":1,"tag":"e"} getExpressionInfo(rethrow) = {"id":55,"type":1,"target":"l0"} -getExpressionInfo(try_catch) = {"id":52,"type":1,"name":"l0","hasCatchAll":false,"delegateTarget":"","isDelegate":false} -getExpressionInfo(try_delegate) = {"id":52,"type":0,"name":"try_outer","hasCatchAll":true,"delegateTarget":"","isDelegate":false} +getExpressionInfo(try_catch) = {"id":52,"type":1,"name":"l0","hasCatchAll":false,"delegateTarget":null,"isDelegate":false} +getExpressionInfo(try_delegate) = {"id":52,"type":0,"name":"try_outer","hasCatchAll":true,"delegateTarget":null,"isDelegate":false} diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index df3be3df452..3cbe7e59448 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -7,11 +7,6 @@ function assertDeepEqual(x, y) { } } -function assertInfoEqual(wrapper, info) { - for (let i in info) - assertDeepEqual(typeof wrapper[i] === "function" ? wrapper[i]() : wrapper[i], info[i]); -} - console.log("# Expression"); (function testWrapper() { var theExpression = binaryen.Block(42); // works without new @@ -32,10 +27,15 @@ console.log("# Block"); const theBlock = binaryen.Block(module.block(null, [])); assert(theBlock instanceof binaryen.Block); assert(theBlock instanceof binaryen.Expression); - assertInfoEqual(theBlock, binaryen.getExpressionInfo(theBlock)); assert(theBlock.id === binaryen.BlockId); assert(theBlock.name === null); assert(theBlock.type === binaryen.none); + + var info = binaryen.getExpressionInfo(theBlock); + assert(info.id === theBlock.id); + assert(info.type === theBlock.type); + assert(info.name === theBlock.name); + assertDeepEqual(info.children, theBlock.children); theBlock.name ="theName"; assert(theBlock.name === "theName"); @@ -75,6 +75,10 @@ console.log("# Block"); assert(theBlock.getChildAt(0) === child0); theBlock.finalize(); + info = binaryen.getExpressionInfo(theBlock); + assert(info.name === theBlock.name); + assertDeepEqual(info.children, theBlock.children); + console.log(theBlock.toText()); assert( theBlock.toText() @@ -97,13 +101,19 @@ console.log("# If"); const theIf = binaryen.If(module.if(condition, ifTrue, ifFalse)); assert(theIf instanceof binaryen.If); assert(theIf instanceof binaryen.Expression); - assertInfoEqual(theIf, binaryen.getExpressionInfo(theIf)); assert(theIf.id === binaryen.IfId); assert(theIf.condition === condition); assert(theIf.ifTrue === ifTrue); assert(theIf.ifFalse === ifFalse); assert(theIf.type == binaryen.i32); + var info = binaryen.getExpressionInfo(theIf); + assert(info.id === theIf.id); + assert(info.type === theIf.type); + assert(info.condition === theIf.condition); + assert(info.ifTrue === theIf.ifTrue); + assert(info.ifFalse === theIf.ifFalse); + theIf.condition = condition = module.i32.const(4); assert(theIf.condition === condition); theIf.ifTrue = ifTrue = module.i32.const(5); @@ -112,6 +122,11 @@ console.log("# If"); assert(theIf.ifFalse === ifFalse); theIf.finalize(); + info = binaryen.getExpressionInfo(theIf); + assert(info.condition === theIf.condition); + assert(info.ifTrue === theIf.ifTrue); + assert(info.ifFalse === theIf.ifFalse); + console.log(theIf.toText()); assert( theIf.toText() @@ -121,6 +136,10 @@ console.log("# If"); theIf.ifFalse = null; assert(!theIf.ifFalse); + + info = binaryen.getExpressionInfo(theIf); + assert(info.ifFalse === theIf.ifFalse); + console.log(theIf.toText()); assert( theIf.toText() @@ -140,12 +159,17 @@ console.log("# Loop"); const theLoop = binaryen.Loop(module.loop(name, body)); assert(theLoop instanceof binaryen.Loop); assert(theLoop instanceof binaryen.Expression); - assertInfoEqual(theLoop, binaryen.getExpressionInfo(theLoop)); assert(theLoop.id === binaryen.LoopId); assert(theLoop.name === name); assert(theLoop.body === body); assert(theLoop.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theLoop); + assert(info.id === theLoop.id); + assert(info.type === theLoop.type); + assert(info.name === theLoop.name); + assert(info.body === theLoop.body); + theLoop.name = name = "theName"; assert(theLoop.name === name); theLoop.body = body = module.drop(body); @@ -153,6 +177,11 @@ console.log("# Loop"); theLoop.finalize(); assert(theLoop.type === binaryen.none); + info = binaryen.getExpressionInfo(theLoop); + assert(info.type === theLoop.type); + assert(info.name === theLoop.name); + assert(info.body === theLoop.body); + console.log(theLoop.toText()); assert( theLoop.toText() @@ -173,12 +202,18 @@ console.log("# Break"); const theBreak = binaryen.Break(module.br(name, condition, value)); assert(theBreak instanceof binaryen.Break); assert(theBreak instanceof binaryen.Expression); - assertInfoEqual(theBreak, binaryen.getExpressionInfo(theBreak)); assert(theBreak.name === name); assert(theBreak.condition === condition); assert(theBreak.value === value); assert(theBreak.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theBreak); + assert(info.id === theBreak.id); + assert(info.type === theBreak.type); + assert(info.name === theBreak.name); + assert(info.condition === theBreak.condition); + assert(info.value === theBreak.value); + theBreak.name = name = "theNewName"; assert(theBreak.name === "theNewName"); theBreak.condition = condition = module.i32.const(3); @@ -187,6 +222,11 @@ console.log("# Break"); assert(theBreak.value === value); theBreak.finalize(); + info = binaryen.getExpressionInfo(theBreak); + assert(info.name === theBreak.name); + assert(info.condition === theBreak.condition); + assert(info.value === theBreak.value); + console.log(theBreak.toText()); assert( theBreak.toText() @@ -208,7 +248,6 @@ console.log("# Switch"); const theSwitch = binaryen.Switch(module.switch(names, defaultName, condition, value)); assert(theSwitch instanceof binaryen.Switch); assert(theSwitch instanceof binaryen.Expression); - assertInfoEqual(theSwitch, binaryen.getExpressionInfo(theSwitch)); assert(theSwitch.numNames === 2); assertDeepEqual(theSwitch.names, names); assert(theSwitch.defaultName === defaultName); @@ -216,6 +255,14 @@ console.log("# Switch"); assert(theSwitch.value === value); assert(theSwitch.type === binaryen.unreachable); + var info = binaryen.getExpressionInfo(theSwitch); + assert(info.id === theSwitch.id); + assert(info.type === theSwitch.type); + assertDeepEqual(info.names, theSwitch.names); + assert(info.defaultName === theSwitch.defaultName); + assert(info.condition === theSwitch.condition); + assert(info.value === theSwitch.value); + names = [ "1", // set "2", //set @@ -237,6 +284,12 @@ console.log("# Switch"); assert(theSwitch.value === value); theSwitch.finalize(); + info = binaryen.getExpressionInfo(theSwitch); + assertDeepEqual(info.names, theSwitch.names); + assert(info.defaultName === theSwitch.defaultName); + assert(info.condition === theSwitch.condition); + assert(info.value === theSwitch.value); + console.log(theSwitch.toText()); assert( theSwitch.toText() @@ -259,13 +312,19 @@ console.log("# Call"); const theCall = binaryen.Call(module.call(target, operands, binaryen.i32)); assert(theCall instanceof binaryen.Call); assert(theCall instanceof binaryen.Expression); - assertInfoEqual(theCall, binaryen.getExpressionInfo(theCall)); assert(theCall.target === target); assertDeepEqual(theCall.operands, operands); assertDeepEqual(theCall.getOperands(), operands); assert(theCall.return === false); assert(theCall.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theCall); + assert(info.id === theCall.id); + assert(info.type === theCall.type); + assert(info.target === theCall.target); + assertDeepEqual(info.operands, theCall.operands); + assert(info.isReturn === theCall.return); + theCall.target = "bar"; assert(theCall.target === "bar"); theCall.operands = operands = [ @@ -287,11 +346,21 @@ console.log("# Call"); theCall.finalize(); assert(theCall.type === binaryen.unreachable); // finalized tail call + info = binaryen.getExpressionInfo(theCall); + assert(info.type === theCall.type); + assert(info.target === theCall.target); + assertDeepEqual(info.operands, theCall.operands); + assert(info.isReturn === theCall.return); + theCall.return = false; theCall.type = binaryen.i32; theCall.finalize(); assert(theCall.type === binaryen.i32); // finalized call + info = binaryen.getExpressionInfo(theCall); + assert(info.type === theCall.type); + assert(info.isReturn === theCall.return); + console.log(theCall.toText()); assert( theCall.toText() @@ -317,7 +386,6 @@ console.log("# CallIndirect"); const theCallIndirect = binaryen.CallIndirect(module.call_indirect(table, target, operands, params, results)); assert(theCallIndirect instanceof binaryen.CallIndirect); assert(theCallIndirect instanceof binaryen.Expression); - assertInfoEqual(theCallIndirect, binaryen.getExpressionInfo(theCallIndirect)); assert(theCallIndirect.table === table); assert(theCallIndirect.target === target); assertDeepEqual(theCallIndirect.operands, operands); @@ -326,6 +394,16 @@ console.log("# CallIndirect"); assert(theCallIndirect.return === false); assert(theCallIndirect.type === theCallIndirect.results); + var info = binaryen.getExpressionInfo(theCallIndirect); + assert(info.id === theCallIndirect.id); + assert(info.type === theCallIndirect.type); + assert(info.table === theCallIndirect.table); + assert(info.target === theCallIndirect.target); + assertDeepEqual(info.operands, theCallIndirect.operands); + assert(info.params === theCallIndirect.params); + assert(info.results === theCallIndirect.results); + assert(info.isReturn === theCallIndirect.return); + theCallIndirect.target = target = module.i32.const(9000); assert(theCallIndirect.target === target); theCallIndirect.operands = operands = [ @@ -352,10 +430,21 @@ console.log("# CallIndirect"); theCallIndirect.finalize(); assert(theCallIndirect.type === binaryen.unreachable); // finalized tail call + info = binaryen.getExpressionInfo(theCallIndirect); + assert(info.type === theCallIndirect.type); + assert(info.target === theCallIndirect.target); + assertDeepEqual(info.operands, theCallIndirect.operands); + assert(info.params === theCallIndirect.params); + assert(info.results === theCallIndirect.results); + assert(info.isReturn === theCallIndirect.return); + theCallIndirect.return = false; theCallIndirect.finalize(); assert(theCallIndirect.type === results); // finalized call + info = binaryen.getExpressionInfo(theCallIndirect); + assert(info.isReturn === theCallIndirect.return); + console.log(theCallIndirect.toText()); assert( theCallIndirect.toText() @@ -375,16 +464,24 @@ console.log("# LocalGet"); const theLocalGet = binaryen.LocalGet(module.local.get(index, type)); assert(theLocalGet instanceof binaryen.LocalGet); assert(theLocalGet instanceof binaryen.Expression); - assertInfoEqual(theLocalGet, binaryen.getExpressionInfo(theLocalGet)); assert(theLocalGet.index === index); assert(theLocalGet.type === type); + var info = binaryen.getExpressionInfo(theLocalGet); + assert(info.id === theLocalGet.id); + assert(info.type === theLocalGet.type); + assert(info.index === theLocalGet.index); + theLocalGet.index = index = 2; assert(theLocalGet.index === index); theLocalGet.type = type = binaryen.f64; assert(theLocalGet.type === type); theLocalGet.finalize(); + info = binaryen.getExpressionInfo(theLocalGet); + assert(info.type === theLocalGet.type); + assert(info.index === theLocalGet.index); + console.log(theLocalGet.toText()); assert( theLocalGet.toText() @@ -404,12 +501,18 @@ console.log("# LocalSet"); const theLocalSet = binaryen.LocalSet(module.local.set(index, value)); assert(theLocalSet instanceof binaryen.LocalSet); assert(theLocalSet instanceof binaryen.Expression); - assertInfoEqual(theLocalSet, binaryen.getExpressionInfo(theLocalSet)); assert(theLocalSet.index === index); assert(theLocalSet.value === value); assert(theLocalSet.tee === false); assert(theLocalSet.type == binaryen.none); + var info = binaryen.getExpressionInfo(theLocalSet); + assert(info.id === theLocalSet.id); + assert(info.type === theLocalSet.type); + assert(info.index === theLocalSet.index); + assert(info.value === theLocalSet.value); + assert(info.isTee === theLocalSet.tee) + theLocalSet.index = index = 2; assert(theLocalSet.index === index); theLocalSet.value = value = module.i32.const(3); @@ -420,6 +523,12 @@ console.log("# LocalSet"); theLocalSet.type = binaryen.none; theLocalSet.finalize(); + info = binaryen.getExpressionInfo(theLocalSet); + assert(info.type === theLocalSet.type); + assert(info.index === theLocalSet.index); + assert(info.value === theLocalSet.value); + assert(info.isTee === theLocalSet.tee) + console.log(theLocalSet.toText()); assert( theLocalSet.toText() @@ -439,16 +548,24 @@ console.log("# GlobalGet"); const theGlobalGet = binaryen.GlobalGet(module.global.get(name, type)); assert(theGlobalGet instanceof binaryen.GlobalGet); assert(theGlobalGet instanceof binaryen.Expression); - assertInfoEqual(theGlobalGet, binaryen.getExpressionInfo(theGlobalGet)); assert(theGlobalGet.name === name); assert(theGlobalGet.type === type); + var info = binaryen.getExpressionInfo(theGlobalGet); + assert(info.id === theGlobalGet.id); + assert(info.type === theGlobalGet.type); + assert(info.name === theGlobalGet.name); + theGlobalGet.name = name = "b"; assert(theGlobalGet.name === name); theGlobalGet.type = type = binaryen.f64; assert(theGlobalGet.type === type); theGlobalGet.finalize(); + info = binaryen.getExpressionInfo(theGlobalGet); + assert(info.type === theGlobalGet.type); + assert(info.name === theGlobalGet.name); + console.log(theGlobalGet.toText()); assert( theGlobalGet.toText() @@ -468,17 +585,26 @@ console.log("# GlobalSet"); const theGlobalSet = binaryen.GlobalSet(module.global.set(name, value)); assert(theGlobalSet instanceof binaryen.GlobalSet); assert(theGlobalSet instanceof binaryen.Expression); - assertInfoEqual(theGlobalSet, binaryen.getExpressionInfo(theGlobalSet)); assert(theGlobalSet.name === name); assert(theGlobalSet.value === value); assert(theGlobalSet.type == binaryen.none); + var info = binaryen.getExpressionInfo(theGlobalSet); + assert(info.id === theGlobalSet.id); + assert(info.type === theGlobalSet.type); + assert(info.name === theGlobalSet.name); + assert(info.value === theGlobalSet.value); + theGlobalSet.name = name = "b"; assert(theGlobalSet.name === name); theGlobalSet.value = value = module.f64.const(3); assert(theGlobalSet.value === value); theGlobalSet.finalize(); + info = binaryen.getExpressionInfo(theGlobalSet); + assert(info.name === theGlobalSet.name); + assert(info.value === theGlobalSet.value); + console.log(theGlobalSet.toText()); assert( theGlobalSet.toText() @@ -497,10 +623,13 @@ console.log("# MemorySize"); const theMemorySize = binaryen.MemorySize(module.memory.size()); assert(theMemorySize instanceof binaryen.MemorySize); assert(theMemorySize instanceof binaryen.Expression); - assertInfoEqual(theMemorySize, binaryen.getExpressionInfo(theMemorySize)); assert(theMemorySize.type === type); theMemorySize.finalize(); + var info = binaryen.getExpressionInfo(theMemorySize); + assert(info.id === theMemorySize.id); + assert(info.type === theMemorySize.type); + console.log(theMemorySize.toText()); assert( theMemorySize.toText() @@ -521,14 +650,21 @@ console.log("# MemoryGrow"); const theMemoryGrow = binaryen.MemoryGrow(module.memory.grow(delta)); assert(theMemoryGrow instanceof binaryen.MemoryGrow); assert(theMemoryGrow instanceof binaryen.Expression); - assertInfoEqual(theMemoryGrow, binaryen.getExpressionInfo(theMemoryGrow)); assert(theMemoryGrow.delta === delta); assert(theMemoryGrow.type === type); + var info = binaryen.getExpressionInfo(theMemoryGrow); + assert(info.id === theMemoryGrow.id); + assert(info.type === theMemoryGrow.type); + assert(info.delta === theMemoryGrow.delta); + theMemoryGrow.delta = delta = module.i32.const(2); assert(theMemoryGrow.delta === delta); theMemoryGrow.finalize(); + info = binaryen.getExpressionInfo(theMemoryGrow); + assert(info.delta === theMemoryGrow.delta); + console.log(theMemoryGrow.toText()); assert( theMemoryGrow.toText() @@ -550,7 +686,6 @@ console.log("# Load"); const theLoad = binaryen.Load(module.i32.load(offset, align, ptr)); assert(theLoad instanceof binaryen.Load); assert(theLoad instanceof binaryen.Expression); - assertInfoEqual(theLoad, binaryen.getExpressionInfo(theLoad)); assert(theLoad.offset === offset); assert(theLoad.align === align); assert(theLoad.ptr === ptr); @@ -559,6 +694,16 @@ console.log("# Load"); assert(theLoad.atomic === false); assert(theLoad.type == binaryen.i32); + var info = binaryen.getExpressionInfo(theLoad); + assert(info.id === theLoad.id); + assert(info.type === theLoad.type); + assert(info.offset === theLoad.offset); + assert(info.align === theLoad.align); + assert(info.ptr === theLoad.ptr); + assert(info.bytes === theLoad.bytes); + assert(info.isSigned === theLoad.signed); + assert(info.isAtomic === theLoad.atomic); + theLoad.offset = offset = 32; assert(theLoad.offset === offset); theLoad.align = align = 4; @@ -576,6 +721,14 @@ console.log("# Load"); theLoad.finalize(); assert(theLoad.align === 4); + info = binaryen.getExpressionInfo(theLoad); + assert(info.offset === theLoad.offset); + assert(info.align === theLoad.align); + assert(info.ptr === theLoad.ptr); + assert(info.bytes === theLoad.bytes); + assert(info.isSigned === theLoad.signed); + assert(info.isAtomic === theLoad.atomic); + console.log(theLoad.toText()); assert( theLoad.toText() @@ -598,7 +751,6 @@ console.log("# Store"); const theStore = binaryen.Store(module.i32.store(offset, align, ptr, value)); assert(theStore instanceof binaryen.Store); assert(theStore instanceof binaryen.Expression); - assertInfoEqual(theStore, binaryen.getExpressionInfo(theStore)); assert(theStore.offset === offset); assert(theStore.align === align); assert(theStore.ptr === ptr); @@ -608,6 +760,17 @@ console.log("# Store"); assert(theStore.valueType === binaryen.i32); assert(theStore.type === binaryen.none); + var info = binaryen.getExpressionInfo(theStore); + assert(info.id === theStore.id); + assert(info.type === theStore.type); + assert(info.offset === theStore.offset); + assert(info.align === theStore.align); + assert(info.ptr === theStore.ptr); + assert(info.value === theStore.value); + assert(info.bytes === theStore.bytes); + assert(info.isAtomic === theStore.atomic); + assert(info.valueType === theStore.valueType); + theStore.offset = offset = 32; assert(theStore.offset === offset); theStore.align = align = 4; @@ -627,6 +790,15 @@ console.log("# Store"); theStore.finalize(); assert(theStore.align === 4); + info = binaryen.getExpressionInfo(theStore); + assert(info.offset === theStore.offset); + assert(info.align === theStore.align); + assert(info.ptr === theStore.ptr); + assert(info.value === theStore.value); + assert(info.bytes === theStore.bytes); + assert(info.isAtomic === theStore.atomic); + assert(info.valueType === theStore.valueType); + console.log(theStore.toText()); assert( theStore.toText() @@ -647,36 +819,52 @@ console.log("# Const"); assert(theConst.valueI32 === 1); theConst.valueI32 = 2; assert(theConst.valueI32 === 2); - assert(theConst.valueI32 === binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theConst); + assert(info.id === theConst.id); + assert(info.type === theConst.type); + assert(info.value === theConst.valueI32); + theConst.valueI64Low = 3; assert(theConst.valueI64Low === 3); theConst.valueI64High = 4; assert(theConst.valueI64High === 4); theConst.finalize(); - assert(theConst.valueI64Low === binaryen.getExpressionInfo(theConst).value.low); - assert(theConst.valueI64High === binaryen.getExpressionInfo(theConst).value.high); assert(theConst.type == binaryen.i64); + info = binaryen.getExpressionInfo(theConst); + assert(info.type === theConst.type); + assert(info.value.low === theConst.valueI64Low); + assert(info.value.high === theConst.valueI64High); + theConst.valueF32 = 5; assert(theConst.valueF32 === 5); theConst.finalize(); - assert(theConst.valueF32 === binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.f32); + info = binaryen.getExpressionInfo(theConst); + assert(info.type === theConst.type); + assert(info.value === theConst.valueF32); + theConst.valueF64 = 6; assert(theConst.valueF64 === 6); theConst.finalize(); - assert(theConst.valueF64 === binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.f64); + info = binaryen.getExpressionInfo(theConst); + assert(info.type === theConst.type); + assert(info.value === theConst.valueF64); + theConst.valueV128 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; assertDeepEqual(theConst.valueV128, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); theConst.finalize(); - assertDeepEqual(theConst.valueV128, binaryen.getExpressionInfo(theConst).value); assert(theConst.type === binaryen.v128); + info = binaryen.getExpressionInfo(theConst); + assert(info.type === theConst.type); + assertDeepEqual(info.value, theConst.valueV128); + console.log(theConst.toText()); assert( theConst.toText() @@ -696,11 +884,16 @@ console.log("# Unary"); const theUnary = binaryen.Unary(module.i32.eqz(value)); assert(theUnary instanceof binaryen.Unary); assert(theUnary instanceof binaryen.Expression); - assertInfoEqual(theUnary, binaryen.getExpressionInfo(theUnary)); assert(theUnary.op === op); assert(theUnary.value === value); assert(theUnary.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theUnary); + assert(info.id === theUnary.id); + assert(info.type === theUnary.type); + assert(info.op === theUnary.op); + assert(info.value === theUnary.value); + theUnary.op = op = binaryen.Operations.EqZInt64; assert(theUnary.op === op); theUnary.value = value = module.i64.const(2); @@ -709,6 +902,11 @@ console.log("# Unary"); theUnary.finalize(); assert(theUnary.type === binaryen.i32); + info = binaryen.getExpressionInfo(theUnary); + assert(info.type === theUnary.type); + assert(info.op === theUnary.op); + assert(info.value === theUnary.value); + console.log(theUnary.toText()); assert( theUnary.toText() @@ -729,11 +927,17 @@ console.log("# Binary"); const theBinary = binaryen.Binary(module.i32.add(left, right)); assert(theBinary instanceof binaryen.Binary); assert(theBinary instanceof binaryen.Expression); - assertInfoEqual(theBinary, binaryen.getExpressionInfo(theBinary)); assert(theBinary.op === op); assert(theBinary.left === left); assert(theBinary.right === right); - assert(theBinary.type === binaryen.i32); + assert(theBinary.type === binaryen.i32) + + var info = binaryen.getExpressionInfo(theBinary); + assert(info.id === theBinary.id); + assert(info.type === theBinary.type); + assert(info.op === theBinary.op); + assert(info.left === theBinary.left); + assert(info.right === theBinary.right); theBinary.op = op = binaryen.Operations.AddInt64; assert(theBinary.op === op); @@ -745,6 +949,12 @@ console.log("# Binary"); theBinary.finalize(); assert(theBinary.type === binaryen.i64); + info = binaryen.getExpressionInfo(theBinary); + assert(info.type === theBinary.type); + assert(info.op === theBinary.op); + assert(info.left === theBinary.left); + assert(info.right === theBinary.right); + console.log(theBinary.toText()); assert( theBinary.toText() @@ -765,12 +975,18 @@ console.log("# Select"); const theSelect = binaryen.Select(module.select(condition, ifTrue, ifFalse)); assert(theSelect.ifTrue === ifTrue); assert(theSelect instanceof binaryen.Select); assert(theSelect instanceof binaryen.Expression); - assertInfoEqual(theSelect, binaryen.getExpressionInfo(theSelect)); assert(theSelect.condition === condition); assert(theSelect.ifTrue === ifTrue); assert(theSelect.ifFalse === ifFalse); assert(theSelect.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theSelect); + assert(info.id === theSelect.id); + assert(info.type === theSelect.type); + assert(info.condition === theSelect.condition); + assert(info.ifTrue === theSelect.ifTrue); + assert(info.ifFalse === theSelect.ifFalse); + theSelect.condition = condition = module.i32.const(4); assert(theSelect.condition === condition); theSelect.ifTrue = ifTrue = module.i64.const(5); @@ -780,6 +996,12 @@ console.log("# Select"); theSelect.finalize(); assert(theSelect.type === binaryen.i64); + info = binaryen.getExpressionInfo(theSelect); + assert(info.type === theSelect.type); + assert(info.condition === theSelect.condition); + assert(info.ifTrue === theSelect.ifTrue); + assert(info.ifFalse === theSelect.ifFalse); + console.log(theSelect.toText()); assert( theSelect.toText() @@ -798,16 +1020,24 @@ console.log("# Drop"); const theDrop = binaryen.Drop(module.drop(value)); assert(theDrop instanceof binaryen.Drop); assert(theDrop instanceof binaryen.Expression); - assertInfoEqual(theDrop, binaryen.getExpressionInfo(theDrop)); assert(theDrop.value === value); assert(theDrop.type === binaryen.none); + var info = binaryen.getExpressionInfo(theDrop); + assert(info.id === theDrop.id); + assert(info.type === theDrop.type); + assert(info.value === theDrop.value); + theDrop.value = value = module.i32.const(2); assert(theDrop.value === value); theDrop.finalize(); assert(theDrop.type === binaryen.none); + info = binaryen.getExpressionInfo(theDrop); + assert(info.type === theDrop.type); + assert(info.value === theDrop.value); + console.log(theDrop.toText()); assert( theDrop.toText() @@ -826,16 +1056,24 @@ console.log("# Return"); const theReturn = binaryen.Return(module.return(value)); assert(theReturn instanceof binaryen.Return); assert(theReturn instanceof binaryen.Expression); - assertInfoEqual(theReturn, binaryen.getExpressionInfo(theReturn)); assert(theReturn.value === value); assert(theReturn.type === binaryen.unreachable); + var info = binaryen.getExpressionInfo(theReturn); + assert(info.id === theReturn.id); + assert(info.type === theReturn.type); + assert(info.value === theReturn.value); + theReturn.value = value = module.i32.const(2); assert(theReturn.value === value); theReturn.finalize(); assert(theReturn.type === binaryen.unreachable); + info = binaryen.getExpressionInfo(theReturn); + assert(info.type === theReturn.type); + assert(info.value === theReturn.value); + console.log(theReturn.toText()); assert( theReturn.toText() @@ -858,7 +1096,6 @@ console.log("# AtomicRMW"); const theAtomicRMW = binaryen.AtomicRMW(module.i32.atomic.rmw.add(offset, ptr, value)); assert(theAtomicRMW instanceof binaryen.AtomicRMW); assert(theAtomicRMW instanceof binaryen.Expression); - assertInfoEqual(theAtomicRMW, binaryen.getExpressionInfo(theAtomicRMW)); assert(theAtomicRMW.op === op); assert(theAtomicRMW.bytes === 4); assert(theAtomicRMW.offset === offset); @@ -866,6 +1103,15 @@ console.log("# AtomicRMW"); assert(theAtomicRMW.value === value); assert(theAtomicRMW.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theAtomicRMW); + assert(info.id === theAtomicRMW.id); + assert(info.type === theAtomicRMW.type); + assert(info.op === theAtomicRMW.op); + assert(info.bytes === theAtomicRMW.bytes); + assert(info.offset === theAtomicRMW.offset); + assert(info.ptr === theAtomicRMW.ptr); + assert(info.value === theAtomicRMW.value); + theAtomicRMW.op = op = binaryen.Operations.AtomicRMWSub; assert(theAtomicRMW.op === op); theAtomicRMW.bytes = 2; @@ -880,6 +1126,14 @@ console.log("# AtomicRMW"); theAtomicRMW.finalize(); assert(theAtomicRMW.type === binaryen.i64); + info = binaryen.getExpressionInfo(theAtomicRMW); + assert(info.type === theAtomicRMW.type); + assert(info.op === theAtomicRMW.op); + assert(info.bytes === theAtomicRMW.bytes); + assert(info.offset === theAtomicRMW.offset); + assert(info.ptr === theAtomicRMW.ptr); + assert(info.value === theAtomicRMW.value); + console.log(theAtomicRMW.toText()); assert( theAtomicRMW.toText() @@ -902,7 +1156,6 @@ console.log("# AtomicCmpxchg"); const theAtomicCmpxchg = binaryen.AtomicCmpxchg(module.i32.atomic.rmw.cmpxchg(offset, ptr, expected, replacement)); assert(theAtomicCmpxchg instanceof binaryen.AtomicCmpxchg); assert(theAtomicCmpxchg instanceof binaryen.Expression); - assertInfoEqual(theAtomicCmpxchg, binaryen.getExpressionInfo(theAtomicCmpxchg)); assert(theAtomicCmpxchg.bytes === 4); assert(theAtomicCmpxchg.offset === offset); assert(theAtomicCmpxchg.ptr === ptr); @@ -910,6 +1163,15 @@ console.log("# AtomicCmpxchg"); assert(theAtomicCmpxchg.replacement === replacement); assert(theAtomicCmpxchg.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theAtomicCmpxchg); + assert(info.id === theAtomicCmpxchg.id); + assert(info.type === theAtomicCmpxchg.type); + assert(info.bytes === theAtomicCmpxchg.bytes); + assert(info.offset === theAtomicCmpxchg.offset); + assert(info.ptr === theAtomicCmpxchg.ptr); + assert(info.expected === theAtomicCmpxchg.expected); + assert(info.replacement === theAtomicCmpxchg.replacement); + theAtomicCmpxchg.bytes = 2; assert(theAtomicCmpxchg.bytes === 2); theAtomicCmpxchg.offset = offset = 16; @@ -924,6 +1186,14 @@ console.log("# AtomicCmpxchg"); theAtomicCmpxchg.finalize(); assert(theAtomicCmpxchg.type === binaryen.i64); + info = binaryen.getExpressionInfo(theAtomicCmpxchg); + assert(info.type === theAtomicCmpxchg.type); + assert(info.bytes === theAtomicCmpxchg.bytes); + assert(info.offset === theAtomicCmpxchg.offset); + assert(info.ptr === theAtomicCmpxchg.ptr); + assert(info.expected === theAtomicCmpxchg.expected); + assert(info.replacement === theAtomicCmpxchg.replacement); + console.log(theAtomicCmpxchg.toText()); assert( theAtomicCmpxchg.toText() @@ -945,13 +1215,20 @@ console.log("# AtomicWait"); const theAtomicWait = binaryen.AtomicWait(module.memory.atomic.wait32(ptr, expected, timeout)); assert(theAtomicWait instanceof binaryen.AtomicWait); assert(theAtomicWait instanceof binaryen.Expression); - assertInfoEqual(theAtomicWait, binaryen.getExpressionInfo(theAtomicWait)); assert(theAtomicWait.ptr === ptr); assert(theAtomicWait.expected === expected); assert(theAtomicWait.expectedType === binaryen.i32); assert(theAtomicWait.timeout === timeout); assert(theAtomicWait.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theAtomicWait); + assert(info.id === theAtomicWait.id); + assert(info.type === theAtomicWait.type); + assert(info.ptr === theAtomicWait.ptr); + assert(info.expected === theAtomicWait.expected); + assert(info.expectedType === theAtomicWait.expectedType); + assert(info.timeout === theAtomicWait.timeout); + theAtomicWait.ptr = ptr = module.i32.const(5); assert(theAtomicWait.ptr === ptr); theAtomicWait.expected = expected = module.i32.const(6); @@ -964,6 +1241,13 @@ console.log("# AtomicWait"); theAtomicWait.finalize(); assert(theAtomicWait.type === binaryen.i32); + info = binaryen.getExpressionInfo(theAtomicWait); + assert(info.type === theAtomicWait.type); + assert(info.ptr === theAtomicWait.ptr); + assert(info.expected === theAtomicWait.expected); + assert(info.expectedType === theAtomicWait.expectedType); + assert(info.timeout === theAtomicWait.timeout); + console.log(theAtomicWait.toText()); assert( theAtomicWait.toText() @@ -984,11 +1268,16 @@ console.log("# AtomicNotify"); const theAtomicNotify = binaryen.AtomicNotify(module.memory.atomic.notify(ptr, notifyCount)); assert(theAtomicNotify instanceof binaryen.AtomicNotify); assert(theAtomicNotify instanceof binaryen.Expression); - assertInfoEqual(theAtomicNotify, binaryen.getExpressionInfo(theAtomicNotify)); assert(theAtomicNotify.ptr === ptr); assert(theAtomicNotify.notifyCount === notifyCount); assert(theAtomicNotify.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theAtomicNotify); + assert(info.id === theAtomicNotify.id); + assert(info.type === theAtomicNotify.type); + assert(info.ptr === theAtomicNotify.ptr); + assert(info.notifyCount === theAtomicNotify.notifyCount); + theAtomicNotify.ptr = ptr = module.i32.const(3); assert(theAtomicNotify.ptr === ptr); theAtomicNotify.notifyCount = notifyCount = module.i32.const(4); @@ -997,6 +1286,11 @@ console.log("# AtomicNotify"); theAtomicNotify.finalize(); assert(theAtomicNotify.type === binaryen.i32); + info = binaryen.getExpressionInfo(theAtomicNotify); + assert(info.type === theAtomicNotify.type); + assert(info.ptr === theAtomicNotify.ptr); + assert(info.notifyCount === theAtomicNotify.notifyCount); + console.log(theAtomicNotify.toText()); assert( theAtomicNotify.toText() @@ -1014,16 +1308,24 @@ console.log("# AtomicFence"); const theAtomicFence = binaryen.AtomicFence(module.atomic.fence()); assert(theAtomicFence instanceof binaryen.AtomicFence); assert(theAtomicFence instanceof binaryen.Expression); - assertInfoEqual(theAtomicFence, binaryen.getExpressionInfo(theAtomicFence)); assert(theAtomicFence.order === 0); // reserved, not yet used assert(theAtomicFence.type === binaryen.none); + var info = binaryen.getExpressionInfo(theAtomicFence); + assert(info.id === theAtomicFence.id); + assert(info.type === theAtomicFence.type); + assert(info.order === theAtomicFence.order); + theAtomicFence.order = 1; assert(theAtomicFence.order === 1); theAtomicFence.type = binaryen.f64; theAtomicFence.finalize(); assert(theAtomicFence.type === binaryen.none); + info = binaryen.getExpressionInfo(theAtomicFence); + assert(info.type === theAtomicFence.type); + assert(info.order === theAtomicFence.order); + console.log(theAtomicFence.toText()); assert( theAtomicFence.toText() @@ -1044,12 +1346,18 @@ console.log("# SIMDExtract"); const theSIMDExtract = binaryen.SIMDExtract(module.i8x16.extract_lane_s(vec, index)); assert(theSIMDExtract instanceof binaryen.SIMDExtract); assert(theSIMDExtract instanceof binaryen.Expression); - assertInfoEqual(theSIMDExtract, binaryen.getExpressionInfo(theSIMDExtract)); assert(theSIMDExtract.op === op); assert(theSIMDExtract.vec === vec); assert(theSIMDExtract.index === index); assert(theSIMDExtract.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theSIMDExtract); + assert(info.id === theSIMDExtract.id); + assert(info.type === theSIMDExtract.type); + assert(info.op === theSIMDExtract.op); + assert(info.vec === theSIMDExtract.vec); + assert(info.index === theSIMDExtract.index); + theSIMDExtract.op = op = binaryen.Operations.ExtractLaneSVecI16x8; assert(theSIMDExtract.op === op); theSIMDExtract.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); @@ -1059,6 +1367,12 @@ console.log("# SIMDExtract"); theSIMDExtract.type = binaryen.f64; theSIMDExtract.finalize(); assert(theSIMDExtract.type === binaryen.i32); + + info = binaryen.getExpressionInfo(theSIMDExtract); + assert(info.type === theSIMDExtract.type); + assert(info.op === theSIMDExtract.op); + assert(info.vec === theSIMDExtract.vec); + assert(info.index === theSIMDExtract.index); console.log(theSIMDExtract.toText()); assert( @@ -1081,13 +1395,20 @@ console.log("# SIMDReplace"); const theSIMDReplace = binaryen.SIMDReplace(module.i8x16.replace_lane(vec, index, value)); assert(theSIMDReplace instanceof binaryen.SIMDReplace); assert(theSIMDReplace instanceof binaryen.Expression); - assertInfoEqual(theSIMDReplace, binaryen.getExpressionInfo(theSIMDReplace)); assert(theSIMDReplace.op === op); assert(theSIMDReplace.vec === vec); assert(theSIMDReplace.index === index); assert(theSIMDReplace.value === value); assert(theSIMDReplace.type === binaryen.v128); + var info = binaryen.getExpressionInfo(theSIMDReplace); + assert(info.id === theSIMDReplace.id); + assert(info.type === theSIMDReplace.type); + assert(info.op === theSIMDReplace.op); + assert(info.vec === theSIMDReplace.vec); + assert(info.index === theSIMDReplace.index); + assert(info.value === theSIMDReplace.value); + theSIMDReplace.op = op = binaryen.Operations.ReplaceLaneVecI16x8; assert(theSIMDReplace.op === op); theSIMDReplace.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); @@ -1100,6 +1421,13 @@ console.log("# SIMDReplace"); theSIMDReplace.finalize(); assert(theSIMDReplace.type === binaryen.v128); + info = binaryen.getExpressionInfo(theSIMDReplace); + assert(info.type === theSIMDReplace.type); + assert(info.op === theSIMDReplace.op); + assert(info.vec === theSIMDReplace.vec); + assert(info.index === theSIMDReplace.index); + assert(info.value === theSIMDReplace.value); + console.log(theSIMDReplace.toText()); assert( theSIMDReplace.toText() @@ -1120,12 +1448,18 @@ console.log("# SIMDShuffle"); const theSIMDShuffle = binaryen.SIMDShuffle(module.i8x16.shuffle(left, right, mask)); assert(theSIMDShuffle instanceof binaryen.SIMDShuffle); assert(theSIMDShuffle instanceof binaryen.Expression); - assertInfoEqual(theSIMDShuffle, binaryen.getExpressionInfo(theSIMDShuffle)); assert(theSIMDShuffle.left === left); assert(theSIMDShuffle.right === right); assertDeepEqual(theSIMDShuffle.mask, mask); assert(theSIMDShuffle.type === binaryen.v128); + var info = binaryen.getExpressionInfo(theSIMDShuffle); + assert(info.id === theSIMDShuffle.id); + assert(info.type === theSIMDShuffle.type); + assert(info.left === theSIMDShuffle.left); + assert(info.right === theSIMDShuffle.right); + assertDeepEqual(info.mask, theSIMDShuffle.mask); + theSIMDShuffle.left = left = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); assert(theSIMDShuffle.left === left); theSIMDShuffle.right = right = module.v128.const([2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]); @@ -1136,6 +1470,12 @@ console.log("# SIMDShuffle"); theSIMDShuffle.finalize(); assert(theSIMDShuffle.type === binaryen.v128); + info = binaryen.getExpressionInfo(theSIMDShuffle); + assert(info.type === theSIMDShuffle.type); + assert(info.left === theSIMDShuffle.left); + assert(info.right === theSIMDShuffle.right); + assertDeepEqual(info.mask, theSIMDShuffle.mask); + console.log(theSIMDShuffle.toText()); assert( theSIMDShuffle.toText() @@ -1157,13 +1497,20 @@ console.log("# SIMDTernary"); const theSIMDTernary = binaryen.SIMDTernary(module.v128.bitselect(a, b, c)); assert(theSIMDTernary instanceof binaryen.SIMDTernary); assert(theSIMDTernary instanceof binaryen.Expression); - assertInfoEqual(theSIMDTernary, binaryen.getExpressionInfo(theSIMDTernary)); assert(theSIMDTernary.op === op); assert(theSIMDTernary.a === a); assert(theSIMDTernary.b === b); assert(theSIMDTernary.c === c); assert(theSIMDTernary.type === binaryen.v128); + var info = binaryen.getExpressionInfo(theSIMDTernary); + assert(info.id === theSIMDTernary.id); + assert(info.type === theSIMDTernary.type); + assert(info.op === theSIMDTernary.op); + assert(info.a === theSIMDTernary.a); + assert(info.b === theSIMDTernary.b); + assert(info.c === theSIMDTernary.c); + console.log(theSIMDTernary.toText() + "\n"); assert( theSIMDTernary.toText() @@ -1184,12 +1531,18 @@ console.log("# SIMDShift"); const theSIMDShift = binaryen.SIMDShift(module.i8x16.shl(vec, shift)); assert(theSIMDShift instanceof binaryen.SIMDShift); assert(theSIMDShift instanceof binaryen.Expression); - assertInfoEqual(theSIMDShift, binaryen.getExpressionInfo(theSIMDShift)); assert(theSIMDShift.op === op); assert(theSIMDShift.vec === vec); assert(theSIMDShift.shift === shift); assert(theSIMDShift.type === binaryen.v128); + var info = binaryen.getExpressionInfo(theSIMDShift); + assert(info.id === theSIMDShift.id); + assert(info.type === theSIMDShift.type); + assert(info.op === theSIMDShift.op); + assert(info.vec === theSIMDShift.vec); + assert(info.shift === theSIMDShift.shift); + theSIMDShift.op = op = binaryen.Operations.ShrSVecI8x16; assert(theSIMDShift.op === op); theSIMDShift.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); @@ -1200,6 +1553,12 @@ console.log("# SIMDShift"); theSIMDShift.finalize(); assert(theSIMDShift.type === binaryen.v128); + info = binaryen.getExpressionInfo(theSIMDShift); + assert(info.type === theSIMDShift.type); + assert(info.op === theSIMDShift.op); + assert(info.vec === theSIMDShift.vec); + assert(info.shift === theSIMDShift.shift); + console.log(theSIMDShift.toText()); assert( theSIMDShift.toText() @@ -1222,12 +1581,18 @@ console.log("# SIMDLoad"); const theSIMDLoad = binaryen.SIMDLoad(module.v128.load8x8_s(offset, align, ptr)); assert(theSIMDLoad instanceof binaryen.SIMDLoad); assert(theSIMDLoad instanceof binaryen.Expression); - assertInfoEqual(theSIMDLoad, binaryen.getExpressionInfo(theSIMDLoad)); assert(theSIMDLoad.offset === offset); assert(theSIMDLoad.align === align); assert(theSIMDLoad.ptr === ptr); assert(theSIMDLoad.type === binaryen.v128); + var info = binaryen.getExpressionInfo(theSIMDLoad); + assert(info.id === theSIMDLoad.id); + assert(info.type === theSIMDLoad.type); + assert(info.offset === theSIMDLoad.offset); + assert(info.align === theSIMDLoad.align); + assert(info.ptr === theSIMDLoad.ptr); + theSIMDLoad.op = op = binaryen.Operations.Load8SplatVec128; assert(theSIMDLoad.op === op); theSIMDLoad.offset = offset = 32; @@ -1240,6 +1605,12 @@ console.log("# SIMDLoad"); theSIMDLoad.finalize(); assert(theSIMDLoad.type === binaryen.v128); + info = binaryen.getExpressionInfo(theSIMDLoad); + assert(info.type === theSIMDLoad.type); + assert(info.offset === theSIMDLoad.offset); + assert(info.align === theSIMDLoad.align); + assert(info.ptr === theSIMDLoad.ptr); + console.log(theSIMDLoad.toText()); assert( theSIMDLoad.toText() @@ -1264,7 +1635,6 @@ console.log("# SIMDLoadStoreLane"); const theSIMDLoadStoreLane = binaryen.SIMDLoadStoreLane(module.v128.load8_lane(offset, align, index, ptr, vec)); assert(theSIMDLoadStoreLane instanceof binaryen.SIMDLoadStoreLane); assert(theSIMDLoadStoreLane instanceof binaryen.Expression); - assertInfoEqual(theSIMDLoadStoreLane, binaryen.getExpressionInfo(theSIMDLoadStoreLane)); assert(theSIMDLoadStoreLane.op === op); assert(theSIMDLoadStoreLane.offset === offset); assert(theSIMDLoadStoreLane.align === align); @@ -1274,6 +1644,17 @@ console.log("# SIMDLoadStoreLane"); assert(theSIMDLoadStoreLane.type === binaryen.v128); assert(theSIMDLoadStoreLane.store === false); + var info = binaryen.getExpressionInfo(theSIMDLoadStoreLane); + assert(info.id === theSIMDLoadStoreLane.id); + assert(info.type === theSIMDLoadStoreLane.type); + assert(info.op === theSIMDLoadStoreLane.op); + assert(info.offset === theSIMDLoadStoreLane.offset); + assert(info.align === theSIMDLoadStoreLane.align); + assert(info.index === theSIMDLoadStoreLane.index); + assert(info.ptr === theSIMDLoadStoreLane.ptr); + assert(info.vec === theSIMDLoadStoreLane.vec); + assert(info.isStore === theSIMDLoadStoreLane.store); + theSIMDLoadStoreLane.op = op = binaryen.Operations.Load16LaneVec128; assert(theSIMDLoadStoreLane.op === op); theSIMDLoadStoreLane.offset = offset = 32; @@ -1290,6 +1671,15 @@ console.log("# SIMDLoadStoreLane"); theSIMDLoadStoreLane.finalize(); assert(theSIMDLoadStoreLane.type === binaryen.v128); + info = binaryen.getExpressionInfo(theSIMDLoadStoreLane); + assert(info.type === theSIMDLoadStoreLane.type); + assert(info.op === theSIMDLoadStoreLane.op); + assert(info.offset === theSIMDLoadStoreLane.offset); + assert(info.align === theSIMDLoadStoreLane.align); + assert(info.index === theSIMDLoadStoreLane.index); + assert(info.ptr === theSIMDLoadStoreLane.ptr); + assert(info.vec === theSIMDLoadStoreLane.vec); + console.log(theSIMDLoadStoreLane.toText()); assert( theSIMDLoadStoreLane.toText() @@ -1304,6 +1694,11 @@ console.log("# SIMDLoadStoreLane"); theSIMDLoadStoreLane.finalize(); assert(theSIMDLoadStoreLane.type === binaryen.none); + info = binaryen.getExpressionInfo(theSIMDLoadStoreLane); + assert(info.type === theSIMDLoadStoreLane.type); + assert(info.op === theSIMDLoadStoreLane.op); + assert(info.isStore === theSIMDLoadStoreLane.store); + console.log(theSIMDLoadStoreLane.toText()); assert( theSIMDLoadStoreLane.toText() @@ -1326,13 +1721,20 @@ console.log("# MemoryInit"); const theMemoryInit = binaryen.MemoryInit(module.memory.init(segment, dest, offset, size)); assert(theMemoryInit instanceof binaryen.MemoryInit); assert(theMemoryInit instanceof binaryen.Expression); - assertInfoEqual(theMemoryInit, binaryen.getExpressionInfo(theMemoryInit)); assert(theMemoryInit.segment === segment); assert(theMemoryInit.dest === dest); assert(theMemoryInit.offset === offset); assert(theMemoryInit.size === size); assert(theMemoryInit.type === binaryen.none); + var info = binaryen.getExpressionInfo(theMemoryInit); + assert(info.id === theMemoryInit.id); + assert(info.type === theMemoryInit.type); + assert(info.segment === theMemoryInit.segment); + assert(info.dest === theMemoryInit.dest); + assert(info.offset === theMemoryInit.offset); + assert(info.size === theMemoryInit.size); + theMemoryInit.segment = segment = "5"; assert(theMemoryInit.segment === "5"); theMemoryInit.dest = dest = module.i32.const(6); @@ -1345,6 +1747,13 @@ console.log("# MemoryInit"); theMemoryInit.finalize(); assert(theMemoryInit.type === binaryen.none); + info = binaryen.getExpressionInfo(theMemoryInit); + assert(info.type === theMemoryInit.type); + assert(info.segment === theMemoryInit.segment); + assert(info.dest === theMemoryInit.dest); + assert(info.offset === theMemoryInit.offset); + assert(info.size === theMemoryInit.size); + console.log(theMemoryInit.toText()); assert( theMemoryInit.toText() @@ -1363,16 +1772,24 @@ console.log("# DataDrop"); const theDataDrop = binaryen.DataDrop(module.data.drop(segment)); assert(theDataDrop instanceof binaryen.DataDrop); assert(theDataDrop instanceof binaryen.Expression); - assertInfoEqual(theDataDrop, binaryen.getExpressionInfo(theDataDrop)); assert(theDataDrop.segment === segment); assert(theDataDrop.type === binaryen.none); + var info = binaryen.getExpressionInfo(theDataDrop); + assert(info.id === theDataDrop.id); + assert(info.type === theDataDrop.type); + assert(info.segment === theDataDrop.segment); + theDataDrop.segment = segment = "2"; assert(theDataDrop.segment === "2"); theDataDrop.type = binaryen.f64; theDataDrop.finalize(); assert(theDataDrop.type === binaryen.none); + info = binaryen.getExpressionInfo(theDataDrop); + assert(info.type === theDataDrop.type); + assert(info.segment === theDataDrop.segment); + console.log(theDataDrop.toText()); assert( theDataDrop.toText() @@ -1394,12 +1811,18 @@ console.log("# MemoryCopy"); const theMemoryCopy = binaryen.MemoryCopy(module.memory.copy(dest, source, size)); assert(theMemoryCopy instanceof binaryen.MemoryCopy); assert(theMemoryCopy instanceof binaryen.Expression); - assertInfoEqual(theMemoryCopy, binaryen.getExpressionInfo(theMemoryCopy)); assert(theMemoryCopy.dest === dest); assert(theMemoryCopy.source === source); assert(theMemoryCopy.size === size); assert(theMemoryCopy.type === binaryen.none); + var info = binaryen.getExpressionInfo(theMemoryCopy); + assert(info.id === theMemoryCopy.id); + assert(info.type === theMemoryCopy.type); + assert(info.dest === theMemoryCopy.dest); + assert(info.source === theMemoryCopy.source); + assert(info.size === theMemoryCopy.size); + theMemoryCopy.dest = dest = module.i32.const(4); assert(theMemoryCopy.dest === dest); theMemoryCopy.source = source = module.i32.const(5); @@ -1410,6 +1833,12 @@ console.log("# MemoryCopy"); theMemoryCopy.finalize(); assert(theMemoryCopy.type === binaryen.none); + info = binaryen.getExpressionInfo(theMemoryCopy); + assert(info.type === theMemoryCopy.type); + assert(info.dest === theMemoryCopy.dest); + assert(info.source === theMemoryCopy.source); + assert(info.size === theMemoryCopy.size); + console.log(theMemoryCopy.toText()); assert( theMemoryCopy.toText() @@ -1431,12 +1860,18 @@ console.log("# MemoryFill"); const theMemoryFill = binaryen.MemoryFill(module.memory.fill(dest, value, size)); assert(theMemoryFill instanceof binaryen.MemoryFill); assert(theMemoryFill instanceof binaryen.Expression); - assertInfoEqual(theMemoryFill, binaryen.getExpressionInfo(theMemoryFill)); assert(theMemoryFill.dest === dest); assert(theMemoryFill.value === value); assert(theMemoryFill.size === size); assert(theMemoryFill.type === binaryen.none); + var info = binaryen.getExpressionInfo(theMemoryFill); + assert(info.id === theMemoryFill.id); + assert(info.type === theMemoryFill.type); + assert(info.dest === theMemoryFill.dest); + assert(info.value === theMemoryFill.value); + assert(info.size === theMemoryFill.size); + theMemoryFill.dest = dest = module.i32.const(4); assert(theMemoryFill.dest === dest); theMemoryFill.value = value = module.i32.const(5); @@ -1447,6 +1882,12 @@ console.log("# MemoryFill"); theMemoryFill.finalize(); assert(theMemoryFill.type === binaryen.none); + info = binaryen.getExpressionInfo(theMemoryFill); + assert(info.type === theMemoryFill.type); + assert(info.dest === theMemoryFill.dest); + assert(info.value === theMemoryFill.value); + assert(info.size === theMemoryFill.size); + console.log(theMemoryFill.toText()); assert( theMemoryFill.toText() @@ -1465,16 +1906,24 @@ console.log("# RefIsNull"); const theRefIsNull = binaryen.RefIsNull(module.ref.is_null(value)); assert(theRefIsNull instanceof binaryen.RefIsNull); assert(theRefIsNull instanceof binaryen.Expression); - assertInfoEqual(theRefIsNull, binaryen.getExpressionInfo(theRefIsNull)); assert(theRefIsNull.value === value); assert(theRefIsNull.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theRefIsNull); + assert(info.id === theRefIsNull.id); + assert(info.type === theRefIsNull.type); + assert(info.value === theRefIsNull.value); + theRefIsNull.value = value = module.local.get(2, binaryen.externref); assert(theRefIsNull.value === value); theRefIsNull.type = binaryen.f64; theRefIsNull.finalize(); assert(theRefIsNull.type === binaryen.i32); + info = binaryen.getExpressionInfo(theRefIsNull); + assert(info.type === theRefIsNull.type); + assert(info.value === theRefIsNull.value); + console.log(theRefIsNull.toText()); assert( theRefIsNull.toText() @@ -1495,11 +1944,16 @@ console.log("# RefAs"); const theRefAs = binaryen.RefAs(module.ref.as_non_null(value)); assert(theRefAs instanceof binaryen.RefAs); assert(theRefAs instanceof binaryen.Expression); - assertInfoEqual(theRefAs, binaryen.getExpressionInfo(theRefAs)); assert(theRefAs.op === op); assert(theRefAs.value === value); assert(theRefAs.type !== binaryen.i32); // TODO: === (ref any) + var info = binaryen.getExpressionInfo(theRefAs); + assert(info.id === theRefAs.id); + assert(info.type === theRefAs.type); + assert(info.op === theRefAs.op); + assert(info.value === theRefAs.value); + theRefAs.op = op = binaryen.Operations.RefAsExternConvertAny; assert(theRefAs.op === op); theRefAs.op = op = binaryen.Operations.RefAsNonNull; @@ -1509,6 +1963,11 @@ console.log("# RefAs"); theRefAs.finalize(); assert(theRefAs.type !== binaryen.f64); // TODO: === (ref any) + info = binaryen.getExpressionInfo(theRefAs); + assert(info.type === theRefAs.type); + assert(info.op === theRefAs.op); + assert(info.value === theRefAs.value); + console.log(theRefAs.toText()); assert( theRefAs.toText() @@ -1531,15 +1990,23 @@ console.log("# RefFunc"); const theRefFunc = binaryen.RefFunc(module.ref.func(func, type)); assert(theRefFunc instanceof binaryen.RefFunc); assert(theRefFunc instanceof binaryen.Expression); - assertInfoEqual(theRefFunc, binaryen.getExpressionInfo(theRefFunc)); assert(theRefFunc.func === func); assert(theRefFunc.type === type); + var info = binaryen.getExpressionInfo(theRefFunc); + assert(info.id === theRefFunc.id); + assert(info.type === theRefFunc.type); + assert(info.func === theRefFunc.func); + theRefFunc.func = func = "b"; assert(theRefFunc.func === func); theRefFunc.finalize(); assert(theRefFunc.type === type); + info = binaryen.getExpressionInfo(theRefFunc); + assert(info.type === theRefFunc.type); + assert(info.func === theRefFunc.func); + console.log(theRefFunc.toText()); assert( theRefFunc.toText() @@ -1559,11 +2026,16 @@ console.log("# RefEq"); const theRefEq = binaryen.RefEq(module.ref.eq(left, right)); assert(theRefEq instanceof binaryen.RefEq); assert(theRefEq instanceof binaryen.Expression); - assertInfoEqual(theRefEq, binaryen.getExpressionInfo(theRefEq)); assert(theRefEq.left === left); assert(theRefEq.right === right); assert(theRefEq.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theRefEq); + assert(info.id === theRefEq.id); + assert(info.type === theRefEq.type); + assert(info.left === theRefEq.left); + assert(info.right === theRefEq.right); + theRefEq.left = left = module.local.get(2, binaryen.eqref); assert(theRefEq.left === left); theRefEq.right = right = module.local.get(3, binaryen.eqref); @@ -1572,6 +2044,11 @@ console.log("# RefEq"); theRefEq.finalize(); assert(theRefEq.type === binaryen.i32); + info = binaryen.getExpressionInfo(theRefEq); + assert(info.type === theRefEq.type); + assert(info.left === theRefEq.left); + assert(info.right === theRefEq.right); + console.log(theRefEq.toText()); assert( theRefEq.toText() @@ -1591,11 +2068,16 @@ console.log("# RefTest"); const theRefTest = binaryen.RefTest(module.ref.test(ref, castType)); assert(theRefTest instanceof binaryen.RefTest); assert(theRefTest instanceof binaryen.Expression); - assertInfoEqual(theRefTest, binaryen.getExpressionInfo(theRefTest)); assert(theRefTest.ref === ref); assert(theRefTest.castType === castType); assert(theRefTest.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theRefTest); + assert(info.id === theRefTest.id); + assert(info.type === theRefTest.type); + assert(info.ref === theRefTest.ref); + assert(info.castType === theRefTest.castType); + theRefTest.ref = ref = module.local.get(2, binaryen.externref); assert(theRefTest.ref === ref); theRefTest.castType = castType = binaryen.externref; @@ -1604,6 +2086,11 @@ console.log("# RefTest"); theRefTest.finalize(); assert(theRefTest.type === binaryen.i32); + info = binaryen.getExpressionInfo(theRefTest); + assert(info.type === theRefTest.type); + assert(info.ref === theRefTest.ref); + assert(info.castType === theRefTest.castType); + console.log(theRefTest.toText()); assert( theRefTest.toText() @@ -1623,16 +2110,24 @@ console.log("# RefCast"); const theRefCast = binaryen.RefCast(module.ref.cast(ref, type)); assert(theRefCast instanceof binaryen.RefCast); assert(theRefCast instanceof binaryen.Expression); - assertInfoEqual(theRefCast, binaryen.getExpressionInfo(theRefCast)); assert(theRefCast.ref === ref); assert(theRefCast.type === type); + var info = binaryen.getExpressionInfo(theRefCast); + assert(info.id === theRefCast.id); + assert(info.type === theRefCast.type); + assert(info.ref === theRefCast.ref); + theRefCast.ref = ref = module.local.get(2, binaryen.externref); assert(theRefCast.ref === ref); theRefCast.type = type = binaryen.externref; theRefCast.finalize(); assert(theRefCast.type === type); + info = binaryen.getExpressionInfo(theRefCast); + assert(info.type === theRefCast.type); + assert(info.ref === theRefCast.ref); + console.log(theRefCast.toText()); assert( theRefCast.toText() @@ -1654,7 +2149,6 @@ console.log("# BrOn"); const theBrOn = binaryen.BrOn(module.br_on_null(name, ref)); assert(theBrOn instanceof binaryen.BrOn); assert(theBrOn instanceof binaryen.Expression); - assertInfoEqual(theBrOn, binaryen.getExpressionInfo(theBrOn)); assert(theBrOn.name === name); assert(theBrOn.ref === ref); assert(theBrOn.op === op); @@ -1662,6 +2156,14 @@ console.log("# BrOn"); // TODO: What should theBrOn.type be equal to? + var info = binaryen.getExpressionInfo(theBrOn); + assert(info.id === theBrOn.id); + assert(info.type === theBrOn.type); + assert(info.name === theBrOn.name); + assert(info.ref === theBrOn.ref); + assert(info.op === theBrOn.op); + assert(info.castType === theBrOn.castType); + theBrOn.name = name = "br2"; assert(theBrOn.name === name); theBrOn.ref = ref = module.local.get(1, binaryen.anyref); @@ -1672,6 +2174,12 @@ console.log("# BrOn"); assert(theBrOn.castType === castType); theBrOn.finalize(); + info = binaryen.getExpressionInfo(theBrOn); + assert(info.name === theBrOn.name); + assert(info.ref === theBrOn.ref); + assert(info.op === theBrOn.op); + assert(info.castType === theBrOn.castType); + console.log(theBrOn.toText()); assert( theBrOn.toText() @@ -1707,11 +2215,15 @@ console.log("# StructNew"); const theStructNew = binaryen.StructNew(module.struct.new(operands, type)); assert(theStructNew instanceof binaryen.StructNew); assert(theStructNew instanceof binaryen.Expression); - assertInfoEqual(theStructNew, binaryen.getExpressionInfo(theStructNew)); assertDeepEqual(theStructNew.operands, operands); assertDeepEqual(theStructNew.getOperands(), operands); assert(theStructNew.type === type); + var info = binaryen.getExpressionInfo(theStructNew); + assert(info.id === theStructNew.id); + assert(info.type === theStructNew.type); + assertDeepEqual(info.operands, theStructNew.operands); + theStructNew.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set @@ -1730,6 +2242,10 @@ console.log("# StructNew"); theStructNew.finalize(); assert(theStructNew.type === type); + info = binaryen.getExpressionInfo(theStructNew); + assert(info.type === theStructNew.type); + assertDeepEqual(info.operands, theStructNew.operands); + console.log(theStructNew.toText()); assert( theStructNew.toText() @@ -1764,12 +2280,18 @@ console.log("# StructGet"); const theStructGet = binaryen.StructGet(module.struct.get(index, ref, type, signed)); assert(theStructGet instanceof binaryen.StructGet); assert(theStructGet instanceof binaryen.Expression); - assertInfoEqual(theStructGet, binaryen.getExpressionInfo(theStructGet)); assert(theStructGet.index === index); assert(theStructGet.ref === ref); assert(theStructGet.signed === signed); assert(theStructGet.type === type); + var info = binaryen.getExpressionInfo(theStructGet); + assert(info.id === theStructGet.id); + assert(info.type === theStructGet.type); + assert(info.index === theStructGet.index); + assert(info.ref === theStructGet.ref); + assert(info.isSigned === theStructGet.signed); + theStructGet.index = index = 1; assert(theStructGet.index === index); theStructGet.ref = ref = module.local.get(1, struct1Type); @@ -1780,6 +2302,12 @@ console.log("# StructGet"); theStructGet.finalize(); assert(theStructGet.type === type); + info = binaryen.getExpressionInfo(theStructGet); + assert(info.type === theStructGet.type); + assert(info.index === theStructGet.index); + assert(info.ref === theStructGet.ref); + assert(info.isSigned === theStructGet.signed); + console.log(theStructGet.toText()); assert( theStructGet.toText() @@ -1813,12 +2341,18 @@ console.log("# StructSet"); const theStructSet = binaryen.StructSet(module.struct.set(index, ref, value)); assert(theStructSet instanceof binaryen.StructSet); assert(theStructSet instanceof binaryen.Expression); - assertInfoEqual(theStructSet, binaryen.getExpressionInfo(theStructSet)); assert(theStructSet.index === index); assert(theStructSet.ref === ref); assert(theStructSet.value === value); assert(theStructSet.type === binaryen.none); + var info = binaryen.getExpressionInfo(theStructSet); + assert(info.id === theStructSet.id); + assert(info.type === theStructSet.type); + assert(info.index === theStructSet.index); + assert(info.ref === theStructSet.ref); + assert(info.value === theStructSet.value); + theStructSet.index = index = 1; assert(theStructSet.index === index); theStructSet.ref = ref = module.local.get(2, struct1Type); @@ -1829,6 +2363,12 @@ console.log("# StructSet"); theStructSet.finalize(); assert(theStructSet.type === binaryen.none); + info = binaryen.getExpressionInfo(theStructSet); + assert(info.type === theStructSet.type); + assert(info.index === theStructSet.index); + assert(info.ref === theStructSet.ref); + assert(info.value === theStructSet.value); + console.log(theStructSet.toText()); assert( theStructSet.toText() @@ -1857,11 +2397,16 @@ console.log("# ArrayNew"); const theArrayNew = binaryen.ArrayNew(module.array.new(type, size, init)); assert(theArrayNew instanceof binaryen.ArrayNew); assert(theArrayNew instanceof binaryen.Expression); - assertInfoEqual(theArrayNew, binaryen.getExpressionInfo(theArrayNew)); assert(theArrayNew.size === size); assert(theArrayNew.init === init); assert(theArrayNew.type === type); + var info = binaryen.getExpressionInfo(theArrayNew); + assert(info.id === theArrayNew.id); + assert(info.type === theArrayNew.type); + assert(info.size === theArrayNew.size); + assert(info.init === theArrayNew.init); + theArrayNew.size = size = module.i32.const(4); assert(theArrayNew.size === size); theArrayNew.init = init = module.i32.const(3); @@ -1870,6 +2415,11 @@ console.log("# ArrayNew"); theArrayNew.finalize(); assert(theArrayNew.type === type); + info = binaryen.getExpressionInfo(theArrayNew); + assert(info.type === theArrayNew.type); + assert(info.size === theArrayNew.size); + assert(info.init === theArrayNew.init); + console.log(theArrayNew.toText()); assert( theArrayNew.toText() @@ -1900,11 +2450,15 @@ console.log("# ArrayNewFixed"); const theArrayNewFixed = binaryen.ArrayNewFixed(module.array.new_fixed(type, values)); assert(theArrayNewFixed instanceof binaryen.ArrayNewFixed); assert(theArrayNewFixed instanceof binaryen.Expression); - assertInfoEqual(theArrayNewFixed, binaryen.getExpressionInfo(theArrayNewFixed)); assertDeepEqual(theArrayNewFixed.values, values); assertDeepEqual(theArrayNewFixed.getValues(), values); assert(theArrayNewFixed.type === type); + var info = binaryen.getExpressionInfo(theArrayNewFixed); + assert(info.id === theArrayNewFixed.id); + assert(info.type === theArrayNewFixed.type); + assertDeepEqual(info.values, theArrayNewFixed.values); + theArrayNewFixed.values = values = [ module.i32.const(3), // set module.i32.const(4), // set @@ -1923,6 +2477,10 @@ console.log("# ArrayNewFixed"); theArrayNewFixed.finalize(); assert(theArrayNewFixed.type === type); + info = binaryen.getExpressionInfo(theArrayNewFixed); + assert(info.type === theArrayNewFixed.type); + assertDeepEqual(info.values, theArrayNewFixed.values); + console.log(theArrayNewFixed.toText()); assert( theArrayNewFixed.toText() @@ -1952,12 +2510,18 @@ console.log("# ArrayNewData"); const theArrayNewData = binaryen.ArrayNewData(module.array.new_data(type, segment, offset, size)); assert(theArrayNewData instanceof binaryen.ArrayNewData); assert(theArrayNewData instanceof binaryen.Expression); - assertInfoEqual(theArrayNewData, binaryen.getExpressionInfo(theArrayNewData)); assert(theArrayNewData.segment === segment); assert(theArrayNewData.offset === offset); assert(theArrayNewData.size === size); assert(theArrayNewData.type === type); + var info = binaryen.getExpressionInfo(theArrayNewData); + assert(info.id === theArrayNewData.id); + assert(info.type === theArrayNewData.type); + assert(info.segment === theArrayNewData.segment); + assert(info.offset === theArrayNewData.offset); + assert(info.size === theArrayNewData.size); + theArrayNewData.segment = segment = "3"; assert(theArrayNewData.segment === segment); theArrayNewData.offset = offset = module.i32.const(4); @@ -1968,6 +2532,12 @@ console.log("# ArrayNewData"); theArrayNewData.finalize(); assert(theArrayNewData.type === type); + info = binaryen.getExpressionInfo(theArrayNewData); + assert(info.type === theArrayNewData.type); + assert(info.segment === theArrayNewData.segment); + assert(info.offset === theArrayNewData.offset); + assert(info.size === theArrayNewData.size); + console.log(theArrayNewData.toText()); assert( theArrayNewData.toText() @@ -1997,12 +2567,18 @@ console.log("# ArrayNewElem"); const theArrayNewElem = binaryen.ArrayNewElem(module.array.new_elem(type, segment, offset, size)); assert(theArrayNewElem instanceof binaryen.ArrayNewElem); assert(theArrayNewElem instanceof binaryen.Expression); - assertInfoEqual(theArrayNewElem, binaryen.getExpressionInfo(theArrayNewElem)); assert(theArrayNewElem.segment === segment); assert(theArrayNewElem.offset === offset); assert(theArrayNewElem.size === size); assert(theArrayNewElem.type === type); + var info = binaryen.getExpressionInfo(theArrayNewElem); + assert(info.id === theArrayNewElem.id); + assert(info.type === theArrayNewElem.type); + assert(info.segment === theArrayNewElem.segment); + assert(info.offset === theArrayNewElem.offset); + assert(info.size === theArrayNewElem.size); + theArrayNewElem.segment = segment = "3"; assert(theArrayNewElem.segment === segment); theArrayNewElem.offset = offset = module.i32.const(4); @@ -2013,6 +2589,13 @@ console.log("# ArrayNewElem"); theArrayNewElem.finalize(); assert(theArrayNewElem.type === type); + info = binaryen.getExpressionInfo(theArrayNewElem); + assert(info.id === theArrayNewElem.id); + assert(info.type === theArrayNewElem.type); + assert(info.segment === theArrayNewElem.segment); + assert(info.offset === theArrayNewElem.offset); + assert(info.size === theArrayNewElem.size); + console.log(theArrayNewElem.toText()); assert( theArrayNewElem.toText() @@ -2042,12 +2625,18 @@ console.log("# ArrayGet"); const theArrayGet = binaryen.ArrayGet(module.array.get(ref, index, type, signed)); assert(theArrayGet instanceof binaryen.ArrayGet); assert(theArrayGet instanceof binaryen.Expression); - assertInfoEqual(theArrayGet, binaryen.getExpressionInfo(theArrayGet)); assert(theArrayGet.ref === ref); assert(theArrayGet.index === index); assert(theArrayGet.signed === signed); assert(theArrayGet.type === type); + var info = binaryen.getExpressionInfo(theArrayGet); + assert(info.id === theArrayGet.id); + assert(info.type === theArrayGet.type); + assert(info.ref === theArrayGet.ref); + assert(info.index === theArrayGet.index); + assert(info.isSigned === theArrayGet.signed); + theArrayGet.ref = ref = module.local.get(1, array1Type); assert(theArrayGet.ref === ref); theArrayGet.index = index = module.i32.const(1); @@ -2058,6 +2647,12 @@ console.log("# ArrayGet"); theArrayGet.finalize(); assert(theArrayGet.type === type); + info = binaryen.getExpressionInfo(theArrayGet); + assert(info.type === theArrayGet.type); + assert(info.ref === theArrayGet.ref); + assert(info.index === theArrayGet.index); + assert(info.isSigned === theArrayGet.signed); + console.log(theArrayGet.toText()); assert( theArrayGet.toText() @@ -2086,12 +2681,18 @@ console.log("# ArraySet"); const theArraySet = binaryen.ArraySet(module.array.set(ref, index, value)); assert(theArraySet instanceof binaryen.ArraySet); assert(theArraySet instanceof binaryen.Expression); - assertInfoEqual(theArraySet, binaryen.getExpressionInfo(theArraySet)); assert(theArraySet.ref === ref); assert(theArraySet.index === index); assert(theArraySet.value === value); assert(theArraySet.type === binaryen.none); + var info = binaryen.getExpressionInfo(theArraySet); + assert(info.id === theArraySet.id); + assert(info.type === theArraySet.type); + assert(info.ref === theArraySet.ref); + assert(info.index === theArraySet.index); + assert(info.value === theArraySet.value); + theArraySet.ref = ref = module.local.get(2, array1Type); assert(theArraySet.ref === ref); theArraySet.index = index = module.i32.const(1); @@ -2102,6 +2703,12 @@ console.log("# ArraySet"); theArraySet.finalize(); assert(theArraySet.type === binaryen.none); + info = binaryen.getExpressionInfo(theArraySet); + assert(info.type === theArraySet.type); + assert(info.ref === theArraySet.ref); + assert(info.index === theArraySet.index); + assert(info.value === theArraySet.value); + console.log(theArraySet.toText()); assert( theArraySet.toText() @@ -2128,16 +2735,24 @@ console.log("# ArrayLen"); const theArrayLen = binaryen.ArrayLen(module.array.len(ref)); assert(theArrayLen instanceof binaryen.ArrayLen); assert(theArrayLen instanceof binaryen.Expression); - assertInfoEqual(theArrayLen, binaryen.getExpressionInfo(theArrayLen)); assert(theArrayLen.ref === ref); assert(theArrayLen.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theArrayLen); + assert(info.id === theArrayLen.id); + assert(info.type === theArrayLen.type); + assert(info.ref === theArrayLen.ref); + theArrayLen.ref = ref = module.local.get(1, array1Type); assert(theArrayLen.ref === ref); theArrayLen.type = binaryen.i64; theArrayLen.finalize(); assert(theArrayLen.type === binaryen.i32); + info = binaryen.getExpressionInfo(theArrayLen); + assert(info.type === theArrayLen.type); + assert(info.ref === theArrayLen.ref); + console.log(theArrayLen.toText()); assert( theArrayLen.toText() @@ -2167,13 +2782,20 @@ console.log("# ArrayFill"); const theArrayFill = binaryen.ArrayFill(module.array.fill(ref, index, value, size)); assert(theArrayFill instanceof binaryen.ArrayFill); assert(theArrayFill instanceof binaryen.Expression); - assertInfoEqual(theArrayFill, binaryen.getExpressionInfo(theArrayFill)); assert(theArrayFill.ref === ref); assert(theArrayFill.index === index); assert(theArrayFill.value === value); assert(theArrayFill.size === size); assert(theArrayFill.type === binaryen.none); + var info = binaryen.getExpressionInfo(theArrayFill); + assert(info.id === theArrayFill.id); + assert(info.type === theArrayFill.type); + assert(info.ref === theArrayFill.ref); + assert(info.index === theArrayFill.index); + assert(info.value === theArrayFill.value); + assert(info.size === theArrayFill.size); + theArrayFill.ref = ref = module.local.get(2, array1Type); assert(theArrayFill.ref === ref); theArrayFill.index = index = module.i32.const(2); @@ -2186,6 +2808,13 @@ console.log("# ArrayFill"); theArrayFill.finalize(); assert(theArrayFill.type === binaryen.none); + info = binaryen.getExpressionInfo(theArrayFill); + assert(info.type === theArrayFill.type); + assert(info.ref === theArrayFill.ref); + assert(info.index === theArrayFill.index); + assert(info.value === theArrayFill.value); + assert(info.size === theArrayFill.size); + console.log(theArrayFill.toText()); assert( theArrayFill.toText() @@ -2216,7 +2845,6 @@ console.log("# ArrayCopy"); const theArrayCopy = binaryen.ArrayCopy(module.array.copy(destRef, destIndex, srcRef, srcIndex, length)); assert(theArrayCopy instanceof binaryen.ArrayCopy); assert(theArrayCopy instanceof binaryen.Expression); - assertInfoEqual(theArrayCopy, binaryen.getExpressionInfo(theArrayCopy)); assert(theArrayCopy.destRef === destRef); assert(theArrayCopy.destIndex === destIndex); assert(theArrayCopy.srcRef === srcRef); @@ -2224,6 +2852,15 @@ console.log("# ArrayCopy"); assert(theArrayCopy.length === length); assert(theArrayCopy.type === binaryen.none); + var info = binaryen.getExpressionInfo(theArrayCopy); + assert(info.id === theArrayCopy.id); + assert(info.type === theArrayCopy.type); + assert(info.destRef === theArrayCopy.destRef); + assert(info.destIndex === theArrayCopy.destIndex); + assert(info.srcRef === theArrayCopy.srcRef); + assert(info.srcIndex === theArrayCopy.srcIndex); + assert(info.length === theArrayCopy.length); + theArrayCopy.destRef = destRef = module.local.get(2, array1Type); assert(theArrayCopy.destRef === destRef); theArrayCopy.destIndex = destIndex = module.i32.const(2); @@ -2238,6 +2875,14 @@ console.log("# ArrayCopy"); theArrayCopy.finalize(); assert(theArrayCopy.type === binaryen.none); + info = binaryen.getExpressionInfo(theArrayCopy); + assert(info.type === theArrayCopy.type); + assert(info.destRef === theArrayCopy.destRef); + assert(info.destIndex === theArrayCopy.destIndex); + assert(info.srcRef === theArrayCopy.srcRef); + assert(info.srcIndex === theArrayCopy.srcIndex); + assert(info.length === theArrayCopy.length); + console.log(theArrayCopy.toText()); assert( theArrayCopy.toText() @@ -2268,13 +2913,21 @@ console.log("# ArrayInitData"); const theArrayInitData = binaryen.ArrayInitData(module.array.init_data(segment, ref, index, offset, size)); assert(theArrayInitData instanceof binaryen.ArrayInitData); assert(theArrayInitData instanceof binaryen.Expression); - assertInfoEqual(theArrayInitData, binaryen.getExpressionInfo(theArrayInitData)); assert(theArrayInitData.segment === segment); assert(theArrayInitData.ref === ref); assert(theArrayInitData.index === index); assert(theArrayInitData.offset === offset); assert(theArrayInitData.size === size); assert(theArrayInitData.type === binaryen.none); + + var info = binaryen.getExpressionInfo(theArrayInitData); + assert(info.id === theArrayInitData.id); + assert(info.type === theArrayInitData.type); + assert(info.segment === theArrayInitData.segment); + assert(info.ref === theArrayInitData.ref); + assert(info.index === theArrayInitData.index); + assert(info.offset === theArrayInitData.offset); + assert(info.size === theArrayInitData.size); theArrayInitData.segment = segment = "1"; assert(theArrayInitData.segment === segment); @@ -2290,6 +2943,14 @@ console.log("# ArrayInitData"); theArrayInitData.finalize(); assert(theArrayInitData.type === binaryen.none); + info = binaryen.getExpressionInfo(theArrayInitData); + assert(info.type === theArrayInitData.type); + assert(info.segment === theArrayInitData.segment); + assert(info.ref === theArrayInitData.ref); + assert(info.index === theArrayInitData.index); + assert(info.offset === theArrayInitData.offset); + assert(info.size === theArrayInitData.size); + console.log(theArrayInitData.toText()); assert( theArrayInitData.toText() @@ -2320,7 +2981,6 @@ console.log("# ArrayInitElem"); const theArrayInitElem = binaryen.ArrayInitElem(module.array.init_elem(segment, ref, index, offset, size)); assert(theArrayInitElem instanceof binaryen.ArrayInitElem); assert(theArrayInitElem instanceof binaryen.Expression); - assertInfoEqual(theArrayInitElem, binaryen.getExpressionInfo(theArrayInitElem)); assert(theArrayInitElem.segment === segment); assert(theArrayInitElem.ref === ref); assert(theArrayInitElem.index === index); @@ -2328,6 +2988,15 @@ console.log("# ArrayInitElem"); assert(theArrayInitElem.size === size); assert(theArrayInitElem.type === binaryen.none); + var info = binaryen.getExpressionInfo(theArrayInitElem); + assert(info.id === theArrayInitElem.id); + assert(info.type === theArrayInitElem.type); + assert(info.segment === theArrayInitElem.segment); + assert(info.ref === theArrayInitElem.ref); + assert(info.index === theArrayInitElem.index); + assert(info.offset === theArrayInitElem.offset); + assert(info.size === theArrayInitElem.size); + theArrayInitElem.segment = segment = "1"; assert(theArrayInitElem.segment === segment); theArrayInitElem.ref = ref = module.local.get(1, array1Type); @@ -2342,6 +3011,14 @@ console.log("# ArrayInitElem"); theArrayInitElem.finalize(); assert(theArrayInitElem.type === binaryen.none); + info = binaryen.getExpressionInfo(theArrayInitElem); + assert(info.type === theArrayInitElem.type); + assert(info.segment === theArrayInitElem.segment); + assert(info.ref === theArrayInitElem.ref); + assert(info.index === theArrayInitElem.index); + assert(info.offset === theArrayInitElem.offset); + assert(info.size === theArrayInitElem.size); + console.log(theArrayInitElem.toText()); assert( theArrayInitElem.toText() @@ -2367,7 +3044,6 @@ console.log("# Try"); const theTry = binaryen.Try(module.try('', body, ["tag1"], catchBodies, '')); assert(theTry instanceof binaryen.Try); assert(theTry instanceof binaryen.Expression); - assertInfoEqual(theTry, binaryen.getExpressionInfo(theTry)); assert(theTry.body === body); assertDeepEqual(theTry.catchBodies, catchBodies); assert(theTry.type === binaryen.i32); @@ -2376,6 +3052,17 @@ console.log("# Try"); assert(theTry.hasCatchAll() == 1); console.log(theTry.toText()); + var info = binaryen.getExpressionInfo(theTry); + assert(info.id === theTry.id); + assert(info.type === theTry.type); + assert(info.name === theTry.name); + assert(info.body === theTry.body); + assertDeepEqual(info.catchTags, theTry.catchTags); + assertDeepEqual(info.catchBodies, theTry.catchBodies); + assert(info.hasCatchAll === theTry.hasCatchAll()); + assert(info.delegateTarget === theTry.delegateTarget); + assert(info.isDelegate === theTry.delegate); + theTry.body = body = module.i32.const(4); assert(theTry.body === body); catchBodies = [ @@ -2418,6 +3105,17 @@ console.log("# Try"); theTry.finalize(); assert(theTry.type === binaryen.i32); + info = binaryen.getExpressionInfo(theTry); + assert(info.id === theTry.id); + assert(info.type === theTry.type); + assert(info.name === theTry.name); + assert(info.body === theTry.body); + assertDeepEqual(info.catchTags, theTry.catchTags); + assertDeepEqual(info.catchBodies, theTry.catchBodies); + assert(info.hasCatchAll === theTry.hasCatchAll()); + assert(info.delegateTarget === theTry.delegateTarget); + assert(info.isDelegate === theTry.delegate); + console.log(theTry.toText()); const tryDelegate = binaryen.Try(module.try('', body, [], [], "try_blah")); @@ -2425,6 +3123,11 @@ console.log("# Try"); assert(tryDelegate.getDelegateTarget() == "try_blah"); tryDelegate.setDelegateTarget("try_outer"); assert(tryDelegate.getDelegateTarget() == "try_outer"); + + info = binaryen.getExpressionInfo(tryDelegate); + assert(info.delegateTarget === tryDelegate.delegateTarget); + assert(info.isDelegate === tryDelegate.delegate); + console.log(tryDelegate.toText()); module.dispose(); @@ -2442,11 +3145,16 @@ console.log("# Throw"); const theThrow = binaryen.Throw(module.throw(tag, operands)); assert(theThrow instanceof binaryen.Throw); assert(theThrow instanceof binaryen.Expression); - assertInfoEqual(theThrow, binaryen.getExpressionInfo(theThrow)); assert(theThrow.tag === tag); assertDeepEqual(theThrow.operands, operands); assert(theThrow.type === binaryen.unreachable); + var info = binaryen.getExpressionInfo(theThrow); + assert(info.id === theThrow.id); + assert(info.type === theThrow.type); + assert(info.tag === theThrow.tag); + assertDeepEqual(info.operands, theThrow.operands); + theThrow.tag = "bar"; assert(theThrow.tag === "bar"); theThrow.operands = operands = [ @@ -2468,6 +3176,11 @@ console.log("# Throw"); theThrow.finalize(); assert(theThrow.type === binaryen.unreachable); + info = binaryen.getExpressionInfo(theThrow); + assert(info.type === theThrow.type); + assert(info.tag === theThrow.tag); + assertDeepEqual(info.operands, theThrow.operands); + console.log(theThrow.toText()); assert( theThrow.toText() @@ -2485,16 +3198,24 @@ console.log("# Rethrow"); const theRethrow = binaryen.Rethrow(module.rethrow("l0")); assert(theRethrow instanceof binaryen.Rethrow); assert(theRethrow instanceof binaryen.Expression); - assertInfoEqual(theRethrow, binaryen.getExpressionInfo(theRethrow)); assert(theRethrow.target === "l0"); assert(theRethrow.type === binaryen.unreachable); + var info = binaryen.getExpressionInfo(theRethrow); + assert(info.id === theRethrow.id); + assert(info.type === theRethrow.type); + assert(info.target === theRethrow.target); + theRethrow.target = "l1"; assert(theRethrow.target === "l1"); theRethrow.type = binaryen.f64; theRethrow.finalize(); assert(theRethrow.type === binaryen.unreachable); + info = binaryen.getExpressionInfo(theRethrow); + assert(info.type === theRethrow.type); + assert(info.target === theRethrow.target); + console.log(theRethrow.toText()); assert( theRethrow.toText() @@ -2517,10 +3238,14 @@ console.log("# TupleMake"); const theTupleMake = binaryen.TupleMake(module.tuple.make(operands)); assert(theTupleMake instanceof binaryen.TupleMake); assert(theTupleMake instanceof binaryen.Expression); - assertInfoEqual(theTupleMake, binaryen.getExpressionInfo(theTupleMake)); assertDeepEqual(theTupleMake.operands, operands); assert(theTupleMake.type === type); + var info = binaryen.getExpressionInfo(theTupleMake); + assert(info.id === theTupleMake.id); + assert(info.type === theTupleMake.type); + assertDeepEqual(info.operands, theTupleMake.operands); + theTupleMake.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set @@ -2540,6 +3265,10 @@ console.log("# TupleMake"); theTupleMake.finalize(); assert(theTupleMake.type === type); + info = binaryen.getExpressionInfo(theTupleMake); + assert(info.type === theTupleMake.type); + assertDeepEqual(info.operands, theTupleMake.operands); + console.log(theTupleMake.toText()); assert( theTupleMake.toText() @@ -2562,11 +3291,16 @@ console.log("# TupleExtract"); const theTupleExtract = binaryen.TupleExtract(module.tuple.extract(tuple, index)); assert(theTupleExtract instanceof binaryen.TupleExtract); assert(theTupleExtract instanceof binaryen.Expression); - assertInfoEqual(theTupleExtract, binaryen.getExpressionInfo(theTupleExtract)); assert(theTupleExtract.tuple === tuple); assert(theTupleExtract.index === index); assert(theTupleExtract.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theTupleExtract); + assert(info.id === theTupleExtract.id); + assert(info.type === theTupleExtract.type); + assert(info.tuple === theTupleExtract.tuple); + assert(info.index === theTupleExtract.index); + theTupleExtract.tuple = tuple = module.tuple.make([ module.f64.const(3), module.f64.const(4) @@ -2578,6 +3312,11 @@ console.log("# TupleExtract"); theTupleExtract.finalize(); assert(theTupleExtract.type === binaryen.f64); + info = binaryen.getExpressionInfo(theTupleExtract); + assert(info.type === theTupleExtract.type); + assert(info.tuple === theTupleExtract.tuple); + assert(info.index === theTupleExtract.index); + console.log(theTupleExtract.toText()); assert( theTupleExtract.toText() @@ -2596,13 +3335,20 @@ console.log("# RefI31"); const theRefI31 = binaryen.RefI31(module.ref.i31(value)); assert(theRefI31 instanceof binaryen.RefI31); assert(theRefI31 instanceof binaryen.Expression); - assertInfoEqual(theRefI31, binaryen.getExpressionInfo(theRefI31)); assert(theRefI31.value === value); // assert(theRefI31.type === binaryen.?); // TODO: (ref i31) + var info = binaryen.getExpressionInfo(theRefI31); + assert(info.id === theRefI31.id); + assert(info.type === theRefI31.type); + assert(info.value === theRefI31.value); + theRefI31.value = value = module.local.get(2, binaryen.i32); assert(theRefI31.value === value); + info = binaryen.getExpressionInfo(theRefI31); + assert(info.value === theRefI31.value); + console.log(theRefI31.toText()); assert( theRefI31.toText() @@ -2621,11 +3367,16 @@ console.log("# I31Get"); const theI31Get = binaryen.I31Get(module.i31.get_s(i31)); assert(theI31Get instanceof binaryen.I31Get); assert(theI31Get instanceof binaryen.Expression); - assertInfoEqual(theI31Get, binaryen.getExpressionInfo(theI31Get)); assert(theI31Get.i31 === i31); assert(theI31Get.signed === true); assert(theI31Get.type === binaryen.i32); + var info = binaryen.getExpressionInfo(theI31Get); + assert(info.id === theI31Get.id); + assert(info.type === theI31Get.type); + assert(info.i31 === theI31Get.i31); + assert(info.isSigned === theI31Get.signed); + theI31Get.i31 = i31 = module.local.get(2, binaryen.i31ref); assert(theI31Get.i31 === i31); theI31Get.signed = false; @@ -2634,6 +3385,11 @@ console.log("# I31Get"); theI31Get.finalize(); assert(theI31Get.type === binaryen.i32); + info = binaryen.getExpressionInfo(theI31Get); + assert(info.type === theI31Get.type); + assert(info.i31 === theI31Get.i31); + assert(info.isSigned === theI31Get.signed); + console.log(theI31Get.toText()); assert( theI31Get.toText() From 7e8776a0fa1c56e7433908274d503f3bf0b055f4 Mon Sep 17 00:00:00 2001 From: GulgDev Date: Fri, 18 Apr 2025 12:11:45 +0500 Subject: [PATCH 4/6] Update `getExpressionInfo` & add `wrapExpression` --- src/js/binaryen.js-post.js | 745 ++++----------------------- test/binaryen.js/kitchen-sink.js.txt | 2 +- 2 files changed, 102 insertions(+), 645 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 4695a5a4d85..c6e7d64b8a4 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3058,600 +3058,54 @@ Module['getExpressionType'] = function(expr) { Module['getExpressionInfo'] = function(expr) { const id = Module['_BinaryenExpressionGetId'](expr); const type = Module['_BinaryenExpressionGetType'](expr); + const info = { id, type }; switch (id) { - case Module['BlockId']: { - const name = Module['_BinaryenBlockGetName'](expr); - return { - 'id': id, - 'type': type, - 'name': name ? UTF8ToString(name) : null, - 'children': getAllNested(expr, Module['_BinaryenBlockGetNumChildren'], Module['_BinaryenBlockGetChildAt']) - }; - } - case Module['IfId']: - return { - 'id': id, - 'type': type, - 'condition': Module['_BinaryenIfGetCondition'](expr), - 'ifTrue': Module['_BinaryenIfGetIfTrue'](expr), - 'ifFalse': Module['_BinaryenIfGetIfFalse'](expr) - }; - case Module['LoopId']: { - const name = Module['_BinaryenLoopGetName'](expr); - return { - 'id': id, - 'type': type, - 'name': name ? UTF8ToString(name) : null, - 'body': Module['_BinaryenLoopGetBody'](expr) - }; - } - case Module['BreakId']: { - const name = Module['_BinaryenBreakGetName'](expr); - return { - 'id': id, - 'type': type, - 'name': name ? UTF8ToString(name) : null, - 'condition': Module['_BinaryenBreakGetCondition'](expr), - 'value': Module['_BinaryenBreakGetValue'](expr) - }; - } - case Module['SwitchId']: - return { - 'id': id, - 'type': type, - // Do not pass the index as the second parameter to UTF8ToString as that will cut off the string. - 'names': getAllNested(expr, Module['_BinaryenSwitchGetNumNames'], Module['_BinaryenSwitchGetNameAt']).map(p => UTF8ToString(p)), - 'defaultName': UTF8ToString(Module['_BinaryenSwitchGetDefaultName'](expr)), - 'condition': Module['_BinaryenSwitchGetCondition'](expr), - 'value': Module['_BinaryenSwitchGetValue'](expr) - }; - case Module['CallId']: - return { - 'id': id, - 'type': type, - 'isReturn': Boolean(Module['_BinaryenCallIsReturn'](expr)), - 'target': UTF8ToString(Module['_BinaryenCallGetTarget'](expr)), - 'operands': getAllNested(expr, Module[ '_BinaryenCallGetNumOperands'], Module['_BinaryenCallGetOperandAt']) - }; - case Module['CallIndirectId']: - return { - 'id': id, - 'type': type, - 'isReturn': Boolean(Module['_BinaryenCallIndirectIsReturn'](expr)), - 'target': Module['_BinaryenCallIndirectGetTarget'](expr), - 'table': UTF8ToString(Module['_BinaryenCallIndirectGetTable'](expr)), - 'operands': getAllNested(expr, Module['_BinaryenCallIndirectGetNumOperands'], Module['_BinaryenCallIndirectGetOperandAt']), - 'params': Module['_BinaryenCallIndirectGetParams'](expr), - 'results': Module['_BinaryenCallIndirectGetResults'](expr) - }; - case Module['LocalGetId']: - return { - 'id': id, - 'type': type, - 'index': Module['_BinaryenLocalGetGetIndex'](expr) - }; - case Module['LocalSetId']: - return { - 'id': id, - 'type': type, - 'isTee': Boolean(Module['_BinaryenLocalSetIsTee'](expr)), - 'index': Module['_BinaryenLocalSetGetIndex'](expr), - 'value': Module['_BinaryenLocalSetGetValue'](expr) - }; - case Module['GlobalGetId']: - return { - 'id': id, - 'type': type, - 'name': UTF8ToString(Module['_BinaryenGlobalGetGetName'](expr)) - }; - case Module['GlobalSetId']: - return { - 'id': id, - 'type': type, - 'name': UTF8ToString(Module['_BinaryenGlobalSetGetName'](expr)), - 'value': Module['_BinaryenGlobalSetGetValue'](expr) - }; - case Module['TableGetId']: - return { - 'id': id, - 'type': type, - 'table': UTF8ToString(Module['_BinaryenTableGetGetTable'](expr)), - 'index': Module['_BinaryenTableGetGetIndex'](expr) - }; - case Module['TableSetId']: - return { - 'id': id, - 'type': type, - 'table': UTF8ToString(Module['_BinaryenTableSetGetTable'](expr)), - 'index': Module['_BinaryenTableSetGetIndex'](expr), - 'value': Module['_BinaryenTableSetGetValue'](expr) - }; - case Module['TableSizeId']: - return { - 'id': id, - 'type': type, - 'table': UTF8ToString(Module['_BinaryenTableSizeGetTable'](expr)), - }; - case Module['TableGrowId']: - return { - 'id': id, - 'type': type, - 'table': UTF8ToString(Module['_BinaryenTableGrowGetTable'](expr)), - 'value': Module['_BinaryenTableGrowGetValue'](expr), - 'delta': Module['_BinaryenTableGrowGetDelta'](expr), - }; - case Module['LoadId']: - return { - 'id': id, - 'type': type, - 'isAtomic': Boolean(Module['_BinaryenLoadIsAtomic'](expr)), - 'isSigned': Boolean(Module['_BinaryenLoadIsSigned'](expr)), - 'offset': Module['_BinaryenLoadGetOffset'](expr), - 'bytes': Module['_BinaryenLoadGetBytes'](expr), - 'align': Module['_BinaryenLoadGetAlign'](expr), - 'ptr': Module['_BinaryenLoadGetPtr'](expr) - }; - case Module['StoreId']: - return { - 'id': id, - 'type': type, - 'isAtomic': Boolean(Module['_BinaryenStoreIsAtomic'](expr)), - 'offset': Module['_BinaryenStoreGetOffset'](expr), - 'bytes': Module['_BinaryenStoreGetBytes'](expr), - 'align': Module['_BinaryenStoreGetAlign'](expr), - 'ptr': Module['_BinaryenStoreGetPtr'](expr), - 'value': Module['_BinaryenStoreGetValue'](expr), - 'valueType': Module['_BinaryenStoreGetValueType'](expr) - }; - case Module['ConstId']: { - let value; + case Module['ConstId']: switch (type) { - case Module['i32']: value = Module['_BinaryenConstGetValueI32'](expr); break; - case Module['i64']: value = { + case Module['i32']: info.value = Module['_BinaryenConstGetValueI32'](expr); break; + case Module['i64']: info.value = { 'low': Module['_BinaryenConstGetValueI64Low'](expr), 'high': Module['_BinaryenConstGetValueI64High'](expr) }; break; - case Module['f32']: value = Module['_BinaryenConstGetValueF32'](expr); break; - case Module['f64']: value = Module['_BinaryenConstGetValueF64'](expr); break; + case Module['f32']: info.value = Module['_BinaryenConstGetValueF32'](expr); break; + case Module['f64']: info.value = Module['_BinaryenConstGetValueF64'](expr); break; case Module['v128']: { preserveStack(() => { const tempBuffer = stackAlloc(16); Module['_BinaryenConstGetValueV128'](expr, tempBuffer); - value = new Array(16); + info.value = new Array(16); for (let i = 0; i < 16; i++) { - value[i] = HEAPU8[tempBuffer + i]; + info.value[i] = HEAPU8[tempBuffer + i]; } }); break; } default: throw Error('unexpected type: ' + type); } - return { - 'id': id, - 'type': type, - 'value': value - }; - } - case Module['UnaryId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenUnaryGetOp'](expr), - 'value': Module['_BinaryenUnaryGetValue'](expr) - }; - case Module['BinaryId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenBinaryGetOp'](expr), - 'left': Module['_BinaryenBinaryGetLeft'](expr), - 'right': Module['_BinaryenBinaryGetRight'](expr) - }; - case Module['SelectId']: - return { - 'id': id, - 'type': type, - 'ifTrue': Module['_BinaryenSelectGetIfTrue'](expr), - 'ifFalse': Module['_BinaryenSelectGetIfFalse'](expr), - 'condition': Module['_BinaryenSelectGetCondition'](expr) - }; - case Module['DropId']: - return { - 'id': id, - 'type': type, - 'value': Module['_BinaryenDropGetValue'](expr) - }; - case Module['ReturnId']: - return { - 'id': id, - 'type': type, - 'value': Module['_BinaryenReturnGetValue'](expr) - }; - case Module['NopId']: - case Module['UnreachableId']: - case Module['PopId']: - return { - 'id': id, - 'type': type - }; - case Module['MemorySizeId']: - return { - 'id': id, - 'type': type - }; - case Module['MemoryGrowId']: - return { - 'id': id, - 'type': type, - 'delta': Module['_BinaryenMemoryGrowGetDelta'](expr) - } - case Module['AtomicRMWId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenAtomicRMWGetOp'](expr), - 'bytes': Module['_BinaryenAtomicRMWGetBytes'](expr), - 'offset': Module['_BinaryenAtomicRMWGetOffset'](expr), - 'ptr': Module['_BinaryenAtomicRMWGetPtr'](expr), - 'value': Module['_BinaryenAtomicRMWGetValue'](expr) - }; - case Module['AtomicCmpxchgId']: - return { - 'id': id, - 'type': type, - 'bytes': Module['_BinaryenAtomicCmpxchgGetBytes'](expr), - 'offset': Module['_BinaryenAtomicCmpxchgGetOffset'](expr), - 'ptr': Module['_BinaryenAtomicCmpxchgGetPtr'](expr), - 'expected': Module['_BinaryenAtomicCmpxchgGetExpected'](expr), - 'replacement': Module['_BinaryenAtomicCmpxchgGetReplacement'](expr) - }; - case Module['AtomicWaitId']: - return { - 'id': id, - 'type': type, - 'ptr': Module['_BinaryenAtomicWaitGetPtr'](expr), - 'expected': Module['_BinaryenAtomicWaitGetExpected'](expr), - 'timeout': Module['_BinaryenAtomicWaitGetTimeout'](expr), - 'expectedType': Module['_BinaryenAtomicWaitGetExpectedType'](expr) - }; - case Module['AtomicNotifyId']: - return { - 'id': id, - 'type': type, - 'ptr': Module['_BinaryenAtomicNotifyGetPtr'](expr), - 'notifyCount': Module['_BinaryenAtomicNotifyGetNotifyCount'](expr) - }; - case Module['AtomicFenceId']: - return { - 'id': id, - 'type': type, - 'order': Module['_BinaryenAtomicFenceGetOrder'](expr) - }; - case Module['SIMDExtractId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenSIMDExtractGetOp'](expr), - 'vec': Module['_BinaryenSIMDExtractGetVec'](expr), - 'index': Module['_BinaryenSIMDExtractGetIndex'](expr) - }; - case Module['SIMDReplaceId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenSIMDReplaceGetOp'](expr), - 'vec': Module['_BinaryenSIMDReplaceGetVec'](expr), - 'index': Module['_BinaryenSIMDReplaceGetIndex'](expr), - 'value': Module['_BinaryenSIMDReplaceGetValue'](expr) - }; - case Module['SIMDShuffleId']: - return preserveStack(() => { - const tempBuffer = stackAlloc(16); - Module['_BinaryenSIMDShuffleGetMask'](expr, tempBuffer); - const mask = new Array(16); - for (let i = 0; i < 16; i++) { - mask[i] = HEAPU8[tempBuffer + i]; + break; + default: { + const staticMembers = Expression['wrappers'][id]; + Object.keys(staticMembers).forEach(memberName => { + const member = staticMembers[memberName]; + if (typeof member === "function") { + let match; + if (member.length === 1 && (match = memberName.match(/(^get|^(?=is|has))/))) { + const index = match[1].length; + const propertyName = memberName.charAt(index).toLowerCase() + memberName.substring(index + 1); + info[propertyName] = member(expr); + } } - return { - 'id': id, - 'type': type, - 'left': Module['_BinaryenSIMDShuffleGetLeft'](expr), - 'right': Module['_BinaryenSIMDShuffleGetRight'](expr), - 'mask': mask - }; }); - case Module['SIMDTernaryId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenSIMDTernaryGetOp'](expr), - 'a': Module['_BinaryenSIMDTernaryGetA'](expr), - 'b': Module['_BinaryenSIMDTernaryGetB'](expr), - 'c': Module['_BinaryenSIMDTernaryGetC'](expr) - }; - case Module['SIMDShiftId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenSIMDShiftGetOp'](expr), - 'vec': Module['_BinaryenSIMDShiftGetVec'](expr), - 'shift': Module['_BinaryenSIMDShiftGetShift'](expr) - }; - case Module['SIMDLoadId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenSIMDLoadGetOp'](expr), - 'offset': Module['_BinaryenSIMDLoadGetOffset'](expr), - 'align': Module['_BinaryenSIMDLoadGetAlign'](expr), - 'ptr': Module['_BinaryenSIMDLoadGetPtr'](expr) - }; - case Module['SIMDLoadStoreLaneId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenSIMDLoadStoreLaneGetOp'](expr), - 'offset': Module['_BinaryenSIMDLoadStoreLaneGetOffset'](expr), - 'align': Module['_BinaryenSIMDLoadStoreLaneGetAlign'](expr), - 'index': Module['_BinaryenSIMDLoadStoreLaneGetIndex'](expr), - 'ptr': Module['_BinaryenSIMDLoadStoreLaneGetPtr'](expr), - 'vec': Module['_BinaryenSIMDLoadStoreLaneGetVec'](expr), - 'isStore': Boolean(Module['_BinaryenSIMDLoadStoreLaneIsStore'](expr)) - }; - case Module['MemoryInitId']: - return { - 'id': id, - 'type': type, - 'segment': UTF8ToString(Module['_BinaryenMemoryInitGetSegment'](expr)), - 'dest': Module['_BinaryenMemoryInitGetDest'](expr), - 'offset': Module['_BinaryenMemoryInitGetOffset'](expr), - 'size': Module['_BinaryenMemoryInitGetSize'](expr) - }; - case Module['DataDropId']: - return { - 'id': id, - 'type': type, - 'segment': UTF8ToString(Module['_BinaryenDataDropGetSegment'](expr)), - }; - case Module['MemoryCopyId']: - return { - 'id': id, - 'type': type, - 'dest': Module['_BinaryenMemoryCopyGetDest'](expr), - 'source': Module['_BinaryenMemoryCopyGetSource'](expr), - 'size': Module['_BinaryenMemoryCopyGetSize'](expr) - }; - case Module['MemoryFillId']: - return { - 'id': id, - 'type': type, - 'dest': Module['_BinaryenMemoryFillGetDest'](expr), - 'value': Module['_BinaryenMemoryFillGetValue'](expr), - 'size': Module['_BinaryenMemoryFillGetSize'](expr) - }; - case Module['RefNullId']: - return { - 'id': id, - 'type': type - }; - case Module['RefIsNullId']: - return { - 'id': id, - 'type': type, - 'value': Module['_BinaryenRefIsNullGetValue'](expr) - }; - case Module['RefAsId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenRefAsGetOp'](expr), - 'value': Module['_BinaryenRefAsGetValue'](expr) - }; - case Module['RefFuncId']: - return { - 'id': id, - 'type': type, - 'func': UTF8ToString(Module['_BinaryenRefFuncGetFunc'](expr)), - }; - case Module['RefEqId']: - return { - 'id': id, - 'type': type, - 'left': Module['_BinaryenRefEqGetLeft'](expr), - 'right': Module['_BinaryenRefEqGetRight'](expr) - }; - case Module['RefTestId']: - return { - 'id': id, - 'type': type, - 'ref': Module['_BinaryenRefTestGetRef'](expr), - 'castType': Module['_BinaryenRefTestGetCastType'](expr) - }; - case Module['RefCastId']: - return { - 'id': id, - 'type': type, - 'ref': Module['_BinaryenRefCastGetRef'](expr) - }; - case Module['BrOnId']: - return { - 'id': id, - 'type': type, - 'op': Module['_BinaryenBrOnGetOp'](expr), - 'name': UTF8ToString(Module['_BinaryenBrOnGetName'](expr)), - 'ref': Module['_BinaryenBrOnGetRef'](expr), - 'castType': Module['_BinaryenBrOnGetCastType'](expr) - }; - case Module['StructNewId']: - return { - 'id': id, - 'type': type, - 'operands': getAllNested(expr, Module['_BinaryenStructNewGetNumOperands'], Module['_BinaryenStructNewGetOperandAt']), - }; - case Module['StructGetId']: - return { - 'id': id, - 'type': type, - 'index': Module['_BinaryenStructGetGetIndex'](expr), - 'ref': Module['_BinaryenStructGetGetRef'](expr), - 'isSigned': Boolean(Module['_BinaryenStructGetIsSigned'](expr)) - }; - case Module['StructSetId']: - return { - 'id': id, - 'type': type, - 'index': Module['_BinaryenStructSetGetIndex'](expr), - 'ref': Module['_BinaryenStructSetGetRef'](expr), - 'value': Module['_BinaryenStructSetGetValue'](expr) - }; - case Module['ArrayNewId']: - return { - 'id': id, - 'type': type, - 'init': Module['_BinaryenArrayNewGetInit'](expr), - 'size': Module['_BinaryenArrayNewGetSize'](expr) - }; - case Module['ArrayNewFixedId']: - return { - 'id': id, - 'type': type, - 'values': getAllNested(expr, Module['_BinaryenArrayNewFixedGetNumValues'], Module['_BinaryenArrayNewFixedGetValueAt']) - }; - case Module['ArrayNewDataId']: - return { - 'id': id, - 'type': type, - 'segment': UTF8ToString(Module['_BinaryenArrayNewDataGetSegment'](expr)), - 'offset': Module['_BinaryenArrayNewDataGetOffset'](expr), - 'size': Module['_BinaryenArrayNewDataGetSize'](expr) - }; - case Module['ArrayNewElemId']: - return { - 'id': id, - 'type': type, - 'segment': UTF8ToString(Module['_BinaryenArrayNewElemGetSegment'](expr)), - 'offset': Module['_BinaryenArrayNewElemGetOffset'](expr), - 'size': Module['_BinaryenArrayNewElemGetSize'](expr) - }; - case Module['ArrayGetId']: - return { - 'id': id, - 'type': type, - 'ref': Module['_BinaryenArrayGetGetRef'](expr), - 'index': Module['_BinaryenArrayGetGetIndex'](expr), - 'isSigned': Boolean(Module['_BinaryenArrayGetIsSigned'](expr)) - }; - case Module['ArraySetId']: - return { - 'id': id, - 'type': type, - 'ref': Module['_BinaryenArraySetGetRef'](expr), - 'index': Module['_BinaryenArraySetGetIndex'](expr), - 'value': Module['_BinaryenArraySetGetValue'](expr) - }; - case Module['ArrayLenId']: - return { - 'id': id, - 'type': type, - 'ref': Module['_BinaryenArrayLenGetRef'](expr) - }; - case Module['ArrayFillId']: - return { - 'id': id, - 'type': type, - 'ref': Module['_BinaryenArrayFillGetRef'](expr), - 'index': Module['_BinaryenArrayFillGetIndex'](expr), - 'value': Module['_BinaryenArrayFillGetValue'](expr), - 'size': Module['_BinaryenArrayFillGetSize'](expr) - }; - case Module['ArrayCopyId']: - return { - 'id': id, - 'type': type, - 'destRef': Module['_BinaryenArrayCopyGetDestRef'](expr), - 'destIndex': Module['_BinaryenArrayCopyGetDestIndex'](expr), - 'srcRef': Module['_BinaryenArrayCopyGetSrcRef'](expr), - 'srcIndex': Module['_BinaryenArrayCopyGetSrcIndex'](expr), - 'length': Module['_BinaryenArrayCopyGetLength'](expr) - }; - case Module['ArrayInitDataId']: - return { - 'id': id, - 'type': type, - 'segment': UTF8ToString(Module['_BinaryenArrayInitDataGetSegment'](expr)), - 'ref': Module['_BinaryenArrayInitDataGetRef'](expr), - 'index': Module['_BinaryenArrayInitDataGetIndex'](expr), - 'offset': Module['_BinaryenArrayInitDataGetOffset'](expr), - 'size': Module['_BinaryenArrayInitDataGetSize'](expr) - }; - case Module['ArrayInitElemId']: - return { - 'id': id, - 'type': type, - 'segment': UTF8ToString(Module['_BinaryenArrayInitElemGetSegment'](expr)), - 'ref': Module['_BinaryenArrayInitElemGetRef'](expr), - 'index': Module['_BinaryenArrayInitElemGetIndex'](expr), - 'offset': Module['_BinaryenArrayInitElemGetOffset'](expr), - 'size': Module['_BinaryenArrayInitElemGetSize'](expr) - }; - case Module['TryId']: { - const name = Module['_BinaryenTryGetName'](expr); - const delegateTarget = Module['_BinaryenTryGetDelegateTarget'](expr); - return { - 'id': id, - 'type': type, - 'name': name ? UTF8ToString(name) : null, - 'body': Module['_BinaryenTryGetBody'](expr), - 'catchTags': getAllNested(expr, Module['_BinaryenTryGetNumCatchTags'], Module['_BinaryenTryGetCatchTagAt']).map(p => UTF8ToString(p)), - 'catchBodies': getAllNested(expr, Module['_BinaryenTryGetNumCatchBodies'], Module['_BinaryenTryGetCatchBodyAt']), - 'hasCatchAll': Boolean(Module['_BinaryenTryHasCatchAll'](expr)), - 'delegateTarget': delegateTarget ? UTF8ToString(delegateTarget) : null, - 'isDelegate': Boolean(Module['_BinaryenTryIsDelegate'](expr)) - }; + break; } - case Module['ThrowId']: - return { - 'id': id, - 'type': type, - 'tag': UTF8ToString(Module['_BinaryenThrowGetTag'](expr)), - 'operands': getAllNested(expr, Module['_BinaryenThrowGetNumOperands'], Module['_BinaryenThrowGetOperandAt']) - }; - case Module['RethrowId']: - return { - 'id': id, - 'type': type, - 'target': UTF8ToString(Module['_BinaryenRethrowGetTarget'](expr)) - }; - case Module['TupleMakeId']: - return { - 'id': id, - 'type': type, - 'operands': getAllNested(expr, Module['_BinaryenTupleMakeGetNumOperands'], Module['_BinaryenTupleMakeGetOperandAt']) - }; - case Module['TupleExtractId']: - return { - 'id': id, - 'type': type, - 'tuple': Module['_BinaryenTupleExtractGetTuple'](expr), - 'index': Module['_BinaryenTupleExtractGetIndex'](expr) - }; - case Module['RefI31Id']: - return { - 'id': id, - 'type': type, - 'value': Module['_BinaryenRefI31GetValue'](expr) - }; - case Module['I31GetId']: - return { - 'id': id, - 'type': type, - 'i31': Module['_BinaryenI31GetGetI31'](expr), - 'isSigned': Boolean(Module['_BinaryenI31GetIsSigned'](expr)) - }; - - default: - throw Error('unexpected id: ' + id); } + return info; +}; + +// Creates an expression wrapper from an expression pointer +Module['wrapExpression'] = function(expr) { + const id = Module['_BinaryenExpressionGetId'](expr); + return Expression['wrappers'][id](expr); }; // Gets the side effects of the specified expression @@ -3984,7 +3438,7 @@ const thisPtr = Symbol(); // Makes a specific expression wrapper class with the specified static members // while automatically deriving instance methods and accessors. -function makeExpressionWrapper(ownStaticMembers) { +function makeExpressionWrapper(expressionId, ownStaticMembers) { /** * @constructor * @extends Expression @@ -4005,6 +3459,8 @@ function makeExpressionWrapper(ownStaticMembers) { (SpecificExpression.prototype = Object.create(Expression.prototype)).constructor = SpecificExpression; // derive own instance members deriveWrapperInstanceMembers(SpecificExpression.prototype, ownStaticMembers); + // register the expression wrapper + Expression['wrappers'][expressionId] = SpecificExpression; return SpecificExpression; } @@ -4055,6 +3511,7 @@ function Expression(expr) { if (!expr) throw Error("expression reference must not be null"); this[thisPtr] = expr; } +Expression['wrappers'] = {}; Expression['getId'] = function(expr) { return Module['_BinaryenExpressionGetId'](expr); }; @@ -4077,7 +3534,7 @@ Expression.prototype['valueOf'] = function() { Module['Expression'] = Expression; -Module['Block'] = makeExpressionWrapper({ +Module['Block'] = makeExpressionWrapper(Module['_BinaryenBlockId'](), { 'getName'(expr) { const name = Module['_BinaryenBlockGetName'](expr); return name ? UTF8ToString(name) : null; @@ -4111,7 +3568,7 @@ Module['Block'] = makeExpressionWrapper({ } }); -Module['If'] = makeExpressionWrapper({ +Module['If'] = makeExpressionWrapper(Module['_BinaryenIfId'](), { 'getCondition'(expr) { return Module['_BinaryenIfGetCondition'](expr); }, @@ -4132,7 +3589,7 @@ Module['If'] = makeExpressionWrapper({ } }); -Module['Loop'] = makeExpressionWrapper({ +Module['Loop'] = makeExpressionWrapper(Module['_BinaryenLoopId'](), { 'getName'(expr) { const name = Module['_BinaryenLoopGetName'](expr); return name ? UTF8ToString(name) : null; @@ -4148,7 +3605,7 @@ Module['Loop'] = makeExpressionWrapper({ } }); -Module['Break'] = makeExpressionWrapper({ +Module['Break'] = makeExpressionWrapper(Module['_BinaryenBreakId'](), { 'getName'(expr) { const name = Module['_BinaryenBreakGetName'](expr); return name ? UTF8ToString(name) : null; @@ -4170,7 +3627,7 @@ Module['Break'] = makeExpressionWrapper({ } }); -Module['Switch'] = makeExpressionWrapper({ +Module['Switch'] = makeExpressionWrapper(Module['_BinaryenSwitchId'](), { 'getNumNames'(expr) { return Module['_BinaryenSwitchGetNumNames'](expr); }, @@ -4218,7 +3675,7 @@ Module['Switch'] = makeExpressionWrapper({ }, }); -Module['Call'] = makeExpressionWrapper({ +Module['Call'] = makeExpressionWrapper(Module['_BinaryenCallId'](), { 'getTarget'(expr) { return UTF8ToString(Module['_BinaryenCallGetTarget'](expr)); }, @@ -4257,7 +3714,7 @@ Module['Call'] = makeExpressionWrapper({ } }); -Module['CallIndirect'] = makeExpressionWrapper({ +Module['CallIndirect'] = makeExpressionWrapper(Module['_BinaryenCallIndirectId'](), { 'getTarget'(expr) { return Module['_BinaryenCallIndirectGetTarget'](expr); }, @@ -4314,7 +3771,7 @@ Module['CallIndirect'] = makeExpressionWrapper({ } }); -Module['LocalGet'] = makeExpressionWrapper({ +Module['LocalGet'] = makeExpressionWrapper(Module['_BinaryenLocalGetId'](), { 'getIndex'(expr) { return Module['_BinaryenLocalGetGetIndex'](expr); }, @@ -4323,7 +3780,7 @@ Module['LocalGet'] = makeExpressionWrapper({ } }); -Module['LocalSet'] = makeExpressionWrapper({ +Module['LocalSet'] = makeExpressionWrapper(Module['_BinaryenLocalSetId'](), { 'getIndex'(expr) { return Module['_BinaryenLocalSetGetIndex'](expr); }, @@ -4341,7 +3798,7 @@ Module['LocalSet'] = makeExpressionWrapper({ } }); -Module['GlobalGet'] = makeExpressionWrapper({ +Module['GlobalGet'] = makeExpressionWrapper(Module['_BinaryenGlobalGetId'](), { 'getName'(expr) { return UTF8ToString(Module['_BinaryenGlobalGetGetName'](expr)); }, @@ -4350,7 +3807,7 @@ Module['GlobalGet'] = makeExpressionWrapper({ } }); -Module['GlobalSet'] = makeExpressionWrapper({ +Module['GlobalSet'] = makeExpressionWrapper(Module['_BinaryenGlobalSetId'](), { 'getName'(expr) { return UTF8ToString(Module['_BinaryenGlobalSetGetName'](expr)); }, @@ -4365,7 +3822,7 @@ Module['GlobalSet'] = makeExpressionWrapper({ } }); -Module['TableGet'] = makeExpressionWrapper({ +Module['TableGet'] = makeExpressionWrapper(Module['_BinaryenTableGetId'](), { 'getTable'(expr) { return UTF8ToString(Module['_BinaryenTableGetGetTable'](expr)); }, @@ -4380,7 +3837,7 @@ Module['TableGet'] = makeExpressionWrapper({ } }); -Module['TableSet'] = makeExpressionWrapper({ +Module['TableSet'] = makeExpressionWrapper(Module['_BinaryenTableSetId'](), { 'getTable'(expr) { return UTF8ToString(Module['_BinaryenTableSetGetTable'](expr)); }, @@ -4401,7 +3858,7 @@ Module['TableSet'] = makeExpressionWrapper({ } }); -Module['TableSize'] = makeExpressionWrapper({ +Module['TableSize'] = makeExpressionWrapper(Module['_BinaryenTableSizeId'](), { 'getTable'(expr) { return UTF8ToString(Module['_BinaryenTableSizeGetTable'](expr)); }, @@ -4410,7 +3867,7 @@ Module['TableSize'] = makeExpressionWrapper({ }, }); -Module['TableGrow'] = makeExpressionWrapper({ +Module['TableGrow'] = makeExpressionWrapper(Module['_BinaryenTableGrowId'](), { 'getTable'(expr) { return UTF8ToString(Module['_BinaryenTableGrowGetTable'](expr)); }, @@ -4431,9 +3888,9 @@ Module['TableGrow'] = makeExpressionWrapper({ } }); -Module['MemorySize'] = makeExpressionWrapper({}); +Module['MemorySize'] = makeExpressionWrapper(Module['_BinaryenMemorySizeId'](), {}); -Module['MemoryGrow'] = makeExpressionWrapper({ +Module['MemoryGrow'] = makeExpressionWrapper(Module['_BinaryenMemoryGrowId'](), { 'getDelta'(expr) { return Module['_BinaryenMemoryGrowGetDelta'](expr); }, @@ -4442,7 +3899,7 @@ Module['MemoryGrow'] = makeExpressionWrapper({ } }); -Module['Load'] = makeExpressionWrapper({ +Module['Load'] = makeExpressionWrapper(Module['_BinaryenLoadId'](), { 'isAtomic'(expr) { return Boolean(Module['_BinaryenLoadIsAtomic'](expr)); }, @@ -4481,7 +3938,7 @@ Module['Load'] = makeExpressionWrapper({ } }); -Module['Store'] = makeExpressionWrapper({ +Module['Store'] = makeExpressionWrapper(Module['_BinaryenStoreId'](), { 'isAtomic'(expr) { return Boolean(Module['_BinaryenStoreIsAtomic'](expr)); }, @@ -4526,7 +3983,7 @@ Module['Store'] = makeExpressionWrapper({ } }); -Module['Const'] = makeExpressionWrapper({ +Module['Const'] = makeExpressionWrapper(Module['_BinaryenConstId'](), { 'getValueI32'(expr) { return Module['_BinaryenConstGetValueI32'](expr); }, @@ -4580,7 +4037,7 @@ Module['Const'] = makeExpressionWrapper({ } }); -Module['Unary'] = makeExpressionWrapper({ +Module['Unary'] = makeExpressionWrapper(Module['_BinaryenUnaryId'](), { 'getOp'(expr) { return Module['_BinaryenUnaryGetOp'](expr); }, @@ -4595,7 +4052,7 @@ Module['Unary'] = makeExpressionWrapper({ } }); -Module['Binary'] = makeExpressionWrapper({ +Module['Binary'] = makeExpressionWrapper(Module['_BinaryenBinaryId'](), { 'getOp'(expr) { return Module['_BinaryenBinaryGetOp'](expr); }, @@ -4616,7 +4073,7 @@ Module['Binary'] = makeExpressionWrapper({ } }); -Module['Select'] = makeExpressionWrapper({ +Module['Select'] = makeExpressionWrapper(Module['_BinaryenSelectId'](), { 'getIfTrue'(expr) { return Module['_BinaryenSelectGetIfTrue'](expr); }, @@ -4637,7 +4094,7 @@ Module['Select'] = makeExpressionWrapper({ } }); -Module['Drop'] = makeExpressionWrapper({ +Module['Drop'] = makeExpressionWrapper(Module['_BinaryenDropId'](), { 'getValue'(expr) { return Module['_BinaryenDropGetValue'](expr); }, @@ -4646,7 +4103,7 @@ Module['Drop'] = makeExpressionWrapper({ } }); -Module['Return'] = makeExpressionWrapper({ +Module['Return'] = makeExpressionWrapper(Module['_BinaryenReturnId'](), { 'getValue'(expr) { return Module['_BinaryenReturnGetValue'](expr); }, @@ -4655,7 +4112,7 @@ Module['Return'] = makeExpressionWrapper({ } }); -Module['AtomicRMW'] = makeExpressionWrapper({ +Module['AtomicRMW'] = makeExpressionWrapper(Module['_BinaryenAtomicRMWId'](), { 'getOp'(expr) { return Module['_BinaryenAtomicRMWGetOp'](expr); }, @@ -4688,7 +4145,7 @@ Module['AtomicRMW'] = makeExpressionWrapper({ } }); -Module['AtomicCmpxchg'] = makeExpressionWrapper({ +Module['AtomicCmpxchg'] = makeExpressionWrapper(Module['_BinaryenAtomicCmpxchgId'](), { 'getBytes'(expr) { return Module['_BinaryenAtomicCmpxchgGetBytes'](expr); }, @@ -4721,7 +4178,7 @@ Module['AtomicCmpxchg'] = makeExpressionWrapper({ } }); -Module['AtomicWait'] = makeExpressionWrapper({ +Module['AtomicWait'] = makeExpressionWrapper(Module['_BinaryenAtomicWaitId'](), { 'getPtr'(expr) { return Module['_BinaryenAtomicWaitGetPtr'](expr); }, @@ -4748,7 +4205,7 @@ Module['AtomicWait'] = makeExpressionWrapper({ } }); -Module['AtomicNotify'] = makeExpressionWrapper({ +Module['AtomicNotify'] = makeExpressionWrapper(Module['_BinaryenAtomicNotifyId'](), { 'getPtr'(expr) { return Module['_BinaryenAtomicNotifyGetPtr'](expr); }, @@ -4763,7 +4220,7 @@ Module['AtomicNotify'] = makeExpressionWrapper({ } }); -Module['AtomicFence'] = makeExpressionWrapper({ +Module['AtomicFence'] = makeExpressionWrapper(Module['_BinaryenAtomicFenceId'](), { 'getOrder'(expr) { return Module['_BinaryenAtomicFenceGetOrder'](expr); }, @@ -4772,7 +4229,7 @@ Module['AtomicFence'] = makeExpressionWrapper({ } }); -Module['SIMDExtract'] = makeExpressionWrapper({ +Module['SIMDExtract'] = makeExpressionWrapper(Module['_BinaryenSIMDExtractId'](), { 'getOp'(expr) { return Module['_BinaryenSIMDExtractGetOp'](expr); }, @@ -4793,7 +4250,7 @@ Module['SIMDExtract'] = makeExpressionWrapper({ } }); -Module['SIMDReplace'] = makeExpressionWrapper({ +Module['SIMDReplace'] = makeExpressionWrapper(Module['_BinaryenSIMDReplaceId'](), { 'getOp'(expr) { return Module['_BinaryenSIMDReplaceGetOp'](expr); }, @@ -4820,7 +4277,7 @@ Module['SIMDReplace'] = makeExpressionWrapper({ } }); -Module['SIMDShuffle'] = makeExpressionWrapper({ +Module['SIMDShuffle'] = makeExpressionWrapper(Module['_BinaryenSIMDShuffleId'](), { 'getLeft'(expr) { return Module['_BinaryenSIMDShuffleGetLeft'](expr); }, @@ -4856,7 +4313,7 @@ Module['SIMDShuffle'] = makeExpressionWrapper({ } }); -Module['SIMDTernary'] = makeExpressionWrapper({ +Module['SIMDTernary'] = makeExpressionWrapper(Module['_BinaryenSIMDTernaryId'](), { 'getOp'(expr) { return Module['_BinaryenSIMDTernaryGetOp'](expr); }, @@ -4883,7 +4340,7 @@ Module['SIMDTernary'] = makeExpressionWrapper({ } }); -Module['SIMDShift'] = makeExpressionWrapper({ +Module['SIMDShift'] = makeExpressionWrapper(Module['_BinaryenSIMDShiftId'](), { 'getOp'(expr) { return Module['_BinaryenSIMDShiftGetOp'](expr); }, @@ -4904,7 +4361,7 @@ Module['SIMDShift'] = makeExpressionWrapper({ } }); -Module['SIMDLoad'] = makeExpressionWrapper({ +Module['SIMDLoad'] = makeExpressionWrapper(Module['_BinaryenSIMDLoadId'](), { 'getOp'(expr) { return Module['_BinaryenSIMDLoadGetOp'](expr); }, @@ -4931,7 +4388,7 @@ Module['SIMDLoad'] = makeExpressionWrapper({ } }); -Module['SIMDLoadStoreLane'] = makeExpressionWrapper({ +Module['SIMDLoadStoreLane'] = makeExpressionWrapper(Module['_BinaryenSIMDLoadStoreLaneId'](), { 'getOp'(expr) { return Module['_BinaryenSIMDLoadStoreLaneGetOp'](expr); }, @@ -4973,7 +4430,7 @@ Module['SIMDLoadStoreLane'] = makeExpressionWrapper({ } }); -Module['MemoryInit'] = makeExpressionWrapper({ +Module['MemoryInit'] = makeExpressionWrapper(Module['_BinaryenMemoryInitId'](), { 'getSegment'(expr) { return UTF8ToString(Module['_BinaryenMemoryInitGetSegment'](expr)); }, @@ -5000,7 +4457,7 @@ Module['MemoryInit'] = makeExpressionWrapper({ } }); -Module['DataDrop'] = makeExpressionWrapper({ +Module['DataDrop'] = makeExpressionWrapper(Module['_BinaryenDataDropId'](), { 'getSegment'(expr) { return UTF8ToString(Module['_BinaryenDataDropGetSegment'](expr)); }, @@ -5009,7 +4466,7 @@ Module['DataDrop'] = makeExpressionWrapper({ } }); -Module['MemoryCopy'] = makeExpressionWrapper({ +Module['MemoryCopy'] = makeExpressionWrapper(Module['_BinaryenMemoryCopyId'](), { 'getDest'(expr) { return Module['_BinaryenMemoryCopyGetDest'](expr); }, @@ -5030,7 +4487,7 @@ Module['MemoryCopy'] = makeExpressionWrapper({ } }); -Module['MemoryFill'] = makeExpressionWrapper({ +Module['MemoryFill'] = makeExpressionWrapper(Module['_BinaryenMemoryFillId'](), { 'getDest'(expr) { return Module['_BinaryenMemoryFillGetDest'](expr); }, @@ -5051,7 +4508,7 @@ Module['MemoryFill'] = makeExpressionWrapper({ } }); -Module['RefIsNull'] = makeExpressionWrapper({ +Module['RefIsNull'] = makeExpressionWrapper(Module['_BinaryenRefIsNullId'](), { 'getValue'(expr) { return Module['_BinaryenRefIsNullGetValue'](expr); }, @@ -5060,7 +4517,7 @@ Module['RefIsNull'] = makeExpressionWrapper({ } }); -Module['RefAs'] = makeExpressionWrapper({ +Module['RefAs'] = makeExpressionWrapper(Module['_BinaryenRefAsId'](), { 'getOp'(expr) { return Module['_BinaryenRefAsGetOp'](expr); }, @@ -5075,7 +4532,7 @@ Module['RefAs'] = makeExpressionWrapper({ } }); -Module['RefFunc'] = makeExpressionWrapper({ +Module['RefFunc'] = makeExpressionWrapper(Module['_BinaryenRefFuncId'](), { 'getFunc'(expr) { return UTF8ToString(Module['_BinaryenRefFuncGetFunc'](expr)); }, @@ -5084,7 +4541,7 @@ Module['RefFunc'] = makeExpressionWrapper({ } }); -Module['RefEq'] = makeExpressionWrapper({ +Module['RefEq'] = makeExpressionWrapper(Module['_BinaryenRefEqId'](), { 'getLeft'(expr) { return Module['_BinaryenRefEqGetLeft'](expr); }, @@ -5099,7 +4556,7 @@ Module['RefEq'] = makeExpressionWrapper({ } }); -Module['RefTest'] = makeExpressionWrapper({ +Module['RefTest'] = makeExpressionWrapper(Module['_BinaryenRefTestId'](), { 'getRef'(expr) { return Module['_BinaryenRefTestGetRef'](expr); }, @@ -5114,7 +4571,7 @@ Module['RefTest'] = makeExpressionWrapper({ } }); -Module['RefCast'] = makeExpressionWrapper({ +Module['RefCast'] = makeExpressionWrapper(Module['_BinaryenRefCastId'](), { 'getRef'(expr) { return Module['_BinaryenRefCastGetRef'](expr); }, @@ -5126,7 +4583,7 @@ Module['RefCast'] = makeExpressionWrapper({ // TODO: any.convert_extern // TODO: extern.convert_any -Module['BrOn'] = makeExpressionWrapper({ +Module['BrOn'] = makeExpressionWrapper(Module['_BinaryenBrOnId'](), { 'getOp'(expr) { return Module['_BinaryenBrOnGetOp'](expr); }, @@ -5153,7 +4610,7 @@ Module['BrOn'] = makeExpressionWrapper({ } }); -Module['StructNew'] = makeExpressionWrapper({ +Module['StructNew'] = makeExpressionWrapper(Module['_BinaryenStructNewId'](), { 'getNumOperands'(expr) { return Module['_BinaryenStructNewGetNumOperands'](expr); }, @@ -5187,7 +4644,7 @@ Module['StructNew'] = makeExpressionWrapper({ } }); -Module['StructGet'] = makeExpressionWrapper({ +Module['StructGet'] = makeExpressionWrapper(Module['_BinaryenStructGetId'](), { 'getIndex'(expr) { return Module['_BinaryenStructGetGetIndex'](expr); }, @@ -5208,7 +4665,7 @@ Module['StructGet'] = makeExpressionWrapper({ } }); -Module['StructSet'] = makeExpressionWrapper({ +Module['StructSet'] = makeExpressionWrapper(Module['_BinaryenStructSetId'](), { 'getIndex'(expr) { return Module['_BinaryenStructSetGetIndex'](expr); }, @@ -5229,7 +4686,7 @@ Module['StructSet'] = makeExpressionWrapper({ } }); -Module['ArrayNew'] = makeExpressionWrapper({ +Module['ArrayNew'] = makeExpressionWrapper(Module['_BinaryenArrayNewId'](), { 'getInit'(expr) { return Module['_BinaryenArrayNewGetInit'](expr); }, @@ -5244,7 +4701,7 @@ Module['ArrayNew'] = makeExpressionWrapper({ } }); -Module['ArrayNewFixed'] = makeExpressionWrapper({ +Module['ArrayNewFixed'] = makeExpressionWrapper(Module['_BinaryenArrayNewFixedId'](), { 'getNumValues'(expr) { return Module['_BinaryenArrayNewFixedGetNumValues'](expr); }, @@ -5280,7 +4737,7 @@ Module['ArrayNewFixed'] = makeExpressionWrapper({ } }); -Module['ArrayNewData'] = makeExpressionWrapper({ +Module['ArrayNewData'] = makeExpressionWrapper(Module['_BinaryenArrayNewDataId'](), { 'getSegment'(expr) { return UTF8ToString(Module['_BinaryenArrayNewDataGetSegment'](expr)); }, @@ -5301,7 +4758,7 @@ Module['ArrayNewData'] = makeExpressionWrapper({ } }); -Module['ArrayNewElem'] = makeExpressionWrapper({ +Module['ArrayNewElem'] = makeExpressionWrapper(Module['_BinaryenArrayNewElemId'](), { 'getSegment'(expr) { return UTF8ToString(Module['_BinaryenArrayNewElemGetSegment'](expr)); }, @@ -5322,7 +4779,7 @@ Module['ArrayNewElem'] = makeExpressionWrapper({ } }); -Module['ArrayGet'] = makeExpressionWrapper({ +Module['ArrayGet'] = makeExpressionWrapper(Module['_BinaryenArrayGetId'](), { 'getRef'(expr) { return Module['_BinaryenArrayGetGetRef'](expr); }, @@ -5343,7 +4800,7 @@ Module['ArrayGet'] = makeExpressionWrapper({ } }); -Module['ArraySet'] = makeExpressionWrapper({ +Module['ArraySet'] = makeExpressionWrapper(Module['_BinaryenArraySetId'](), { 'getRef'(expr) { return Module['_BinaryenArraySetGetRef'](expr); }, @@ -5364,7 +4821,7 @@ Module['ArraySet'] = makeExpressionWrapper({ } }); -Module['ArrayLen'] = makeExpressionWrapper({ +Module['ArrayLen'] = makeExpressionWrapper(Module['_BinaryenArrayLenId'](), { 'getRef'(expr) { return Module['_BinaryenArrayLenGetRef'](expr); }, @@ -5373,7 +4830,7 @@ Module['ArrayLen'] = makeExpressionWrapper({ } }); -Module['ArrayFill'] = makeExpressionWrapper({ +Module['ArrayFill'] = makeExpressionWrapper(Module['_BinaryenArrayFillId'](), { 'getRef'(expr) { return Module['_BinaryenArrayFillGetRef'](expr); }, @@ -5400,7 +4857,7 @@ Module['ArrayFill'] = makeExpressionWrapper({ } }); -Module['ArrayCopy'] = makeExpressionWrapper({ +Module['ArrayCopy'] = makeExpressionWrapper(Module['_BinaryenArrayCopyId'](), { 'getDestRef'(expr) { return Module['_BinaryenArrayCopyGetDestRef'](expr); }, @@ -5433,7 +4890,7 @@ Module['ArrayCopy'] = makeExpressionWrapper({ } }); -Module['ArrayInitData'] = makeExpressionWrapper({ +Module['ArrayInitData'] = makeExpressionWrapper(Module['_BinaryenArrayInitDataId'](), { 'getSegment'(expr) { return UTF8ToString(Module['_BinaryenArrayInitDataGetSegment'](expr)); }, @@ -5466,7 +4923,7 @@ Module['ArrayInitData'] = makeExpressionWrapper({ } }); -Module['ArrayInitElem'] = makeExpressionWrapper({ +Module['ArrayInitElem'] = makeExpressionWrapper(Module['_BinaryenArrayInitElemId'](), { 'getSegment'(expr) { return UTF8ToString(Module['_BinaryenArrayInitElemGetSegment'](expr)); }, @@ -5499,7 +4956,7 @@ Module['ArrayInitElem'] = makeExpressionWrapper({ } }); -Module['Try'] = makeExpressionWrapper({ +Module['Try'] = makeExpressionWrapper(Module['_BinaryenTryId'](), { 'getName'(expr) { const name = Module['_BinaryenTryGetName'](expr); return name ? UTF8ToString(name) : null; @@ -5578,7 +5035,7 @@ Module['Try'] = makeExpressionWrapper({ } }); -Module['Throw'] = makeExpressionWrapper({ +Module['Throw'] = makeExpressionWrapper(Module['_BinaryenThrowId'](), { 'getTag'(expr) { return UTF8ToString(Module['_BinaryenThrowGetTag'](expr)); }, @@ -5611,7 +5068,7 @@ Module['Throw'] = makeExpressionWrapper({ }, }); -Module['Rethrow'] = makeExpressionWrapper({ +Module['Rethrow'] = makeExpressionWrapper(Module['_BinaryenRethrowId'](), { 'getTarget'(expr) { const target = Module['_BinaryenRethrowGetTarget'](expr); return target ? UTF8ToString(target) : null; @@ -5621,7 +5078,7 @@ Module['Rethrow'] = makeExpressionWrapper({ } }); -Module['TupleMake'] = makeExpressionWrapper({ +Module['TupleMake'] = makeExpressionWrapper(Module['_BinaryenTupleMakeId'](), { 'getNumOperands'(expr) { return Module['_BinaryenTupleMakeGetNumOperands'](expr); }, @@ -5648,7 +5105,7 @@ Module['TupleMake'] = makeExpressionWrapper({ } }); -Module['TupleExtract'] = makeExpressionWrapper({ +Module['TupleExtract'] = makeExpressionWrapper(Module['_BinaryenTupleExtractId'](), { 'getTuple'(expr) { return Module['_BinaryenTupleExtractGetTuple'](expr); }, @@ -5663,7 +5120,7 @@ Module['TupleExtract'] = makeExpressionWrapper({ } }); -Module['RefI31'] = makeExpressionWrapper({ +Module['RefI31'] = makeExpressionWrapper(Module['_BinaryenRefI31Id'](), { 'getValue'(expr) { return Module['_BinaryenRefI31GetValue'](expr); }, @@ -5672,7 +5129,7 @@ Module['RefI31'] = makeExpressionWrapper({ } }); -Module['I31Get'] = makeExpressionWrapper({ +Module['I31Get'] = makeExpressionWrapper(Module['_BinaryenI31GetId'](), { 'getI31'(expr) { return Module['_BinaryenI31GetGetI31'](expr); }, diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index bee1d298937..be7a06f7ad8 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -2821,4 +2821,4 @@ sizeof Literal: 24 ) getExpressionInfo(memory.grow)={"id":21,"type":2,"delta":1} -getExpressionInfo(switch)={"id":5,"type":1,"names":["label"],"defaultName":"label","condition":0,"value":0} +getExpressionInfo(switch)={"id":5,"type":1,"numNames":1,"names":["label"],"defaultName":"label","condition":0,"value":0} From 96cf475a03f2298fb5483c967d04bcc0f728f878 Mon Sep 17 00:00:00 2001 From: GulgDev Date: Sat, 19 Apr 2025 15:10:42 +0500 Subject: [PATCH 5/6] Internalize expression wrapper map --- src/js/binaryen.js-post.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index c6e7d64b8a4..e3860e95fd0 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3084,7 +3084,7 @@ Module['getExpressionInfo'] = function(expr) { } break; default: { - const staticMembers = Expression['wrappers'][id]; + const staticMembers = expressionWrappers[id]; Object.keys(staticMembers).forEach(memberName => { const member = staticMembers[memberName]; if (typeof member === "function") { @@ -3105,7 +3105,7 @@ Module['getExpressionInfo'] = function(expr) { // Creates an expression wrapper from an expression pointer Module['wrapExpression'] = function(expr) { const id = Module['_BinaryenExpressionGetId'](expr); - return Expression['wrappers'][id](expr); + return expressionWrappers[id](expr); }; // Gets the side effects of the specified expression @@ -3433,6 +3433,9 @@ Module['setAllowInliningFunctionsWithLoops'] = function(value) { // Expression wrappers +// Expression ID-to-wrapper map +let expressionWrappers = {}; + // Private symbol used to store the underlying C-API pointer of a wrapped object. const thisPtr = Symbol(); @@ -3460,7 +3463,7 @@ function makeExpressionWrapper(expressionId, ownStaticMembers) { // derive own instance members deriveWrapperInstanceMembers(SpecificExpression.prototype, ownStaticMembers); // register the expression wrapper - Expression['wrappers'][expressionId] = SpecificExpression; + expressionWrappers[expressionId] = SpecificExpression; return SpecificExpression; } @@ -3511,7 +3514,6 @@ function Expression(expr) { if (!expr) throw Error("expression reference must not be null"); this[thisPtr] = expr; } -Expression['wrappers'] = {}; Expression['getId'] = function(expr) { return Module['_BinaryenExpressionGetId'](expr); }; From 313bed74b1183fa0dc53d2302708bd807099f4e9 Mon Sep 17 00:00:00 2001 From: GulgDev Date: Wed, 23 Apr 2025 17:12:32 +0500 Subject: [PATCH 6/6] Modify Expression constructor to return specific expression wrappers --- src/js/binaryen.js-post.js | 12 ++++++------ test/binaryen.js/expressions.js | 10 ++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index e3860e95fd0..1743c97388e 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3102,12 +3102,6 @@ Module['getExpressionInfo'] = function(expr) { return info; }; -// Creates an expression wrapper from an expression pointer -Module['wrapExpression'] = function(expr) { - const id = Module['_BinaryenExpressionGetId'](expr); - return expressionWrappers[id](expr); -}; - // Gets the side effects of the specified expression Module['getSideEffects'] = function(expr, module) { assert(module); // guard against incorrect old API usage: a module must be @@ -3511,6 +3505,12 @@ function deriveWrapperInstanceMembers(prototype, staticMembers) { // Base class of all expression wrappers /** @constructor */ function Expression(expr) { + // Returns the specific wrapper if called without `new` + if (!(this instanceof Expression)) { + if (!expr) return null; + const id = Module['_BinaryenExpressionGetId'](expr); + return expressionWrappers[id](expr); + } if (!expr) throw Error("expression reference must not be null"); this[thisPtr] = expr; } diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index 3cbe7e59448..f249f95493c 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -9,7 +9,11 @@ function assertDeepEqual(x, y) { console.log("# Expression"); (function testWrapper() { - var theExpression = binaryen.Block(42); // works without new + const module = new binaryen.Module(); + + const ptr = module.block(null, []); + + var theExpression = binaryen.Expression(ptr); // works without new assert(theExpression instanceof binaryen.Block); assert(theExpression instanceof binaryen.Expression); assert(theExpression.constructor === binaryen.Block); @@ -17,7 +21,9 @@ console.log("# Expression"); assert(typeof binaryen.Block.getName === "function"); // own assert(typeof theExpression.getId === "function"); // proto assert(typeof theExpression.getName === "function"); // own - assert((theExpression | 0) === 42); // via valueOf + assert((theExpression | 0) === ptr); // via valueOf + + module.dispose(); })(); console.log("# Block");