};
static const njs_object_init_t *object_init[] = {
- &njs_math_object_init,
+ NULL, /* global this */
+ &njs_math_object_init, /* Math */
};
static const njs_object_init_t *function_init[] = {
objects = vm->shared->objects;
- for (i = NJS_OBJECT_MATH; i < NJS_OBJECT_MAX; i++) {
- ret = njs_object_hash_create(vm, &objects[i].shared_hash,
- object_init[i]->properties,
- object_init[i]->items);
- if (nxt_slow_path(ret != NXT_OK)) {
- return NXT_ERROR;
+ for (i = NJS_OBJECT_THIS; i < NJS_OBJECT_MAX; i++) {
+ if (object_init[i] != NULL) {
+ ret = njs_object_hash_create(vm, &objects[i].shared_hash,
+ object_init[i]->properties,
+ object_init[i]->items);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return NXT_ERROR;
+ }
}
objects[i].shared = 1;
case NJS_TOKEN_NAME:
return njs_generate_name(vm, parser, node);
+ case NJS_TOKEN_GLOBAL_THIS:
case NJS_TOKEN_MATH:
case NJS_TOKEN_EVAL:
case NJS_TOKEN_TO_STRING:
case NJS_TOKEN_THIS:
nxt_thread_log_debug("JS: this");
- node->index = NJS_INDEX_THIS;
- break;
+ if (parser->scope != NJS_SCOPE_GLOBAL) {
+ node->index = NJS_INDEX_THIS;
+ break;
+ }
+
+ node->token = NJS_TOKEN_GLOBAL_THIS;
+
+ /* Fall through. */
case NJS_TOKEN_MATH:
return njs_parser_builtin_object(vm, parser, node);
NJS_TOKEN_THIS,
-#define NJS_TOKEN_FIRST_OBJECT NJS_TOKEN_MATH
+#define NJS_TOKEN_FIRST_OBJECT NJS_TOKEN_GLOBAL_THIS
+ NJS_TOKEN_GLOBAL_THIS,
NJS_TOKEN_MATH,
NJS_TOKEN_OBJECT_CONSTRUCTOR,
{ nxt_string("/./ instanceof Object"),
nxt_string("true") },
+ { nxt_string("this"),
+ nxt_string("[object Object]") },
+
{ nxt_string("var o = Object(); o"),
nxt_string("[object Object]") },