зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1276887 - webidl "Deprecated" keyword should work in workers, r=smaug
This commit is contained in:
Родитель
d3ee2f3f49
Коммит
e004a6613e
|
@ -26,6 +26,8 @@
|
||||||
#include "nsIPrincipal.h"
|
#include "nsIPrincipal.h"
|
||||||
#include "nsIXPConnect.h"
|
#include "nsIXPConnect.h"
|
||||||
#include "nsUTF8Utils.h"
|
#include "nsUTF8Utils.h"
|
||||||
|
#include "WorkerPrivate.h"
|
||||||
|
#include "WorkerRunnable.h"
|
||||||
#include "WrapperFactory.h"
|
#include "WrapperFactory.h"
|
||||||
#include "xpcprivate.h"
|
#include "xpcprivate.h"
|
||||||
#include "XrayWrapper.h"
|
#include "XrayWrapper.h"
|
||||||
|
@ -56,6 +58,8 @@
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
|
using namespace workers;
|
||||||
|
|
||||||
const JSErrorFormatString ErrorFormatString[] = {
|
const JSErrorFormatString ErrorFormatString[] = {
|
||||||
#define MSG_DEF(_name, _argc, _exn, _str) \
|
#define MSG_DEF(_name, _argc, _exn, _str) \
|
||||||
{ #_name, _str, _argc, _exn },
|
{ #_name, _str, _argc, _exn },
|
||||||
|
@ -2501,7 +2505,6 @@ ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
|
||||||
bool
|
bool
|
||||||
IsInPrivilegedApp(JSContext* aCx, JSObject* aObj)
|
IsInPrivilegedApp(JSContext* aCx, JSObject* aObj)
|
||||||
{
|
{
|
||||||
using mozilla::dom::workers::GetWorkerPrivateFromContext;
|
|
||||||
if (!NS_IsMainThread()) {
|
if (!NS_IsMainThread()) {
|
||||||
return GetWorkerPrivateFromContext(aCx)->IsInPrivilegedApp();
|
return GetWorkerPrivateFromContext(aCx)->IsInPrivilegedApp();
|
||||||
}
|
}
|
||||||
|
@ -2516,7 +2519,6 @@ IsInPrivilegedApp(JSContext* aCx, JSObject* aObj)
|
||||||
bool
|
bool
|
||||||
IsInCertifiedApp(JSContext* aCx, JSObject* aObj)
|
IsInCertifiedApp(JSContext* aCx, JSObject* aObj)
|
||||||
{
|
{
|
||||||
using mozilla::dom::workers::GetWorkerPrivateFromContext;
|
|
||||||
if (!NS_IsMainThread()) {
|
if (!NS_IsMainThread()) {
|
||||||
return GetWorkerPrivateFromContext(aCx)->IsInCertifiedApp();
|
return GetWorkerPrivateFromContext(aCx)->IsInCertifiedApp();
|
||||||
}
|
}
|
||||||
|
@ -3285,6 +3287,114 @@ SetDocumentAndPageUseCounter(JSContext* aCx, JSObject* aObject,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// This runnable is used to write a deprecation message from a worker to the
|
||||||
|
// console running on the main-thread.
|
||||||
|
class DeprecationWarningRunnable final : public Runnable
|
||||||
|
, public WorkerFeature
|
||||||
|
{
|
||||||
|
WorkerPrivate* mWorkerPrivate;
|
||||||
|
nsIDocument::DeprecatedOperations mOperation;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DeprecationWarningRunnable(WorkerPrivate* aWorkerPrivate,
|
||||||
|
nsIDocument::DeprecatedOperations aOperation)
|
||||||
|
: mWorkerPrivate(aWorkerPrivate)
|
||||||
|
, mOperation(aOperation)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aWorkerPrivate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Dispatch()
|
||||||
|
{
|
||||||
|
if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(this)))) {
|
||||||
|
mWorkerPrivate->RemoveFeature(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool
|
||||||
|
Notify(Status aStatus) override
|
||||||
|
{
|
||||||
|
// We don't care about the notification. We just want to keep the
|
||||||
|
// mWorkerPrivate alive.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
NS_IMETHOD
|
||||||
|
Run() override
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
// Walk up to our containing page
|
||||||
|
WorkerPrivate* wp = mWorkerPrivate;
|
||||||
|
while (wp->GetParent()) {
|
||||||
|
wp = wp->GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsPIDOMWindowInner* window = wp->GetWindow();
|
||||||
|
if (window && window->GetExtantDoc()) {
|
||||||
|
window->GetExtantDoc()->WarnOnceAbout(mOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReleaseWorker();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ReleaseWorker()
|
||||||
|
{
|
||||||
|
class ReleaseRunnable final : public WorkerRunnable
|
||||||
|
{
|
||||||
|
RefPtr<DeprecationWarningRunnable> mRunnable;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ReleaseRunnable(WorkerPrivate* aWorkerPrivate,
|
||||||
|
DeprecationWarningRunnable* aRunnable)
|
||||||
|
: WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
|
||||||
|
, mRunnable(aRunnable)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual bool
|
||||||
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aWorkerPrivate);
|
||||||
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||||
|
|
||||||
|
aWorkerPrivate->RemoveFeature(mRunnable);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool
|
||||||
|
PreDispatch(WorkerPrivate* aWorkerPrivate) override
|
||||||
|
{
|
||||||
|
AssertIsOnMainThread();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
PostDispatch(WorkerPrivate* aWorkerPrivate,
|
||||||
|
bool aDispatchResult) override
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RefPtr<ReleaseRunnable> runnable =
|
||||||
|
new ReleaseRunnable(mWorkerPrivate, this);
|
||||||
|
NS_WARN_IF(!runnable->Dispatch());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
void
|
void
|
||||||
DeprecationWarning(JSContext* aCx, JSObject* aObject,
|
DeprecationWarning(JSContext* aCx, JSObject* aObject,
|
||||||
nsIDocument::DeprecatedOperations aOperation)
|
nsIDocument::DeprecatedOperations aOperation)
|
||||||
|
@ -3295,10 +3405,23 @@ DeprecationWarning(JSContext* aCx, JSObject* aObject,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global.GetAsSupports());
|
if (NS_IsMainThread()) {
|
||||||
if (window && window->GetExtantDoc()) {
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global.GetAsSupports());
|
||||||
window->GetExtantDoc()->WarnOnceAbout(aOperation);
|
if (window && window->GetExtantDoc()) {
|
||||||
|
window->GetExtantDoc()->WarnOnceAbout(aOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||||
|
if (!workerPrivate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<DeprecationWarningRunnable> runnable =
|
||||||
|
new DeprecationWarningRunnable(workerPrivate, aOperation);
|
||||||
|
runnable->Dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace binding_detail {
|
namespace binding_detail {
|
||||||
|
@ -3309,7 +3432,7 @@ UnprivilegedJunkScopeOrWorkerGlobal()
|
||||||
return xpc::UnprivilegedJunkScope();
|
return xpc::UnprivilegedJunkScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
return workers::GetCurrentThreadWorkerGlobal();
|
return GetCurrentThreadWorkerGlobal();
|
||||||
}
|
}
|
||||||
} // namespace binding_detail
|
} // namespace binding_detail
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ GetCurrentJSStack(int32_t aMaxDepth)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return exceptions::CreateStack(cx, aMaxDepth);
|
return dom::exceptions::CreateStack(cx, aMaxDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoForceSetExceptionOnContext::AutoForceSetExceptionOnContext(JSContext* aCx)
|
AutoForceSetExceptionOnContext::AutoForceSetExceptionOnContext(JSContext* aCx)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче