mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 926890 - Throw JavaScript exceptions for URL, r=ehsan
This commit is contained in:
parent
d2181e5021
commit
f1f2c23069
@ -46,7 +46,7 @@ URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
|
||||
rv = ioService->NewURI(NS_ConvertUTF16toUTF8(aUrl), nullptr, aBase.GetURI(),
|
||||
getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
|
||||
rv = ioService->NewURI(NS_ConvertUTF16toUTF8(aBase), nullptr, nullptr,
|
||||
getter_AddRefs(baseUri));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
|
||||
rv = ioService->NewURI(NS_ConvertUTF16toUTF8(aUrl), nullptr, baseUri,
|
||||
getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -191,7 +191,23 @@ URL::GetHref(nsString& aHref) const
|
||||
void
|
||||
URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
||||
{
|
||||
aRv = mURI->SetSpec(NS_ConvertUTF16toUTF8(aHref));
|
||||
nsCString href = NS_ConvertUTF16toUTF8(aHref);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = ioService->NewURI(href, nullptr, nullptr, getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
aRv = mURI->SetSpec(href);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -35,3 +35,4 @@ support-files =
|
||||
[test_window_extensible.html]
|
||||
[test_window_indexing.html]
|
||||
[test_writable-replaceable.html]
|
||||
[test_urlExceptions.html]
|
||||
|
57
dom/base/test/test_urlExceptions.html
Normal file
57
dom/base/test/test_urlExceptions.html
Normal file
@ -0,0 +1,57 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=926890
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 926890</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=926890">Mozilla Bug 926890</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
<iframe name="x" id="x"></iframe>
|
||||
<iframe name="y" id="y"></iframe>
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<script type="application/javascript">
|
||||
|
||||
// URL.href throws
|
||||
var url = new URL('http://www.example.com');
|
||||
ok(url, "URL created");
|
||||
|
||||
var status = false;
|
||||
try {
|
||||
url.href = '42';
|
||||
} catch(e) {
|
||||
status = true;
|
||||
}
|
||||
ok(status, "url.href = 42 should throw");
|
||||
|
||||
url.href = 'http://www.example.org';
|
||||
ok(true, "url.href should not throw");
|
||||
|
||||
status = false
|
||||
try {
|
||||
new URL('42');
|
||||
} catch(e) {
|
||||
status = true;
|
||||
}
|
||||
ok(status, "new URL(42) should throw");
|
||||
|
||||
status = false
|
||||
try {
|
||||
new URL('http://www.example.com', '42');
|
||||
} catch(e) {
|
||||
status = true;
|
||||
}
|
||||
ok(status, "new URL(something, 42) should throw");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -53,6 +53,7 @@ support-files =
|
||||
xhrAbort_worker.js
|
||||
xhr_implicit_cancel_worker.js
|
||||
xhr_worker.js
|
||||
url_exceptions_worker.js
|
||||
|
||||
[test_404.html]
|
||||
[test_atob.html]
|
||||
@ -107,3 +108,4 @@ support-files =
|
||||
[test_xhr_parameters.js]
|
||||
[test_xhr_system.html]
|
||||
[test_xhr_system.js]
|
||||
[test_url_exceptions.html]
|
||||
|
44
dom/workers/test/test_url_exceptions.html
Normal file
44
dom/workers/test/test_url_exceptions.html
Normal file
@ -0,0 +1,44 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for URL exceptions in workers</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
var worker = new Worker("url_exceptions_worker.js");
|
||||
|
||||
worker.onmessage = function(event) {
|
||||
is(event.target, worker);
|
||||
|
||||
if (event.data.type == 'finish') {
|
||||
SimpleTest.finish();
|
||||
} else if (event.data.type == 'status') {
|
||||
ok(event.data.status, event.data.msg);
|
||||
}
|
||||
};
|
||||
|
||||
worker.onerror = function(event) {
|
||||
is(event.target, worker);
|
||||
ok(false, "Worker had an error: " + event.data);
|
||||
SimpleTest.finish();
|
||||
};
|
||||
|
||||
worker.postMessage(0);
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
38
dom/workers/test/url_exceptions_worker.js
Normal file
38
dom/workers/test/url_exceptions_worker.js
Normal file
@ -0,0 +1,38 @@
|
||||
function ok(a, msg) {
|
||||
postMessage({type: 'status', status: !!a, msg: msg });
|
||||
}
|
||||
|
||||
onmessage = function(event) {
|
||||
// URL.href throws
|
||||
var url = new URL('http://www.example.com');
|
||||
ok(url, "URL created");
|
||||
|
||||
var status = false;
|
||||
try {
|
||||
url.href = '42';
|
||||
} catch(e) {
|
||||
status = true;
|
||||
}
|
||||
ok(status, "url.href = 42 should throw");
|
||||
|
||||
url.href = 'http://www.example.org';
|
||||
ok(true, "url.href should not throw");
|
||||
|
||||
status = false
|
||||
try {
|
||||
new URL('42');
|
||||
} catch(e) {
|
||||
status = true;
|
||||
}
|
||||
ok(status, "new URL(42) should throw");
|
||||
|
||||
status = false
|
||||
try {
|
||||
new URL('http://www.example.com', '42');
|
||||
} catch(e) {
|
||||
status = true;
|
||||
}
|
||||
ok(status, "new URL(something, 42) should throw");
|
||||
|
||||
postMessage({type: 'finish' });
|
||||
}
|
Loading…
Reference in New Issue
Block a user