|
28 | 28 | #include "Helpers.h" // for tns::Exists |
29 | 29 | #include "HttpLoader.h" |
30 | 30 | #include "ModuleInternal.h" // for CompileFileEsModule / EvaluateModuleGraph |
| 31 | +#include "ModuleUrl.h" |
31 | 32 | #include "NativeScriptException.h" |
32 | 33 | #include "NativeScriptPlatform.h" |
33 | 34 | #include "NsBuiltinModules.h" |
34 | 35 | #include "Runtime.h" // for GetAppConfigValue |
35 | 36 | #include "RuntimeConfig.h" |
36 | | -#include "ada/ada.h" |
37 | 37 |
|
38 | 38 | // Do NOT pull all v8 symbols into namespace here; String would clash with |
39 | 39 | // other typedefs inside the NativeScript codebase. We refer to v8 symbols |
@@ -90,19 +90,6 @@ static inline bool StartsWith(const std::string& s, const char* prefix) { |
90 | 90 | return s.size() >= n && s.compare(0, n, prefix) == 0; |
91 | 91 | } |
92 | 92 |
|
93 | | -// Whether `key` is spelled the way the loader keys an HTTP module: a lowercase |
94 | | -// `http://` or `https://` prefix, file modules being keyed by absolute paths. |
95 | | -// Deliberately not a URL parse: it gates the rule that an HTTP importer never |
96 | | -// reaches the filesystem implicitly, so a key the URL parser would reject (an |
97 | | -// IPv6 zone id, say) must still count as HTTP. |
98 | | -static bool IsHttpRegistryKey(const std::string& key) { |
99 | | - if (key.compare(0, 4, "http") != 0) { |
100 | | - return false; |
101 | | - } |
102 | | - const size_t schemeEnd = key.size() > 4 && key[4] == 's' ? 5 : 4; |
103 | | - return key.compare(schemeEnd, 3, "://") == 0; |
104 | | -} |
105 | | -
|
106 | 93 | static bool ShouldTraceRegistryKey(const std::string& rawKey, const std::string& registryKey); |
107 | 94 | static std::string CanonicalizeRegistryKey(const std::string& key); |
108 | 95 | static const char* ModuleStatusToString(v8::Module::Status status); |
@@ -1560,85 +1547,6 @@ static void DrainStreamedCompilesForIsolate(v8::Isolate* isolate) { |
1560 | 1547 | return "Cannot find module '" + resolution.specifier + "' (tried " + resolution.attempted + ")"; |
1561 | 1548 | } |
1562 | 1549 |
|
1563 | | -static bool HasHttpScheme(const ada::url_aggregator& url) { |
1564 | | - return url.type == ada::scheme::type::HTTP || url.type == ada::scheme::type::HTTPS; |
1565 | | -} |
1566 | | -
|
1567 | | -// The authority (userinfo, host, port) of an absolute or scheme-relative URL |
1568 | | -// exactly as written, or empty when `url` does not spell one plainly. |
1569 | | -static std::string WrittenAuthority(const std::string& url) { |
1570 | | - size_t start = 0; |
1571 | | - if (StartsWith(url, "//")) { |
1572 | | - start = 2; |
1573 | | - } else { |
1574 | | - const size_t colon = url.find(':'); |
1575 | | - if (colon == std::string::npos || url.compare(colon, 3, "://") != 0) { |
1576 | | - return std::string(); |
1577 | | - } |
1578 | | - start = colon + 3; |
1579 | | - } |
1580 | | - const size_t end = url.find_first_of("/?#", start); |
1581 | | - std::string authority = url.substr(start, end == std::string::npos ? end : end - start); |
1582 | | - for (const char c : authority) { |
1583 | | - if (static_cast<unsigned char>(c) <= 0x20 || c == '\\') { |
1584 | | - return std::string(); |
1585 | | - } |
1586 | | - } |
1587 | | - return authority; |
1588 | | -} |
1589 | | -
|
1590 | | -struct ModuleUrl { |
1591 | | - bool parsed = false; |
1592 | | - bool http = false; // the scheme is http or https |
1593 | | - std::string href; |
1594 | | -}; |
1595 | | -
|
1596 | | -// `input` parsed with the WHATWG URL parser (the one behind JS `new URL()`): |
1597 | | -// as an absolute URL when `base` is empty, otherwise as a path- or |
1598 | | -// scheme-relative reference against `base`. |
1599 | | -// |
1600 | | -// An http(s) result keeps its authority as written by whichever string |
1601 | | -// supplied it: tooling compares module URLs against the origin string it was |
1602 | | -// configured with, so that spelling is part of a module's identity until every |
1603 | | -// loader entry point canonicalizes. The parser's own href is used whenever the |
1604 | | -// written authority would not name the same URL. |
1605 | | -static ModuleUrl ParseModuleUrl(const std::string& input, const std::string& base) { |
1606 | | - ModuleUrl result; |
1607 | | - ada::result<ada::url_aggregator> url; |
1608 | | - if (base.empty()) { |
1609 | | - url = ada::parse<ada::url_aggregator>(input, nullptr); |
1610 | | - } else { |
1611 | | - auto baseUrl = ada::parse<ada::url_aggregator>(base, nullptr); |
1612 | | - if (!baseUrl) { |
1613 | | - return result; |
1614 | | - } |
1615 | | - url = ada::parse<ada::url_aggregator>(input, &baseUrl.value()); |
1616 | | - } |
1617 | | - if (!url) { |
1618 | | - return result; |
1619 | | - } |
1620 | | - result.parsed = true; |
1621 | | - result.http = HasHttpScheme(*url); |
1622 | | - result.href = std::string(url->get_href()); |
1623 | | - if (!result.http) { |
1624 | | - return result; |
1625 | | - } |
1626 | | -
|
1627 | | - const std::string authority = |
1628 | | - WrittenAuthority(base.empty() || StartsWith(input, "//") ? input : base); |
1629 | | - if (authority.empty()) { |
1630 | | - return result; |
1631 | | - } |
1632 | | - const std::string written = std::string(url->get_protocol()) + "//" + authority + |
1633 | | - std::string(url->get_pathname()) + std::string(url->get_search()) + |
1634 | | - std::string(url->get_hash()); |
1635 | | - auto reparsed = ada::parse<ada::url_aggregator>(written, nullptr); |
1636 | | - if (reparsed && reparsed->get_href() == url->get_href()) { |
1637 | | - result.href = written; |
1638 | | - } |
1639 | | - return result; |
1640 | | -} |
1641 | | -
|
1642 | 1550 | struct UrlSpecifier { |
1643 | 1551 | enum class Kind { |
1644 | 1552 | kHttpUrl, // an http(s) URL |
@@ -3163,8 +3071,7 @@ static void FinishHttpDynamicImport(v8::Isolate* isolate, v8::Local<v8::Context> |
3163 | 3071 | // app path the registry keys by, or no scope would match it. |
3164 | 3072 | const std::string resourceName(*resourceUtf8); |
3165 | 3073 | const std::string resourceUrl = RepairCollapsedUrlScheme(resourceName); |
3166 | | - const auto parsedResource = ada::parse<ada::url_aggregator>(resourceUrl, nullptr); |
3167 | | - if (parsedResource && HasHttpScheme(*parsedResource)) { |
| 3074 | + if (ParseModuleUrl(resourceUrl, std::string()).http) { |
3168 | 3075 | dynamicReferrerKey = CanonicalizeRegistryKey(resourceUrl); |
3169 | 3076 | } else { |
3170 | 3077 | const ModuleResolution referrer = |
|
0 commit comments