Bug 1224596 part 14. Switch URL to using the new WorkerMainThreadRunnable::Dispatch signature. r=baku

This commit is contained in:
Boris Zbarsky 2015-11-24 00:04:21 -05:00
parent 9b5cdb634a
commit e082980731
5 changed files with 113 additions and 128 deletions

View File

@ -188,18 +188,31 @@ GetRequestURLFromWorker(const GlobalObject& aGlobal, const nsAString& aInput,
}
nsString username;
url->GetUsername(username);
url->GetUsername(username, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
nsString password;
url->GetPassword(password);
url->GetPassword(password, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (!username.IsEmpty() || !password.IsEmpty()) {
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
return;
}
url->SetHash(EmptyString());
url->Stringify(aRequestURL);
url->SetHash(EmptyString(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
url->Stringify(aRequestURL, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
} // namespace

View File

@ -92,7 +92,11 @@ Response::Redirect(const GlobalObject& aGlobal, const nsAString& aUrl,
return nullptr;
}
url->Stringify(parsedURL);
url->Stringify(parsedURL, aRv);
}
if (aRv.Failed()) {
return nullptr;
}
if (aStatus != 301 && aStatus != 302 && aStatus != 303 && aStatus != 307 && aStatus != 308) {

View File

@ -21,21 +21,31 @@ interface URL {
// stringifier attribute USVString href;
// Bug 824857 should remove this.
[Throws=Workers]
stringifier;
[SetterThrows]
[SetterThrows, GetterThrows=Workers]
attribute USVString href;
[Throws=Workers]
readonly attribute USVString origin;
[Throws=Workers]
attribute USVString protocol;
[Throws=Workers]
attribute USVString username;
[Throws=Workers]
attribute USVString password;
[Throws=Workers]
attribute USVString host;
[Throws=Workers]
attribute USVString hostname;
[Throws=Workers]
attribute USVString port;
[Throws=Workers]
attribute USVString pathname;
[Throws=Workers]
attribute USVString search;
readonly attribute URLSearchParams searchParams;
[Throws=Workers]
attribute USVString hash;
};

View File

@ -553,10 +553,7 @@ already_AddRefed<URL>
URL::FinishConstructor(JSContext* aCx, WorkerPrivate* aPrivate,
ConstructorRunnable* aRunnable, ErrorResult& aRv)
{
if (!aRunnable->Dispatch(aCx)) {
JS_ReportPendingException(aCx);
}
aRunnable->Dispatch(aRv);
if (aRv.Failed()) {
return nullptr;
}
@ -600,15 +597,13 @@ URL::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
}
void
URL::GetHref(nsAString& aHref) const
URL::GetHref(nsAString& aHref, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHref, aHref,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
@ -618,8 +613,9 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHref, aHref,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
runnable->Dispatch(aRv);
if (aRv.Failed()) {
return;
}
if (runnable->Failed()) {
@ -631,228 +627,194 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
}
void
URL::GetOrigin(nsAString& aOrigin) const
URL::GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterOrigin, aOrigin,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::GetProtocol(nsAString& aProtocol) const
URL::GetProtocol(nsAString& aProtocol, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterProtocol, aProtocol,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetProtocol(const nsAString& aProtocol)
URL::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterProtocol,
aProtocol, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
void
URL::GetUsername(nsAString& aUsername) const
URL::GetUsername(nsAString& aUsername, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterUsername, aUsername,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetUsername(const nsAString& aUsername)
URL::SetUsername(const nsAString& aUsername, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterUsername,
aUsername, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
void
URL::GetPassword(nsAString& aPassword) const
URL::GetPassword(nsAString& aPassword, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPassword, aPassword,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetPassword(const nsAString& aPassword)
URL::SetPassword(const nsAString& aPassword, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPassword,
aPassword, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
void
URL::GetHost(nsAString& aHost) const
URL::GetHost(nsAString& aHost, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHost, aHost,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetHost(const nsAString& aHost)
URL::SetHost(const nsAString& aHost, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHost,
aHost, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
void
URL::GetHostname(nsAString& aHostname) const
URL::GetHostname(nsAString& aHostname, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHostname, aHostname,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetHostname(const nsAString& aHostname)
URL::SetHostname(const nsAString& aHostname, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHostname,
aHostname, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
void
URL::GetPort(nsAString& aPort) const
URL::GetPort(nsAString& aPort, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPort, aPort,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetPort(const nsAString& aPort)
URL::SetPort(const nsAString& aPort, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPort,
aPort, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
void
URL::GetPathname(nsAString& aPathname) const
URL::GetPathname(nsAString& aPathname, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterPathname, aPathname,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetPathname(const nsAString& aPathname)
URL::SetPathname(const nsAString& aPathname, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterPathname,
aPathname, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
void
URL::GetSearch(nsAString& aSearch) const
URL::GetSearch(nsAString& aSearch, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterSearch, aSearch,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetSearch(const nsAString& aSearch)
URL::SetSearch(const nsAString& aSearch, ErrorResult& aRv)
{
SetSearchInternal(aSearch);
SetSearchInternal(aSearch, aRv);
UpdateURLSearchParams();
}
void
URL::SetSearchInternal(const nsAString& aSearch)
URL::SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterSearch,
aSearch, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
@ -865,27 +827,23 @@ URL::SearchParams()
}
void
URL::GetHash(nsAString& aHash) const
URL::GetHash(nsAString& aHash, ErrorResult& aRv) const
{
RefPtr<GetterRunnable> runnable =
new GetterRunnable(mWorkerPrivate, GetterRunnable::GetterHash, aHash,
mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
}
void
URL::SetHash(const nsAString& aHash)
URL::SetHash(const nsAString& aHash, ErrorResult& aRv)
{
RefPtr<SetterRunnable> runnable =
new SetterRunnable(mWorkerPrivate, SetterRunnable::SetterHash,
aHash, mURLProxy);
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
}
runnable->Dispatch(aRv);
MOZ_ASSERT(!runnable->Failed());
}
@ -910,10 +868,7 @@ URL::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
RefPtr<CreateURLRunnable> runnable =
new CreateURLRunnable(workerPrivate, blobImpl, aOptions, aResult);
if (!runnable->Dispatch(cx)) {
JS_ReportPendingException(cx);
}
runnable->Dispatch(aRv);
if (aRv.Failed()) {
return;
}
@ -937,10 +892,7 @@ URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl,
RefPtr<RevokeURLRunnable> runnable =
new RevokeURLRunnable(workerPrivate, aUrl);
if (!runnable->Dispatch(cx)) {
JS_ReportPendingException(cx);
}
runnable->Dispatch(aRv);
if (aRv.Failed()) {
return;
}
@ -961,7 +913,10 @@ URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
nsAutoString search;
mSearchParams->Serialize(search);
SetSearchInternal(search);
ErrorResult rv;
SetSearchInternal(search, rv);
// XXXbz and now what? We're supposed to stop everything if rv failed!
rv.SuppressException();
}
void
@ -969,7 +924,10 @@ URL::UpdateURLSearchParams()
{
if (mSearchParams) {
nsAutoString search;
GetSearch(search);
ErrorResult rv;
GetSearch(search, rv);
// XXXbz and now what? We're supposed to stop everything if rv failed!
rv.SuppressException();
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)));
}
}

View File

@ -70,53 +70,53 @@ public:
RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl,
ErrorResult& aRv);
void GetHref(nsAString& aHref) const;
void GetHref(nsAString& aHref, ErrorResult& aRv) const;
void SetHref(const nsAString& aHref, ErrorResult& aRv);
void GetOrigin(nsAString& aOrigin) const;
void GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const;
void GetProtocol(nsAString& aProtocol) const;
void GetProtocol(nsAString& aProtocol, ErrorResult& aRv) const;
void SetProtocol(const nsAString& aProtocol);
void SetProtocol(const nsAString& aProtocol, ErrorResult& aRv);
void GetUsername(nsAString& aUsername) const;
void GetUsername(nsAString& aUsername, ErrorResult& aRv) const;
void SetUsername(const nsAString& aUsername);
void SetUsername(const nsAString& aUsername, ErrorResult& aRv);
void GetPassword(nsAString& aPassword) const;
void GetPassword(nsAString& aPassword, ErrorResult& aRv) const;
void SetPassword(const nsAString& aPassword);
void SetPassword(const nsAString& aPassword, ErrorResult& aRv);
void GetHost(nsAString& aHost) const;
void GetHost(nsAString& aHost, ErrorResult& aRv) const;
void SetHost(const nsAString& aHost);
void SetHost(const nsAString& aHost, ErrorResult& aRv);
void GetHostname(nsAString& aHostname) const;
void GetHostname(nsAString& aHostname, ErrorResult& aRv) const;
void SetHostname(const nsAString& aHostname);
void SetHostname(const nsAString& aHostname, ErrorResult& aRv);
void GetPort(nsAString& aPort) const;
void GetPort(nsAString& aPort, ErrorResult& aRv) const;
void SetPort(const nsAString& aPort);
void SetPort(const nsAString& aPort, ErrorResult& aRv);
void GetPathname(nsAString& aPathname) const;
void GetPathname(nsAString& aPathname, ErrorResult& aRv) const;
void SetPathname(const nsAString& aPathname);
void SetPathname(const nsAString& aPathname, ErrorResult& aRv);
void GetSearch(nsAString& aSearch) const;
void GetSearch(nsAString& aSearch, ErrorResult& aRv) const;
void SetSearch(const nsAString& aSearch);
void SetSearch(const nsAString& aSearch, ErrorResult& aRv);
URLSearchParams* SearchParams();
void GetHash(nsAString& aHost) const;
void GetHash(nsAString& aHost, ErrorResult& aRv) const;
void SetHash(const nsAString& aHash);
void SetHash(const nsAString& aHash, ErrorResult& aRv);
void Stringify(nsAString& aRetval) const
void Stringify(nsAString& aRetval, ErrorResult& aRv) const
{
GetHref(aRetval);
GetHref(aRetval, aRv);
}
// IURLSearchParamsObserver
@ -134,7 +134,7 @@ private:
void CreateSearchParamsIfNeeded();
void SetSearchInternal(const nsAString& aSearch);
void SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv);
void UpdateURLSearchParams();