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

Function TestForeignFunctions

deps/v8/test/mjsunit/wasm/asm-wasm-imports.js:21–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19
20
21function TestForeignFunctions() {
22 function AsmModule(stdlib, foreign, buffer) {
23 "use asm";
24
25 var setVal = foreign.setVal;
26 var getVal = foreign.getVal;
27
28 function caller(initial_value, new_value) {
29 initial_value = initial_value|0;
30 new_value = new_value|0;
31 if ((getVal()|0) == (initial_value|0)) {
32 setVal(new_value|0);
33 return getVal()|0;
34 }
35 return 0;
36 }
37
38 return {caller:caller};
39 }
40
41 function ffi(initial_val) {
42 var val = initial_val;
43
44 function getVal() {
45 return val;
46 }
47
48 function setVal(new_val) {
49 val = new_val;
50 }
51
52 return {getVal:getVal, setVal:setVal};
53 }
54
55 var foreign = new ffi(23);
56
57 var module = AsmModule({Math: Math}, foreign, null);
58 assertValidAsm(AsmModule);
59
60 assertEquals(103, module.caller(23, 103));
61}
62
63print("TestForeignFunctions...");
64TestForeignFunctions();

Callers 1

Calls 3

AsmModuleFunction · 0.70
assertValidAsmFunction · 0.70
assertEqualsFunction · 0.50

Tested by

no test coverage detected