Skip to content

Commit

Permalink
Bug 1328964 - part 2 - WorkletThread r=baku
Browse files Browse the repository at this point in the history
Initial version r=smaug.
Rebased to c616a6fd5e4b by Jan-Ivar Bruaroey <[email protected]> r=karlt.
Rebased to 83de58ddda20 by Karl Tomlinson <[email protected]> r=baku.

MozReview-Commit-ID: Lo8TWtN8qyz
  • Loading branch information
bakulf committed Apr 12, 2018
1 parent cce2516 commit 98e6f93
Show file tree
Hide file tree
Showing 15 changed files with 867 additions and 83 deletions.
4 changes: 4 additions & 0 deletions caps/nsJSPrincipals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "mozilla/dom/StructuredCloneTags.h"
// for mozilla::dom::workerinternals::kJSPrincipalsDebugToken
#include "mozilla/dom/workerinternals/JSSettings.h"
// for mozilla::dom::worklet::kJSPrincipalsDebugToken
#include "mozilla/dom/WorkletPrincipal.h"
#include "mozilla/ipc/BackgroundUtils.h"

using namespace mozilla;
Expand Down Expand Up @@ -92,6 +94,8 @@ JSPrincipals::dump()
NS_SUCCEEDED(rv) ? str.get() : "(unknown)");
} else if (debugToken == dom::workerinternals::kJSPrincipalsDebugToken) {
fprintf(stderr, "Web Worker principal singleton (%p)\n", this);
} else if (debugToken == mozilla::dom::WorkletPrincipal::kJSPrincipalsDebugToken) {
fprintf(stderr, "Web Worklet principal singleton (%p)\n", this);
} else {
fprintf(stderr,
"!!! JSPrincipals (%p) is not nsJSPrincipals instance - bad token: "
Expand Down
6 changes: 6 additions & 0 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/XULCommandEvent.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkletThread.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStateManager.h"
Expand Down Expand Up @@ -6083,6 +6084,11 @@ nsContentUtils::GetCurrentJSContextForThread()
if (MOZ_LIKELY(NS_IsMainThread())) {
return GetCurrentJSContext();
}

if (WorkletThread::IsOnWorkletThread()) {
return WorkletThread::Get()->GetJSContext();
}

return GetCurrentWorkerThreadJSContext();
}

Expand Down
18 changes: 9 additions & 9 deletions dom/console/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/dom/WorkerScope.h"
#include "mozilla/dom/WorkletGlobalScope.h"
#include "mozilla/dom/WorkletThread.h"
#include "mozilla/Maybe.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDocument.h"
Expand Down Expand Up @@ -2421,15 +2422,6 @@ Console::GetConsole(const GlobalObject& aGlobal)
/* static */ already_AddRefed<Console>
Console::GetConsoleInternal(const GlobalObject& aGlobal, ErrorResult& aRv)
{
// Worklet
if (NS_IsMainThread()) {
nsCOMPtr<WorkletGlobalScope> workletScope =
do_QueryInterface(aGlobal.GetAsSupports());
if (workletScope) {
return workletScope->GetConsole(aGlobal.Context(), aRv);
}
}

// Window
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindowInner> innerWindow =
Expand All @@ -2450,6 +2442,14 @@ Console::GetConsoleInternal(const GlobalObject& aGlobal, ErrorResult& aRv)
return window->GetConsole(aGlobal.Context(), aRv);
}

// Worklet
nsCOMPtr<WorkletGlobalScope> workletScope =
do_QueryInterface(aGlobal.GetAsSupports());
if (workletScope) {
WorkletThread::AssertIsOnWorkletThread();
return workletScope->GetConsole(aGlobal.Context(), aRv);
}

// Workers
MOZ_ASSERT(!NS_IsMainThread());

Expand Down
4 changes: 2 additions & 2 deletions dom/worklet/AudioWorkletGlobalScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "AudioWorkletGlobalScope.h"
#include "WorkletPrincipal.h"
#include "mozilla/dom/AudioWorkletGlobalScopeBinding.h"
#include "mozilla/dom/FunctionBinding.h"

Expand All @@ -17,13 +18,12 @@ AudioWorkletGlobalScope::AudioWorkletGlobalScope()

bool
AudioWorkletGlobalScope::WrapGlobalObject(JSContext* aCx,
nsIPrincipal* aPrincipal,
JS::MutableHandle<JSObject*> aReflector)
{
JS::CompartmentOptions options;
return AudioWorkletGlobalScopeBinding::Wrap(aCx, this, this,
options,
nsJSPrincipals::get(aPrincipal),
WorkletPrincipal::GetWorkletPrincipal(),
true, aReflector);
}

Expand Down
2 changes: 1 addition & 1 deletion dom/worklet/AudioWorkletGlobalScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AudioWorkletGlobalScope final : public WorkletGlobalScope
AudioWorkletGlobalScope();

bool
WrapGlobalObject(JSContext* aCx, nsIPrincipal* aPrincipal,
WrapGlobalObject(JSContext* aCx,
JS::MutableHandle<JSObject*> aReflector) override;

void
Expand Down
4 changes: 2 additions & 2 deletions dom/worklet/PaintWorkletGlobalScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "PaintWorkletGlobalScope.h"
#include "WorkletPrincipal.h"
#include "mozilla/dom/PaintWorkletGlobalScopeBinding.h"
#include "mozilla/dom/FunctionBinding.h"

Expand All @@ -17,13 +18,12 @@ PaintWorkletGlobalScope::PaintWorkletGlobalScope()

bool
PaintWorkletGlobalScope::WrapGlobalObject(JSContext* aCx,
nsIPrincipal* aPrincipal,
JS::MutableHandle<JSObject*> aReflector)
{
JS::CompartmentOptions options;
return PaintWorkletGlobalScopeBinding::Wrap(aCx, this, this,
options,
nsJSPrincipals::get(aPrincipal),
WorkletPrincipal::GetWorkletPrincipal(),
true, aReflector);
}

Expand Down
2 changes: 1 addition & 1 deletion dom/worklet/PaintWorkletGlobalScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PaintWorkletGlobalScope final : public WorkletGlobalScope
PaintWorkletGlobalScope();

bool
WrapGlobalObject(JSContext* aCx, nsIPrincipal* aPrincipal,
WrapGlobalObject(JSContext* aCx,
JS::MutableHandle<JSObject*> aReflector) override;

void
Expand Down
Loading

0 comments on commit 98e6f93

Please sign in to comment.