MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / main

Function main

test/core/test_getValue_setValue.cpp:9–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <stdint.h>
8
9int main() {
10 char buffer_char[8] = { 'x' };
11 int buffer_ptr[] = { 0x12345678, 0x77665544 };
12 EM_ASM({
13#ifdef DIRECT
14 out('i32: ' + getValue($0, 'i32'));
15 setValue($0, 1234, 'i32');
16 out('i32: ' + getValue($0, 'i32'));
17#ifdef WASM_BIGINT
18 var i64 = getValue($1, 'i64');
19 out('i64: 0x' + i64.toString(16) + ' ' + typeof(i64));
20#endif
21 var ptr = getValue($1, '*');
22 out('ptr: 0x' + ptr.toString(16) + ' ' + typeof(ptr));
23#else
24 out('i32: ' + getValue($0, 'i32'));
25 Module['setValue']($0, 1234, 'i32');
26 out('i32: ' + Module['getValue']($0, 'i32'));
27#ifdef WASM_BIGINT
28 var i64 = Module['getValue']($1, 'i64');
29 out('i64: 0x' + i64.toString(16) + ' ' + typeof(i64));
30#endif
31 var ptr = Module['getValue']($1, '*');
32 out('ptr: 0x' + ptr.toString(16) + ' ' + typeof(ptr));
33#endif
34
35 /* In ASSERTIONS=2 mode we check the limits of input values */
36 var min = $2;
37 var max = $3;
38 setValue($1, max, 'i8');
39 setValue($1, min, 'i8');
40#ifdef ASSERTIONS_2
41 function checkAsserts(f, expected) {
42 try {
43 f();
44 } catch(e) {
45 assert(e.message.includes(expected), "expected assertion to include:" + expected);
46 return;
47 }
48 assert(false, "expected assertion");
49 }
50 checkAsserts(() => setValue($1, max + 1, 'i8'), "value (256) too large to write as 8-bit value");
51 checkAsserts(() => setValue($1, min - 1, 'i8'), "value (-129) too small to write as 8-bit value");
52#else
53 setValue($1, max + 1, 'i8');
54 setValue($1, min - 1, 'i8');
55#endif
56 }, buffer_char, buffer_ptr, INT8_MIN, UINT8_MAX);
57}
58

Callers

nothing calls this directly

Calls 6

setValueFunction · 0.85
typeofFunction · 0.85
checkAssertsFunction · 0.85
EM_ASMFunction · 0.50
outFunction · 0.50
getValueFunction · 0.50

Tested by

no test coverage detected