static const njs_object_init_t *function_init[] = {
&njs_eval_function_init,
+ NULL,
};
static const njs_function_init_t native_functions[] = {
/* SunC does not allow empty array initialization. */
- { njs_eval_function, { 0 } },
+ { njs_eval_function, { 0 } },
+ { njs_object_prototype_to_string, { 0 } },
};
static const njs_object_prop_t null_proto_property = {
functions = vm->shared->functions;
for (i = NJS_FUNCTION_EVAL; i < NJS_FUNCTION_MAX; i++) {
- ret = njs_object_hash_create(vm, &functions[i].object.shared_hash,
- function_init[i]->properties,
- function_init[i]->items);
- if (nxt_slow_path(ret != NXT_OK)) {
- return NXT_ERROR;
+ if (function_init[i] != NULL) {
+ ret = njs_object_hash_create(vm, &functions[i].object.shared_hash,
+ function_init[i]->properties,
+ function_init[i]->items);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return NXT_ERROR;
+ }
}
functions[i].object.shared = 1;
case NJS_TOKEN_MATH:
case NJS_TOKEN_EVAL:
+ case NJS_TOKEN_TO_STRING:
return njs_generate_builtin_object(vm, parser, node);
case NJS_TOKEN_FUNCTION:
func->code.ctor = node->ctor;
func->name = name->index;
- ret = njs_generator_node_index_release(vm, parser, name);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
-
ret = njs_generate_call(vm, parser, node);
if (nxt_fast_path(ret >= 0)) {
{ nxt_string("Date"), NJS_TOKEN_DATE_CONSTRUCTOR, 0 },
{ nxt_string("eval"), NJS_TOKEN_EVAL, 0 },
+ { nxt_string("toString"), NJS_TOKEN_TO_STRING, 0 },
/* Reserved words. */
break;
case NJS_TOKEN_EVAL:
+ case NJS_TOKEN_TO_STRING:
return njs_parser_builtin_function(vm, parser, node);
default:
#define NJS_TOKEN_FIRST_FUNCTION NJS_TOKEN_EVAL
NJS_TOKEN_EVAL,
+ NJS_TOKEN_TO_STRING,
NJS_TOKEN_RESERVED,
} njs_token_t;
enum njs_function_e {
NJS_FUNCTION_EVAL = 0,
-#define NJS_FUNCTION_MAX (NJS_FUNCTION_EVAL + 1)
+ NJS_FUNCTION_TO_STRING = 1,
+#define NJS_FUNCTION_MAX (NJS_FUNCTION_TO_STRING + 1)
};
{ nxt_string("/./.__proto__ === RegExp.prototype"),
nxt_string("true") },
+ { nxt_string("toString()"),
+ nxt_string("[object Undefined]") },
+
+ { nxt_string("toString() + Object.prototype.toString"),
+ nxt_string("[object Undefined][object Function]") },
+
+#if 0
+ { nxt_string("toString === Object.prototype.toString"),
+ nxt_string("true") },
+
+ { nxt_string("Object.prototype.toString.yes = 'OK'; toString.yes"),
+ nxt_string("OK") },
+#endif
+
{ nxt_string("Object.prototype.toString.call()"),
nxt_string("[object Undefined]") },