Skip to content

Commit 11c36e9

Browse files
committed
Fixed absolute scope in cloned VMs.
1 parent 983b397 commit 11c36e9

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/njs_vm.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external)
384384
njs_mp_t *nmp;
385385
njs_vm_t *nvm;
386386
njs_int_t ret;
387-
njs_value_t **global;
387+
njs_value_t **global, **value;
388388

389389
njs_thread_log_debug("CLONE:");
390390

@@ -423,6 +423,24 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external)
423423
goto fail;
424424
}
425425

426+
if (nvm->options.unsafe) {
427+
nvm->scope_absolute = njs_arr_create(nvm->mem_pool,
428+
vm->scope_absolute->items,
429+
sizeof(njs_value_t *));
430+
if (njs_slow_path(nvm->scope_absolute == NULL)) {
431+
goto fail;
432+
}
433+
434+
value = njs_arr_add_multiple(nvm->scope_absolute,
435+
vm->scope_absolute->items);
436+
if (njs_slow_path(value == NULL)) {
437+
goto fail;
438+
}
439+
440+
memcpy(value, vm->scope_absolute->start,
441+
vm->scope_absolute->items * sizeof(njs_value_t *));
442+
}
443+
426444
nvm->levels[NJS_LEVEL_GLOBAL] = global;
427445

428446
/* globalThis and this */

0 commit comments

Comments
 (0)