Skip to content

Commit

Permalink
revert #59
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Sep 23, 2024
1 parent 7e9aa5d commit a00bfcc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions polyfills/URL/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ notes = [ ]
license = "CC0-1.0"
repo = "https://github.com/inexorabletash/polyfill"
docs = "https://developer.mozilla.org/en-US/docs/Web/API/URL"
spec = "https://url.spec.whatwg.org/#url"

[browsers]
android = "*"
Expand Down
14 changes: 12 additions & 2 deletions polyfills/URL/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,15 @@
return anchor;
}

function URLSearchParams(init) {
function URLSearchParams() {
var $this = this;
this._list = [];

var init;
if (arguments.length > 0) {
init = arguments[0];
}

if (init === undefined || init === null) {
// no-op
} else if (init instanceof URLSearchParams) {
Expand Down Expand Up @@ -366,7 +371,12 @@
writable: true, enumerable: true, configurable: true});
}

function URL(url, base) {
function URL(url) {
var base;
if (arguments.length > 1) {
base = arguments[1];
}

if (!(this instanceof global.URL))
throw new TypeError("Failed to construct 'URL': Please use the 'new' operator.");

Expand Down
45 changes: 44 additions & 1 deletion polyfills/URL/polyfill.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
it('URL IDL', function() {
it("has correct arity", function () {
proclaim.arity(URL, 1);
proclaim.arity(URLSearchParams, 0);
});
it("has correct instance", function () {
proclaim.isInstanceOf(new URL("http://hello"), URL);
proclaim.isInstanceOf(new URLSearchParams(), URLSearchParams);
});
it("has correct name", function () {
proclaim.hasName(URL, "URL");
proclaim.hasName(URLSearchParams, "URLSearchParams");
});

it('URL IDL', function () {
var url = new URL('http://example.com:8080/foo/bar?a=1&b=2#p1');
proclaim.equal(typeof url.protocol, 'string', 'protocol');
proclaim.equal(typeof url.host, 'string', 'host');
Expand Down Expand Up @@ -195,6 +208,36 @@ it('Base URL', function () {
proclaim.equal(new URL('#cd', 'https://example.org/foo').href, 'https://example.org/foo#cd');
});

it("Invalid URL inputs", function () {
proclaim.throws(function () {
new URL();
}, TypeError);

proclaim.throws(function () {
new URL();
}, 'Failed to construct \'URL\': Invalid URL');

proclaim.throws(function () {
new URL("");
}, 'Failed to construct \'URL\': Invalid URL');

proclaim.throws(function () {
new URL("/there");
}, 'Failed to construct \'URL\': Invalid URL');

proclaim.throws(function () {
new URL("invalid");
}, 'Failed to construct \'URL\': Invalid URL');

proclaim.throws(function () {
new URL({
toString: function () {
throw new Error();
}
});
});
});

it('URLSearchParams', function () {
var url = new URL('http://example.com?a=1&b=2');
proclaim.ok(url.searchParams instanceof URLSearchParams);
Expand Down

0 comments on commit a00bfcc

Please sign in to comment.