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

Function main

test/embind/test_i64_binding.cpp:40–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38extern "C" void ensure_js_throws_with_assertions_enabled(const char* js_code, const char* error_type);
39
40int main()
41{
42 test("limits");
43
44 assert_js_eq("Module.int64_min()", to_string(numeric_limits<int64_t>::min()) + "n");
45 assert_js_eq("Module.int64_max()", to_string(numeric_limits<int64_t>::max()) + "n");
46 assert_js_eq("Module.uint64_max()", to_string(numeric_limits<uint64_t>::max()) + "n");
47
48 printf("start\n");
49
50 test("vector<int64_t>");
51 val myval(std::vector<int64_t>{1, 2, 3, -4});
52 val::global().set("v64", myval);
53 assert_js_eq("v64.get(0)", "1n");
54 assert_js_eq("v64.get(1)", "2n");
55 assert_js_eq("v64.get(2)", "3n");
56 assert_js_eq("v64.get(3)", "-4n");
57
58 emscripten_run_script("v64.push_back(1234n)");
59 assert_js_eq("v64.size()", "5");
60 assert_js_eq("v64.get(4)", "1234n");
61
62 test("vector<int64_t> Cannot convert bigint that is too big");
63 ensure_js_throws_with_assertions_enabled("v64.push_back(12345678901234567890123456n)", "TypeError");
64
65 test("vector<uint64_t>");
66 val myval2(vector<uint64_t>{1, 2, 3, 4});
67 val::global().set("vU64", myval2);
68 assert_js_eq("vU64.get(0)", "1n");
69 assert_js_eq("vU64.get(1)", "2n");
70 assert_js_eq("vU64.get(2)", "3n");
71 assert_js_eq("vU64.get(3)", "4n");
72
73 emscripten_run_script("vU64.push_back(1234n)");
74 assert_js_eq("vU64.size()", "5");
75 assert_js_eq("vU64.get(4)", "1234n");
76
77 emscripten_run_script("vU64.push_back(1234)");
78 assert_js_eq("vU64.size()", "6");
79 assert_js_eq("vU64.get(5)", "1234n");
80
81 test("vector<uint64_t> Cannot convert bigint that is too big");
82 ensure_js_throws_with_assertions_enabled("vU64.push_back(12345678901234567890123456n)", "TypeError");
83
84 test("vector<uint64_t> Cannot convert bigint that is negative");
85 ensure_js_throws_with_assertions_enabled("vU64.push_back(-1n)", "TypeError");
86
87 myval.call<void>("delete");
88 myval2.call<void>("delete");
89 printf("end\n");
90
91 return 0;
92}

Callers

nothing calls this directly

Calls 8

assert_js_eqFunction · 0.85
printfFunction · 0.85
globalFunction · 0.85
testFunction · 0.70
setMethod · 0.65
to_stringFunction · 0.50
minFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected