1 /* eslint-env worker */
4 dump("OK: " + !!a
+ " => " + a
+ " " + msg
+ "\n");
5 postMessage({ type
: "status", status
: !!a
, msg
: a
+ ": " + msg
});
8 function is(a
, b
, msg
) {
9 dump("IS: " + (a
=== b
) + " => " + a
+ " | " + b
+ " " + msg
+ "\n");
13 msg
: a
+ " === " + b
+ ": " + msg
,
17 // eslint-disable-next-line complexity
18 onmessage = function () {
21 if (URL
instanceof Object
) {
26 ok(status
, "URL in workers \\o/");
30 url
: "http://www.abc.com",
33 href
: "http://www.abc.com/",
34 origin
: "http://www.abc.com",
39 hostname
: "www.abc.com",
46 url
: "ftp://auser:apw@www.abc.com",
49 href
: "ftp://auser:apw@www.abc.com/",
50 origin
: "ftp://www.abc.com",
55 hostname
: "www.abc.com",
62 url
: "http://www.abc.com:90/apath/",
65 href
: "http://www.abc.com:90/apath/",
66 origin
: "http://www.abc.com:90",
70 host
: "www.abc.com:90",
71 hostname
: "www.abc.com",
78 url
: "http://www.abc.com/apath/afile.txt#ahash",
81 href
: "http://www.abc.com/apath/afile.txt#ahash",
82 origin
: "http://www.abc.com",
87 hostname
: "www.abc.com",
89 pathname
: "/apath/afile.txt",
94 url
: "http://example.com/?test#hash",
97 href
: "http://example.com/?test#hash",
98 origin
: "http://example.com",
103 hostname
: "example.com",
110 url
: "http://example.com/?test",
113 href
: "http://example.com/?test",
114 origin
: "http://example.com",
119 hostname
: "example.com",
126 url
: "http://example.com/carrot#question%3f",
129 hash
: "#question%3f",
132 url
: "https://example.com:4443?",
142 url
: "http://www.abc.com/apath/afile.txt#ahash?asearch",
145 href
: "http://www.abc.com/apath/afile.txt#ahash?asearch",
147 pathname
: "/apath/afile.txt",
148 hash
: "#ahash?asearch",
152 url
: "http://www.abc.com/apath/afile.txt?asearch#ahash",
155 href
: "http://www.abc.com/apath/afile.txt?asearch#ahash",
157 pathname
: "/apath/afile.txt",
162 url
: "http://abc.com/apath/afile.txt?#ahash",
165 pathname
: "/apath/afile.txt",
170 url
: "http://auser:apassword@www.abc.com:90/apath/afile.txt?asearch#ahash",
175 password
: "apassword",
176 host
: "www.abc.com:90",
177 hostname
: "www.abc.com",
179 pathname
: "/apath/afile.txt",
182 origin
: "http://www.abc.com:90",
185 { url
: "/foo#bar", base
: "www.test.org", error
: true },
186 { url
: "/foo#bar", base
: null, error
: true },
187 { url
: "/foo#bar", base
: 42, error
: true },
189 url
: "ftp://ftp.something.net",
195 url
: "file:///tmp/file",
201 url
: "gopher://gopher.something.net",
205 expectedChangedProtocol
: "https:",
208 url
: "ws://ws.something.net",
214 url
: "wss://ws.something.net",
220 url
: "foo://foo.something.net",
224 expectedChangedProtocol
: "https:",
228 while (tests
.length
) {
229 var test
= tests
.shift();
235 url
= new URL(test
.url
, test
.base
);
237 url
= new URL(test
.url
);
243 is(test
.error
, error
, "Error creating URL");
248 if ("href" in test
) {
249 is(url
.href
, test
.href
, "href");
251 if ("origin" in test
) {
252 is(url
.origin
, test
.origin
, "origin");
254 if ("protocol" in test
) {
255 is(url
.protocol
, test
.protocol
, "protocol");
257 if ("username" in test
) {
258 is(url
.username
, test
.username
, "username");
260 if ("password" in test
) {
261 is(url
.password
, test
.password
, "password");
263 if ("host" in test
) {
264 is(url
.host
, test
.host
, "host");
266 if ("hostname" in test
) {
267 is(url
.hostname
, test
.hostname
, "hostname");
269 if ("port" in test
) {
270 is(url
.port
, test
.port
, "port");
272 if ("pathname" in test
) {
273 is(url
.pathname
, test
.pathname
, "pathname");
275 if ("search" in test
) {
276 is(url
.search
, test
.search
, "search");
278 if ("hash" in test
) {
279 is(url
.hash
, test
.hash
, "hash");
282 url
= new URL("https://www.example.net/what#foo?bar");
283 ok(url
, "Url exists!");
285 if ("href" in test
) {
286 url
.href
= test
.href
;
288 if ("protocol" in test
) {
289 url
.protocol
= test
.protocol
;
291 if ("username" in test
&& test
.username
) {
292 url
.username
= test
.username
;
294 if ("password" in test
&& test
.password
) {
295 url
.password
= test
.password
;
297 if ("host" in test
) {
298 url
.host
= test
.host
;
300 if ("hostname" in test
) {
301 url
.hostname
= test
.hostname
;
303 if ("port" in test
) {
304 url
.port
= test
.port
;
306 if ("pathname" in test
) {
307 url
.pathname
= test
.pathname
;
309 if ("search" in test
) {
310 url
.search
= test
.search
;
312 if ("hash" in test
) {
313 url
.hash
= test
.hash
;
316 if ("href" in test
) {
317 is(url
.href
, test
.href
, "href");
319 if ("origin" in test
) {
320 is(url
.origin
, test
.origin
, "origin");
322 if ("expectedChangedProtocol" in test
) {
323 is(url
.protocol
, test
.expectedChangedProtocol
, "protocol");
324 } else if ("protocol" in test
) {
325 is(url
.protocol
, test
.protocol
, "protocol");
327 if ("username" in test
) {
328 is(url
.username
, test
.username
, "username");
330 if ("password" in test
) {
331 is(url
.password
, test
.password
, "password");
333 if ("host" in test
) {
334 is(url
.host
, test
.host
, "host");
336 if ("hostname" in test
) {
337 is(test
.hostname
, url
.hostname
, "hostname");
339 if ("port" in test
) {
340 is(test
.port
, url
.port
, "port");
342 if ("pathname" in test
) {
343 is(test
.pathname
, url
.pathname
, "pathname");
345 if ("search" in test
) {
346 is(test
.search
, url
.search
, "search");
348 if ("hash" in test
) {
349 is(test
.hash
, url
.hash
, "hash");
352 if ("href" in test
) {
353 is(test
.href
, url
+ "", "stringify works");
357 postMessage({ type
: "finish" });