]> git.kaiwu.me - njs.git/commitdiff
Function expressions did not have prototypes.
authorIgor Sysoev <igor@sysoev.ru>
Fri, 4 Nov 2016 20:45:35 +0000 (23:45 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 4 Nov 2016 20:45:35 +0000 (23:45 +0300)
njs/njs_vm.c
njs/test/njs_unit_test.c

index 00daacd73a326829a1f44ec506e6d88842a9acac..d62f925aefb3328072a6953e7e2ca1d532c0f066 100644 (file)
@@ -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;
index c7301cc043a91a4354afabb7a2ae0ee7831fc677..f891b83d4c06066d5963d400a4ece16d42e7e0c3 100644 (file)
@@ -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"),