*/
njs_int_t
-njs_builtin_objects_clone(njs_vm_t *vm)
+njs_builtin_objects_clone(njs_vm_t *vm, njs_value_t *global)
{
size_t size;
njs_uint_t i;
vm->constructors[i].object.__proto__ = function_prototype;
}
+ vm->global_object = vm->shared->objects[0];
+ vm->global_object.__proto__ = &vm->prototypes[NJS_PROTOTYPE_OBJECT].object;
+ vm->global_object.shared = 0;
+
+ njs_set_object(global, &vm->global_object);
+
vm->string_object = vm->shared->string_object;
vm->string_object.__proto__ = &vm->prototypes[NJS_PROTOTYPE_STRING].object;
case NJS_TOKEN_NON_LOCAL_THIS:
return njs_generate_name(vm, generator, node);
- case NJS_TOKEN_GLOBAL_THIS:
+ case NJS_TOKEN_GLOBAL_OBJECT:
if (vm->options.module) {
- node->index = njs_value_index(vm, &node->u.value,
+ node->index = njs_value_index(vm, &njs_value_undefined,
generator->runtime);
if (njs_fast_path(node->index != NJS_INDEX_NONE)) {
return NJS_OK;
return NJS_ERROR;
}
- /* Fall through. */
+ node->index = NJS_INDEX_GLOBAL_OBJECT;
+
+ return NJS_OK;
case NJS_TOKEN_NJS:
case NJS_TOKEN_PROCESS:
NJS_TOKEN_NON_LOCAL_THIS,
NJS_TOKEN_ARGUMENTS,
-#define NJS_TOKEN_FIRST_OBJECT NJS_TOKEN_GLOBAL_THIS
+#define NJS_TOKEN_FIRST_OBJECT NJS_TOKEN_GLOBAL_OBJECT
- NJS_TOKEN_GLOBAL_THIS,
+ NJS_TOKEN_GLOBAL_OBJECT,
NJS_TOKEN_NJS,
NJS_TOKEN_PROCESS,
NJS_TOKEN_MATH,
break;
}
- node->token = NJS_TOKEN_GLOBAL_THIS;
+ node->token = NJS_TOKEN_GLOBAL_OBJECT;
- if (vm->options.module) {
- njs_set_undefined(&node->u.value);
- break;
- }
-
- /* Fall through. */
+ break;
case NJS_TOKEN_NJS:
case NJS_TOKEN_PROCESS:
if (name.length == 0
|| lexer->prev_token == NJS_TOKEN_THIS
- || lexer->prev_token == NJS_TOKEN_GLOBAL_THIS)
+ || lexer->prev_token == NJS_TOKEN_GLOBAL_OBJECT)
{
return NJS_TOKEN_ILLEGAL;
}
u_char *values;
njs_int_t ret;
njs_arr_t *backtrace;
+ njs_value_t *global;
njs_frame_t *frame;
scope_size = vm->scope_size + NJS_INDEX_GLOBAL_OFFSET;
return NJS_ERROR;
}
- ret = njs_builtin_objects_clone(vm);
+ global = (njs_value_t *) (values + NJS_INDEX_GLOBAL_OBJECT_OFFSET);
+
+ ret = njs_builtin_objects_clone(vm, global);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
#define NJS_INDEX_OBJECT_MEMORY_ERROR \
njs_global_scope_index(NJS_CONSTRUCTOR_MEMORY_ERROR)
-#define NJS_INDEX_GLOBAL_RETVAL njs_global_scope_index(NJS_CONSTRUCTOR_MAX)
+#define NJS_INDEX_GLOBAL_OBJECT njs_global_scope_index(NJS_CONSTRUCTOR_MAX)
+#define NJS_INDEX_GLOBAL_OBJECT_OFFSET \
+ njs_scope_index(NJS_CONSTRUCTOR_MAX, 0)
+
+#define NJS_INDEX_GLOBAL_RETVAL \
+ njs_global_scope_index(NJS_CONSTRUCTOR_MAX + 1)
#define NJS_INDEX_GLOBAL_OFFSET njs_scope_index(NJS_CONSTRUCTOR_MAX + 1, 0)
njs_object_t memory_error_object;
njs_object_t string_object;
+ njs_object_t global_object;
njs_arr_t *codes; /* of njs_vm_code_t */
njs_int_t njs_vm_add_backtrace_entry(njs_vm_t *vm, njs_frame_t *frame);
njs_int_t njs_builtin_objects_create(njs_vm_t *vm);
-njs_int_t njs_builtin_objects_clone(njs_vm_t *vm);
+njs_int_t njs_builtin_objects_clone(njs_vm_t *vm, njs_value_t *global);
njs_int_t njs_builtin_match_native_function(njs_vm_t *vm,
njs_function_t *function, njs_str_t *name);