2015-05-03 22:32:37 +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: */
|
2014-02-28 03:39:00 +04:00
|
|
|
/* 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 "mozilla/dom/Console.h"
|
2018-01-04 21:19:43 +03:00
|
|
|
#include "mozilla/dom/ConsoleInstance.h"
|
2014-02-28 03:39:00 +04:00
|
|
|
#include "mozilla/dom/ConsoleBinding.h"
|
2018-01-11 00:06:37 +03:00
|
|
|
#include "ConsoleCommon.h"
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2015-02-02 18:40:15 +03:00
|
|
|
#include "mozilla/dom/BlobBinding.h"
|
2014-02-28 03:39:00 +04:00
|
|
|
#include "mozilla/dom/Exceptions.h"
|
2015-02-02 18:40:15 +03:00
|
|
|
#include "mozilla/dom/File.h"
|
2016-03-24 00:55:07 +03:00
|
|
|
#include "mozilla/dom/FunctionBinding.h"
|
2016-06-09 20:04:42 +03:00
|
|
|
#include "mozilla/dom/Performance.h"
|
2017-05-08 09:24:22 +03:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2015-09-30 15:22:08 +03:00
|
|
|
#include "mozilla/dom/StructuredCloneHolder.h"
|
2014-04-16 06:58:44 +04:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2018-01-31 10:25:30 +03:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
|
|
|
#include "mozilla/dom/WorkerRunnable.h"
|
|
|
|
#include "mozilla/dom/WorkerScope.h"
|
2016-11-06 11:54:52 +03:00
|
|
|
#include "mozilla/dom/WorkletGlobalScope.h"
|
2014-04-16 06:58:44 +04:00
|
|
|
#include "mozilla/Maybe.h"
|
2014-02-28 03:39:00 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDocument.h"
|
|
|
|
#include "nsDOMNavigationTiming.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsJSUtils.h"
|
2015-09-14 22:38:57 +03:00
|
|
|
#include "nsNetUtil.h"
|
2016-08-04 21:35:13 +03:00
|
|
|
#include "xpcpublic.h"
|
2014-04-16 06:58:44 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-10-23 01:51:00 +04:00
|
|
|
#include "nsDocShell.h"
|
2015-04-03 22:37:52 +03:00
|
|
|
#include "nsProxyRelease.h"
|
2015-08-31 15:56:37 +03:00
|
|
|
#include "mozilla/ConsoleTimelineMarker.h"
|
|
|
|
#include "mozilla/TimestampTimelineMarker.h"
|
2014-02-28 03:39:00 +04:00
|
|
|
|
|
|
|
#include "nsIConsoleAPIStorage.h"
|
|
|
|
#include "nsIDOMWindowUtils.h"
|
2018-02-06 00:34:05 +03:00
|
|
|
#include "nsIException.h" // for nsIStackFrame
|
2014-02-28 03:39:00 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsILoadContext.h"
|
2015-09-14 22:38:57 +03:00
|
|
|
#include "nsISensitiveInfoHiddenURI.h"
|
2014-02-28 03:39:00 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2015-01-06 18:45:00 +03:00
|
|
|
#include "nsIXPConnect.h"
|
2014-02-28 03:39:00 +04:00
|
|
|
|
|
|
|
// The maximum allowed number of concurrent timers per page.
|
|
|
|
#define MAX_PAGE_TIMERS 10000
|
|
|
|
|
2014-02-28 03:39:24 +04:00
|
|
|
// The maximum allowed number of concurrent counters per page.
|
|
|
|
#define MAX_PAGE_COUNTERS 10000
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
// The maximum stacktrace depth when populating the stacktrace array used for
|
|
|
|
// console.trace().
|
|
|
|
#define DEFAULT_MAX_STACKTRACE_DEPTH 200
|
|
|
|
|
2015-02-02 18:40:15 +03:00
|
|
|
// This tags are used in the Structured Clone Algorithm to move js values from
|
2014-02-28 03:39:30 +04:00
|
|
|
// worker thread to main thread
|
2015-02-05 21:50:43 +03:00
|
|
|
#define CONSOLE_TAG_BLOB JS_SCTAG_USER_MIN
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
// This value is taken from ConsoleAPIStorage.js
|
2016-04-19 15:10:15 +03:00
|
|
|
#define STORAGE_MAX_EVENTS 1000
|
2016-03-24 00:55:07 +03:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
using namespace mozilla::dom::exceptions;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-02-02 18:40:15 +03:00
|
|
|
struct
|
|
|
|
ConsoleStructuredCloneData
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<BlobImpl>> mBlobs;
|
2015-02-02 18:40:15 +03:00
|
|
|
};
|
|
|
|
|
2014-02-28 03:39:30 +04:00
|
|
|
/**
|
|
|
|
* Console API in workers uses the Structured Clone Algorithm to move any value
|
|
|
|
* from the worker thread to the main-thread. Some object cannot be moved and,
|
|
|
|
* in these cases, we convert them to strings.
|
|
|
|
* It's not the best, but at least we are able to show something.
|
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ConsoleCallData final
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-02-07 13:29:12 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(ConsoleCallData)
|
2015-04-03 22:37:52 +03:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
ConsoleCallData()
|
|
|
|
: mMethodName(Console::MethodLog)
|
2014-05-12 21:03:55 +04:00
|
|
|
, mTimeStamp(JS_Now() / PR_USEC_PER_MSEC)
|
2016-02-11 20:09:22 +03:00
|
|
|
, mStartTimerValue(0)
|
2017-05-12 00:36:09 +03:00
|
|
|
, mStartTimerStatus(Console::eTimerUnknown)
|
2016-02-11 20:09:22 +03:00
|
|
|
, mStopTimerDuration(0)
|
2017-05-12 00:36:12 +03:00
|
|
|
, mStopTimerStatus(Console::eTimerUnknown)
|
2016-02-11 20:09:22 +03:00
|
|
|
, mCountValue(MAX_PAGE_COUNTERS)
|
2015-01-06 18:45:00 +03:00
|
|
|
, mIDType(eUnknown)
|
|
|
|
, mOuterIDNumber(0)
|
|
|
|
, mInnerIDNumber(0)
|
2016-04-25 08:53:49 +03:00
|
|
|
, mStatus(eUnused)
|
2016-03-24 00:55:07 +03:00
|
|
|
{}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
bool
|
2014-04-17 00:51:07 +04:00
|
|
|
Initialize(JSContext* aCx, Console::MethodName aName,
|
2016-02-07 13:29:12 +03:00
|
|
|
const nsAString& aString,
|
|
|
|
const Sequence<JS::Value>& aArguments,
|
|
|
|
Console* aConsole)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2016-02-07 13:29:12 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aConsole);
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
// We must be registered before doing any JS operation otherwise it can
|
|
|
|
// happen that mCopiedArguments are not correctly traced.
|
|
|
|
aConsole->StoreCallData(this);
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
mMethodName = aName;
|
|
|
|
mMethodString = aString;
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
mGlobal = JS::CurrentGlobalOrNull(aCx);
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
for (uint32_t i = 0; i < aArguments.Length(); ++i) {
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!mCopiedArguments.AppendElement(aArguments[i]))) {
|
2016-03-24 00:55:07 +03:00
|
|
|
aConsole->UnstoreCallData(this);
|
2016-03-24 00:55:07 +03:00
|
|
|
return false;
|
2015-05-25 14:50:15 +03:00
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
2016-03-24 00:55:07 +03:00
|
|
|
|
|
|
|
return true;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
void
|
|
|
|
SetIDs(uint64_t aOuterID, uint64_t aInnerID)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIDType == eUnknown);
|
|
|
|
|
|
|
|
mOuterIDNumber = aOuterID;
|
|
|
|
mInnerIDNumber = aInnerID;
|
|
|
|
mIDType = eNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetIDs(const nsAString& aOuterID, const nsAString& aInnerID)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIDType == eUnknown);
|
|
|
|
|
|
|
|
mOuterIDString = aOuterID;
|
|
|
|
mInnerIDString = aInnerID;
|
|
|
|
mIDType = eString;
|
|
|
|
}
|
|
|
|
|
2016-04-01 14:55:40 +03:00
|
|
|
void
|
2017-01-12 19:38:48 +03:00
|
|
|
SetOriginAttributes(const OriginAttributes& aOriginAttributes)
|
2016-04-01 14:55:40 +03:00
|
|
|
{
|
|
|
|
mOriginAttributes = aOriginAttributes;
|
|
|
|
}
|
|
|
|
|
2017-02-27 00:13:45 +03:00
|
|
|
void
|
|
|
|
SetAddonId(nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
nsAutoString addonId;
|
|
|
|
aPrincipal->GetAddonId(addonId);
|
|
|
|
|
|
|
|
mAddonId = addonId;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
bool
|
|
|
|
PopulateArgumentsSequence(Sequence<JS::Value>& aSequence) const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mCopiedArguments.Length(); ++i) {
|
|
|
|
if (NS_WARN_IF(!aSequence.AppendElement(mCopiedArguments[i],
|
|
|
|
fallible))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
void
|
|
|
|
Trace(const TraceCallbacks& aCallbacks, void* aClosure)
|
|
|
|
{
|
|
|
|
ConsoleCallData* tmp = this;
|
|
|
|
for (uint32_t i = 0; i < mCopiedArguments.Length(); ++i) {
|
2016-02-22 21:11:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCopiedArguments[i])
|
2016-02-07 13:29:12 +03:00
|
|
|
}
|
2016-03-24 00:55:07 +03:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mGlobal);
|
2016-02-07 13:29:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
{
|
2017-05-03 18:48:54 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(ConsoleCallData);
|
2015-01-06 18:45:00 +03:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Heap<JSObject*> mGlobal;
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
// This is a copy of the arguments we received from the DOM bindings. Console
|
|
|
|
// object traces them because this ConsoleCallData calls
|
|
|
|
// RegisterConsoleCallData() in the Initialize().
|
|
|
|
nsTArray<JS::Heap<JS::Value>> mCopiedArguments;
|
2014-04-17 00:51:07 +04:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
Console::MethodName mMethodName;
|
|
|
|
int64_t mTimeStamp;
|
2016-02-11 20:09:22 +03:00
|
|
|
|
|
|
|
// These values are set in the owning thread and they contain the timestamp of
|
|
|
|
// when the new timer has started, the name of it and the status of the
|
|
|
|
// creation of it. If status is false, something went wrong. User
|
|
|
|
// DOMHighResTimeStamp instead mozilla::TimeStamp because we use
|
|
|
|
// monotonicTimer from Performance.now();
|
|
|
|
// They will be set on the owning thread and never touched again on that
|
2016-03-24 00:55:07 +03:00
|
|
|
// thread. They will be used in order to create a ConsoleTimerStart dictionary
|
|
|
|
// when console.time() is used.
|
2016-02-11 20:09:22 +03:00
|
|
|
DOMHighResTimeStamp mStartTimerValue;
|
|
|
|
nsString mStartTimerLabel;
|
2017-05-12 00:36:12 +03:00
|
|
|
Console::TimerStatus mStartTimerStatus;
|
2016-02-11 20:09:22 +03:00
|
|
|
|
|
|
|
// These values are set in the owning thread and they contain the duration,
|
|
|
|
// the name and the status of the StopTimer method. If status is false,
|
|
|
|
// something went wrong. They will be set on the owning thread and never
|
2016-03-24 00:55:07 +03:00
|
|
|
// touched again on that thread. They will be used in order to create a
|
|
|
|
// ConsoleTimerEnd dictionary. This members are set when
|
2016-02-11 20:09:22 +03:00
|
|
|
// console.timeEnd() is called.
|
|
|
|
double mStopTimerDuration;
|
|
|
|
nsString mStopTimerLabel;
|
2017-05-12 00:36:12 +03:00
|
|
|
Console::TimerStatus mStopTimerStatus;
|
2016-02-11 20:09:22 +03:00
|
|
|
|
|
|
|
// These 2 values are set by IncreaseCounter on the owning thread and they are
|
2016-03-24 00:55:07 +03:00
|
|
|
// used CreateCounterValue. These members are set when console.count() is
|
|
|
|
// called.
|
2016-02-11 20:09:22 +03:00
|
|
|
nsString mCountLabel;
|
|
|
|
uint32_t mCountValue;
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
// The concept of outerID and innerID is misleading because when a
|
|
|
|
// ConsoleCallData is created from a window, these are the window IDs, but
|
|
|
|
// when the object is created from a SharedWorker, a ServiceWorker or a
|
|
|
|
// subworker of a ChromeWorker these IDs are the type of worker and the
|
|
|
|
// filename of the callee.
|
|
|
|
// In Console.jsm the ID is 'jsm'.
|
|
|
|
enum {
|
|
|
|
eString,
|
|
|
|
eNumber,
|
|
|
|
eUnknown
|
|
|
|
} mIDType;
|
|
|
|
|
|
|
|
uint64_t mOuterIDNumber;
|
|
|
|
nsString mOuterIDString;
|
|
|
|
|
|
|
|
uint64_t mInnerIDNumber;
|
|
|
|
nsString mInnerIDString;
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes mOriginAttributes;
|
2016-04-01 14:55:40 +03:00
|
|
|
|
2017-02-27 00:13:45 +03:00
|
|
|
nsString mAddonId;
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
nsString mMethodString;
|
2014-04-16 06:58:44 +04:00
|
|
|
|
|
|
|
// Stack management is complicated, because we want to do it as
|
|
|
|
// lazily as possible. Therefore, we have the following behavior:
|
|
|
|
// 1) mTopStackFrame is initialized whenever we have any JS on the stack
|
|
|
|
// 2) mReifiedStack is initialized if we're created in a worker.
|
|
|
|
// 3) mStack is set (possibly to null if there is no JS on the stack) if
|
|
|
|
// we're created on main thread.
|
|
|
|
Maybe<ConsoleStackEntry> mTopStackFrame;
|
|
|
|
Maybe<nsTArray<ConsoleStackEntry>> mReifiedStack;
|
|
|
|
nsCOMPtr<nsIStackFrame> mStack;
|
2015-04-03 22:37:52 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
// mStatus is about the lifetime of this object. Console must take care of
|
|
|
|
// keep it alive or not following this enumeration.
|
|
|
|
enum {
|
|
|
|
// If the object is created but it is owned by some runnable, this is its
|
|
|
|
// status. It can be deleted at any time.
|
|
|
|
eUnused,
|
|
|
|
|
|
|
|
// When a runnable takes ownership of a ConsoleCallData and send it to
|
|
|
|
// different thread, this is its status. Console cannot delete it at this
|
|
|
|
// time.
|
|
|
|
eInUse,
|
|
|
|
|
|
|
|
// When a runnable owns this ConsoleCallData, we can't delete it directly.
|
|
|
|
// instead, we mark it with this new status and we move it in
|
|
|
|
// mCallDataStoragePending list in order to keep it alive an trace it
|
|
|
|
// correctly. Once the runnable finishs its task, it will delete this object
|
|
|
|
// calling ReleaseCallData().
|
|
|
|
eToBeDeleted
|
|
|
|
} mStatus;
|
|
|
|
|
2015-04-03 22:37:52 +03:00
|
|
|
private:
|
|
|
|
~ConsoleCallData()
|
2016-02-07 13:29:12 +03:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2016-03-24 00:55:07 +03:00
|
|
|
MOZ_ASSERT(mStatus != eInUse);
|
2016-02-07 13:29:12 +03:00
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
};
|
|
|
|
|
2016-07-04 09:19:10 +03:00
|
|
|
class ConsoleRunnable : public WorkerProxyToMainThreadRunnable
|
2015-09-30 15:22:08 +03:00
|
|
|
, public StructuredCloneHolderBase
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-01-07 02:00:50 +03:00
|
|
|
explicit ConsoleRunnable(Console* aConsole)
|
2016-07-04 09:19:10 +03:00
|
|
|
: WorkerProxyToMainThreadRunnable(GetCurrentThreadWorkerPrivate())
|
2015-01-06 18:45:00 +03:00
|
|
|
, mConsole(aConsole)
|
2016-07-04 09:19:10 +03:00
|
|
|
{}
|
2014-02-28 03:39:30 +04:00
|
|
|
|
|
|
|
virtual
|
|
|
|
~ConsoleRunnable()
|
|
|
|
{
|
2015-09-30 15:22:08 +03:00
|
|
|
// Clear the StructuredCloneHolderBase class.
|
|
|
|
Clear();
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-03-24 00:55:07 +03:00
|
|
|
Dispatch(JSContext* aCx)
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
2016-07-04 09:19:10 +03:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!PreDispatch(aCx))) {
|
2017-06-02 12:05:27 +03:00
|
|
|
RunBackOnWorkerThreadForCleanup();
|
2014-02-28 03:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-04 09:19:10 +03:00
|
|
|
if (NS_WARN_IF(!WorkerProxyToMainThreadRunnable::Dispatch())) {
|
2017-06-02 12:05:27 +03:00
|
|
|
// RunBackOnWorkerThreadForCleanup() will be called by
|
2016-08-16 10:35:21 +03:00
|
|
|
// WorkerProxyToMainThreadRunnable::Dispatch().
|
2016-07-04 09:19:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-15 13:46:40 +03:00
|
|
|
|
2015-04-03 22:37:52 +03:00
|
|
|
return true;
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
2016-07-04 09:19:10 +03:00
|
|
|
protected:
|
|
|
|
void
|
|
|
|
RunOnMainThread() override
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
// Walk up to our containing page
|
|
|
|
WorkerPrivate* wp = mWorkerPrivate;
|
|
|
|
while (wp->GetParent()) {
|
|
|
|
wp = wp->GetParent();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* window = wp->GetWindow();
|
2015-01-06 18:45:00 +03:00
|
|
|
if (!window) {
|
|
|
|
RunWindowless();
|
|
|
|
} else {
|
|
|
|
RunWithWindow(window);
|
|
|
|
}
|
2015-04-15 13:46:40 +03:00
|
|
|
}
|
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
RunWithWindow(nsPIDOMWindowInner* aWindow)
|
2015-01-06 18:45:00 +03:00
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
2017-11-04 01:25:38 +03:00
|
|
|
RefPtr<nsGlobalWindowInner> win = nsGlobalWindowInner::Cast(aWindow);
|
2015-01-06 18:45:00 +03:00
|
|
|
if (NS_WARN_IF(!jsapi.Init(win))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* outerWindow = aWindow->GetOuterWindow();
|
2015-11-23 20:16:22 +03:00
|
|
|
if (NS_WARN_IF(!outerWindow)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-06 18:45:00 +03:00
|
|
|
|
|
|
|
RunConsole(jsapi.cx(), outerWindow, aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RunWindowless()
|
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
WorkerPrivate* wp = mWorkerPrivate;
|
|
|
|
while (wp->GetParent()) {
|
|
|
|
wp = wp->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!wp->GetWindow());
|
|
|
|
|
2017-09-29 10:20:58 +03:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
jsapi.Init();
|
|
|
|
|
|
|
|
JSContext* cx = jsapi.cx();
|
2015-01-06 18:45:00 +03:00
|
|
|
|
2015-07-21 21:31:44 +03:00
|
|
|
JS::Rooted<JSObject*> global(cx, mConsole->GetOrCreateSandbox(cx, wp->GetPrincipal()));
|
2015-01-06 18:45:00 +03:00
|
|
|
if (NS_WARN_IF(!global)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-29 10:20:58 +03:00
|
|
|
// The GetOrCreateSandbox call returns a proxy to the actual sandbox object.
|
|
|
|
// We don't need a proxy here.
|
2015-01-06 18:45:00 +03:00
|
|
|
global = js::UncheckedUnwrap(global);
|
|
|
|
|
|
|
|
JSAutoCompartment ac(cx, global);
|
|
|
|
|
|
|
|
RunConsole(cx, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2016-07-04 09:19:10 +03:00
|
|
|
void
|
2017-06-02 12:05:27 +03:00
|
|
|
RunBackOnWorkerThreadForCleanup() override
|
2016-07-04 09:19:10 +03:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
ReleaseData();
|
|
|
|
mConsole = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
// This method is called in the owning thread of the Console object.
|
2014-02-28 03:39:30 +04:00
|
|
|
virtual bool
|
2016-03-24 00:55:07 +03:00
|
|
|
PreDispatch(JSContext* aCx) = 0;
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
// This method is called in the main-thread.
|
2014-02-28 03:39:30 +04:00
|
|
|
virtual void
|
2016-01-30 20:05:36 +03:00
|
|
|
RunConsole(JSContext* aCx, nsPIDOMWindowOuter* aOuterWindow,
|
|
|
|
nsPIDOMWindowInner* aInnerWindow) = 0;
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
// This method is called in the owning thread of the Console object.
|
|
|
|
virtual void
|
|
|
|
ReleaseData() = 0;
|
|
|
|
|
2015-09-30 15:22:08 +03:00
|
|
|
virtual JSObject* CustomReadHandler(JSContext* aCx,
|
|
|
|
JSStructuredCloneReader* aReader,
|
|
|
|
uint32_t aTag,
|
|
|
|
uint32_t aIndex) override
|
2015-07-19 10:54:41 +03:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
if (aTag == CONSOLE_TAG_BLOB) {
|
|
|
|
MOZ_ASSERT(mClonedData.mBlobs.Length() > aIndex);
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> val(aCx);
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Blob> blob =
|
2015-07-19 10:54:41 +03:00
|
|
|
Blob::Create(mClonedData.mParent, mClonedData.mBlobs.ElementAt(aIndex));
|
|
|
|
if (!ToJSValue(aCx, blob, &val)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &val.toObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("No other tags are supported.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-30 15:22:08 +03:00
|
|
|
virtual bool CustomWriteHandler(JSContext* aCx,
|
|
|
|
JSStructuredCloneWriter* aWriter,
|
|
|
|
JS::Handle<JSObject*> aObj) override
|
2015-07-19 10:54:41 +03:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Blob> blob;
|
2015-07-19 10:54:41 +03:00
|
|
|
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) &&
|
|
|
|
blob->Impl()->MayBeClonedToOtherThreads()) {
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_BLOB,
|
|
|
|
mClonedData.mBlobs.Length()))) {
|
2015-07-19 10:54:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mClonedData.mBlobs.AppendElement(blob->Impl());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-19 11:26:00 +03:00
|
|
|
if (!JS_ObjectNotWritten(aWriter, aObj)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-19 10:54:41 +03:00
|
|
|
JS::Rooted<JS::Value> value(aCx, JS::ObjectOrNullValue(aObj));
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!jsString)) {
|
2015-07-19 10:54:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!JS_WriteString(aWriter, jsString))) {
|
2015-07-19 10:54:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-15 13:46:40 +03:00
|
|
|
// This must be released on the worker thread.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Console> mConsole;
|
2015-07-19 10:54:41 +03:00
|
|
|
|
|
|
|
ConsoleStructuredCloneData mClonedData;
|
2014-02-28 03:39:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// This runnable appends a CallData object into the Console queue running on
|
|
|
|
// the main-thread.
|
2015-03-21 19:28:04 +03:00
|
|
|
class ConsoleCallDataRunnable final : public ConsoleRunnable
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-01-06 18:45:00 +03:00
|
|
|
ConsoleCallDataRunnable(Console* aConsole,
|
|
|
|
ConsoleCallData* aCallData)
|
|
|
|
: ConsoleRunnable(aConsole)
|
|
|
|
, mCallData(aCallData)
|
2016-03-24 00:55:07 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCallData);
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mCallData->AssertIsOnOwningThread();
|
2018-01-10 14:30:53 +03:00
|
|
|
|
|
|
|
// Marking this CallData as in use.
|
|
|
|
mCallData->mStatus = ConsoleCallData::eInUse;
|
2016-03-24 00:55:07 +03:00
|
|
|
}
|
2014-02-28 03:39:30 +04:00
|
|
|
|
|
|
|
private:
|
2016-03-24 00:55:07 +03:00
|
|
|
~ConsoleCallDataRunnable()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mCallData);
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:30 +04:00
|
|
|
bool
|
2016-03-24 00:55:07 +03:00
|
|
|
PreDispatch(JSContext* aCx) override
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
2015-01-06 18:45:00 +03:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2016-03-24 00:55:07 +03:00
|
|
|
mCallData->AssertIsOnOwningThread();
|
2015-01-06 18:45:00 +03:00
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2014-02-28 03:39:30 +04:00
|
|
|
|
|
|
|
JS::Rooted<JSObject*> arguments(aCx,
|
2016-02-07 13:29:12 +03:00
|
|
|
JS_NewArrayObject(aCx, mCallData->mCopiedArguments.Length()));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!arguments)) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-30 13:10:33 +04:00
|
|
|
JS::Rooted<JS::Value> arg(aCx);
|
2016-02-07 13:29:12 +03:00
|
|
|
for (uint32_t i = 0; i < mCallData->mCopiedArguments.Length(); ++i) {
|
|
|
|
arg = mCallData->mCopiedArguments[i];
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!JS_DefineElement(aCx, arguments, i, arg,
|
|
|
|
JSPROP_ENUMERATE))) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx, JS::ObjectValue(*arguments));
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!Write(aCx, value))) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
RunConsole(JSContext* aCx, nsPIDOMWindowOuter* aOuterWindow,
|
|
|
|
nsPIDOMWindowInner* aInnerWindow) override
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
// The windows have to run in parallel.
|
|
|
|
MOZ_ASSERT(!!aOuterWindow == !!aInnerWindow);
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
if (aOuterWindow) {
|
|
|
|
mCallData->SetIDs(aOuterWindow->WindowID(), aInnerWindow->WindowID());
|
|
|
|
} else {
|
|
|
|
ConsoleStackEntry frame;
|
|
|
|
if (mCallData->mTopStackFrame) {
|
|
|
|
frame = *mCallData->mTopStackFrame;
|
|
|
|
}
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2015-11-05 23:03:31 +03:00
|
|
|
nsString id = frame.mFilename;
|
|
|
|
nsString innerID;
|
2015-01-06 18:45:00 +03:00
|
|
|
if (mWorkerPrivate->IsSharedWorker()) {
|
2015-11-05 23:03:31 +03:00
|
|
|
innerID = NS_LITERAL_STRING("SharedWorker");
|
2015-01-06 18:45:00 +03:00
|
|
|
} else if (mWorkerPrivate->IsServiceWorker()) {
|
2015-11-05 23:03:31 +03:00
|
|
|
innerID = NS_LITERAL_STRING("ServiceWorker");
|
|
|
|
// Use scope as ID so the webconsole can decide if the message should
|
|
|
|
// show up per tab
|
2017-07-24 20:23:52 +03:00
|
|
|
CopyASCIItoUTF16(mWorkerPrivate->ServiceWorkerScope(), id);
|
2015-01-06 18:45:00 +03:00
|
|
|
} else {
|
2015-11-05 23:03:31 +03:00
|
|
|
innerID = NS_LITERAL_STRING("Worker");
|
2015-01-06 18:45:00 +03:00
|
|
|
}
|
2014-05-30 13:38:30 +04:00
|
|
|
|
2015-11-05 23:03:31 +03:00
|
|
|
mCallData->SetIDs(id, innerID);
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
2015-02-02 18:40:15 +03:00
|
|
|
// Now we could have the correct window (if we are not window-less).
|
2015-07-19 10:54:41 +03:00
|
|
|
mClonedData.mParent = aInnerWindow;
|
2015-02-02 18:40:15 +03:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
ProcessCallData(aCx);
|
2015-02-02 18:40:15 +03:00
|
|
|
|
2015-07-19 10:54:41 +03:00
|
|
|
mClonedData.mParent = nullptr;
|
2015-01-06 18:45:00 +03:00
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
virtual void
|
|
|
|
ReleaseData() override
|
|
|
|
{
|
2016-03-24 00:55:07 +03:00
|
|
|
mConsole->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mCallData->mStatus == ConsoleCallData::eToBeDeleted) {
|
|
|
|
mConsole->ReleaseCallData(mCallData);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mCallData->mStatus == ConsoleCallData::eInUse);
|
|
|
|
mCallData->mStatus = ConsoleCallData::eUnused;
|
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
mCallData = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
void
|
|
|
|
ProcessCallData(JSContext* aCx)
|
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2015-01-06 18:45:00 +03:00
|
|
|
|
|
|
|
JS::Rooted<JS::Value> argumentsValue(aCx);
|
2015-07-19 10:54:41 +03:00
|
|
|
if (!Read(aCx, &argumentsValue)) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(argumentsValue.isObject());
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
JS::Rooted<JSObject*> argumentsObj(aCx, &argumentsValue.toObject());
|
2014-02-28 03:39:30 +04:00
|
|
|
|
|
|
|
uint32_t length;
|
2015-01-06 18:45:00 +03:00
|
|
|
if (!JS_GetArrayLength(aCx, argumentsObj, &length)) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
Sequence<JS::Value> values;
|
|
|
|
SequenceRooter<JS::Value> arguments(aCx, &values);
|
|
|
|
|
2014-02-28 03:39:30 +04:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2015-01-06 18:45:00 +03:00
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
if (!JS_GetElement(aCx, argumentsObj, i, &value)) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
if (!values.AppendElement(value, fallible)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
MOZ_ASSERT(values.Length() == length);
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
mConsole->ProcessCallData(aCx, mCallData, values);
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ConsoleCallData> mCallData;
|
2014-02-28 03:39:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// This runnable calls ProfileMethod() on the console on the main-thread.
|
2015-03-21 19:28:04 +03:00
|
|
|
class ConsoleProfileRunnable final : public ConsoleRunnable
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
|
|
|
public:
|
2018-01-04 21:19:44 +03:00
|
|
|
ConsoleProfileRunnable(Console* aConsole, Console::MethodName aName,
|
|
|
|
const nsAString& aAction,
|
2014-02-28 03:39:30 +04:00
|
|
|
const Sequence<JS::Value>& aArguments)
|
2015-01-06 18:45:00 +03:00
|
|
|
: ConsoleRunnable(aConsole)
|
2018-01-04 21:19:44 +03:00
|
|
|
, mName(aName)
|
2015-01-06 18:45:00 +03:00
|
|
|
, mAction(aAction)
|
2014-02-28 03:39:30 +04:00
|
|
|
, mArguments(aArguments)
|
|
|
|
{
|
2015-01-06 18:45:00 +03:00
|
|
|
MOZ_ASSERT(aConsole);
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool
|
2016-03-24 00:55:07 +03:00
|
|
|
PreDispatch(JSContext* aCx) override
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2014-02-28 03:39:30 +04:00
|
|
|
|
|
|
|
JS::Rooted<JSObject*> arguments(aCx,
|
|
|
|
JS_NewArrayObject(aCx, mArguments.Length()));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!arguments)) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-30 13:10:33 +04:00
|
|
|
JS::Rooted<JS::Value> arg(aCx);
|
2014-02-28 03:39:30 +04:00
|
|
|
for (uint32_t i = 0; i < mArguments.Length(); ++i) {
|
2014-04-30 13:10:33 +04:00
|
|
|
arg = mArguments[i];
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!JS_DefineElement(aCx, arguments, i, arg,
|
|
|
|
JSPROP_ENUMERATE))) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx, JS::ObjectValue(*arguments));
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!Write(aCx, value))) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
RunConsole(JSContext* aCx, nsPIDOMWindowOuter* aOuterWindow,
|
|
|
|
nsPIDOMWindowInner* aInnerWindow) override
|
2014-02-28 03:39:30 +04:00
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2015-02-02 18:40:15 +03:00
|
|
|
// Now we could have the correct window (if we are not window-less).
|
2015-07-19 10:54:41 +03:00
|
|
|
mClonedData.mParent = aInnerWindow;
|
2015-02-02 18:40:15 +03:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
JS::Rooted<JS::Value> argumentsValue(aCx);
|
2015-07-19 10:54:41 +03:00
|
|
|
bool ok = Read(aCx, &argumentsValue);
|
|
|
|
mClonedData.mParent = nullptr;
|
2015-02-02 18:40:15 +03:00
|
|
|
|
|
|
|
if (!ok) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(argumentsValue.isObject());
|
2015-01-06 18:45:00 +03:00
|
|
|
JS::Rooted<JSObject*> argumentsObj(aCx, &argumentsValue.toObject());
|
2017-04-18 23:22:55 +03:00
|
|
|
if (NS_WARN_IF(!argumentsObj)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 03:39:30 +04:00
|
|
|
|
|
|
|
uint32_t length;
|
2015-01-06 18:45:00 +03:00
|
|
|
if (!JS_GetArrayLength(aCx, argumentsObj, &length)) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sequence<JS::Value> arguments;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2015-01-06 18:45:00 +03:00
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
2014-02-28 03:39:30 +04:00
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
if (!JS_GetElement(aCx, argumentsObj, i, &value)) {
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-28 21:07:44 +03:00
|
|
|
if (!arguments.AppendElement(value, fallible)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
mConsole->ProfileMethodInternal(aCx, mName, mAction, arguments);
|
2014-02-28 03:39:30 +04:00
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
virtual void
|
|
|
|
ReleaseData() override
|
|
|
|
{}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
Console::MethodName mName;
|
2014-02-28 03:39:30 +04:00
|
|
|
nsString mAction;
|
2016-02-07 13:29:12 +03:00
|
|
|
|
|
|
|
// This is a reference of the sequence of arguments we receive from the DOM
|
|
|
|
// bindings and it's rooted by them. It's only used on the owning thread in
|
|
|
|
// PreDispatch().
|
|
|
|
const Sequence<JS::Value>& mArguments;
|
2014-02-28 03:39:30 +04:00
|
|
|
};
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Console)
|
|
|
|
|
2015-07-21 21:31:44 +03:00
|
|
|
// We don't need to traverse/unlink mStorage and mSandbox because they are not
|
2015-01-06 18:45:00 +03:00
|
|
|
// CCed objects and they are only used on the main thread, even when this
|
|
|
|
// Console object is used on workers.
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Console)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
2016-03-24 00:55:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsoleEventNotifier)
|
2018-01-04 21:19:44 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDumpFunction)
|
2016-03-24 00:55:07 +03:00
|
|
|
tmp->Shutdown();
|
2014-02-28 03:39:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Console)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
2016-03-24 00:55:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsoleEventNotifier)
|
2018-01-04 21:19:44 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDumpFunction)
|
2014-02-28 03:39:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Console)
|
2016-03-24 00:55:07 +03:00
|
|
|
for (uint32_t i = 0; i < tmp->mCallDataStorage.Length(); ++i) {
|
|
|
|
tmp->mCallDataStorage[i]->Trace(aCallbacks, aClosure);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < tmp->mCallDataStoragePending.Length(); ++i) {
|
|
|
|
tmp->mCallDataStoragePending[i]->Trace(aCallbacks, aClosure);
|
2016-02-07 13:29:12 +03:00
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Console)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Console)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Console)
|
2014-02-28 03:39:17 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
2016-01-21 16:17:33 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2014-02-28 03:39:00 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
/* static */ already_AddRefed<Console>
|
|
|
|
Console::Create(nsPIDOMWindowInner* aWindow, ErrorResult& aRv)
|
|
|
|
{
|
2016-04-12 13:12:07 +03:00
|
|
|
MOZ_ASSERT_IF(NS_IsMainThread(), aWindow);
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
RefPtr<Console> console = new Console(aWindow);
|
|
|
|
console->Initialize(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return console.forget();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
Console::Console(nsPIDOMWindowInner* aWindow)
|
2014-02-28 03:39:00 +04:00
|
|
|
: mWindow(aWindow)
|
|
|
|
, mOuterID(0)
|
|
|
|
, mInnerID(0)
|
2018-01-04 21:19:44 +03:00
|
|
|
, mDumpToStdout(false)
|
2018-01-04 21:19:44 +03:00
|
|
|
, mChromeInstance(false)
|
2018-01-04 21:19:44 +03:00
|
|
|
, mMaxLogLevel(ConsoleLogLevel::All)
|
2016-03-24 00:55:07 +03:00
|
|
|
, mStatus(eUnknown)
|
2017-12-20 16:35:34 +03:00
|
|
|
, mCreationTimeStamp(TimeStamp::Now())
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
|
|
|
if (mWindow) {
|
|
|
|
mInnerID = mWindow->WindowID();
|
|
|
|
|
2015-11-23 20:16:22 +03:00
|
|
|
// Without outerwindow any console message coming from this object will not
|
|
|
|
// shown in the devtools webconsole. But this should be fine because
|
|
|
|
// probably we are shutting down, or the window is CCed/GCed.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* outerWindow = mWindow->GetOuterWindow();
|
2015-11-23 20:16:22 +03:00
|
|
|
if (outerWindow) {
|
|
|
|
mOuterID = outerWindow->WindowID();
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Console::~Console()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
Shutdown();
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Console::Initialize(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mStatus == eUnknown);
|
|
|
|
|
2014-02-28 03:39:17 +04:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!obs)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
if (mWindow) {
|
|
|
|
aRv = obs->AddObserver(this, "inner-window-destroyed", true);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 03:39:17 +04:00
|
|
|
}
|
2016-03-24 00:55:07 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
aRv = obs->AddObserver(this, "memory-pressure", true);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 03:39:17 +04:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
mStatus = eInitialized;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
void
|
|
|
|
Console::Shutdown()
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2016-02-11 20:11:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (mStatus == eUnknown || mStatus == eShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-06 18:45:00 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, "inner-window-destroyed");
|
2016-03-24 00:55:07 +03:00
|
|
|
obs->RemoveObserver(this, "memory-pressure");
|
2015-01-06 18:45:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 09:49:22 +03:00
|
|
|
NS_ReleaseOnMainThreadSystemGroup("Console::mStorage", mStorage.forget());
|
|
|
|
NS_ReleaseOnMainThreadSystemGroup("Console::mSandbox", mSandbox.forget());
|
2016-03-24 00:55:07 +03:00
|
|
|
|
|
|
|
mTimerRegistry.Clear();
|
|
|
|
mCounterRegistry.Clear();
|
2016-03-24 00:55:07 +03:00
|
|
|
|
|
|
|
mCallDataStorage.Clear();
|
|
|
|
mCallDataStoragePending.Clear();
|
2016-03-24 00:55:07 +03:00
|
|
|
|
|
|
|
mStatus = eShuttingDown;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Console::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData)
|
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
2014-02-28 03:39:17 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (!strcmp(aTopic, "inner-window-destroyed")) {
|
|
|
|
nsCOMPtr<nsISupportsPRUint64> wrapper = do_QueryInterface(aSubject);
|
|
|
|
NS_ENSURE_TRUE(wrapper, NS_ERROR_FAILURE);
|
2014-02-28 03:39:17 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
uint64_t innerID;
|
|
|
|
nsresult rv = wrapper->GetData(&innerID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-02-28 03:39:17 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (innerID == mInnerID) {
|
|
|
|
Shutdown();
|
|
|
|
}
|
2014-02-28 03:39:17 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, "memory-pressure")) {
|
|
|
|
ClearStorage();
|
|
|
|
return NS_OK;
|
2014-02-28 03:39:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
void
|
|
|
|
Console::ClearStorage()
|
|
|
|
{
|
|
|
|
mCallDataStorage.Clear();
|
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
#define METHOD(name, string) \
|
|
|
|
/* static */ void \
|
|
|
|
Console::name(const GlobalObject& aGlobal, const Sequence<JS::Value>& aData) \
|
|
|
|
{ \
|
|
|
|
Method(aGlobal, Method##name, NS_LITERAL_STRING(string), aData); \
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(Log, "log")
|
|
|
|
METHOD(Info, "info")
|
|
|
|
METHOD(Warn, "warn")
|
|
|
|
METHOD(Error, "error")
|
|
|
|
METHOD(Exception, "exception")
|
|
|
|
METHOD(Debug, "debug")
|
2014-08-28 02:32:32 +04:00
|
|
|
METHOD(Table, "table")
|
2017-04-20 14:52:24 +03:00
|
|
|
METHOD(Trace, "trace")
|
2017-04-20 14:50:13 +03:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
// Displays an interactive listing of all the properties of an object.
|
|
|
|
METHOD(Dir, "dir");
|
2015-04-29 18:34:00 +03:00
|
|
|
METHOD(Dirxml, "dirxml");
|
2014-02-28 03:39:00 +04:00
|
|
|
|
|
|
|
METHOD(Group, "group")
|
|
|
|
METHOD(GroupCollapsed, "groupCollapsed")
|
2017-04-18 11:04:00 +03:00
|
|
|
|
2018-01-04 21:19:43 +03:00
|
|
|
#undef METHOD
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
Console::Clear(const GlobalObject& aGlobal)
|
|
|
|
{
|
|
|
|
const Sequence<JS::Value> data;
|
|
|
|
Method(aGlobal, MethodClear, NS_LITERAL_STRING("clear"), data);
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:04:00 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::GroupEnd(const GlobalObject& aGlobal)
|
|
|
|
{
|
|
|
|
const Sequence<JS::Value> data;
|
|
|
|
Method(aGlobal, MethodGroupEnd, NS_LITERAL_STRING("groupEnd"), data);
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
2017-04-20 14:52:31 +03:00
|
|
|
Console::Time(const GlobalObject& aGlobal, const nsAString& aLabel)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2017-04-20 14:52:41 +03:00
|
|
|
StringMethod(aGlobal, aLabel, MethodTime, NS_LITERAL_STRING("time"));
|
2017-04-20 14:52:31 +03:00
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2017-04-20 14:52:31 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::TimeEnd(const GlobalObject& aGlobal, const nsAString& aLabel)
|
|
|
|
{
|
2017-04-20 14:52:41 +03:00
|
|
|
StringMethod(aGlobal, aLabel, MethodTimeEnd, NS_LITERAL_STRING("timeEnd"));
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
2017-04-20 14:52:41 +03:00
|
|
|
Console::StringMethod(const GlobalObject& aGlobal, const nsAString& aLabel,
|
|
|
|
MethodName aMethodName, const nsAString& aMethodString)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2018-01-04 21:19:43 +03:00
|
|
|
RefPtr<Console> console = GetConsole(aGlobal);
|
|
|
|
if (!console) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-11 20:11:02 +03:00
|
|
|
|
2018-01-04 21:19:43 +03:00
|
|
|
console->StringMethodInternal(aGlobal.Context(), aLabel, aMethodName,
|
|
|
|
aMethodString);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Console::StringMethodInternal(JSContext* aCx, const nsAString& aLabel,
|
|
|
|
MethodName aMethodName,
|
|
|
|
const nsAString& aMethodString)
|
|
|
|
{
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2017-04-20 14:52:31 +03:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
Sequence<JS::Value> data;
|
2018-01-04 21:19:43 +03:00
|
|
|
SequenceRooter<JS::Value> rooter(aCx, &data);
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2018-01-04 21:19:43 +03:00
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
if (!dom::ToJSValue(aCx, aLabel, &value)) {
|
2017-04-20 14:52:31 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data.AppendElement(value, fallible)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:43 +03:00
|
|
|
MethodInternal(aCx, aMethodName, aMethodString, data);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::TimeStamp(const GlobalObject& aGlobal,
|
|
|
|
const JS::Handle<JS::Value> aData)
|
2015-04-29 22:48:57 +03:00
|
|
|
{
|
2016-06-04 10:32:51 +03:00
|
|
|
JSContext* cx = aGlobal.Context();
|
2016-02-11 20:11:02 +03:00
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(cx);
|
2017-04-18 23:22:55 +03:00
|
|
|
|
2015-04-29 22:48:57 +03:00
|
|
|
Sequence<JS::Value> data;
|
2016-06-04 10:32:51 +03:00
|
|
|
SequenceRooter<JS::Value> rooter(cx, &data);
|
2015-04-29 22:48:57 +03:00
|
|
|
|
2015-05-28 21:07:44 +03:00
|
|
|
if (aData.isString() && !data.AppendElement(aData, fallible)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return;
|
2015-04-29 22:48:57 +03:00
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
Method(aGlobal, MethodTimeStamp, NS_LITERAL_STRING("timeStamp"), data);
|
2015-04-29 22:48:57 +03:00
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::Profile(const GlobalObject& aGlobal, const Sequence<JS::Value>& aData)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2018-01-04 21:19:44 +03:00
|
|
|
ProfileMethod(aGlobal, MethodProfile, NS_LITERAL_STRING("profile"), aData);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::ProfileEnd(const GlobalObject& aGlobal,
|
|
|
|
const Sequence<JS::Value>& aData)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2018-01-04 21:19:44 +03:00
|
|
|
ProfileMethod(aGlobal, MethodProfileEnd, NS_LITERAL_STRING("profileEnd"),
|
|
|
|
aData);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
2018-01-04 21:19:44 +03:00
|
|
|
Console::ProfileMethod(const GlobalObject& aGlobal, MethodName aName,
|
|
|
|
const nsAString& aAction,
|
2014-04-29 10:49:57 +04:00
|
|
|
const Sequence<JS::Value>& aData)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2016-06-04 10:32:51 +03:00
|
|
|
RefPtr<Console> console = GetConsole(aGlobal);
|
|
|
|
if (!console) {
|
2016-05-03 11:19:39 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-03-24 00:55:07 +03:00
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
JSContext* cx = aGlobal.Context();
|
2018-01-04 21:19:44 +03:00
|
|
|
console->ProfileMethodInternal(cx, aName, aAction, aData);
|
2016-06-04 10:32:51 +03:00
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
bool
|
|
|
|
Console::IsEnabled(JSContext* aCx) const
|
|
|
|
{
|
|
|
|
// Console is always enabled if it is a custom Chrome-Only instance.
|
|
|
|
if (mChromeInstance) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make all Console API no-op if DevTools aren't enabled.
|
2018-01-08 16:05:06 +03:00
|
|
|
return DOMPrefs::DevToolsEnabled();
|
2018-01-04 21:19:44 +03:00
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
void
|
2018-01-04 21:19:44 +03:00
|
|
|
Console::ProfileMethodInternal(JSContext* aCx, MethodName aMethodName,
|
|
|
|
const nsAString& aAction,
|
2016-06-04 10:32:51 +03:00
|
|
|
const Sequence<JS::Value>& aData)
|
|
|
|
{
|
2018-01-04 21:19:44 +03:00
|
|
|
if (!IsEnabled(aCx)) {
|
2017-08-08 17:29:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
if (!ShouldProceed(aMethodName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
MaybeExecuteDumpFunction(aCx, aAction, aData);
|
|
|
|
|
2014-02-28 03:39:30 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
// Here we are in a worker thread.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ConsoleProfileRunnable> runnable =
|
2018-01-04 21:19:44 +03:00
|
|
|
new ConsoleProfileRunnable(this, aMethodName, aAction, aData);
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
runnable->Dispatch(aCx);
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2014-04-29 10:49:57 +04:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
RootedDictionary<ConsoleProfileEvent> event(aCx);
|
|
|
|
event.mAction = aAction;
|
|
|
|
|
|
|
|
event.mArguments.Construct();
|
|
|
|
Sequence<JS::Value>& sequence = event.mArguments.Value();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < aData.Length(); ++i) {
|
2015-05-28 21:07:44 +03:00
|
|
|
if (!sequence.AppendElement(aData[i], fallible)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> eventValue(aCx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(aCx, event, &eventValue)) {
|
2014-02-28 03:39:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> eventObj(aCx, &eventValue.toObject());
|
|
|
|
MOZ_ASSERT(eventObj);
|
|
|
|
|
2014-04-29 10:49:57 +04:00
|
|
|
if (!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventValue,
|
|
|
|
JSPROP_ENUMERATE)) {
|
2014-02-28 03:39:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-04 21:35:13 +03:00
|
|
|
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
2014-02-28 03:39:00 +04:00
|
|
|
nsCOMPtr<nsISupports> wrapper;
|
|
|
|
const nsIID& iid = NS_GET_IID(nsISupports);
|
|
|
|
|
|
|
|
if (NS_FAILED(xpc->WrapJS(aCx, eventObj, iid, getter_AddRefs(wrapper)))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2014-02-28 03:39:00 +04:00
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(wrapper, "console-api-profiler", nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::Assert(const GlobalObject& aGlobal, bool aCondition,
|
2014-02-28 03:39:00 +04:00
|
|
|
const Sequence<JS::Value>& aData)
|
|
|
|
{
|
|
|
|
if (!aCondition) {
|
2016-06-04 10:32:51 +03:00
|
|
|
Method(aGlobal, MethodAssert, NS_LITERAL_STRING("assert"), aData);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 14:52:41 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::Count(const GlobalObject& aGlobal, const nsAString& aLabel)
|
|
|
|
{
|
|
|
|
StringMethod(aGlobal, aLabel, MethodCount, NS_LITERAL_STRING("count"));
|
|
|
|
}
|
2014-02-28 03:39:24 +04:00
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
namespace {
|
|
|
|
|
2018-02-06 00:34:05 +03:00
|
|
|
void
|
2016-03-22 20:50:31 +03:00
|
|
|
StackFrameToStackEntry(JSContext* aCx, nsIStackFrame* aStackFrame,
|
2016-03-22 20:50:31 +03:00
|
|
|
ConsoleStackEntry& aStackEntry)
|
2014-04-16 06:58:44 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aStackFrame);
|
|
|
|
|
2018-02-06 00:34:04 +03:00
|
|
|
aStackFrame->GetFilename(aCx, aStackEntry.mFilename);
|
2014-04-16 06:58:44 +04:00
|
|
|
|
2018-02-06 00:34:04 +03:00
|
|
|
aStackEntry.mLineNumber = aStackFrame->GetLineNumber(aCx);
|
2014-04-16 06:58:44 +04:00
|
|
|
|
2018-02-06 00:34:04 +03:00
|
|
|
aStackEntry.mColumnNumber = aStackFrame->GetColumnNumber(aCx);
|
2014-09-22 22:28:55 +04:00
|
|
|
|
2018-02-06 00:34:05 +03:00
|
|
|
aStackFrame->GetName(aCx, aStackEntry.mFunctionName);
|
2014-04-16 06:58:44 +04:00
|
|
|
|
2015-10-21 09:40:00 +03:00
|
|
|
nsString cause;
|
2018-02-06 00:34:04 +03:00
|
|
|
aStackFrame->GetAsyncCause(aCx, cause);
|
2015-10-21 09:40:00 +03:00
|
|
|
if (!cause.IsEmpty()) {
|
|
|
|
aStackEntry.mAsyncCause.Construct(cause);
|
|
|
|
}
|
2014-04-16 06:58:44 +04:00
|
|
|
}
|
|
|
|
|
2018-02-06 00:34:05 +03:00
|
|
|
void
|
2016-03-22 20:50:31 +03:00
|
|
|
ReifyStack(JSContext* aCx, nsIStackFrame* aStack,
|
|
|
|
nsTArray<ConsoleStackEntry>& aRefiedStack)
|
2014-04-16 06:58:44 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStackFrame> stack(aStack);
|
|
|
|
|
|
|
|
while (stack) {
|
2016-03-22 20:50:31 +03:00
|
|
|
ConsoleStackEntry& data = *aRefiedStack.AppendElement();
|
2018-02-06 00:34:05 +03:00
|
|
|
StackFrameToStackEntry(aCx, stack, data);
|
2014-04-16 06:58:44 +04:00
|
|
|
|
2018-02-06 00:34:05 +03:00
|
|
|
nsCOMPtr<nsIStackFrame> caller = stack->GetCaller(aCx);
|
2014-04-16 06:58:44 +04:00
|
|
|
|
2015-10-21 09:40:00 +03:00
|
|
|
if (!caller) {
|
2018-02-06 00:34:05 +03:00
|
|
|
caller = stack->GetAsyncCaller(aCx);
|
2015-10-21 09:40:00 +03:00
|
|
|
}
|
2014-04-16 06:58:44 +04:00
|
|
|
stack.swap(caller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
// Queue a call to a console method. See the CALL_DELAY constant.
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ void
|
|
|
|
Console::Method(const GlobalObject& aGlobal, MethodName aMethodName,
|
2014-02-28 03:39:00 +04:00
|
|
|
const nsAString& aMethodString,
|
|
|
|
const Sequence<JS::Value>& aData)
|
|
|
|
{
|
2016-06-04 10:32:51 +03:00
|
|
|
RefPtr<Console> console = GetConsole(aGlobal);
|
|
|
|
if (!console) {
|
2016-05-03 11:19:39 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-02-11 20:11:02 +03:00
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
console->MethodInternal(aGlobal.Context(), aMethodName, aMethodString,
|
|
|
|
aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Console::MethodInternal(JSContext* aCx, MethodName aMethodName,
|
|
|
|
const nsAString& aMethodString,
|
|
|
|
const Sequence<JS::Value>& aData)
|
|
|
|
{
|
2018-01-04 21:19:44 +03:00
|
|
|
if (!IsEnabled(aCx)) {
|
2017-08-08 17:29:34 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-01-04 21:19:44 +03:00
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
if (!ShouldProceed(aMethodName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ConsoleCallData> callData(new ConsoleCallData());
|
2014-03-03 04:20:34 +04:00
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2014-04-29 10:49:57 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!callData->Initialize(aCx, aMethodName, aMethodString,
|
|
|
|
aData, this))) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes oa;
|
2016-12-16 13:57:24 +03:00
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
if (mWindow) {
|
|
|
|
// Save the principal's OriginAttributes in the console event data
|
|
|
|
// so that we will be able to filter messages by origin attributes.
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mWindow);
|
|
|
|
if (NS_WARN_IF(!sop)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-01 14:55:40 +03:00
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
|
|
|
|
if (NS_WARN_IF(!principal)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-01 14:55:40 +03:00
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
oa = principal->OriginAttributesRef();
|
|
|
|
callData->SetAddonId(principal);
|
2016-12-17 00:08:31 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2017-12-20 16:35:34 +03:00
|
|
|
if (!nsContentUtils::IsSystemPrincipal(principal)) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(mWindow);
|
|
|
|
if (webNav) {
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
|
|
|
|
MOZ_ASSERT(loadContext);
|
|
|
|
|
|
|
|
bool pb;
|
|
|
|
if (NS_SUCCEEDED(loadContext->GetUsePrivateBrowsing(&pb))) {
|
|
|
|
MOZ_ASSERT(pb == !!oa.mPrivateBrowsingId);
|
|
|
|
}
|
2016-12-17 00:08:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2017-12-20 16:35:34 +03:00
|
|
|
}
|
2016-12-17 00:08:31 +03:00
|
|
|
} else {
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
oa = workerPrivate->GetOriginAttributes();
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-12-17 00:08:31 +03:00
|
|
|
callData->SetOriginAttributes(oa);
|
|
|
|
|
2016-07-22 06:41:02 +03:00
|
|
|
JS::StackCapture captureMode = ShouldIncludeStackTrace(aMethodName) ?
|
|
|
|
JS::StackCapture(JS::MaxFrames(DEFAULT_MAX_STACKTRACE_DEPTH)) :
|
|
|
|
JS::StackCapture(JS::FirstSubsumedFrame(aCx));
|
|
|
|
nsCOMPtr<nsIStackFrame> stack = CreateStack(aCx, mozilla::Move(captureMode));
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2016-03-22 20:50:31 +03:00
|
|
|
if (stack) {
|
|
|
|
callData->mTopStackFrame.emplace();
|
2018-02-06 00:34:05 +03:00
|
|
|
StackFrameToStackEntry(aCx, stack, *callData->mTopStackFrame);
|
2016-03-22 20:50:31 +03:00
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2014-04-16 06:58:44 +04:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
callData->mStack = stack;
|
|
|
|
} else {
|
|
|
|
// nsIStackFrame is not threadsafe, so we need to snapshot it now,
|
|
|
|
// before we post our runnable to the main thread.
|
2014-08-14 02:39:41 +04:00
|
|
|
callData->mReifiedStack.emplace();
|
2018-02-06 00:34:05 +03:00
|
|
|
ReifyStack(aCx, stack, *callData->mReifiedStack);
|
2014-04-16 06:58:44 +04:00
|
|
|
}
|
|
|
|
|
2016-02-11 20:09:22 +03:00
|
|
|
DOMHighResTimeStamp monotonicTimer;
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
// Monotonic timer for 'time' and 'timeEnd'
|
2017-12-20 16:35:34 +03:00
|
|
|
if ((aMethodName == MethodTime ||
|
|
|
|
aMethodName == MethodTimeEnd ||
|
|
|
|
aMethodName == MethodTimeStamp) &&
|
|
|
|
!MonotonicTimer(aCx, aMethodName, aData, &monotonicTimer)) {
|
|
|
|
return;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-02-11 20:09:22 +03:00
|
|
|
if (aMethodName == MethodTime && !aData.IsEmpty()) {
|
|
|
|
callData->mStartTimerStatus = StartTimer(aCx, aData[0],
|
|
|
|
monotonicTimer,
|
|
|
|
callData->mStartTimerLabel,
|
|
|
|
&callData->mStartTimerValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (aMethodName == MethodTimeEnd && !aData.IsEmpty()) {
|
|
|
|
callData->mStopTimerStatus = StopTimer(aCx, aData[0],
|
|
|
|
monotonicTimer,
|
|
|
|
callData->mStopTimerLabel,
|
|
|
|
&callData->mStopTimerDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (aMethodName == MethodCount) {
|
2017-04-20 14:52:41 +03:00
|
|
|
callData->mCountValue = IncreaseCounter(aCx, aData, callData->mCountLabel);
|
|
|
|
if (!callData->mCountValue) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-11 20:09:22 +03:00
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
// Before processing this CallData differently, it's time to call the dump
|
|
|
|
// function.
|
|
|
|
if (aMethodName == MethodTrace) {
|
|
|
|
MaybeExecuteDumpFunctionForTrace(aCx, stack);
|
2018-01-29 15:25:15 +03:00
|
|
|
} else if ((aMethodName == MethodTime ||
|
|
|
|
aMethodName == MethodTimeEnd) &&
|
|
|
|
!aData.IsEmpty()) {
|
|
|
|
MaybeExecuteDumpFunctionForTime(aCx, aMethodName, aMethodString,
|
|
|
|
monotonicTimer, aData[0]);
|
2018-01-04 21:19:44 +03:00
|
|
|
} else {
|
|
|
|
MaybeExecuteDumpFunction(aCx, aMethodString, aData);
|
|
|
|
}
|
|
|
|
|
2015-01-06 18:45:00 +03:00
|
|
|
if (NS_IsMainThread()) {
|
2017-12-20 16:35:34 +03:00
|
|
|
if (mWindow) {
|
|
|
|
callData->SetIDs(mOuterID, mInnerID);
|
2018-01-04 21:19:43 +03:00
|
|
|
} else if (!mPassedInnerID.IsEmpty()) {
|
|
|
|
callData->SetIDs(NS_LITERAL_STRING("jsm"), mPassedInnerID);
|
2017-12-20 16:35:34 +03:00
|
|
|
} else {
|
|
|
|
nsAutoString filename;
|
|
|
|
if (callData->mTopStackFrame.isSome()) {
|
|
|
|
filename = callData->mTopStackFrame->mFilename;
|
|
|
|
}
|
|
|
|
|
|
|
|
callData->SetIDs(NS_LITERAL_STRING("jsm"), filename);
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
ProcessCallData(aCx, callData, aData);
|
2016-03-24 00:55:07 +03:00
|
|
|
|
|
|
|
// Just because we don't want to expose
|
|
|
|
// retrieveConsoleEvents/setConsoleEventHandler to main-thread, we can
|
|
|
|
// cleanup the mCallDataStorage:
|
|
|
|
UnstoreCallData(callData);
|
2014-02-28 03:39:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
// We do this only in workers for now.
|
2016-03-24 00:55:07 +03:00
|
|
|
NotifyHandler(aCx, aData, callData);
|
2016-03-24 00:55:07 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ConsoleCallDataRunnable> runnable =
|
2015-01-06 18:45:00 +03:00
|
|
|
new ConsoleCallDataRunnable(this, callData);
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(!runnable->Dispatch(aCx));
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-04-16 06:58:44 +04:00
|
|
|
// We store information to lazily compute the stack in the reserved slots of
|
|
|
|
// LazyStackGetter. The first slot always stores a JS object: it's either the
|
|
|
|
// JS wrapper of the nsIStackFrame or the actual reified stack representation.
|
|
|
|
// The second slot is a PrivateValue() holding an nsIStackFrame* when we haven't
|
|
|
|
// reified the stack yet, or an UndefinedValue() otherwise.
|
|
|
|
enum {
|
|
|
|
SLOT_STACKOBJ,
|
|
|
|
SLOT_RAW_STACK
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
LazyStackGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
|
|
|
|
{
|
|
|
|
JS::CallArgs args = CallArgsFromVp(aArgc, aVp);
|
|
|
|
JS::Rooted<JSObject*> callee(aCx, &args.callee());
|
|
|
|
|
|
|
|
JS::Value v = js::GetFunctionNativeReserved(&args.callee(), SLOT_RAW_STACK);
|
|
|
|
if (v.isUndefined()) {
|
|
|
|
// Already reified.
|
|
|
|
args.rval().set(js::GetFunctionNativeReserved(callee, SLOT_STACKOBJ));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStackFrame* stack = reinterpret_cast<nsIStackFrame*>(v.toPrivate());
|
|
|
|
nsTArray<ConsoleStackEntry> reifiedStack;
|
2018-02-06 00:34:05 +03:00
|
|
|
ReifyStack(aCx, stack, reifiedStack);
|
2014-04-16 06:58:44 +04:00
|
|
|
|
|
|
|
JS::Rooted<JS::Value> stackVal(aCx);
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!ToJSValue(aCx, reifiedStack, &stackVal))) {
|
2014-04-16 06:58:44 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(stackVal.isObject());
|
|
|
|
|
|
|
|
js::SetFunctionNativeReserved(callee, SLOT_STACKOBJ, stackVal);
|
|
|
|
js::SetFunctionNativeReserved(callee, SLOT_RAW_STACK, JS::UndefinedValue());
|
|
|
|
|
|
|
|
args.rval().set(stackVal);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
void
|
2016-03-24 00:55:07 +03:00
|
|
|
Console::ProcessCallData(JSContext* aCx, ConsoleCallData* aData,
|
2016-02-07 13:29:12 +03:00
|
|
|
const Sequence<JS::Value>& aArguments)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-02-11 20:11:02 +03:00
|
|
|
MOZ_ASSERT(aData);
|
2014-03-03 04:20:34 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Rooted<JS::Value> eventValue(aCx);
|
|
|
|
|
|
|
|
// We want to create a console event object and pass it to our
|
|
|
|
// nsIConsoleAPIStorage implementation. We want to define some accessor
|
|
|
|
// properties on this object, and those will need to keep an nsIStackFrame
|
|
|
|
// alive. But nsIStackFrame cannot be wrapped in an untrusted scope. And
|
|
|
|
// further, passing untrusted objects to system code is likely to run afoul of
|
|
|
|
// Object Xrays. So we want to wrap in a system-principal scope here. But
|
|
|
|
// which one? We could cheat and try to get the underlying JSObject* of
|
|
|
|
// mStorage, but that's a bit fragile. Instead, we just use the junk scope,
|
|
|
|
// with explicit permission from the XPConnect module owner. If you're
|
|
|
|
// tempted to do that anywhere else, talk to said module owner first.
|
2016-03-24 00:55:07 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
// aCx and aArguments are in the same compartment.
|
2016-03-24 11:29:08 +03:00
|
|
|
if (NS_WARN_IF(!PopulateConsoleNotificationInTheTargetScope(aCx, aArguments,
|
|
|
|
xpc::PrivilegedJunkScope(),
|
|
|
|
&eventValue, aData))) {
|
2016-03-24 00:55:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mStorage) {
|
|
|
|
mStorage = do_GetService("@mozilla.org/consoleAPI-storage;1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mStorage) {
|
|
|
|
NS_WARNING("Failed to get the ConsoleAPIStorage service.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString innerID, outerID;
|
|
|
|
|
|
|
|
MOZ_ASSERT(aData->mIDType != ConsoleCallData::eUnknown);
|
|
|
|
if (aData->mIDType == ConsoleCallData::eString) {
|
|
|
|
outerID = aData->mOuterIDString;
|
|
|
|
innerID = aData->mInnerIDString;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(aData->mIDType == ConsoleCallData::eNumber);
|
|
|
|
outerID.AppendInt(aData->mOuterIDNumber);
|
|
|
|
innerID.AppendInt(aData->mInnerIDNumber);
|
|
|
|
}
|
|
|
|
|
2016-04-13 17:33:43 +03:00
|
|
|
if (aData->mMethodName == MethodClear) {
|
2016-09-02 10:12:24 +03:00
|
|
|
DebugOnly<nsresult> rv = mStorage->ClearEvents(innerID);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "ClearEvents failed");
|
2016-04-13 17:33:43 +03:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_FAILED(mStorage->RecordEvent(innerID, outerID, eventValue))) {
|
|
|
|
NS_WARNING("Failed to record a console event.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-03-24 11:29:08 +03:00
|
|
|
Console::PopulateConsoleNotificationInTheTargetScope(JSContext* aCx,
|
|
|
|
const Sequence<JS::Value>& aArguments,
|
|
|
|
JSObject* aTargetScope,
|
|
|
|
JS::MutableHandle<JS::Value> aEventValue,
|
2017-04-18 11:04:00 +03:00
|
|
|
ConsoleCallData* aData)
|
2016-03-24 00:55:07 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCx);
|
|
|
|
MOZ_ASSERT(aData);
|
2016-03-24 00:55:07 +03:00
|
|
|
MOZ_ASSERT(aTargetScope);
|
2016-03-24 00:55:07 +03:00
|
|
|
|
2016-03-24 05:15:05 +03:00
|
|
|
JS::Rooted<JSObject*> targetScope(aCx, aTargetScope);
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
ConsoleStackEntry frame;
|
|
|
|
if (aData->mTopStackFrame) {
|
|
|
|
frame = *aData->mTopStackFrame;
|
|
|
|
}
|
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2016-03-24 00:55:07 +03:00
|
|
|
RootedDictionary<ConsoleEvent> event(aCx);
|
|
|
|
|
2017-02-27 00:13:45 +03:00
|
|
|
event.mAddonId = aData->mAddonId;
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
event.mID.Construct();
|
|
|
|
event.mInnerID.Construct();
|
2015-01-06 18:45:00 +03:00
|
|
|
|
|
|
|
if (aData->mIDType == ConsoleCallData::eString) {
|
|
|
|
event.mID.Value().SetAsString() = aData->mOuterIDString;
|
|
|
|
event.mInnerID.Value().SetAsString() = aData->mInnerIDString;
|
2016-03-24 00:55:07 +03:00
|
|
|
} else if (aData->mIDType == ConsoleCallData::eNumber) {
|
2015-03-17 14:13:00 +03:00
|
|
|
event.mID.Value().SetAsUnsignedLongLong() = aData->mOuterIDNumber;
|
|
|
|
event.mInnerID.Value().SetAsUnsignedLongLong() = aData->mInnerIDNumber;
|
2016-03-24 00:55:07 +03:00
|
|
|
} else {
|
|
|
|
// aData->mIDType can be eUnknown when we dispatch notifications via
|
2016-03-24 00:55:07 +03:00
|
|
|
// mConsoleEventNotifier.
|
2016-03-24 00:55:07 +03:00
|
|
|
event.mID.Value().SetAsUnsignedLongLong() = 0;
|
|
|
|
event.mInnerID.Value().SetAsUnsignedLongLong() = 0;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:43 +03:00
|
|
|
event.mConsoleID = mConsoleID;
|
2014-03-03 04:20:34 +04:00
|
|
|
event.mLevel = aData->mMethodString;
|
2014-02-28 03:39:00 +04:00
|
|
|
event.mFilename = frame.mFilename;
|
2018-01-17 20:19:36 +03:00
|
|
|
event.mPrefix = mPrefix;
|
2015-09-14 22:38:57 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> filenameURI;
|
|
|
|
nsAutoCString pass;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_IsMainThread() &&
|
|
|
|
NS_SUCCEEDED(NS_NewURI(getter_AddRefs(filenameURI), frame.mFilename)) &&
|
2015-09-14 22:38:57 +03:00
|
|
|
NS_SUCCEEDED(filenameURI->GetPassword(pass)) && !pass.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsISensitiveInfoHiddenURI> safeURI = do_QueryInterface(filenameURI);
|
|
|
|
nsAutoCString spec;
|
|
|
|
if (safeURI &&
|
|
|
|
NS_SUCCEEDED(safeURI->GetSensitiveInfoHiddenSpec(spec))) {
|
|
|
|
CopyUTF8toUTF16(spec, event.mFilename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
event.mLineNumber = frame.mLineNumber;
|
2014-09-22 22:28:55 +04:00
|
|
|
event.mColumnNumber = frame.mColumnNumber;
|
2014-02-28 03:39:00 +04:00
|
|
|
event.mFunctionName = frame.mFunctionName;
|
2014-03-03 04:20:34 +04:00
|
|
|
event.mTimeStamp = aData->mTimeStamp;
|
2016-12-17 00:08:31 +03:00
|
|
|
event.mPrivate = !!aData->mOriginAttributes.mPrivateBrowsingId;
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2014-03-03 04:20:34 +04:00
|
|
|
switch (aData->mMethodName) {
|
2014-02-28 03:39:00 +04:00
|
|
|
case MethodLog:
|
|
|
|
case MethodInfo:
|
|
|
|
case MethodWarn:
|
|
|
|
case MethodError:
|
|
|
|
case MethodException:
|
|
|
|
case MethodDebug:
|
|
|
|
case MethodAssert:
|
2017-04-11 16:14:40 +03:00
|
|
|
case MethodGroup:
|
|
|
|
case MethodGroupCollapsed:
|
2014-02-28 03:39:00 +04:00
|
|
|
event.mArguments.Construct();
|
2014-04-10 18:59:21 +04:00
|
|
|
event.mStyles.Construct();
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!ProcessArguments(aCx, aArguments,
|
|
|
|
event.mArguments.Value(),
|
|
|
|
event.mStyles.Value()))) {
|
|
|
|
return false;
|
2015-05-25 14:50:15 +03:00
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
event.mArguments.Construct();
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!ArgumentsToValueList(aArguments,
|
|
|
|
event.mArguments.Value()))) {
|
|
|
|
return false;
|
2015-05-25 14:50:15 +03:00
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-04-16 06:58:44 +04:00
|
|
|
if (aData->mMethodName == MethodGroup ||
|
2017-04-18 11:04:00 +03:00
|
|
|
aData->mMethodName == MethodGroupCollapsed) {
|
|
|
|
ComposeAndStoreGroupName(aCx, event.mArguments.Value(), event.mGroupName);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (aData->mMethodName == MethodGroupEnd) {
|
|
|
|
if (!UnstoreGroupName(event.mGroupName)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
else if (aData->mMethodName == MethodTime && !aArguments.IsEmpty()) {
|
2016-03-24 00:55:07 +03:00
|
|
|
event.mTimer = CreateStartTimerValue(aCx, aData->mStartTimerLabel,
|
2016-02-11 20:09:22 +03:00
|
|
|
aData->mStartTimerStatus);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
else if (aData->mMethodName == MethodTimeEnd && !aArguments.IsEmpty()) {
|
2016-03-24 00:55:07 +03:00
|
|
|
event.mTimer = CreateStopTimerValue(aCx, aData->mStopTimerLabel,
|
2016-02-11 20:09:22 +03:00
|
|
|
aData->mStopTimerDuration,
|
|
|
|
aData->mStopTimerStatus);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-03-03 04:20:34 +04:00
|
|
|
else if (aData->mMethodName == MethodCount) {
|
2016-03-24 00:55:07 +03:00
|
|
|
event.mCounter = CreateCounterValue(aCx, aData->mCountLabel,
|
2016-02-11 20:09:22 +03:00
|
|
|
aData->mCountValue);
|
2014-02-28 03:39:24 +04:00
|
|
|
}
|
|
|
|
|
2016-03-24 05:15:05 +03:00
|
|
|
JSAutoCompartment ac2(aCx, targetScope);
|
2014-04-16 23:09:23 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!ToJSValue(aCx, event, aEventValue))) {
|
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Rooted<JSObject*> eventObj(aCx, &aEventValue.toObject());
|
|
|
|
if (NS_WARN_IF(!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventObj,
|
|
|
|
JSPROP_ENUMERATE))) {
|
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-10-20 12:34:00 +04:00
|
|
|
if (ShouldIncludeStackTrace(aData->mMethodName)) {
|
2014-04-16 06:58:44 +04:00
|
|
|
// Now define the "stacktrace" property on eventObj. There are two cases
|
|
|
|
// here. Either we came from a worker and have a reified stack, or we want
|
|
|
|
// to define a getter that will lazily reify the stack.
|
2014-08-14 02:39:41 +04:00
|
|
|
if (aData->mReifiedStack) {
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Rooted<JS::Value> stacktrace(aCx);
|
|
|
|
if (NS_WARN_IF(!ToJSValue(aCx, *aData->mReifiedStack, &stacktrace)) ||
|
|
|
|
NS_WARN_IF(!JS_DefineProperty(aCx, eventObj, "stacktrace", stacktrace,
|
|
|
|
JSPROP_ENUMERATE))) {
|
|
|
|
return false;
|
2014-04-16 06:58:44 +04:00
|
|
|
}
|
|
|
|
} else {
|
2016-03-24 00:55:07 +03:00
|
|
|
JSFunction* fun = js::NewFunctionWithReserved(aCx, LazyStackGetter, 0, 0,
|
2015-03-09 19:50:07 +03:00
|
|
|
"stacktrace");
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!fun)) {
|
|
|
|
return false;
|
2014-04-16 06:58:44 +04:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Rooted<JSObject*> funObj(aCx, JS_GetFunctionObject(fun));
|
2014-04-16 06:58:44 +04:00
|
|
|
|
|
|
|
// We want to store our stack in the function and have it stay alive. But
|
|
|
|
// we also need sane access to the C++ nsIStackFrame. So store both a JS
|
|
|
|
// wrapper and the raw pointer: the former will keep the latter alive.
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Rooted<JS::Value> stackVal(aCx);
|
|
|
|
nsresult rv = nsContentUtils::WrapNative(aCx, aData->mStack,
|
2014-04-16 06:58:44 +04:00
|
|
|
&stackVal);
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
2014-04-16 06:58:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
js::SetFunctionNativeReserved(funObj, SLOT_STACKOBJ, stackVal);
|
|
|
|
js::SetFunctionNativeReserved(funObj, SLOT_RAW_STACK,
|
|
|
|
JS::PrivateValue(aData->mStack.get()));
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!JS_DefineProperty(aCx, eventObj, "stacktrace",
|
|
|
|
JS_DATA_TO_FUNC_PTR(JSNative, funObj.get()),
|
2017-08-30 16:35:06 +03:00
|
|
|
nullptr,
|
2017-09-26 13:26:50 +03:00
|
|
|
JSPROP_ENUMERATE |
|
2017-08-30 16:35:06 +03:00
|
|
|
JSPROP_GETTER | JSPROP_SETTER))) {
|
2016-03-24 00:55:07 +03:00
|
|
|
return false;
|
2014-04-16 06:58:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
return true;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2015-05-04 18:28:25 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Helper method for ProcessArguments. Flushes output, if non-empty, to aSequence.
|
2015-05-25 14:50:15 +03:00
|
|
|
bool
|
|
|
|
FlushOutput(JSContext* aCx, Sequence<JS::Value>& aSequence, nsString &aOutput)
|
2015-05-04 18:28:25 +03:00
|
|
|
{
|
2015-05-25 14:50:15 +03:00
|
|
|
if (!aOutput.IsEmpty()) {
|
2015-05-04 18:28:25 +03:00
|
|
|
JS::Rooted<JSString*> str(aCx, JS_NewUCStringCopyN(aCx,
|
2015-05-25 14:50:15 +03:00
|
|
|
aOutput.get(),
|
|
|
|
aOutput.Length()));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!str)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!aSequence.AppendElement(JS::StringValue(str), fallible))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2015-05-04 18:28:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-25 14:50:15 +03:00
|
|
|
aOutput.Truncate();
|
2015-05-04 18:28:25 +03:00
|
|
|
}
|
2015-05-25 14:50:15 +03:00
|
|
|
|
|
|
|
return true;
|
2015-05-04 18:28:25 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2015-05-04 18:28:25 +03:00
|
|
|
|
2015-05-25 14:50:15 +03:00
|
|
|
bool
|
2014-02-28 03:39:00 +04:00
|
|
|
Console::ProcessArguments(JSContext* aCx,
|
2016-02-07 13:29:12 +03:00
|
|
|
const Sequence<JS::Value>& aData,
|
2014-04-10 18:59:21 +04:00
|
|
|
Sequence<JS::Value>& aSequence,
|
2016-02-13 19:08:17 +03:00
|
|
|
Sequence<nsString>& aStyles) const
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
|
|
|
if (aData.IsEmpty()) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return true;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Length() == 1 || !aData[0].isString()) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return ArgumentsToValueList(aData, aSequence);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> format(aCx, aData[0]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, format));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!jsString)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString string;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!string.init(aCx, jsString))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsString::const_iterator start, end;
|
|
|
|
string.BeginReading(start);
|
|
|
|
string.EndReading(end);
|
|
|
|
|
|
|
|
nsString output;
|
|
|
|
uint32_t index = 1;
|
|
|
|
|
|
|
|
while (start != end) {
|
|
|
|
if (*start != '%') {
|
|
|
|
output.Append(*start);
|
|
|
|
++start;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++start;
|
2014-03-05 07:22:32 +04:00
|
|
|
if (start == end) {
|
|
|
|
output.Append('%');
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
|
|
|
if (*start == '%') {
|
|
|
|
output.Append(*start);
|
|
|
|
++start;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:12 +04:00
|
|
|
nsAutoString tmp;
|
|
|
|
tmp.Append('%');
|
|
|
|
|
|
|
|
int32_t integer = -1;
|
|
|
|
int32_t mantissa = -1;
|
|
|
|
|
|
|
|
// Let's parse %<number>.<number> for %d and %f
|
|
|
|
if (*start >= '0' && *start <= '9') {
|
|
|
|
integer = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
integer = integer * 10 + *start - '0';
|
|
|
|
tmp.Append(*start);
|
|
|
|
++start;
|
2014-03-05 07:22:32 +04:00
|
|
|
} while (*start >= '0' && *start <= '9' && start != end);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start == end) {
|
|
|
|
output.Append(tmp);
|
|
|
|
break;
|
2014-02-28 03:39:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*start == '.') {
|
|
|
|
tmp.Append(*start);
|
|
|
|
++start;
|
|
|
|
|
2014-03-05 07:22:32 +04:00
|
|
|
if (start == end) {
|
|
|
|
output.Append(tmp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:12 +04:00
|
|
|
// '.' must be followed by a number.
|
|
|
|
if (*start < '0' || *start > '9') {
|
|
|
|
output.Append(tmp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mantissa = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
mantissa = mantissa * 10 + *start - '0';
|
|
|
|
tmp.Append(*start);
|
|
|
|
++start;
|
2014-03-05 07:22:32 +04:00
|
|
|
} while (*start >= '0' && *start <= '9' && start != end);
|
|
|
|
|
|
|
|
if (start == end) {
|
|
|
|
output.Append(tmp);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 03:39:12 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
char ch = *start;
|
2014-02-28 03:39:12 +04:00
|
|
|
tmp.Append(ch);
|
2014-02-28 03:39:00 +04:00
|
|
|
++start;
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case 'o':
|
2014-04-10 18:59:21 +04:00
|
|
|
case 'O':
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!FlushOutput(aCx, aSequence, output))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
|
|
|
JS::Rooted<JS::Value> v(aCx);
|
|
|
|
if (index < aData.Length()) {
|
|
|
|
v = aData[index++];
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!aSequence.AppendElement(v, fallible))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-10 18:59:21 +04:00
|
|
|
case 'c':
|
|
|
|
{
|
2015-09-11 17:44:06 +03:00
|
|
|
// If there isn't any output but there's already a style, then
|
|
|
|
// discard the previous style and use the next one instead.
|
|
|
|
if (output.IsEmpty() && !aStyles.IsEmpty()) {
|
|
|
|
aStyles.TruncateLength(aStyles.Length() - 1);
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!FlushOutput(aCx, aSequence, output))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-10 18:59:21 +04:00
|
|
|
|
|
|
|
if (index < aData.Length()) {
|
|
|
|
JS::Rooted<JS::Value> v(aCx, aData[index++]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, v));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!jsString)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2014-04-10 18:59:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t diff = aSequence.Length() - aStyles.Length();
|
|
|
|
if (diff > 0) {
|
|
|
|
for (int32_t i = 0; i < diff; i++) {
|
2017-09-22 07:35:46 +03:00
|
|
|
if (NS_WARN_IF(!aStyles.AppendElement(VoidString(), fallible))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-10 18:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-25 14:50:15 +03:00
|
|
|
|
2016-02-13 19:08:17 +03:00
|
|
|
nsAutoJSString string;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!string.init(aCx, jsString))) {
|
2016-02-13 19:08:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!aStyles.AppendElement(string, fallible))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-10 18:59:21 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
case 's':
|
|
|
|
if (index < aData.Length()) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx, aData[index++]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!jsString)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString v;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!v.init(aCx, jsString))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
output.Append(v);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
case 'i':
|
|
|
|
if (index < aData.Length()) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx, aData[index++]);
|
|
|
|
|
|
|
|
int32_t v;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!JS::ToInt32(aCx, value, &v))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:12 +04:00
|
|
|
nsCString format;
|
|
|
|
MakeFormatString(format, integer, mantissa, 'd');
|
|
|
|
output.AppendPrintf(format.get(), v);
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
if (index < aData.Length()) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx, aData[index++]);
|
|
|
|
|
|
|
|
double v;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!JS::ToNumber(aCx, value, &v))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-01-28 01:22:45 +03:00
|
|
|
// nspr returns "nan", but we want to expose it as "NaN"
|
|
|
|
if (std::isnan(v)) {
|
|
|
|
output.AppendFloat(v);
|
|
|
|
} else {
|
|
|
|
nsCString format;
|
|
|
|
MakeFormatString(format, integer, mantissa, 'f');
|
|
|
|
output.AppendPrintf(format.get(), v);
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-02-28 03:39:12 +04:00
|
|
|
output.Append(tmp);
|
2014-02-28 03:39:00 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!FlushOutput(aCx, aSequence, output))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
|
2015-05-04 18:28:25 +03:00
|
|
|
// Discard trailing style element if there is no output to apply it to.
|
|
|
|
if (aStyles.Length() > aSequence.Length()) {
|
|
|
|
aStyles.TruncateLength(aSequence.Length());
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The rest of the array, if unused by the format string.
|
|
|
|
for (; index < aData.Length(); ++index) {
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!aSequence.AppendElement(aData[index], fallible))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
2015-05-25 14:50:15 +03:00
|
|
|
|
|
|
|
return true;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:12 +04:00
|
|
|
void
|
|
|
|
Console::MakeFormatString(nsCString& aFormat, int32_t aInteger,
|
2016-02-07 13:29:12 +03:00
|
|
|
int32_t aMantissa, char aCh) const
|
2014-02-28 03:39:12 +04:00
|
|
|
{
|
2014-05-22 07:48:52 +04:00
|
|
|
aFormat.Append('%');
|
2014-02-28 03:39:12 +04:00
|
|
|
if (aInteger >= 0) {
|
|
|
|
aFormat.AppendInt(aInteger);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMantissa >= 0) {
|
2014-05-22 07:48:52 +04:00
|
|
|
aFormat.Append('.');
|
2014-02-28 03:39:12 +04:00
|
|
|
aFormat.AppendInt(aMantissa);
|
|
|
|
}
|
|
|
|
|
|
|
|
aFormat.Append(aCh);
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
void
|
2017-04-18 11:04:00 +03:00
|
|
|
Console::ComposeAndStoreGroupName(JSContext* aCx,
|
|
|
|
const Sequence<JS::Value>& aData,
|
|
|
|
nsAString& aName)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < aData.Length(); ++i) {
|
|
|
|
if (i != 0) {
|
|
|
|
aName.AppendASCII(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx, aData[i]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
|
|
|
|
if (!jsString) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString string;
|
2014-02-28 03:39:00 +04:00
|
|
|
if (!string.init(aCx, jsString)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aName.Append(string);
|
|
|
|
}
|
2017-04-18 11:04:00 +03:00
|
|
|
|
|
|
|
mGroupStack.AppendElement(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Console::UnstoreGroupName(nsAString& aName)
|
|
|
|
{
|
|
|
|
if (mGroupStack.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t pos = mGroupStack.Length() - 1;
|
|
|
|
aName = mGroupStack[pos];
|
|
|
|
mGroupStack.RemoveElementAt(pos);
|
|
|
|
return true;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2017-05-12 00:36:12 +03:00
|
|
|
Console::TimerStatus
|
2014-02-28 03:39:00 +04:00
|
|
|
Console::StartTimer(JSContext* aCx, const JS::Value& aName,
|
2016-02-11 20:09:22 +03:00
|
|
|
DOMHighResTimeStamp aTimestamp,
|
|
|
|
nsAString& aTimerLabel,
|
|
|
|
DOMHighResTimeStamp* aTimerValue)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2016-02-11 20:11:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-02-11 20:09:22 +03:00
|
|
|
MOZ_ASSERT(aTimerValue);
|
2016-02-11 20:11:02 +03:00
|
|
|
|
2016-02-11 20:09:22 +03:00
|
|
|
*aTimerValue = 0;
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(mTimerRegistry.Count() >= MAX_PAGE_TIMERS)) {
|
2017-05-12 00:36:09 +03:00
|
|
|
return eTimerMaxReached;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> name(aCx, aName);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, name));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!jsString)) {
|
2017-05-12 00:36:09 +03:00
|
|
|
return eTimerJSException;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-02-11 20:09:22 +03:00
|
|
|
nsAutoJSString label;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!label.init(aCx, jsString))) {
|
2017-05-12 00:36:09 +03:00
|
|
|
return eTimerJSException;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2017-05-12 00:36:09 +03:00
|
|
|
aTimerLabel = label;
|
|
|
|
|
2017-06-14 18:27:25 +03:00
|
|
|
auto entry = mTimerRegistry.LookupForAdd(label);
|
|
|
|
if (entry) {
|
2017-05-12 00:36:09 +03:00
|
|
|
return eTimerAlreadyExists;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
2017-06-14 18:27:25 +03:00
|
|
|
entry.OrInsert([&aTimestamp](){ return aTimestamp; });
|
2017-05-12 00:36:09 +03:00
|
|
|
|
2016-02-11 20:09:22 +03:00
|
|
|
*aTimerValue = aTimestamp;
|
2017-05-12 00:36:12 +03:00
|
|
|
return eTimerDone;
|
2016-02-11 20:09:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
Console::CreateStartTimerValue(JSContext* aCx, const nsAString& aTimerLabel,
|
2017-05-12 00:36:12 +03:00
|
|
|
TimerStatus aTimerStatus) const
|
2016-02-11 20:09:22 +03:00
|
|
|
{
|
2017-05-12 00:36:09 +03:00
|
|
|
MOZ_ASSERT(aTimerStatus != eTimerUnknown);
|
|
|
|
|
2017-05-12 00:36:12 +03:00
|
|
|
if (aTimerStatus != eTimerDone) {
|
|
|
|
return CreateTimerError(aCx, aTimerLabel, aTimerStatus);
|
2016-02-11 20:09:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RootedDictionary<ConsoleTimerStart> timer(aCx);
|
|
|
|
|
|
|
|
timer.mName = aTimerLabel;
|
2014-02-28 03:39:00 +04:00
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(aCx, timer, &value)) {
|
2014-02-28 03:39:00 +04:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2017-05-12 00:36:12 +03:00
|
|
|
Console::TimerStatus
|
2014-02-28 03:39:00 +04:00
|
|
|
Console::StopTimer(JSContext* aCx, const JS::Value& aName,
|
2016-02-11 20:09:22 +03:00
|
|
|
DOMHighResTimeStamp aTimestamp,
|
|
|
|
nsAString& aTimerLabel,
|
|
|
|
double* aTimerDuration)
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
2016-02-11 20:11:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-02-11 20:09:22 +03:00
|
|
|
MOZ_ASSERT(aTimerDuration);
|
2016-02-11 20:11:02 +03:00
|
|
|
|
2016-02-11 20:09:22 +03:00
|
|
|
*aTimerDuration = 0;
|
2016-02-07 13:29:12 +03:00
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
JS::Rooted<JS::Value> name(aCx, aName);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, name));
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!jsString)) {
|
2017-05-12 00:36:12 +03:00
|
|
|
return eTimerJSException;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString key;
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!key.init(aCx, jsString))) {
|
2017-05-12 00:36:12 +03:00
|
|
|
return eTimerJSException;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2017-05-12 00:36:12 +03:00
|
|
|
aTimerLabel = key;
|
|
|
|
|
2017-06-18 18:07:54 +03:00
|
|
|
DOMHighResTimeStamp value = 0;
|
2017-07-05 03:01:44 +03:00
|
|
|
if (!mTimerRegistry.Remove(key, &value)) {
|
2017-06-18 18:07:54 +03:00
|
|
|
NS_WARNING("mTimerRegistry entry not found");
|
2017-05-12 00:36:12 +03:00
|
|
|
return eTimerDoesntExist;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2017-06-18 18:07:54 +03:00
|
|
|
*aTimerDuration = aTimestamp - value;
|
2017-05-12 00:36:12 +03:00
|
|
|
return eTimerDone;
|
2016-02-11 20:09:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
Console::CreateStopTimerValue(JSContext* aCx, const nsAString& aLabel,
|
2017-05-12 00:36:12 +03:00
|
|
|
double aDuration, TimerStatus aStatus) const
|
2016-02-11 20:09:22 +03:00
|
|
|
{
|
2017-05-12 00:36:12 +03:00
|
|
|
if (aStatus != eTimerDone) {
|
|
|
|
return CreateTimerError(aCx, aLabel, aStatus);
|
2016-02-11 20:09:22 +03:00
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
RootedDictionary<ConsoleTimerEnd> timer(aCx);
|
2016-02-11 20:09:22 +03:00
|
|
|
timer.mName = aLabel;
|
|
|
|
timer.mDuration = aDuration;
|
2014-02-28 03:39:00 +04:00
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(aCx, timer, &value)) {
|
2014-02-28 03:39:00 +04:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2017-05-12 00:36:12 +03:00
|
|
|
JS::Value
|
|
|
|
Console::CreateTimerError(JSContext* aCx, const nsAString& aLabel,
|
|
|
|
TimerStatus aStatus) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aStatus != eTimerUnknown && aStatus != eTimerDone);
|
|
|
|
|
|
|
|
RootedDictionary<ConsoleTimerError> error(aCx);
|
|
|
|
|
|
|
|
error.mName = aLabel;
|
|
|
|
|
|
|
|
switch (aStatus) {
|
|
|
|
case eTimerAlreadyExists:
|
|
|
|
error.mError.AssignLiteral("timerAlreadyExists");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTimerDoesntExist:
|
|
|
|
error.mError.AssignLiteral("timerDoesntExist");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTimerJSException:
|
|
|
|
error.mError.AssignLiteral("timerJSError");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTimerMaxReached:
|
|
|
|
error.mError.AssignLiteral("maxTimersExceeded");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unsupported status");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
if (!ToJSValue(aCx, error, &value)) {
|
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-05-25 14:50:15 +03:00
|
|
|
bool
|
2016-02-07 13:29:12 +03:00
|
|
|
Console::ArgumentsToValueList(const Sequence<JS::Value>& aData,
|
|
|
|
Sequence<JS::Value>& aSequence) const
|
2014-02-28 03:39:00 +04:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < aData.Length(); ++i) {
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(!aSequence.AppendElement(aData[i], fallible))) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
2015-05-25 14:50:15 +03:00
|
|
|
|
|
|
|
return true;
|
2014-02-28 03:39:00 +04:00
|
|
|
}
|
|
|
|
|
2016-02-11 20:09:22 +03:00
|
|
|
uint32_t
|
2017-04-07 19:04:10 +03:00
|
|
|
Console::IncreaseCounter(JSContext* aCx, const Sequence<JS::Value>& aArguments,
|
2016-02-11 20:09:22 +03:00
|
|
|
nsAString& aCountLabel)
|
2014-02-28 03:39:24 +04:00
|
|
|
{
|
2016-02-11 20:11:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2014-02-28 03:39:24 +04:00
|
|
|
|
2017-04-20 14:52:41 +03:00
|
|
|
MOZ_ASSERT(!aArguments.IsEmpty());
|
2014-02-28 03:39:24 +04:00
|
|
|
|
2017-04-20 14:52:41 +03:00
|
|
|
JS::Rooted<JS::Value> labelValue(aCx, aArguments[0]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, labelValue));
|
|
|
|
if (!jsString) {
|
|
|
|
return 0; // We cannot continue.
|
|
|
|
}
|
2014-02-28 03:39:24 +04:00
|
|
|
|
2017-04-20 14:52:41 +03:00
|
|
|
nsAutoJSString string;
|
|
|
|
if (!string.init(aCx, jsString)) {
|
|
|
|
return 0; // We cannot continue.
|
2014-02-28 03:39:24 +04:00
|
|
|
}
|
|
|
|
|
2017-04-20 14:52:41 +03:00
|
|
|
aCountLabel = string;
|
|
|
|
|
2017-06-14 18:27:25 +03:00
|
|
|
const bool maxCountersReached = mCounterRegistry.Count() >= MAX_PAGE_COUNTERS;
|
|
|
|
auto entry = mCounterRegistry.LookupForAdd(aCountLabel);
|
|
|
|
if (entry) {
|
|
|
|
++entry.Data();
|
|
|
|
} else {
|
|
|
|
entry.OrInsert([](){ return 1; });
|
|
|
|
if (maxCountersReached) {
|
|
|
|
// oops, we speculatively added an entry even though we shouldn't
|
|
|
|
mCounterRegistry.Remove(aCountLabel);
|
|
|
|
return MAX_PAGE_COUNTERS;
|
|
|
|
}
|
2014-02-28 03:39:24 +04:00
|
|
|
}
|
2017-06-14 18:27:25 +03:00
|
|
|
return entry.Data();
|
2016-02-11 20:09:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
|
|
|
Console::CreateCounterValue(JSContext* aCx, const nsAString& aCountLabel,
|
|
|
|
uint32_t aCountValue) const
|
|
|
|
{
|
2018-01-11 00:06:37 +03:00
|
|
|
ConsoleCommon::ClearException ce(aCx);
|
2016-02-11 20:09:22 +03:00
|
|
|
|
|
|
|
if (aCountValue == MAX_PAGE_COUNTERS) {
|
|
|
|
RootedDictionary<ConsoleCounterError> error(aCx);
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
if (!ToJSValue(aCx, error, &value)) {
|
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:24 +04:00
|
|
|
RootedDictionary<ConsoleCounter> data(aCx);
|
2016-02-11 20:09:22 +03:00
|
|
|
data.mLabel = aCountLabel;
|
|
|
|
data.mCount = aCountValue;
|
2014-02-28 03:39:24 +04:00
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
2014-06-11 23:38:55 +04:00
|
|
|
if (!ToJSValue(aCx, data, &value)) {
|
2014-02-28 03:39:24 +04:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2014-04-11 00:02:37 +04:00
|
|
|
bool
|
2016-02-07 13:29:12 +03:00
|
|
|
Console::ShouldIncludeStackTrace(MethodName aMethodName) const
|
2014-04-11 00:02:37 +04:00
|
|
|
{
|
|
|
|
switch (aMethodName) {
|
|
|
|
case MethodError:
|
|
|
|
case MethodException:
|
|
|
|
case MethodAssert:
|
|
|
|
case MethodTrace:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:31:44 +03:00
|
|
|
JSObject*
|
2015-01-06 18:45:00 +03:00
|
|
|
Console::GetOrCreateSandbox(JSContext* aCx, nsIPrincipal* aPrincipal)
|
|
|
|
{
|
2016-02-11 20:09:22 +03:00
|
|
|
AssertIsOnMainThread();
|
2015-01-06 18:45:00 +03:00
|
|
|
|
|
|
|
if (!mSandbox) {
|
|
|
|
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
|
|
|
MOZ_ASSERT(xpc, "This should never be null!");
|
|
|
|
|
2015-07-21 21:31:44 +03:00
|
|
|
JS::Rooted<JSObject*> sandbox(aCx);
|
|
|
|
nsresult rv = xpc->CreateSandbox(aCx, aPrincipal, sandbox.address());
|
2015-01-06 18:45:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-21 21:31:44 +03:00
|
|
|
|
|
|
|
mSandbox = new JSObjectHolder(aCx, sandbox);
|
2015-01-06 18:45:00 +03:00
|
|
|
}
|
|
|
|
|
2015-07-21 21:31:44 +03:00
|
|
|
return mSandbox->GetJSObject();
|
2015-01-06 18:45:00 +03:00
|
|
|
}
|
|
|
|
|
2016-02-07 13:29:12 +03:00
|
|
|
void
|
2016-03-24 00:55:07 +03:00
|
|
|
Console::StoreCallData(ConsoleCallData* aCallData)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_ASSERT(aCallData);
|
|
|
|
MOZ_ASSERT(!mCallDataStorage.Contains(aCallData));
|
|
|
|
MOZ_ASSERT(!mCallDataStoragePending.Contains(aCallData));
|
|
|
|
|
|
|
|
mCallDataStorage.AppendElement(aCallData);
|
|
|
|
|
|
|
|
if (mCallDataStorage.Length() > STORAGE_MAX_EVENTS) {
|
|
|
|
RefPtr<ConsoleCallData> callData = mCallDataStorage[0];
|
|
|
|
mCallDataStorage.RemoveElementAt(0);
|
|
|
|
|
|
|
|
MOZ_ASSERT(callData->mStatus != ConsoleCallData::eToBeDeleted);
|
|
|
|
|
|
|
|
// We cannot delete this object now because we have to trace its JSValues
|
|
|
|
// until the pending operation (ConsoleCallDataRunnable) is completed.
|
|
|
|
if (callData->mStatus == ConsoleCallData::eInUse) {
|
|
|
|
callData->mStatus = ConsoleCallData::eToBeDeleted;
|
|
|
|
mCallDataStoragePending.AppendElement(callData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Console::UnstoreCallData(ConsoleCallData* aCallData)
|
2016-02-07 13:29:12 +03:00
|
|
|
{
|
2016-02-11 20:11:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
MOZ_ASSERT(aCallData);
|
2016-06-08 13:49:51 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
MOZ_ASSERT(!mCallDataStoragePending.Contains(aCallData));
|
|
|
|
|
2016-06-08 13:49:51 +03:00
|
|
|
// It can be that mCallDataStorage has been already cleaned in case the
|
|
|
|
// processing of the argument of some Console methods triggers the
|
|
|
|
// window.close().
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
mCallDataStorage.RemoveElement(aCallData);
|
2016-02-07 13:29:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-24 00:55:07 +03:00
|
|
|
Console::ReleaseCallData(ConsoleCallData* aCallData)
|
2016-02-07 13:29:12 +03:00
|
|
|
{
|
2016-02-11 20:11:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-03-24 00:55:07 +03:00
|
|
|
MOZ_ASSERT(aCallData);
|
|
|
|
MOZ_ASSERT(aCallData->mStatus == ConsoleCallData::eToBeDeleted);
|
|
|
|
MOZ_ASSERT(mCallDataStoragePending.Contains(aCallData));
|
2016-02-11 20:11:02 +03:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
mCallDataStoragePending.RemoveElement(aCallData);
|
2016-02-07 13:29:12 +03:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
void
|
2016-03-24 00:55:07 +03:00
|
|
|
Console::NotifyHandler(JSContext* aCx, const Sequence<JS::Value>& aArguments,
|
2017-04-18 11:04:00 +03:00
|
|
|
ConsoleCallData* aCallData)
|
2016-03-24 00:55:07 +03:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aCallData);
|
|
|
|
|
|
|
|
if (!mConsoleEventNotifier) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
2016-03-24 00:55:07 +03:00
|
|
|
|
2016-11-15 08:25:37 +03:00
|
|
|
JS::Rooted<JSObject*> callable(aCx, mConsoleEventNotifier->CallableOrNull());
|
|
|
|
if (NS_WARN_IF(!callable)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
// aCx and aArguments are in the same compartment because this method is
|
|
|
|
// called directly when a Console.something() runs.
|
|
|
|
// mConsoleEventNotifier->Callable() is the scope where value will be sent to.
|
2016-03-24 11:29:08 +03:00
|
|
|
if (NS_WARN_IF(!PopulateConsoleNotificationInTheTargetScope(aCx, aArguments,
|
2016-11-15 08:25:37 +03:00
|
|
|
callable,
|
2016-03-24 11:29:08 +03:00
|
|
|
&value,
|
|
|
|
aCallData))) {
|
2016-03-24 00:55:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> ignored(aCx);
|
|
|
|
mConsoleEventNotifier->Call(value, &ignored);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Console::RetrieveConsoleEvents(JSContext* aCx, nsTArray<JS::Value>& aEvents,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
// We don't want to expose this functionality to main-thread yet.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Rooted<JSObject*> targetScope(aCx, JS::CurrentGlobalOrNull(aCx));
|
2016-03-24 00:55:07 +03:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mCallDataStorage.Length(); ++i) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx);
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
JS::Rooted<JSObject*> sequenceScope(aCx, mCallDataStorage[i]->mGlobal);
|
|
|
|
JSAutoCompartment ac(aCx, sequenceScope);
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
Sequence<JS::Value> sequence;
|
|
|
|
SequenceRooter<JS::Value> arguments(aCx, &sequence);
|
|
|
|
|
|
|
|
if (!mCallDataStorage[i]->PopulateArgumentsSequence(sequence)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
// Here we have aCx and sequence in the same compartment.
|
|
|
|
// targetScope is the destination scope and value will be populated in its
|
|
|
|
// compartment.
|
2016-03-24 11:29:08 +03:00
|
|
|
if (NS_WARN_IF(!PopulateConsoleNotificationInTheTargetScope(aCx, sequence,
|
|
|
|
targetScope,
|
|
|
|
&value,
|
|
|
|
mCallDataStorage[i]))) {
|
2016-03-24 00:55:07 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvents.AppendElement(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-29 17:56:10 +03:00
|
|
|
Console::SetConsoleEventHandler(AnyCallback* aHandler)
|
2016-03-24 00:55:07 +03:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
// We don't want to expose this functionality to main-thread yet.
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
2016-03-29 17:56:10 +03:00
|
|
|
mConsoleEventNotifier = aHandler;
|
2016-03-24 00:55:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-11 20:11:02 +03:00
|
|
|
void
|
|
|
|
Console::AssertIsOnOwningThread() const
|
|
|
|
{
|
2017-05-03 18:48:54 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(Console);
|
2016-02-11 20:11:02 +03:00
|
|
|
}
|
|
|
|
|
2016-05-03 11:19:39 +03:00
|
|
|
bool
|
|
|
|
Console::IsShuttingDown() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mStatus != eUnknown);
|
|
|
|
return mStatus == eShuttingDown;
|
|
|
|
}
|
|
|
|
|
2016-06-04 10:32:51 +03:00
|
|
|
/* static */ already_AddRefed<Console>
|
|
|
|
Console::GetConsole(const GlobalObject& aGlobal)
|
|
|
|
{
|
2016-11-06 11:54:52 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
RefPtr<Console> console = GetConsoleInternal(aGlobal, rv);
|
|
|
|
if (NS_WARN_IF(rv.Failed()) || !console) {
|
|
|
|
rv.SuppressException();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
console->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (console->IsShuttingDown()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return console.forget();
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
/* static */ already_AddRefed<Console>
|
2016-11-06 11:54:52 +03:00
|
|
|
Console::GetConsoleInternal(const GlobalObject& aGlobal, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Worklet
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<WorkletGlobalScope> workletScope =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (workletScope) {
|
|
|
|
return workletScope->GetConsole(aRv);
|
|
|
|
}
|
|
|
|
}
|
2016-06-04 10:32:51 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
// Window
|
2016-06-04 10:32:51 +03:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> innerWindow =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
2017-12-20 16:35:34 +03:00
|
|
|
|
|
|
|
// we are probably running a chrome script.
|
|
|
|
if (!innerWindow) {
|
|
|
|
RefPtr<Console> console = new Console(nullptr);
|
|
|
|
console->Initialize(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return console.forget();
|
2016-06-04 10:32:51 +03:00
|
|
|
}
|
|
|
|
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* window = nsGlobalWindowInner::Cast(innerWindow);
|
2016-11-06 11:54:52 +03:00
|
|
|
return window->GetConsole(aRv);
|
|
|
|
}
|
2016-06-04 10:32:51 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
// Workers
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2016-06-04 10:32:51 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
JSContext* cx = aGlobal.Context();
|
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
2016-06-04 10:32:51 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (NS_WARN_IF(!global)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-06-04 10:32:51 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
WorkerGlobalScope* scope = workerPrivate->GlobalScope();
|
|
|
|
MOZ_ASSERT(scope);
|
2016-06-04 10:32:51 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
// Normal worker scope.
|
|
|
|
if (scope == global) {
|
|
|
|
return scope->GetConsole(aRv);
|
2016-06-04 10:32:51 +03:00
|
|
|
}
|
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
// Debugger worker scope
|
|
|
|
else {
|
|
|
|
WorkerDebuggerGlobalScope* debuggerScope =
|
|
|
|
workerPrivate->DebuggerGlobalScope();
|
|
|
|
MOZ_ASSERT(debuggerScope);
|
|
|
|
MOZ_ASSERT(debuggerScope == global, "Which kind of global do we have?");
|
2016-06-04 10:32:51 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
return debuggerScope->GetConsole(aRv);
|
2016-06-04 10:32:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
bool
|
|
|
|
Console::MonotonicTimer(JSContext* aCx, MethodName aMethodName,
|
|
|
|
const Sequence<JS::Value>& aData,
|
|
|
|
DOMHighResTimeStamp* aTimeStamp)
|
|
|
|
{
|
|
|
|
if (mWindow) {
|
|
|
|
nsGlobalWindowInner *win = nsGlobalWindowInner::Cast(mWindow);
|
|
|
|
MOZ_ASSERT(win);
|
|
|
|
|
|
|
|
RefPtr<Performance> performance = win->GetPerformance();
|
|
|
|
if (!performance) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aTimeStamp = performance->Now();
|
|
|
|
|
|
|
|
nsDocShell* docShell = static_cast<nsDocShell*>(mWindow->GetDocShell());
|
|
|
|
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
|
|
|
|
bool isTimelineRecording = timelines && timelines->HasConsumer(docShell);
|
|
|
|
|
|
|
|
// The 'timeStamp' recordings do not need an argument; use empty string
|
|
|
|
// if no arguments passed in.
|
|
|
|
if (isTimelineRecording && aMethodName == MethodTimeStamp) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx, aData.Length() == 0
|
|
|
|
? JS_GetEmptyStringValue(aCx)
|
|
|
|
: aData[0]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
|
|
|
|
if (!jsString) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoJSString key;
|
|
|
|
if (!key.init(aCx, jsString)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
timelines->AddMarkerForDocShell(docShell, Move(
|
|
|
|
MakeUnique<TimestampTimelineMarker>(key)));
|
|
|
|
}
|
|
|
|
// For `console.time(foo)` and `console.timeEnd(foo)`.
|
|
|
|
else if (isTimelineRecording && aData.Length() == 1) {
|
|
|
|
JS::Rooted<JS::Value> value(aCx, aData[0]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
|
|
|
|
if (!jsString) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoJSString key;
|
|
|
|
if (!key.init(aCx, jsString)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
timelines->AddMarkerForDocShell(docShell, Move(
|
|
|
|
MakeUnique<ConsoleTimelineMarker>(
|
|
|
|
key, aMethodName == MethodTime ? MarkerTracingType::START
|
|
|
|
: MarkerTracingType::END)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
double duration = (TimeStamp::Now() - mCreationTimeStamp).ToMilliseconds();
|
|
|
|
|
|
|
|
// Round down to the nearest 5us, because if the timer is too accurate
|
|
|
|
// people can do nasty timing attacks with it. See similar code in the
|
|
|
|
// worker Performance implementation.
|
|
|
|
const double maxResolutionMs = 0.005;
|
2018-01-29 15:25:15 +03:00
|
|
|
*aTimeStamp = nsRFPService::ReduceTimePrecisionAsMSecs(
|
2017-12-20 16:35:34 +03:00
|
|
|
floor(duration / maxResolutionMs) * maxResolutionMs);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
*aTimeStamp = workerPrivate->TimeStampToDOMHighRes(TimeStamp::Now());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:43 +03:00
|
|
|
/* static */ already_AddRefed<ConsoleInstance>
|
|
|
|
Console::CreateInstance(const GlobalObject& aGlobal,
|
|
|
|
const ConsoleInstanceOptions& aOptions)
|
|
|
|
{
|
|
|
|
RefPtr<ConsoleInstance> console = new ConsoleInstance(aOptions);
|
|
|
|
return console.forget();
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
void
|
|
|
|
Console::MaybeExecuteDumpFunction(JSContext* aCx,
|
|
|
|
const nsAString& aMethodName,
|
|
|
|
const Sequence<JS::Value>& aData)
|
|
|
|
{
|
|
|
|
if (!mDumpFunction && !mDumpToStdout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString message;
|
|
|
|
message.AssignLiteral("console.");
|
|
|
|
message.Append(aMethodName);
|
|
|
|
message.AppendLiteral(": ");
|
|
|
|
|
2018-01-17 20:19:36 +03:00
|
|
|
if (!mPrefix.IsEmpty()) {
|
|
|
|
message.Append(mPrefix);
|
2018-01-04 21:19:44 +03:00
|
|
|
message.AppendLiteral(": ");
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
for (uint32_t i = 0; i < aData.Length(); ++i) {
|
|
|
|
JS::Rooted<JS::Value> v(aCx, aData[i]);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS_ValueToSource(aCx, v));
|
|
|
|
if (!jsString) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoJSString string;
|
|
|
|
if (NS_WARN_IF(!string.init(aCx, jsString))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != 0) {
|
|
|
|
message.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
message.Append(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
message.AppendLiteral("\n");
|
|
|
|
ExecuteDumpFunction(message);
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:25:15 +03:00
|
|
|
void
|
|
|
|
Console::MaybeExecuteDumpFunctionForTime(JSContext* aCx,
|
|
|
|
MethodName aMethodName,
|
|
|
|
const nsAString& aMethodString,
|
|
|
|
uint64_t aMonotonicTimer,
|
|
|
|
const JS::Value& aData)
|
|
|
|
{
|
|
|
|
if (!mDumpFunction && !mDumpToStdout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString message;
|
|
|
|
message.AssignLiteral("console.");
|
|
|
|
message.Append(aMethodString);
|
|
|
|
message.AppendLiteral(": ");
|
|
|
|
|
|
|
|
if (!mPrefix.IsEmpty()) {
|
|
|
|
message.Append(mPrefix);
|
|
|
|
message.AppendLiteral(": ");
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> v(aCx, aData);
|
|
|
|
JS::Rooted<JSString*> jsString(aCx, JS_ValueToSource(aCx, v));
|
|
|
|
if (!jsString) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoJSString string;
|
|
|
|
if (NS_WARN_IF(!string.init(aCx, jsString))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message.Append(string);
|
|
|
|
message.AppendLiteral(" @ ");
|
|
|
|
message.AppendInt(aMonotonicTimer);
|
|
|
|
|
|
|
|
message.AppendLiteral("\n");
|
|
|
|
ExecuteDumpFunction(message);
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
void
|
|
|
|
Console::MaybeExecuteDumpFunctionForTrace(JSContext* aCx, nsIStackFrame* aStack)
|
|
|
|
{
|
|
|
|
if (!aStack || (!mDumpFunction && !mDumpToStdout)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString message;
|
|
|
|
message.AssignLiteral("console.trace:\n");
|
|
|
|
|
2018-01-17 20:19:36 +03:00
|
|
|
if (!mPrefix.IsEmpty()) {
|
|
|
|
message.Append(mPrefix);
|
2018-01-04 21:19:44 +03:00
|
|
|
message.AppendLiteral(": ");
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
nsCOMPtr<nsIStackFrame> stack(aStack);
|
|
|
|
|
|
|
|
while (stack) {
|
|
|
|
nsAutoString filename;
|
2018-02-06 00:34:04 +03:00
|
|
|
stack->GetFilename(aCx, filename);
|
2018-01-04 21:19:44 +03:00
|
|
|
|
|
|
|
message.Append(filename);
|
|
|
|
message.AppendLiteral(" ");
|
|
|
|
|
2018-02-06 00:34:04 +03:00
|
|
|
message.AppendInt(stack->GetLineNumber(aCx));
|
2018-01-04 21:19:44 +03:00
|
|
|
message.AppendLiteral(" ");
|
|
|
|
|
|
|
|
nsAutoString functionName;
|
2018-02-06 00:34:05 +03:00
|
|
|
stack->GetName(aCx, functionName);
|
2018-01-04 21:19:44 +03:00
|
|
|
|
|
|
|
message.Append(filename);
|
|
|
|
message.AppendLiteral("\n");
|
|
|
|
|
2018-02-06 00:34:05 +03:00
|
|
|
nsCOMPtr<nsIStackFrame> caller = stack->GetCaller(aCx);
|
2018-01-04 21:19:44 +03:00
|
|
|
|
|
|
|
if (!caller) {
|
2018-02-06 00:34:05 +03:00
|
|
|
caller = stack->GetAsyncCaller(aCx);
|
2018-01-04 21:19:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
stack.swap(caller);
|
|
|
|
}
|
|
|
|
|
|
|
|
message.AppendLiteral("\n");
|
|
|
|
ExecuteDumpFunction(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Console::ExecuteDumpFunction(const nsAString& aMessage)
|
|
|
|
{
|
|
|
|
if (mDumpFunction) {
|
2018-02-01 22:21:14 +03:00
|
|
|
mDumpFunction->Call(aMessage);
|
2018-01-04 21:19:44 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 str(aMessage);
|
|
|
|
MOZ_LOG(nsContentUtils::DOMDumpLog(), LogLevel::Debug, ("%s", str.get()));
|
|
|
|
#ifdef ANDROID
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", str.get());
|
|
|
|
#endif
|
|
|
|
fputs(str.get(), stdout);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2018-01-04 21:19:44 +03:00
|
|
|
bool
|
|
|
|
Console::ShouldProceed(MethodName aName) const
|
|
|
|
{
|
|
|
|
return WebIDLLogLevelToInteger(mMaxLogLevel) <=
|
|
|
|
InternalLogLevelToInteger(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Console::WebIDLLogLevelToInteger(ConsoleLogLevel aLevel) const
|
|
|
|
{
|
|
|
|
switch (aLevel) {
|
|
|
|
case ConsoleLogLevel::All: return 0;
|
|
|
|
case ConsoleLogLevel::Debug: return 2;
|
|
|
|
case ConsoleLogLevel::Log: return 3;
|
|
|
|
case ConsoleLogLevel::Info: return 3;
|
|
|
|
case ConsoleLogLevel::Clear: return 3;
|
|
|
|
case ConsoleLogLevel::Trace: return 3;
|
|
|
|
case ConsoleLogLevel::TimeEnd: return 3;
|
|
|
|
case ConsoleLogLevel::Time: return 3;
|
|
|
|
case ConsoleLogLevel::Group: return 3;
|
|
|
|
case ConsoleLogLevel::GroupEnd: return 3;
|
|
|
|
case ConsoleLogLevel::Profile: return 3;
|
|
|
|
case ConsoleLogLevel::ProfileEnd: return 3;
|
|
|
|
case ConsoleLogLevel::Dir: return 3;
|
|
|
|
case ConsoleLogLevel::Dirxml: return 3;
|
|
|
|
case ConsoleLogLevel::Warn: return 4;
|
|
|
|
case ConsoleLogLevel::Error: return 5;
|
|
|
|
case ConsoleLogLevel::Off: return UINT32_MAX;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("ConsoleLogLevel is out of sync with the Console implementation!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Console::InternalLogLevelToInteger(MethodName aName) const
|
|
|
|
{
|
|
|
|
switch (aName) {
|
|
|
|
case MethodLog: return 3;
|
|
|
|
case MethodInfo: return 3;
|
|
|
|
case MethodWarn: return 4;
|
|
|
|
case MethodError: return 5;
|
|
|
|
case MethodException: return 5;
|
|
|
|
case MethodDebug: return 2;
|
|
|
|
case MethodTable: return 3;
|
|
|
|
case MethodTrace: return 3;
|
|
|
|
case MethodDir: return 3;
|
|
|
|
case MethodDirxml: return 3;
|
|
|
|
case MethodGroup: return 3;
|
|
|
|
case MethodGroupCollapsed: return 3;
|
|
|
|
case MethodGroupEnd: return 3;
|
|
|
|
case MethodTime: return 3;
|
|
|
|
case MethodTimeEnd: return 3;
|
|
|
|
case MethodTimeStamp: return 3;
|
|
|
|
case MethodAssert: return 3;
|
|
|
|
case MethodCount: return 3;
|
|
|
|
case MethodClear: return 3;
|
|
|
|
case MethodProfile: return 3;
|
|
|
|
case MethodProfileEnd: return 3;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("MethodName is out of sync with the Console implementation!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-28 03:39:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|