From: Dmitry Volyntsev Date: Fri, 24 Jul 2020 14:02:04 +0000 (+0000) Subject: Improved String.prototype.toString() for ordinary strings. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=99910758aa5c678c850f46ffd21f84bbfd55d2ed;p=njs.git Improved String.prototype.toString() for ordinary strings. Allowing converting all strings to encodings 'hex', 'base64', 'base64url'. --- diff --git a/src/njs_string.c b/src/njs_string.c index de575b83..6bd5d7f0 100644 --- a/src/njs_string.c +++ b/src/njs_string.c @@ -738,9 +738,9 @@ njs_string_prototype_value_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, /* - * String.toString([encoding]). + * String.prototype.toString([encoding]). * Returns the string as is if no additional argument is provided, - * otherwise converts a byte string into an encoded string: hex, base64, + * otherwise converts a string into an encoded string: hex, base64, * base64url. */ @@ -771,11 +771,6 @@ njs_string_prototype_to_string(njs_vm_t *vm, njs_value_t *args, (void) njs_string_prop(&string, &value); - if (njs_slow_path(string.length != 0)) { - njs_type_error(vm, "argument must be a byte string"); - return NJS_ERROR; - } - njs_string_get(&args[1], &enc); str.length = string.size; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 30618bdf..83cad21b 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -895,9 +895,6 @@ static njs_unit_test_t njs_test[] = { njs_str("'A'.toString()"), njs_str("A") }, - { njs_str("'A'.toString('hex')"), - njs_str("TypeError: argument must be a byte string") }, - { njs_str("'A'.toBytes().toString('latin1')"), njs_str("TypeError: Unknown encoding: \"latin1\"") },