Skip to content

Commit

Permalink
Work around msvc definition of NAN
Browse files Browse the repository at this point in the history
NAN is reportedly no longer a compile-time expression in some versions
of MSVC. Work around that by minting a NaN from a uint64.

Fixes: #622
Fixes: #693
  • Loading branch information
bnoordhuis committed Nov 18, 2024
1 parent bdadad9 commit f93dd58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41116,7 +41116,7 @@ static const JSCFunctionListEntry js_number_funcs[] = {
JS_CFUNC_DEF("isSafeInteger", 1, js_number_isSafeInteger ),
JS_PROP_DOUBLE_DEF("MAX_VALUE", 1.7976931348623157e+308, 0 ),
JS_PROP_DOUBLE_DEF("MIN_VALUE", 5e-324, 0 ),
JS_PROP_DOUBLE_DEF("NaN", NAN, 0 ),
JS_PROP_U2D_DEF("NaN", 0x7FF8ull<<48, 0 ), // workaround for msvc
JS_PROP_DOUBLE_DEF("NEGATIVE_INFINITY", -INFINITY, 0 ),
JS_PROP_DOUBLE_DEF("POSITIVE_INFINITY", INFINITY, 0 ),
JS_PROP_DOUBLE_DEF("EPSILON", 2.220446049250313e-16, 0 ), /* ES6 */
Expand Down Expand Up @@ -50197,7 +50197,7 @@ static const JSCFunctionListEntry js_global_funcs[] = {
JS_CFUNC_DEF("escape", 1, js_global_escape ),
JS_CFUNC_DEF("unescape", 1, js_global_unescape ),
JS_PROP_DOUBLE_DEF("Infinity", 1.0 / 0.0, 0 ),
JS_PROP_DOUBLE_DEF("NaN", NAN, 0 ),
JS_PROP_U2D_DEF("NaN", 0x7FF8ull<<48, 0 ), // workaround for msvc
JS_PROP_UNDEFINED_DEF("undefined", 0 ),
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "global", JS_PROP_CONFIGURABLE ),
};
Expand Down
2 changes: 2 additions & 0 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ typedef struct JSCFunctionListEntry {
const char *str; /* pure ASCII or UTF-8 encoded */
int32_t i32;
int64_t i64;
uint64_t u64;
double f64;
} u;
} JSCFunctionListEntry;
Expand Down Expand Up @@ -998,6 +999,7 @@ typedef struct JSCFunctionListEntry {
#define JS_PROP_INT32_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT32, 0, { .i32 = val } }
#define JS_PROP_INT64_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT64, 0, { .i64 = val } }
#define JS_PROP_DOUBLE_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, { .f64 = val } }
#define JS_PROP_U2D_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, { .u64 = val } }
#define JS_PROP_UNDEFINED_DEF(name, prop_flags) { name, prop_flags, JS_DEF_PROP_UNDEFINED, 0, { .i32 = 0 } }
#define JS_OBJECT_DEF(name, tab, len, prop_flags) { name, prop_flags, JS_DEF_OBJECT, 0, { .prop_list = { tab, len } } }
#define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, { .alias = { from, -1 } } }
Expand Down

0 comments on commit f93dd58

Please sign in to comment.