From: Dmitry Volyntsev Date: Thu, 14 Nov 2024 05:14:34 +0000 (-0800) Subject: Fixed absolute scope in cloned VMs. X-Git-Tag: 0.8.8~5 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=11c36e925bc63633f8ca39ee2f237cc13fe5519d;p=njs.git Fixed absolute scope in cloned VMs. --- diff --git a/src/njs_vm.c b/src/njs_vm.c index 908c40c8..90428cb4 100644 --- a/src/njs_vm.c +++ b/src/njs_vm.c @@ -384,7 +384,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) njs_mp_t *nmp; njs_vm_t *nvm; njs_int_t ret; - njs_value_t **global; + njs_value_t **global, **value; njs_thread_log_debug("CLONE:"); @@ -423,6 +423,24 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) goto fail; } + if (nvm->options.unsafe) { + nvm->scope_absolute = njs_arr_create(nvm->mem_pool, + vm->scope_absolute->items, + sizeof(njs_value_t *)); + if (njs_slow_path(nvm->scope_absolute == NULL)) { + goto fail; + } + + value = njs_arr_add_multiple(nvm->scope_absolute, + vm->scope_absolute->items); + if (njs_slow_path(value == NULL)) { + goto fail; + } + + memcpy(value, vm->scope_absolute->start, + vm->scope_absolute->items * sizeof(njs_value_t *)); + } + nvm->levels[NJS_LEVEL_GLOBAL] = global; /* globalThis and this */