2016-11-06 11:54:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WorkletGlobalScope.h"
|
|
|
|
#include "mozilla/dom/WorkletGlobalScopeBinding.h"
|
2016-11-06 11:54:52 +03:00
|
|
|
#include "mozilla/dom/Console.h"
|
2018-01-08 16:05:03 +03:00
|
|
|
#include "mozilla/dom/DOMPrefs.h"
|
2016-11-06 11:54:29 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(WorkletGlobalScope)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WorkletGlobalScope)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2016-11-06 11:54:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsole)
|
2016-11-06 11:54:29 +03:00
|
|
|
tmp->UnlinkHostObjectURIs();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WorkletGlobalScope)
|
2016-11-06 11:54:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsole)
|
2016-11-06 11:54:29 +03:00
|
|
|
tmp->TraverseHostObjectURIs(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(WorkletGlobalScope)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(WorkletGlobalScope)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(WorkletGlobalScope)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WorkletGlobalScope)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
2016-11-06 11:54:52 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(WorkletGlobalScope)
|
2016-11-06 11:54:29 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
WorkletGlobalScope::WorkletGlobalScope(nsPIDOMWindowInner* aWindow)
|
|
|
|
: mWindow(aWindow)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkletGlobalScope::~WorkletGlobalScope()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-06 11:54:29 +03:00
|
|
|
JSObject*
|
|
|
|
WorkletGlobalScope::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("We should never get here!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
already_AddRefed<Console>
|
2018-02-22 10:49:51 +03:00
|
|
|
WorkletGlobalScope::GetConsole(JSContext* aCx, ErrorResult& aRv)
|
2016-11-06 11:54:52 +03:00
|
|
|
{
|
|
|
|
if (!mConsole) {
|
2018-02-22 10:49:51 +03:00
|
|
|
mConsole = Console::Create(aCx, mWindow, aRv);
|
2016-11-06 11:54:52 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
RefPtr<Console> console = mConsole;
|
|
|
|
return console.forget();
|
2016-11-06 11:54:52 +03:00
|
|
|
}
|
|
|
|
|
2016-11-06 11:55:41 +03:00
|
|
|
void
|
|
|
|
WorkletGlobalScope::Dump(const Optional<nsAString>& aString) const
|
|
|
|
{
|
2018-01-08 16:05:03 +03:00
|
|
|
if (!DOMPrefs::DumpEnabled()) {
|
2016-11-06 11:55:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aString.WasPassed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 str(aString.Value());
|
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", str.get());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fputs(str.get(), stdout);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2016-11-06 11:54:29 +03:00
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|