From: Dmitry Volyntsev Date: Thu, 31 Oct 2019 15:17:34 +0000 (+0300) Subject: Fixed "constructor" property of "Hash" and "Hmac" objects. X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=212987b02622c11c8e93138c5af5b126c26fa871;p=njs.git Fixed "constructor" property of "Hash" and "Hmac" objects. --- diff --git a/src/njs_crypto.c b/src/njs_crypto.c index 61c8802f..fc485efd 100644 --- a/src/njs_crypto.c +++ b/src/njs_crypto.c @@ -343,6 +343,14 @@ static const njs_object_prop_t njs_hash_prototype_properties[] = .writable = 1, .configurable = 1, }, + + { + .type = NJS_PROPERTY_HANDLER, + .name = njs_string("constructor"), + .value = njs_prop_handler(njs_object_prototype_create_constructor), + .writable = 1, + .configurable = 1, + }, }; @@ -634,6 +642,14 @@ static const njs_object_prop_t njs_hmac_prototype_properties[] = .writable = 1, .configurable = 1, }, + + { + .type = NJS_PROPERTY_HANDLER, + .name = njs_string("constructor"), + .value = njs_prop_handler(njs_object_prototype_create_constructor), + .writable = 1, + .configurable = 1, + }, }; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 390f4624..ad5133ef 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -14191,6 +14191,15 @@ static njs_unit_test_t njs_test[] = { njs_str("Object.prototype.toString.call(require('crypto').createHash('sha1'))"), njs_str("[object Object]") }, + { njs_str("var h = require('crypto').createHash('sha1');" + "var Hash = h.constructor; " + "Hash('sha1').update('AB').digest('hex')"), + njs_str("06d945942aa26a61be18c3e22bf19bbca8dd2b5d") }, + + { njs_str("var h = require('crypto').createHash('sha1');" + "h.constructor.name"), + njs_str("Hash") }, + { njs_str("var h = require('crypto').createHash('md5');" "h.update('AB').digest('hex')"), njs_str("b86fc6b051f63d73de262d4c34e3a0a9") }, @@ -14284,6 +14293,15 @@ static njs_unit_test_t njs_test[] = "h.digest().toString('hex')"), njs_str("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d") }, + { njs_str("var h = require('crypto').createHmac('sha1', '');" + "var Hmac = h.constructor; " + "Hmac('sha1', '').digest('hex')"), + njs_str("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d") }, + + { njs_str("var h = require('crypto').createHmac('sha1', '');" + "h.constructor.name"), + njs_str("Hmac") }, + { njs_str("var h = require('crypto').createHmac('md5', 'secret key');" "h.update('AB').digest('hex')"), njs_str("9c72728915eb26620a5caeafd0063b29") },