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

Function test_value

test/embind/test_i64_val.cpp:41–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40template <typename T>
41void test_value(T value) {
42 static_assert(sizeof(T) == 8 || sizeof(T) == 4);
43 cout << " testing value " << value << endl;
44 cout << " setting properties preserves the expected value" << endl;
45 val::global().set("a", val(value));
46 ensure_js(compare_a_number_or_bigint_js(value));
47 cout << " getting properties returns the original value intact" << endl;
48 assert(val::global()["a"].as<T>() == value);
49 cout << " function calls roundtrip the value correctly" << endl;
50 const char* typeName;
51 if constexpr (sizeof(T) == 8) {
52 typeName = "BigInt";
53 } else {
54 typeName = "Number";
55 }
56 assert(val::global(typeName)(value).template as<T>() == value);
57 cout << " method calls roundtrip the value correctly" << endl;
58 assert(val::global().call<T>(typeName, value) == value);
59}
60
61int main() {
62 const int64_t max_int64_t = numeric_limits<int64_t>::max();

Callers 1

mainFunction · 0.70

Calls 6

globalFunction · 0.85
ensure_jsFunction · 0.85
setMethod · 0.65
valFunction · 0.50
assertFunction · 0.50

Tested by

no test coverage detected