Skip to content

Commit

Permalink
Implement URL.prototype.toJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Feb 13, 2017
1 parent 79589fb commit 077dc19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/URL-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,8 @@ exports.implementation = class URLImpl {
this._url.fragment = "";
usm.basicURLParse(input, { url: this._url, stateOverride: "fragment" });
}

toJSON() {
return this.href;
}
};
4 changes: 3 additions & 1 deletion src/URL.idl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ interface URL {
attribute USVString search;
// [SameObject] readonly attribute URLSearchParams searchParams;
attribute USVString hash;
};

USVString toJSON();
};
9 changes: 9 additions & 0 deletions test/to-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
const assert = require("assert");
const URL = require("..").URL;

specify("toJSON() works as expected", () => {
const u = new URL("/", "https://developer.mozilla.org");
assert.strictEqual(u.toJSON(), "https://developer.mozilla.org/");
assert.strictEqual(JSON.stringify(u), "\"https://developer.mozilla.org/\"");
});

0 comments on commit 077dc19

Please sign in to comment.