summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-12-28 15:55:00 -0800
committerJames M Snell <jasnell@gmail.com>2016-12-30 10:14:10 -0800
commitabc1633de649bfa5846ec940e9403249e4be2c92 (patch)
treeddb0f856b9b3418fc39e095b624a7e5ead41a222
parent2213f3640a1c84cd50d86eab9e8b57bb5797f674 (diff)
downloadandroid-node-v8-abc1633de649bfa5846ec940e9403249e4be2c92.tar.gz
android-node-v8-abc1633de649bfa5846ec940e9403249e4be2c92.tar.bz2
android-node-v8-abc1633de649bfa5846ec940e9403249e4be2c92.zip
url: move originFor, domainToAscii and domainToUnicode
Move non-standard methods to `url` module instead of exposing as static methods on the `URL` object. PR-URL: https://github.com/nodejs/node/pull/10512 Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
-rwxr-xr-xlib/internal/url.js15
-rw-r--r--lib/url.js3
-rw-r--r--test/parallel/test-url-domain-ascii-unicode.js4
-rw-r--r--test/parallel/test-util-inspect-tuple-origin.js8
-rw-r--r--test/parallel/test-whatwg-url-origin-for.js4
5 files changed, 20 insertions, 14 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 28d5a073e1..d80f3ca79a 100755
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -69,7 +69,7 @@ class TupleOrigin {
toString(unicode = false) {
var result = this[kScheme];
result += '://';
- result += unicode ? URL.domainToUnicode(this[kHost]) : this[kHost];
+ result += unicode ? domainToUnicode(this[kHost]) : this[kHost];
if (this[kPort] !== undefined && this[kPort] !== null)
result += `:${this[kPort]}`;
return result;
@@ -898,13 +898,16 @@ function originFor(url, base) {
return origin;
}
-URL.originFor = originFor;
-URL.domainToASCII = function(domain) {
+function domainToASCII(domain) {
return binding.domainToASCII(String(domain));
-};
-URL.domainToUnicode = function(domain) {
+}
+
+function domainToUnicode(domain) {
return binding.domainToUnicode(String(domain));
-};
+}
exports.URL = URL;
+exports.originFor = originFor;
+exports.domainToASCII = domainToASCII;
+exports.domainToUnicode = domainToUnicode;
exports.encodeAuth = encodeAuth;
diff --git a/lib/url.js b/lib/url.js
index 49f2a30726..8bdfd0cb66 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -17,6 +17,9 @@ exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
exports.URL = internalUrl.URL;
+exports.originFor = internalUrl.originFor;
+exports.domainToASCII = internalUrl.domainToASCII;
+exports.domainToUnicode = internalUrl.domainToUnicode;
exports.Url = Url;
diff --git a/test/parallel/test-url-domain-ascii-unicode.js b/test/parallel/test-url-domain-ascii-unicode.js
index f9a6be4625..dcc918201b 100644
--- a/test/parallel/test-url-domain-ascii-unicode.js
+++ b/test/parallel/test-url-domain-ascii-unicode.js
@@ -4,8 +4,8 @@ require('../common');
const strictEqual = require('assert').strictEqual;
const url = require('url');
-const domainToASCII = url.URL.domainToASCII;
-const domainToUnicode = url.URL.domainToUnicode;
+const domainToASCII = url.domainToASCII;
+const domainToUnicode = url.domainToUnicode;
const domainWithASCII = [
['ıídيٴ', 'xn--d-iga7ro0q9f'],
diff --git a/test/parallel/test-util-inspect-tuple-origin.js b/test/parallel/test-util-inspect-tuple-origin.js
index 7529273756..743651098f 100644
--- a/test/parallel/test-util-inspect-tuple-origin.js
+++ b/test/parallel/test-util-inspect-tuple-origin.js
@@ -3,10 +3,10 @@
require('../common');
const assert = require('assert');
const inspect = require('util').inspect;
-const URL = require('url').URL;
+const originFor = require('url').originFor;
assert.strictEqual(
- inspect(URL.originFor('http://test.com:8000')),
+ inspect(originFor('http://test.com:8000')),
`TupleOrigin {
scheme: http,
host: test.com,
@@ -16,7 +16,7 @@ assert.strictEqual(
);
assert.strictEqual(
- inspect(URL.originFor('http://test.com')),
+ inspect(originFor('http://test.com')),
`TupleOrigin {
scheme: http,
host: test.com,
@@ -27,7 +27,7 @@ assert.strictEqual(
assert.strictEqual(
- inspect(URL.originFor('https://test.com')),
+ inspect(originFor('https://test.com')),
`TupleOrigin {
scheme: https,
host: test.com,
diff --git a/test/parallel/test-whatwg-url-origin-for.js b/test/parallel/test-whatwg-url-origin-for.js
index a82f624e4e..9e015f8051 100644
--- a/test/parallel/test-whatwg-url-origin-for.js
+++ b/test/parallel/test-whatwg-url-origin-for.js
@@ -2,7 +2,7 @@
const common = require('../common');
-const URL = require('url').URL;
+const originFor = require('url').originFor;
const path = require('path');
const assert = require('assert');
const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
@@ -12,7 +12,7 @@ for (const test of tests) {
continue;
if (test.origin) {
- const origin = URL.originFor(test.input, test.base);
+ const origin = originFor(test.input, test.base);
// Pass true to origin.toString() to enable unicode serialization.
assert.strictEqual(origin.toString(true), test.origin);
}