|
19 | 19 |
|
20 | 20 | #include "builtins/backend.h"
|
21 | 21 | #include "builtins/request-response.h"
|
| 22 | +#include "core/encode.h" |
22 | 23 | #include "host_interface/fastly.h"
|
23 | 24 | #include "js-compute-builtins.h"
|
24 | 25 | #include "js/Conversions.h"
|
@@ -713,23 +714,20 @@ JS::Result<mozilla::Ok> Backend::register_dynamic_backend(JSContext *cx, JS::Han
|
713 | 714 | MOZ_ASSERT(is_instance(backend));
|
714 | 715 |
|
715 | 716 | JS::RootedString name(cx, JS::GetReservedSlot(backend, Backend::Slots::Name).toString());
|
716 |
| - size_t name_len; |
717 |
| - JS::UniqueChars nameChars = encode(cx, name, &name_len); |
718 |
| - std::string_view name_str{nameChars.get(), name_len}; |
| 717 | + auto nameChars = fastly::core::encode(cx, name); |
| 718 | + std::string_view name_str = nameChars; |
719 | 719 |
|
720 | 720 | JS::RootedString target(cx, JS::GetReservedSlot(backend, Backend::Slots::Target).toString());
|
721 |
| - size_t target_len; |
722 |
| - JS::UniqueChars targetChars = encode(cx, target, &target_len); |
723 |
| - std::string_view target_str{targetChars.get(), target_len}; |
| 721 | + auto targetChars = fastly::core::encode(cx, target); |
| 722 | + std::string_view target_str = targetChars; |
724 | 723 |
|
725 | 724 | BackendConfig backend_config;
|
726 | 725 |
|
727 | 726 | auto hostOverrideSlot = JS::GetReservedSlot(backend, Backend::Slots::HostOverride);
|
728 | 727 | if (!hostOverrideSlot.isNullOrUndefined()) {
|
729 | 728 | JS::RootedString hostOverrideString(cx, hostOverrideSlot.toString());
|
730 |
| - size_t hostOverride_len; |
731 |
| - JS::UniqueChars hostOverrideChars = encode(cx, hostOverrideString, &hostOverride_len); |
732 |
| - backend_config.host_override.emplace(std::move(hostOverrideChars), hostOverride_len); |
| 729 | + auto hostOverrideChars = fastly::core::encode(cx, hostOverrideString); |
| 730 | + backend_config.host_override.emplace(std::move(hostOverrideChars)); |
733 | 731 | }
|
734 | 732 |
|
735 | 733 | auto connectTimeoutSlot = JS::GetReservedSlot(backend, Backend::Slots::ConnectTimeout);
|
@@ -770,35 +768,29 @@ JS::Result<mozilla::Ok> Backend::register_dynamic_backend(JSContext *cx, JS::Han
|
770 | 768 | auto certificateHostnameSlot = JS::GetReservedSlot(backend, Backend::Slots::CertificateHostname);
|
771 | 769 | if (!certificateHostnameSlot.isNullOrUndefined()) {
|
772 | 770 | JS::RootedString certificateHostnameString(cx, certificateHostnameSlot.toString());
|
773 |
| - size_t certificateHostname_len; |
774 |
| - JS::UniqueChars certificateHostnameChars = |
775 |
| - encode(cx, certificateHostnameString, &certificateHostname_len); |
776 |
| - backend_config.cert_hostname.emplace(std::move(certificateHostnameChars), |
777 |
| - certificateHostname_len); |
| 771 | + auto certificateHostnameChars = fastly::core::encode(cx, certificateHostnameString); |
| 772 | + backend_config.cert_hostname.emplace(std::move(certificateHostnameChars)); |
778 | 773 | }
|
779 | 774 |
|
780 | 775 | auto caCertificateSlot = JS::GetReservedSlot(backend, Backend::Slots::CaCertificate);
|
781 | 776 | if (!caCertificateSlot.isNullOrUndefined()) {
|
782 | 777 | JS::RootedString caCertificateString(cx, caCertificateSlot.toString());
|
783 |
| - size_t caCertificate_len; |
784 |
| - JS::UniqueChars caCertificateChars = encode(cx, caCertificateString, &caCertificate_len); |
785 |
| - backend_config.ca_cert.emplace(std::move(caCertificateChars), caCertificate_len); |
| 778 | + auto caCertificateChars = fastly::core::encode(cx, caCertificateString); |
| 779 | + backend_config.ca_cert.emplace(std::move(caCertificateChars)); |
786 | 780 | }
|
787 | 781 |
|
788 | 782 | auto ciphersSlot = JS::GetReservedSlot(backend, Backend::Slots::Ciphers);
|
789 | 783 | if (!ciphersSlot.isNullOrUndefined()) {
|
790 | 784 | JS::RootedString ciphersString(cx, ciphersSlot.toString());
|
791 |
| - size_t ciphers_len; |
792 |
| - JS::UniqueChars ciphersChars = encode(cx, ciphersString, &ciphers_len); |
793 |
| - backend_config.ciphers.emplace(std::move(ciphersChars), ciphers_len); |
| 785 | + auto ciphersChars = fastly::core::encode(cx, ciphersString); |
| 786 | + backend_config.ciphers.emplace(std::move(ciphersChars)); |
794 | 787 | }
|
795 | 788 |
|
796 | 789 | auto sniHostnameSlot = JS::GetReservedSlot(backend, Backend::Slots::SniHostname);
|
797 | 790 | if (!sniHostnameSlot.isNullOrUndefined()) {
|
798 | 791 | JS::RootedString sniHostnameString(cx, sniHostnameSlot.toString());
|
799 |
| - size_t sniHostname_len; |
800 |
| - JS::UniqueChars sniHostnameChars = encode(cx, sniHostnameString, &sniHostname_len); |
801 |
| - backend_config.sni_hostname.emplace(std::move(sniHostnameChars), sniHostname_len); |
| 792 | + auto sniHostnameChars = fastly::core::encode(cx, sniHostnameString); |
| 793 | + backend_config.sni_hostname.emplace(std::move(sniHostnameChars)); |
802 | 794 | }
|
803 | 795 |
|
804 | 796 | auto res = HttpReq::register_dynamic_backend(name_str, target_str, backend_config);
|
@@ -915,7 +907,7 @@ bool Backend::set_target(JSContext *cx, JSObject *backend, JS::HandleValue targe
|
915 | 907 | return false;
|
916 | 908 | }
|
917 | 909 |
|
918 |
| - auto targetStringSlice = encode(cx, target_val); |
| 910 | + auto targetStringSlice = fastly::core::encode_spec_string(cx, target_val); |
919 | 911 | if (!targetStringSlice.data) {
|
920 | 912 | return false;
|
921 | 913 | }
|
@@ -948,7 +940,7 @@ bool Backend::set_target(JSContext *cx, JSObject *backend, JS::HandleValue targe
|
948 | 940 |
|
949 | 941 | JSObject *Backend::create(JSContext *cx, JS::HandleObject request) {
|
950 | 942 | JS::RootedValue request_url(cx, RequestOrResponse::url(request));
|
951 |
| - auto url_string = encode(cx, request_url); |
| 943 | + auto url_string = fastly::core::encode_spec_string(cx, request_url); |
952 | 944 | if (!url_string.data) {
|
953 | 945 | return nullptr;
|
954 | 946 | }
|
@@ -1132,7 +1124,7 @@ bool Backend::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
|
1132 | 1124 | return false;
|
1133 | 1125 | }
|
1134 | 1126 |
|
1135 |
| - if (isnan(version)) { |
| 1127 | + if (std::isnan(version)) { |
1136 | 1128 | JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BACKEND_TLS_MIN_INVALID);
|
1137 | 1129 | return false;
|
1138 | 1130 | }
|
@@ -1272,27 +1264,28 @@ bool Backend::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
|
1272 | 1264 | if (!JS_GetProperty(cx, configuration, "ciphers", &ciphers_val)) {
|
1273 | 1265 | return false;
|
1274 | 1266 | }
|
1275 |
| - size_t length; |
1276 |
| - auto ciphers_chars = encode(cx, ciphers_val, &length); |
| 1267 | + auto ciphers_chars = fastly::core::encode(cx, ciphers_val); |
1277 | 1268 | if (!ciphers_chars) {
|
1278 | 1269 | return false;
|
1279 | 1270 | }
|
1280 |
| - if (length == 0) { |
| 1271 | + if (ciphers_chars.size() == 0) { |
1281 | 1272 | JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BACKEND_CIPHERS_EMPTY);
|
1282 | 1273 | return false;
|
1283 | 1274 | }
|
1284 |
| - std::string cipherSpec(ciphers_chars.get(), length); |
| 1275 | + std::string cipherSpec(ciphers_chars.begin(), ciphers_chars.len); |
1285 | 1276 | if (!isCipherSuiteSupportedByFastly(cipherSpec)) {
|
1286 | 1277 | JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BACKEND_CIPHERS_NOT_AVALIABLE);
|
1287 | 1278 | return false;
|
1288 | 1279 | }
|
1289 |
| - JS::SetReservedSlot(backend, Backend::Slots::Ciphers, |
1290 |
| - JS::StringValue(JS_NewStringCopyN(cx, ciphers_chars.get(), length))); |
| 1280 | + JS::SetReservedSlot( |
| 1281 | + backend, Backend::Slots::Ciphers, |
| 1282 | + JS::StringValue(JS_NewStringCopyN(cx, ciphers_chars.begin(), ciphers_chars.len))); |
1291 | 1283 | auto ciphersSlot = JS::GetReservedSlot(backend, Backend::Slots::Ciphers);
|
1292 | 1284 | if (!ciphersSlot.isNullOrUndefined()) {
|
1293 | 1285 | JS::RootedString ciphers(cx, ciphersSlot.toString());
|
1294 |
| - size_t ciphers_len; |
1295 |
| - JS::UniqueChars ciphersChars = encode(cx, ciphers, &ciphers_len); |
| 1286 | + |
| 1287 | + // TODO: what should this be used for? |
| 1288 | + auto ciphersChars = fastly::core::encode(cx, ciphers); |
1296 | 1289 | }
|
1297 | 1290 | }
|
1298 | 1291 |
|
|
0 commit comments