From: Igor Sysoev Date: Fri, 4 Nov 2016 20:45:35 +0000 (+0300) Subject: Function expressions did not have prototypes. X-Git-Tag: 0.1.5~16 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=8d9696273f11301dc89ee8a014b2f7a576ef24b4;p=njs.git Function expressions did not have prototypes. --- diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 00daacd7..d62f925a 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -414,6 +414,7 @@ njs_vmcode_function(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2) function = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_function_t)); if (nxt_fast_path(function != NULL)) { + function->object.shared_hash = vm->shared->function_prototype_hash; function->object.__proto__ = &vm->prototypes[NJS_PROTOTYPE_FUNCTION].object; function->args_offset = 1; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index c7301cc0..f891b83d 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -4167,6 +4167,17 @@ static njs_unit_test_t njs_test[] = "o.constructor === F"), nxt_string("true") }, + { nxt_string("function F() { return }" + "var o = new F();" + "o.__proto__ === F.prototype"), + nxt_string("true") }, + + { nxt_string("function F(){}; typeof F.prototype"), + nxt_string("object") }, + + { nxt_string("var F = function (){}; typeof F.prototype"), + nxt_string("object") }, + { nxt_string("function F() { return Number }" "var o = new (F())(5);" "typeof o +' '+ o"),