&njs_eval_function_init,
NULL,
NULL,
+ NULL,
};
static const njs_function_init_t native_functions[] = {
{ njs_eval_function, { 0 } },
{ njs_object_prototype_to_string, { 0 } },
{ njs_number_is_nan, { NJS_SKIP_ARG, NJS_NUMBER_ARG } },
+ { njs_number_is_finite, { NJS_SKIP_ARG, NJS_NUMBER_ARG } },
};
static const njs_object_prop_t null_proto_property = {
case NJS_TOKEN_EVAL:
case NJS_TOKEN_TO_STRING:
case NJS_TOKEN_IS_NAN:
+ case NJS_TOKEN_IS_FINITE:
return njs_generate_builtin_object(vm, parser, node);
case NJS_TOKEN_FUNCTION:
{ nxt_string("eval"), NJS_TOKEN_EVAL, 0 },
{ nxt_string("toString"), NJS_TOKEN_TO_STRING, 0 },
{ nxt_string("isNaN"), NJS_TOKEN_IS_NAN, 0 },
+ { nxt_string("isFinite"), NJS_TOKEN_IS_FINITE, 0 },
/* Reserved words. */
return NXT_OK;
}
+
+
+njs_ret_t
+njs_number_is_finite(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ double num;
+ const njs_value_t *value;
+
+ value = &njs_value_false;
+
+ if (nargs > 1) {
+ num = args[1].data.u.number;
+
+ if (!njs_is_nan(num) && !njs_is_infinity(num)) {
+ value = &njs_value_true;
+ }
+ }
+
+ vm->retval = *value;
+
+ return NXT_OK;
+}
nxt_uint_t nargs, njs_index_t unused);
njs_ret_t njs_number_is_nan(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused);
+njs_ret_t njs_number_is_finite(njs_vm_t *vm, njs_value_t *args,
+ nxt_uint_t nargs, njs_index_t unused);
extern const njs_object_init_t njs_number_constructor_init;
case NJS_TOKEN_EVAL:
case NJS_TOKEN_TO_STRING:
case NJS_TOKEN_IS_NAN:
+ case NJS_TOKEN_IS_FINITE:
return njs_parser_builtin_function(vm, parser, node);
default:
NJS_TOKEN_EVAL,
NJS_TOKEN_TO_STRING,
NJS_TOKEN_IS_NAN,
+ NJS_TOKEN_IS_FINITE,
NJS_TOKEN_RESERVED,
} njs_token_t;
NJS_FUNCTION_EVAL = 0,
NJS_FUNCTION_TO_STRING = 1,
NJS_FUNCTION_IS_NAN = 2,
-#define NJS_FUNCTION_MAX (NJS_FUNCTION_IS_NAN + 1)
+ NJS_FUNCTION_IS_FINITE = 3,
+#define NJS_FUNCTION_MAX (NJS_FUNCTION_IS_FINITE + 1)
};
{ nxt_string("isNaN('abc')"),
nxt_string("true") },
+ { nxt_string("isFinite"),
+ nxt_string("[object Function]") },
+
+ { nxt_string("isFinite()"),
+ nxt_string("false") },
+
+ { nxt_string("isFinite(123)"),
+ nxt_string("true") },
+
+ { nxt_string("isFinite('123')"),
+ nxt_string("true") },
+
+ { nxt_string("isFinite('Infinity')"),
+ nxt_string("false") },
+
+ { nxt_string("isFinite('abc')"),
+ nxt_string("false") },
+
/* External interface. */
{ nxt_string("function f(req) { return req.uri }"),