[njs] Removed deprecated $262.byteString().

noreply at nginx.com noreply at nginx.com
Tue Oct 8 04:35:02 UTC 2024


details:   https://github.com/nginx/njs/commit/efa5e7d653548505d05d66eaed609db9042b834e
branches:  master
commit:    efa5e7d653548505d05d66eaed609db9042b834e
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon, 7 Oct 2024 17:50:19 -0700
description:
Removed deprecated $262.byteString().


---
 src/test/njs_externals_test.c | 173 ------------------------------------------
 src/test/njs_unit_test.c      |  55 +-------------
 2 files changed, 1 insertion(+), 227 deletions(-)

diff --git a/src/test/njs_externals_test.c b/src/test/njs_externals_test.c
index 7dcad90b..f91c919a 100644
--- a/src/test/njs_externals_test.c
+++ b/src/test/njs_externals_test.c
@@ -650,168 +650,6 @@ njs_unit_test_error_message(njs_vm_t *vm, njs_object_prop_t *prop,
 }
 
 
-static njs_int_t
-njs_262_bytes_from_array_like(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *retval)
-{
-    u_char              *p;
-    int64_t             length;
-    uint32_t            u32;
-    njs_int_t           ret;
-    njs_array_t         *array;
-    njs_value_t         *octet, index, prop;
-    njs_array_buffer_t  *buffer;
-
-    array = NULL;
-    buffer = NULL;
-
-    switch (value->type) {
-    case NJS_ARRAY:
-        array = njs_array(value);
-        length = array->length;
-        break;
-
-    case NJS_ARRAY_BUFFER:
-    case NJS_TYPED_ARRAY:
-
-        if (njs_is_typed_array(value)) {
-            buffer = njs_typed_array(value)->buffer;
-
-        } else {
-            buffer = njs_array_buffer(value);
-        }
-
-        length = buffer->size;
-        break;
-
-    default:
-        ret = njs_object_length(vm, value, &length);
-        if (njs_slow_path(ret == NJS_ERROR)) {
-            return ret;
-        }
-    }
-
-    p = njs_string_alloc(vm, retval, length, 0);
-    if (njs_slow_path(p == NULL)) {
-        return NJS_ERROR;
-    }
-
-    if (array != NULL) {
-        octet = array->start;
-
-        while (length != 0) {
-            ret = njs_value_to_uint32(vm, octet, &u32);
-            if (njs_slow_path(ret != NJS_OK)) {
-                return ret;
-            }
-
-            *p++ = (u_char) u32;
-            octet++;
-            length--;
-        }
-
-    } else if (buffer != NULL) {
-        memcpy(p, buffer->u.u8, length);
-
-    } else {
-        p += length - 1;
-
-        while (length != 0) {
-            njs_set_number(&index, length - 1);
-
-            ret = njs_value_property(vm, value, &index, &prop);
-            if (njs_slow_path(ret == NJS_ERROR)) {
-                return ret;
-            }
-
-            ret = njs_value_to_uint32(vm, &prop, &u32);
-            if (njs_slow_path(ret != NJS_OK)) {
-                return ret;
-            }
-
-            *p-- = (u_char) u32;
-            length--;
-        }
-    }
-
-    return NJS_OK;
-}
-
-
-static njs_int_t
-njs_262_bytes_from_string(njs_vm_t *vm, const njs_value_t *string,
-    const njs_value_t *encoding, njs_value_t *retval)
-{
-    njs_str_t  enc, str;
-
-    if (!njs_is_string(encoding)) {
-        njs_type_error(vm, "\"encoding\" must be a string");
-        return NJS_ERROR;
-    }
-
-    njs_string_get(encoding, &enc);
-    njs_string_get(string, &str);
-
-    if (enc.length == 3 && memcmp(enc.start, "hex", 3) == 0) {
-        return njs_string_decode_hex(vm, retval, &str);
-
-    } else if (enc.length == 6 && memcmp(enc.start, "base64", 6) == 0) {
-        return njs_string_decode_base64(vm, retval, &str);
-
-    } else if (enc.length == 9 && memcmp(enc.start, "base64url", 9) == 0) {
-        return njs_string_decode_base64url(vm, retval, &str);
-    }
-
-    njs_type_error(vm, "Unknown encoding: \"%V\"", &enc);
-
-    return NJS_ERROR;
-}
-
-
-/*
- * $262.byteString(array-like).
- * Converts an array-like object containing octets into a byte string.
- *
- * $262.byteString(string[, encoding]).
- * Converts a string using provided encoding: hex, base64, base64url to
- * a byte string.
- *
- * Note: the function produces a byte string, and byte strings are deprecated.
- * The function is provided for testing of existing code which works with
- * byte strings.  When code working with byte strings is removed
- * the function will be removed as well.
- */
-
-static njs_int_t
-njs_262_byte_string(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
-    njs_index_t unused, njs_value_t *retval)
-{
-    njs_value_t  *value;
-
-    value = njs_arg(args, nargs, 1);
-
-    if (njs_is_string(value)) {
-        return njs_262_bytes_from_string(vm, value, njs_arg(args, nargs, 2),
-                                            retval);
-
-    } else if (njs_is_object(value)) {
-
-        if (njs_is_object_string(value)) {
-            value = njs_object_value(value);
-            return njs_262_bytes_from_string(vm, value,
-                                                njs_arg(args, nargs, 2),
-                                                retval);
-        }
-
-        return njs_262_bytes_from_array_like(vm, value, retval);
-    }
-
-    njs_type_error(vm, "value must be a string or array-like object");
-
-    return NJS_ERROR;
-}
-
-
 static njs_external_t  njs_unit_test_262_external[] = {
 
     {
@@ -833,17 +671,6 @@ static njs_external_t  njs_unit_test_262_external[] = {
         }
     },
 
-    {
-        .flags = NJS_EXTERN_METHOD,
-        .name.string = njs_str("byteString"),
-        .writable = 1,
-        .configurable = 1,
-        .enumerable = 1,
-        .u.method = {
-            .native = njs_262_byte_string,
-        }
-    },
-
 };
 
 
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 10ee6c1e..c52753a7 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -10028,9 +10028,6 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("decodeURI('%D0%B0%D0%B1%D0%B2').length"),
       njs_str("3")},
 
-    { njs_str("decodeURI($262.byteString([0x80,0x80]))"),
-      njs_str("URIError: malformed URI")},
-
     { njs_str("["
               " '%',"
               " '%0',"
@@ -10074,11 +10071,8 @@ static njs_unit_test_t  njs_test[] =
               " String.fromCodePoint(0x100),"
               " String.fromCodePoint(0x00, 0x100),"
               " String.fromCodePoint(0x00, 0x01, 0x100),"
-              " $262.byteString([0x80]),"
-              " $262.byteString([0x60, 0x80]),"
-              " $262.byteString([0x60, 0x60, 0x80]),"
               "].map(v => { try { return btoa(v); } catch (e) { return '#'} })"),
-      njs_str("dW5kZWZpbmVk,,AA==,AAE=,AAEC,AP7/,#,#,#,#,#,#")},
+      njs_str("dW5kZWZpbmVk,,AA==,AAE=,AAEC,AP7/,#,#,#")},
 
     /* atob() */
 
@@ -19359,17 +19353,6 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("var en = new TextEncoder(); var res = en.encode('α1α'); res[2]"),
       njs_str("49") },
 
-    { njs_str("var en = new TextEncoder(); en.encode($262.byteString([0xCE]))"),
-      njs_str("239,191,189") },
-
-    { njs_str("var en = new TextEncoder();"
-              "en.encode($262.byteString([0xCE, 0xB1, 0xCE]))"),
-      njs_str("206,177,239,191,189") },
-
-    { njs_str("var en = new TextEncoder();"
-              "en.encode($262.byteString([0xCE, 0xCE, 0xB1]))"),
-      njs_str("239,191,189,206,177") },
-
     { njs_str("var en = new TextEncoder(); en.encoding"),
       njs_str("utf-8") },
 
@@ -19391,33 +19374,6 @@ static njs_unit_test_t  njs_test[] =
               "en.encodeInto('ααααα', utf8.subarray(2)); utf8[0]"),
       njs_str("0") },
 
-    { njs_str("var str = $262.byteString([0xCE]);"
-              "var en = new TextEncoder();"
-              "var utf8 = new Uint8Array(3);"
-              "var res = en.encodeInto(str, utf8); "
-              "[njs.dump(res), utf8]"),
-      njs_str("{read:1,written:3},239,191,189") },
-
-    { njs_str("var str = $262.byteString([0xCE]);"
-              "var en = new TextEncoder();"
-              "var utf8 = new Uint8Array(5);"
-              "en.encodeInto(str, utf8); utf8"),
-      njs_str("239,191,189,0,0") },
-
-    { njs_str("var str = $262.byteString([0xCE, 0xB1, 0xCE]);"
-              "var en = new TextEncoder();"
-              "var utf8 = new Uint8Array(5);"
-              "var res = en.encodeInto(str, utf8);"
-              "[njs.dump(res), utf8]"),
-      njs_str("{read:2,written:5},206,177,239,191,189") },
-
-    { njs_str("var str = $262.byteString([0xCE, 0xCE, 0xB1]);"
-              "var en = new TextEncoder();"
-              "var utf8 = new Uint8Array(5);"
-              "var res = en.encodeInto(str, utf8);"
-              "[njs.dump(res), utf8]"),
-      njs_str("{read:2,written:5},239,191,189,206,177") },
-
     { njs_str("TextEncoder.prototype.encodeInto.apply({}, [])"),
       njs_str("TypeError: \"this\" is not a TextEncoder") },
 
@@ -20901,11 +20857,6 @@ static njs_unit_test_t  njs_querystring_module_test[] =
               "out.join('; ')"),
       njs_str("baz; fuz; muz; tax") },
 
-    { njs_str("var qs = require('querystring'); "
-              "qs.stringify({a: 'b'}, null, null, "
-              "             {encodeURIComponent: () => $262.byteString([0x9d])})"),
-      njs_str("InternalError: invalid UTF-8 string") },
-
     { njs_str("var qs = require('querystring');"
               "qs.stringify({'baz': 'fuz', 'muz': 'tax'}, null, null, {encodeURIComponent: 123});"
               "out.join('; ')"),
@@ -20955,10 +20906,6 @@ static njs_unit_test_t  njs_querystring_module_test[] =
               "qs.stringify(123)"),
       njs_str("") },
 
-    { njs_str("var qs = require('querystring');"
-              "qs.stringify({X: $262.byteString(Array(4).fill(0x9d))})"),
-      njs_str("X=%9D%9D%9D%9D") },
-
     { njs_str("var qs = require('querystring');"
               "qs.stringify({X:{toString(){return 3}}})"),
       njs_str("X=") },


More information about the nginx-devel mailing list