Debian Codegraph @

debian/tests/test.cpp

raw
1 // Copyright 2024 Simon McVittie
2 // SPDX-License-Identifier: MIT
3
4 #include <cinttypes>
5 #include <cstdio>
6
7 #include <jsapi.h>
8 #include <js/Initialization.h>
9
10 int main(int argc, char** argv)
11 {
12 // Smoke-test
13 const char* reason = JS_InitWithFailureDiagnostic();
14 if (reason) {
15 std::fprintf(stderr, "Fatal error: %s\n", reason);
16 return 1;
17 }
18 JSContext* cx = JS_NewContext(32 * 1024 * 1024);
19
20 // https://bugs.debian.org/1063446
21 uint64_t u64;
22 double d = JS::CanonicalizeNaN(0.0/0.0);
23 static_assert(sizeof(u64) == sizeof(d));
24 memcpy(&u64, &d, sizeof(d));
25 std::printf("Representation of a canonicalized NaN: %" PRIx64 "\n", u64);
26
27 JS_DestroyContext(cx);
28 JS_ShutDown();
29 return 0;
30 }