2013-01-15 04:26:47 +04: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: */
|
2012-05-21 15:12:37 +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/. */
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
1998-07-16 05:16:47 +04:00
|
|
|
#include "nsJSEnvironment.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2005-06-08 06:13:10 +04:00
|
|
|
#include "nsIDOMChromeWindow.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
1998-11-21 03:12:33 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1998-12-23 01:03:20 +03:00
|
|
|
#include "nsDOMCID.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-04-24 06:37:41 +04:00
|
|
|
#include "nsIXPConnect.h"
|
1999-08-30 01:58:42 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2006-06-13 07:07:47 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2014-09-05 19:54:13 +04:00
|
|
|
#include "nsDOMJSUtils.h"
|
1999-12-18 23:29:29 +03:00
|
|
|
#include "nsJSUtils.h"
|
2000-04-24 08:41:27 +04:00
|
|
|
#include "nsIDocShell.h"
|
2000-12-07 05:08:21 +03:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2004-01-04 03:29:27 +03:00
|
|
|
#include "nsIConsoleService.h"
|
2000-12-07 05:08:21 +03:00
|
|
|
#include "nsIScriptError.h"
|
2000-06-24 20:18:41 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-06-24 20:18:41 +04:00
|
|
|
#include "nsIPrompt.h"
|
2000-06-20 07:45:21 +04:00
|
|
|
#include "nsIObserverService.h"
|
2001-11-27 12:46:38 +03:00
|
|
|
#include "nsITimer.h"
|
2002-07-25 22:31:10 +04:00
|
|
|
#include "nsIAtom.h"
|
2004-04-30 03:34:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2006-08-25 01:49:14 +04:00
|
|
|
#include "nsIContent.h"
|
2007-01-05 04:44:42 +03:00
|
|
|
#include "nsCycleCollector.h"
|
2009-01-12 19:05:10 +03:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
|
|
|
#include "nsIXULRuntime.h"
|
2013-08-15 22:17:48 +04:00
|
|
|
#include "nsTextFormatter.h"
|
2014-06-11 20:31:24 +04:00
|
|
|
#include "ScriptSettings.h"
|
1998-07-16 05:16:47 +04:00
|
|
|
|
2011-02-16 23:47:08 +03:00
|
|
|
#include "xpcpublic.h"
|
2003-06-25 01:09:57 +04:00
|
|
|
|
2014-10-12 21:37:41 +04:00
|
|
|
#include "jsapi.h"
|
2011-05-03 02:47:10 +04:00
|
|
|
#include "jswrapper.h"
|
2014-11-06 12:14:00 +03:00
|
|
|
#include "js/SliceBudget.h"
|
2006-06-13 07:07:47 +04:00
|
|
|
#include "nsIArray.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
2012-12-05 13:19:33 +04:00
|
|
|
#include "prmem.h"
|
2010-10-11 02:38:10 +04:00
|
|
|
#include "WrapperFactory.h"
|
2006-07-12 04:26:56 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2011-10-03 23:11:31 +04:00
|
|
|
#include "nsScriptNameSpaceManager.h"
|
2014-02-23 09:01:12 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2016-02-24 13:06:42 +03:00
|
|
|
#include "mozilla/dom/DOMException.h"
|
|
|
|
#include "mozilla/dom/DOMExceptionBinding.h"
|
2014-08-02 00:47:47 +04:00
|
|
|
#include "mozilla/dom/ErrorEvent.h"
|
2013-09-06 21:50:24 +04:00
|
|
|
#include "nsAXPCNativeCallContext.h"
|
2013-11-21 02:35:16 +04:00
|
|
|
#include "mozilla/CycleCollectedJSRuntime.h"
|
2005-06-08 06:13:10 +04:00
|
|
|
|
2011-12-19 21:48:12 +04:00
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
|
2010-10-22 09:15:21 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// AssertMacros.h defines 'check' and conflicts with AccessCheck.h
|
|
|
|
#undef check
|
|
|
|
#endif
|
|
|
|
#include "AccessCheck.h"
|
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2000-05-15 08:21:04 +04:00
|
|
|
#include "prthread.h"
|
1999-12-03 06:40:30 +03:00
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-01-21 00:02:18 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2012-05-03 08:35:38 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-06-15 06:31:55 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-11-19 01:49:53 +04:00
|
|
|
#include "mozilla/dom/asmjscache/AsmJSCache.h"
|
2012-06-13 19:14:15 +04:00
|
|
|
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
|
2013-09-05 01:06:54 +04:00
|
|
|
#include "mozilla/CycleCollectedJSRuntime.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2010-05-20 03:22:19 +04:00
|
|
|
|
2013-09-05 01:06:54 +04:00
|
|
|
#include "nsCycleCollectionNoteRootCallback.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2011-12-03 02:05:33 +04:00
|
|
|
|
2011-04-29 02:48:52 +04:00
|
|
|
using namespace mozilla;
|
2012-04-24 14:58:07 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-04-29 02:48:52 +04:00
|
|
|
|
1998-07-16 05:16:47 +04:00
|
|
|
const size_t gStackSize = 8192;
|
|
|
|
|
2003-06-25 01:09:57 +04:00
|
|
|
// Thank you Microsoft!
|
|
|
|
#ifdef CompareString
|
|
|
|
#undef CompareString
|
|
|
|
#endif
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2011-12-27 15:59:29 +04:00
|
|
|
#define NS_SHRINK_GC_BUFFERS_DELAY 4000 // ms
|
|
|
|
|
2007-01-11 03:02:58 +03:00
|
|
|
// The amount of time we wait from the first request to GC to actually
|
|
|
|
// doing the first GC.
|
|
|
|
#define NS_FIRST_GC_DELAY 10000 // ms
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2012-05-09 22:53:23 +04:00
|
|
|
#define NS_FULL_GC_DELAY 60000 // ms
|
|
|
|
|
2015-07-30 13:03:06 +03:00
|
|
|
// The default amount of time to wait from the user being idle to starting a
|
|
|
|
// shrinking GC.
|
|
|
|
#define NS_DEAULT_INACTIVE_GC_DELAY 300000 // ms
|
2015-02-24 12:40:02 +03:00
|
|
|
|
2012-02-18 02:35:20 +04:00
|
|
|
// Maximum amount of time that should elapse between incremental GC slices
|
|
|
|
#define NS_INTERSLICE_GC_DELAY 100 // ms
|
|
|
|
|
2012-08-01 05:39:39 +04:00
|
|
|
// If we haven't painted in 100ms, we allow for a longer GC budget
|
|
|
|
#define NS_INTERSLICE_GC_BUDGET 40 // ms
|
|
|
|
|
2011-02-17 02:47:12 +03:00
|
|
|
// The amount of time we wait between a request to CC (after GC ran)
|
|
|
|
// and doing the actual CC.
|
2012-02-19 22:36:06 +04:00
|
|
|
#define NS_CC_DELAY 6000 // ms
|
2006-06-13 07:07:47 +04:00
|
|
|
|
2014-11-12 22:33:50 +03:00
|
|
|
#define NS_CC_SKIPPABLE_DELAY 250 // ms
|
2012-01-31 00:06:18 +04:00
|
|
|
|
2013-12-21 18:35:08 +04:00
|
|
|
// Maximum amount of time that should elapse between incremental CC slices
|
|
|
|
static const int64_t kICCIntersliceDelay = 32; // ms
|
|
|
|
|
2013-12-22 18:58:19 +04:00
|
|
|
// Time budget for an incremental CC slice
|
2014-11-12 20:28:51 +03:00
|
|
|
static const int64_t kICCSliceBudget = 5; // ms
|
2013-12-22 18:58:19 +04:00
|
|
|
|
|
|
|
// Maximum total duration for an ICC
|
|
|
|
static const uint32_t kMaxICCDuration = 2000; // ms
|
|
|
|
|
2012-07-15 14:30:39 +04:00
|
|
|
// Force a CC after this long if there's more than NS_CC_FORCED_PURPLE_LIMIT
|
|
|
|
// objects in the purple buffer.
|
2012-03-06 01:48:33 +04:00
|
|
|
#define NS_CC_FORCED (2 * 60 * PR_USEC_PER_SEC) // 2 min
|
2012-07-15 14:30:39 +04:00
|
|
|
#define NS_CC_FORCED_PURPLE_LIMIT 10
|
2012-03-06 01:48:33 +04:00
|
|
|
|
2012-03-09 03:37:13 +04:00
|
|
|
// Don't allow an incremental GC to lock out the CC for too long.
|
2015-09-23 13:12:00 +03:00
|
|
|
#define NS_MAX_CC_LOCKEDOUT_TIME (30 * PR_USEC_PER_SEC) // 30 seconds
|
2012-03-09 03:37:13 +04:00
|
|
|
|
2012-03-06 01:48:33 +04:00
|
|
|
// Trigger a CC if the purple buffer exceeds this size when we check it.
|
2012-07-15 14:30:39 +04:00
|
|
|
#define NS_CC_PURPLE_LIMIT 200
|
2012-01-31 00:06:18 +04:00
|
|
|
|
2013-01-31 21:23:50 +04:00
|
|
|
// Large value used to specify that a script should run essentially forever
|
|
|
|
#define NS_UNLIMITED_SCRIPT_RUNTIME (0x40000000LL << 32)
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
// if you add statics here, add them to the list in StartupJSEnvironment
|
2004-06-09 22:36:25 +04:00
|
|
|
|
2003-06-25 03:06:12 +04:00
|
|
|
static nsITimer *sGCTimer;
|
2011-12-27 15:59:29 +04:00
|
|
|
static nsITimer *sShrinkGCBuffersTimer;
|
2015-02-24 12:40:02 +03:00
|
|
|
static nsITimer *sShrinkingGCTimer;
|
2011-02-17 02:47:12 +03:00
|
|
|
static nsITimer *sCCTimer;
|
2013-12-21 18:35:08 +04:00
|
|
|
static nsITimer *sICCTimer;
|
2012-05-09 22:53:23 +04:00
|
|
|
static nsITimer *sFullGCTimer;
|
2012-06-11 08:27:59 +04:00
|
|
|
static nsITimer *sInterSliceGCTimer;
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
static TimeStamp sLastCCEndTime;
|
2012-01-21 00:02:18 +04:00
|
|
|
|
2012-02-18 02:35:20 +04:00
|
|
|
static bool sCCLockedOut;
|
2012-03-09 03:37:13 +04:00
|
|
|
static PRTime sCCLockedOutTime;
|
2012-02-18 02:35:20 +04:00
|
|
|
|
2013-01-28 00:35:12 +04:00
|
|
|
static JS::GCSliceCallback sPrevGCSliceCallback;
|
2011-02-23 11:08:36 +03:00
|
|
|
|
2013-01-31 02:46:37 +04:00
|
|
|
static bool sHasRunGC;
|
|
|
|
|
2007-01-11 03:02:58 +03:00
|
|
|
// The number of currently pending document loads. This count isn't
|
|
|
|
// guaranteed to always reflect reality and can't easily as we don't
|
|
|
|
// have an easy place to know when a load ends or is interrupted in
|
|
|
|
// all cases. This counter also gets reset if we end up GC'ing while
|
|
|
|
// we're waiting for a slow page to load. IOW, this count may be 0
|
|
|
|
// even when there are pending loads.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sPendingLoadCount;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sLoadingInProgress;
|
2007-01-11 03:02:58 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sCCollectedWaitingForGC;
|
2014-10-20 21:07:52 +04:00
|
|
|
static uint32_t sCCollectedZonesWaitingForGC;
|
2013-03-07 22:53:19 +04:00
|
|
|
static uint32_t sLikelyShortLivingObjectsNeedingGC;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sPostGCEventsToConsole;
|
2012-07-13 23:13:52 +04:00
|
|
|
static bool sPostGCEventsToObserver;
|
2014-03-05 04:21:48 +04:00
|
|
|
static int32_t sCCTimerFireCount = 0;
|
2012-09-28 10:57:33 +04:00
|
|
|
static uint32_t sMinForgetSkippableTime = UINT32_MAX;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sMaxForgetSkippableTime = 0;
|
|
|
|
static uint32_t sTotalForgetSkippableTime = 0;
|
|
|
|
static uint32_t sRemovedPurples = 0;
|
|
|
|
static uint32_t sForgetSkippableBeforeCC = 0;
|
|
|
|
static uint32_t sPreviousSuspectedCount = 0;
|
2012-09-28 10:57:33 +04:00
|
|
|
static uint32_t sCleanupsSinceLastGC = UINT32_MAX;
|
2012-02-27 18:49:59 +04:00
|
|
|
static bool sNeedsFullCC = false;
|
2016-02-19 02:21:48 +03:00
|
|
|
static bool sNeedsFullGC = false;
|
2013-08-22 01:02:12 +04:00
|
|
|
static bool sNeedsGCAfterCC = false;
|
2013-12-21 18:35:08 +04:00
|
|
|
static bool sIncrementalCC = false;
|
2014-11-27 14:47:51 +03:00
|
|
|
static bool sDidPaintAfterPreviousICCSlice = false;
|
2007-01-11 03:02:58 +03:00
|
|
|
|
2012-11-05 02:18:44 +04:00
|
|
|
static nsScriptNameSpaceManager *gNameSpaceManager;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2011-11-10 01:32:17 +04:00
|
|
|
static PRTime sFirstCollectionTime;
|
2002-05-03 07:02:07 +04:00
|
|
|
|
2016-07-07 10:55:41 +03:00
|
|
|
static JSRuntime* sRuntime;
|
|
|
|
static JSContext* sContext;
|
2013-08-20 03:24:29 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sIsInitialized;
|
|
|
|
static bool sDidShutdown;
|
2013-01-22 23:17:48 +04:00
|
|
|
static bool sShuttingDown;
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t sContextCount;
|
2002-05-03 07:02:07 +04:00
|
|
|
|
2003-06-25 03:06:12 +04:00
|
|
|
static nsIScriptSecurityManager *sSecurityManager;
|
2002-05-03 07:02:07 +04:00
|
|
|
|
2013-01-22 23:17:48 +04:00
|
|
|
// nsJSEnvironmentObserver observes the memory-pressure notifications
|
2011-07-07 22:27:07 +04:00
|
|
|
// and forces a garbage collection and cycle collection when it happens, if
|
|
|
|
// the appropriate pref is set.
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sGCOnMemoryPressure;
|
2015-04-13 18:42:41 +03:00
|
|
|
|
|
|
|
// nsJSEnvironmentObserver observes the user-interaction-inactive notifications
|
|
|
|
// and triggers a shrinking a garbage collection if the user is still inactive
|
|
|
|
// after NS_SHRINKING_GC_DELAY ms later, if the appropriate pref is set.
|
|
|
|
|
2015-02-24 12:40:02 +03:00
|
|
|
static bool sCompactOnUserInactive;
|
2015-07-30 13:03:06 +03:00
|
|
|
static uint32_t sCompactOnUserInactiveDelay = NS_DEAULT_INACTIVE_GC_DELAY;
|
2015-04-13 18:42:41 +03:00
|
|
|
static bool sIsCompactingOnUserInactive = false;
|
2007-10-23 01:42:25 +04:00
|
|
|
|
2014-04-26 00:21:04 +04:00
|
|
|
// In testing, we call RunNextCollectorTimer() to ensure that the collectors are run more
|
|
|
|
// aggressively than they would be in regular browsing. sExpensiveCollectorPokes keeps
|
|
|
|
// us from triggering expensive full collections too frequently.
|
|
|
|
static int32_t sExpensiveCollectorPokes = 0;
|
|
|
|
static const int32_t kPokesBetweenExpensiveCollectorTriggers = 5;
|
|
|
|
|
2016-02-22 20:37:50 +03:00
|
|
|
static const char*
|
|
|
|
ProcessNameForCollectorLog()
|
|
|
|
{
|
|
|
|
return XRE_GetProcessType() == GeckoProcessType_Default ?
|
|
|
|
"default" : "content";
|
|
|
|
}
|
|
|
|
|
2016-03-09 01:21:40 +03:00
|
|
|
namespace xpc {
|
|
|
|
|
2016-03-10 06:27:14 +03:00
|
|
|
// This handles JS Exceptions (via ExceptionStackOrNull), as well as DOM and XPC
|
|
|
|
// Exceptions.
|
2016-02-24 13:06:42 +03:00
|
|
|
//
|
2016-03-10 06:27:14 +03:00
|
|
|
// Note that the returned object is _not_ wrapped into the compartment of
|
|
|
|
// exceptionValue.
|
2016-03-09 01:21:40 +03:00
|
|
|
JSObject*
|
2016-03-10 06:27:14 +03:00
|
|
|
FindExceptionStackForConsoleReport(nsPIDOMWindowInner* win,
|
2016-03-09 01:21:40 +03:00
|
|
|
JS::HandleValue exceptionValue)
|
2016-02-24 13:06:42 +03:00
|
|
|
{
|
2016-03-09 01:21:40 +03:00
|
|
|
if (!exceptionValue.isObject()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-03-09 01:21:40 +03:00
|
|
|
if (win && win->InnerObjectsFreed()) {
|
|
|
|
// Pretend like we have no stack, so we don't end up keeping the global
|
|
|
|
// alive via the stack.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-08 03:08:26 +03:00
|
|
|
JSRuntime* rt = GetJSRuntime();
|
|
|
|
JS::RootedObject exceptionObject(rt, &exceptionValue.toObject());
|
2016-03-10 06:27:14 +03:00
|
|
|
JSObject* stackObject = ExceptionStackOrNull(exceptionObject);
|
2016-02-24 13:06:42 +03:00
|
|
|
if (stackObject) {
|
|
|
|
return stackObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is not a JS Exception, try DOM Exception.
|
|
|
|
RefPtr<Exception> exception;
|
|
|
|
UNWRAP_OBJECT(DOMException, exceptionObject, exception);
|
|
|
|
if (!exception) {
|
|
|
|
// Not a DOM Exception, try XPC Exception.
|
|
|
|
UNWRAP_OBJECT(Exception, exceptionObject, exception);
|
|
|
|
if (!exception) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStackFrame> stack = exception->GetLocation();
|
|
|
|
if (!stack) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-07-08 03:08:26 +03:00
|
|
|
JS::RootedValue value(rt);
|
2016-02-24 13:06:42 +03:00
|
|
|
stack->GetNativeSavedFrame(&value);
|
|
|
|
if (value.isObject()) {
|
2016-03-10 06:27:14 +03:00
|
|
|
return &value.toObject();
|
2016-02-24 13:06:42 +03:00
|
|
|
}
|
2016-03-10 06:27:14 +03:00
|
|
|
return nullptr;
|
2016-02-24 13:06:42 +03:00
|
|
|
}
|
|
|
|
|
2016-03-09 01:21:40 +03:00
|
|
|
} /* namespace xpc */
|
|
|
|
|
2012-08-22 22:28:34 +04:00
|
|
|
static PRTime
|
|
|
|
GetCollectionTimeDelta()
|
|
|
|
{
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
if (sFirstCollectionTime) {
|
|
|
|
return now - sFirstCollectionTime;
|
|
|
|
}
|
|
|
|
sFirstCollectionTime = now;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-22 23:17:48 +04:00
|
|
|
static void
|
|
|
|
KillTimers()
|
|
|
|
{
|
|
|
|
nsJSContext::KillGCTimer();
|
2015-02-24 12:40:02 +03:00
|
|
|
nsJSContext::KillShrinkingGCTimer();
|
2013-01-22 23:17:48 +04:00
|
|
|
nsJSContext::KillShrinkGCBuffersTimer();
|
|
|
|
nsJSContext::KillCCTimer();
|
2013-12-21 18:35:08 +04:00
|
|
|
nsJSContext::KillICCTimer();
|
2013-01-22 23:17:48 +04:00
|
|
|
nsJSContext::KillFullGCTimer();
|
|
|
|
nsJSContext::KillInterSliceGCTimer();
|
|
|
|
}
|
|
|
|
|
2014-02-03 19:31:11 +04:00
|
|
|
// If we collected a substantial amount of cycles, poke the GC since more objects
|
|
|
|
// might be unreachable now.
|
|
|
|
static bool
|
|
|
|
NeedsGCAfterCC()
|
|
|
|
{
|
|
|
|
return sCCollectedWaitingForGC > 250 ||
|
2014-10-20 21:07:52 +04:00
|
|
|
sCCollectedZonesWaitingForGC > 0 ||
|
2014-02-03 19:31:11 +04:00
|
|
|
sLikelyShortLivingObjectsNeedingGC > 2500 ||
|
|
|
|
sNeedsGCAfterCC;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsJSEnvironmentObserver final : public nsIObserver
|
2007-10-23 01:42:25 +04:00
|
|
|
{
|
2014-06-23 23:56:07 +04:00
|
|
|
~nsJSEnvironmentObserver() {}
|
2007-10-23 01:42:25 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSEnvironmentObserver, nsIObserver)
|
2007-10-23 01:42:25 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-01-22 23:17:48 +04:00
|
|
|
nsJSEnvironmentObserver::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData)
|
2007-11-07 00:47:35 +03:00
|
|
|
{
|
2015-02-24 12:40:02 +03:00
|
|
|
if (!nsCRT::strcmp(aTopic, "memory-pressure")) {
|
|
|
|
if (sGCOnMemoryPressure) {
|
|
|
|
if(StringBeginsWith(nsDependentString(aData),
|
|
|
|
NS_LITERAL_STRING("low-memory-ongoing"))) {
|
|
|
|
// Don't GC/CC if we are in an ongoing low-memory state since its very
|
|
|
|
// slow and it likely won't help us anyway.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-02-03 19:31:11 +04:00
|
|
|
nsJSContext::GarbageCollectNow(JS::gcreason::MEM_PRESSURE,
|
|
|
|
nsJSContext::NonIncrementalGC,
|
|
|
|
nsJSContext::ShrinkingGC);
|
2015-02-24 12:40:02 +03:00
|
|
|
nsJSContext::CycleCollectNow();
|
|
|
|
if (NeedsGCAfterCC()) {
|
|
|
|
nsJSContext::GarbageCollectNow(JS::gcreason::MEM_PRESSURE,
|
|
|
|
nsJSContext::NonIncrementalGC,
|
|
|
|
nsJSContext::ShrinkingGC);
|
|
|
|
}
|
2014-02-03 19:31:11 +04:00
|
|
|
}
|
2015-02-24 12:40:02 +03:00
|
|
|
} else if (!nsCRT::strcmp(aTopic, "user-interaction-inactive")) {
|
|
|
|
if (sCompactOnUserInactive) {
|
|
|
|
nsJSContext::PokeShrinkingGC();
|
|
|
|
}
|
|
|
|
} else if (!nsCRT::strcmp(aTopic, "user-interaction-active")) {
|
|
|
|
nsJSContext::KillShrinkingGCTimer();
|
2015-04-13 18:42:41 +03:00
|
|
|
if (sIsCompactingOnUserInactive) {
|
2016-07-07 10:55:45 +03:00
|
|
|
JS::AbortIncrementalGC(sContext);
|
2015-04-13 18:42:41 +03:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(!sIsCompactingOnUserInactive);
|
2014-10-22 19:57:32 +04:00
|
|
|
} else if (!nsCRT::strcmp(aTopic, "quit-application") ||
|
|
|
|
!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
2013-01-22 23:17:48 +04:00
|
|
|
sShuttingDown = true;
|
|
|
|
KillTimers();
|
2011-07-07 22:27:07 +04:00
|
|
|
}
|
2013-01-22 23:17:48 +04:00
|
|
|
|
2007-11-07 00:47:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
/****************************************************************
|
|
|
|
************************** AutoFree ****************************
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
class AutoFree {
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit AutoFree(void* aPtr) : mPtr(aPtr) {
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
|
|
|
~AutoFree() {
|
|
|
|
if (mPtr)
|
2015-03-27 03:01:12 +03:00
|
|
|
free(mPtr);
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
|
|
|
void Invalidate() {
|
|
|
|
mPtr = 0;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void *mPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A utility function for script languages to call. Although it looks small,
|
|
|
|
// the use of nsIDocShell and nsPresContext triggers a huge number of
|
|
|
|
// dependencies that most languages would not otherwise need.
|
|
|
|
// XXXmarkh - This function is mis-placed!
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
|
2014-02-23 09:01:12 +04:00
|
|
|
const ErrorEventInit &aErrorEventInit,
|
2006-06-13 07:07:47 +04:00
|
|
|
nsEventStatus *aStatus)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool called = false;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win(do_QueryInterface(aScriptGlobal));
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIDocShell *docShell = win ? win->GetDocShell() : nullptr;
|
2006-06-13 07:07:47 +04:00
|
|
|
if (docShell) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> presContext;
|
2006-06-13 07:07:47 +04:00
|
|
|
docShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t errorDepth; // Recursion prevention
|
2006-06-13 07:07:47 +04:00
|
|
|
++errorDepth;
|
2008-07-27 03:17:12 +04:00
|
|
|
|
2014-02-23 09:01:12 +04:00
|
|
|
if (errorDepth < 2) {
|
2006-06-13 07:07:47 +04:00
|
|
|
// Dispatch() must be synchronous for the recursion block
|
|
|
|
// (errorDepth) to work.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ErrorEvent> event =
|
2016-01-30 20:05:36 +03:00
|
|
|
ErrorEvent::Constructor(nsGlobalWindow::Cast(win),
|
2014-02-23 09:01:12 +04:00
|
|
|
NS_LITERAL_STRING("error"),
|
|
|
|
aErrorEventInit);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::DispatchDOMEvent(win, nullptr, event, presContext,
|
|
|
|
aStatus);
|
2011-10-17 18:59:28 +04:00
|
|
|
called = true;
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
|
|
|
--errorDepth;
|
|
|
|
}
|
|
|
|
return called;
|
|
|
|
}
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ScriptErrorEvent : public Runnable
|
2009-12-18 22:27:57 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-01-30 20:05:36 +03:00
|
|
|
ScriptErrorEvent(nsPIDOMWindowInner* aWindow,
|
2014-09-29 17:34:20 +04:00
|
|
|
JSRuntime* aRuntime,
|
2014-09-09 03:30:10 +04:00
|
|
|
xpc::ErrorReport* aReport,
|
2014-09-29 12:44:29 +04:00
|
|
|
JS::Handle<JS::Value> aError)
|
2014-09-29 17:34:20 +04:00
|
|
|
: mWindow(aWindow)
|
|
|
|
, mReport(aReport)
|
2014-01-03 05:04:15 +04:00
|
|
|
, mError(aRuntime, aError)
|
2014-09-09 03:30:10 +04:00
|
|
|
{}
|
2009-12-18 22:27:57 +03:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* win = mWindow;
|
2014-09-09 03:30:11 +04:00
|
|
|
MOZ_ASSERT(win);
|
2016-03-10 06:27:14 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-05-21 00:07:17 +04:00
|
|
|
// First, notify the DOM that we have a script error, but only if
|
2014-09-09 03:30:11 +04:00
|
|
|
// our window is still the current inner.
|
2016-03-10 06:27:14 +03:00
|
|
|
JSContext* rootingCx = nsContentUtils::RootingCx();
|
2014-09-29 12:44:29 +04:00
|
|
|
if (win->IsCurrentInnerWindow() && win->GetDocShell() && !sHandlingScriptError) {
|
2014-09-09 03:30:11 +04:00
|
|
|
AutoRestore<bool> recursionGuard(sHandlingScriptError);
|
|
|
|
sHandlingScriptError = true;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> presContext;
|
2014-09-09 03:30:11 +04:00
|
|
|
win->GetDocShell()->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
2016-03-10 06:27:14 +03:00
|
|
|
RootedDictionary<ErrorEventInit> init(rootingCx);
|
2014-09-09 03:30:11 +04:00
|
|
|
init.mCancelable = true;
|
|
|
|
init.mFilename = mReport->mFileName;
|
|
|
|
init.mBubbles = true;
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(xoriginMsg, "Script error.");
|
2014-09-29 12:44:30 +04:00
|
|
|
if (!mReport->mIsMuted) {
|
2014-09-09 03:30:11 +04:00
|
|
|
init.mMessage = mReport->mErrorMsg;
|
|
|
|
init.mLineno = mReport->mLineNumber;
|
|
|
|
init.mColno = mReport->mColumn;
|
|
|
|
init.mError = mError;
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Not same origin error!");
|
|
|
|
init.mMessage = xoriginMsg;
|
|
|
|
init.mLineno = 0;
|
|
|
|
}
|
2009-12-18 22:27:57 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ErrorEvent> event =
|
2016-01-30 20:05:36 +03:00
|
|
|
ErrorEvent::Constructor(nsGlobalWindow::Cast(win),
|
2014-09-09 03:30:11 +04:00
|
|
|
NS_LITERAL_STRING("error"), init);
|
|
|
|
event->SetTrusted(true);
|
2014-02-23 09:01:12 +04:00
|
|
|
|
2014-09-09 03:30:11 +04:00
|
|
|
EventDispatcher::DispatchDOMEvent(win, nullptr, event, presContext,
|
|
|
|
&status);
|
2009-12-18 22:27:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
2016-03-10 06:27:14 +03:00
|
|
|
JS::Rooted<JSObject*> stack(rootingCx,
|
|
|
|
xpc::FindExceptionStackForConsoleReport(win, mError));
|
|
|
|
mReport->LogToConsoleWithStack(stack);
|
2009-12-18 22:27:57 +03:00
|
|
|
}
|
2013-08-29 08:30:06 +04:00
|
|
|
|
2009-12-18 22:27:57 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:30:06 +04:00
|
|
|
private:
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<xpc::ErrorReport> mReport;
|
2014-01-03 05:04:15 +04:00
|
|
|
JS::PersistentRootedValue mError;
|
2009-12-18 22:27:57 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sHandlingScriptError;
|
2009-12-18 22:27:57 +03:00
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ScriptErrorEvent::sHandlingScriptError = false;
|
2009-12-18 22:27:57 +03:00
|
|
|
|
2014-09-09 03:30:11 +04:00
|
|
|
// This temporarily lives here to avoid code churn. It will go away entirely
|
|
|
|
// soon.
|
|
|
|
namespace xpc {
|
|
|
|
|
2014-09-29 17:34:21 +04:00
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
DispatchScriptErrorEvent(nsPIDOMWindowInner *win, JSRuntime *rt, xpc::ErrorReport *xpcReport,
|
2014-09-29 17:34:21 +04:00
|
|
|
JS::Handle<JS::Value> exception)
|
|
|
|
{
|
|
|
|
nsContentUtils::AddScriptRunner(new ScriptErrorEvent(win, rt, xpcReport, exception));
|
|
|
|
}
|
|
|
|
|
2014-09-09 03:30:11 +04:00
|
|
|
} /* namespace xpc */
|
|
|
|
|
2006-07-12 01:03:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// A couple of useful functions to call when you're debugging.
|
|
|
|
nsGlobalWindow *
|
2014-01-30 18:31:16 +04:00
|
|
|
JSObject2Win(JSObject *obj)
|
2006-07-12 01:03:52 +04:00
|
|
|
{
|
2014-01-30 18:31:16 +04:00
|
|
|
return xpc::WindowOrNull(obj);
|
2006-07-12 01:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintWinURI(nsGlobalWindow *win)
|
|
|
|
{
|
|
|
|
if (!win) {
|
|
|
|
printf("No window passed in.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-24 08:22:37 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = win->GetExtantDoc();
|
2006-07-12 01:03:52 +04:00
|
|
|
if (!doc) {
|
|
|
|
printf("No document in the window.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI *uri = doc->GetDocumentURI();
|
2006-09-20 04:53:43 +04:00
|
|
|
if (!uri) {
|
2006-07-12 01:03:52 +04:00
|
|
|
printf("Document doesn't have a URI.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2006-07-12 01:03:52 +04:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("%s\n", spec.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PrintWinCodebase(nsGlobalWindow *win)
|
|
|
|
{
|
|
|
|
if (!win) {
|
|
|
|
printf("No window passed in.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal *prin = win->GetPrincipal();
|
|
|
|
if (!prin) {
|
|
|
|
printf("Window doesn't have principals.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
prin->GetURI(getter_AddRefs(uri));
|
|
|
|
if (!uri) {
|
|
|
|
printf("No URI, maybe the system principal.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2006-07-12 01:03:52 +04:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("%s\n", spec.get());
|
|
|
|
}
|
2010-02-12 04:04:41 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
DumpString(const nsAString &str)
|
|
|
|
{
|
|
|
|
printf("%s\n", NS_ConvertUTF16toUTF8(str).get());
|
|
|
|
}
|
2006-07-12 01:03:52 +04:00
|
|
|
#endif
|
|
|
|
|
2000-09-02 05:58:51 +04:00
|
|
|
#define JS_OPTIONS_DOT_STR "javascript.options."
|
|
|
|
|
|
|
|
static const char js_options_dot_str[] = JS_OPTIONS_DOT_STR;
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsJSContext::nsJSContext(bool aGCOnDestruction,
|
2012-11-04 12:05:23 +04:00
|
|
|
nsIScriptGlobalObject* aGlobalObject)
|
2013-09-05 01:06:56 +04:00
|
|
|
: mWindowProxy(nullptr)
|
|
|
|
, mGCOnDestruction(aGCOnDestruction)
|
2012-11-04 12:04:04 +04:00
|
|
|
, mGlobalObjectRef(aGlobalObject)
|
1998-07-16 05:16:47 +04:00
|
|
|
{
|
2013-08-20 03:24:29 +04:00
|
|
|
EnsureStatics();
|
|
|
|
|
2002-05-03 07:02:07 +04:00
|
|
|
++sContextCount;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInitialized = false;
|
2013-01-15 15:46:35 +04:00
|
|
|
mProcessingScriptTag = false;
|
2013-09-05 01:58:23 +04:00
|
|
|
HoldJSObjects(this);
|
1998-07-16 05:16:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsJSContext::~nsJSContext()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mGlobalObjectRef = nullptr;
|
2009-05-07 22:19:36 +04:00
|
|
|
|
2016-06-02 17:34:40 +03:00
|
|
|
Destroy();
|
2007-11-02 01:51:57 +03:00
|
|
|
|
|
|
|
--sContextCount;
|
|
|
|
|
|
|
|
if (!sContextCount && sDidShutdown) {
|
|
|
|
// The last context is being deleted, and we're already in the
|
2015-06-27 04:44:14 +03:00
|
|
|
// process of shutting down, release the security manager.
|
2007-11-02 01:51:57 +03:00
|
|
|
|
|
|
|
NS_IF_RELEASE(sSecurityManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-02 17:34:40 +03:00
|
|
|
nsJSContext::Destroy()
|
2007-11-02 01:51:57 +03:00
|
|
|
{
|
2011-12-27 15:59:29 +04:00
|
|
|
if (mGCOnDestruction) {
|
2015-01-05 08:12:19 +03:00
|
|
|
PokeGC(JS::gcreason::NSJSCONTEXT_DESTROY);
|
2011-12-27 15:59:29 +04:00
|
|
|
}
|
2013-07-03 21:05:19 +04:00
|
|
|
|
2013-09-05 01:58:23 +04:00
|
|
|
DropJSObjects(this);
|
2007-05-25 12:42:08 +04:00
|
|
|
}
|
|
|
|
|
2001-11-27 12:46:38 +03:00
|
|
|
// QueryInterface implementation for nsJSContext
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSContext)
|
|
|
|
|
2010-11-08 18:02:49 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSContext)
|
2013-09-05 01:06:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mWindowProxy)
|
2010-11-08 18:02:49 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2010-11-08 18:02:49 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSContext)
|
2011-10-17 18:59:28 +04:00
|
|
|
tmp->mIsInitialized = false;
|
|
|
|
tmp->mGCOnDestruction = false;
|
2013-09-05 01:06:56 +04:00
|
|
|
tmp->mWindowProxy = nullptr;
|
2016-06-02 17:34:40 +03:00
|
|
|
tmp->Destroy();
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobalObjectRef)
|
2007-11-02 01:51:57 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2016-06-02 17:34:40 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSContext)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobalObjectRef)
|
2013-09-05 01:06:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSContext)
|
2001-11-27 12:46:38 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptContext)
|
2013-08-15 01:00:03 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2001-11-27 12:46:38 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2011-03-06 14:11:31 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsJSContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsJSContext)
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-03-08 18:45:00 +03:00
|
|
|
AtomIsEventHandlerName(nsIAtom *aName)
|
1999-12-03 06:40:30 +03:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *name = aName->GetUTF16String();
|
1999-12-03 06:40:30 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *cp;
|
|
|
|
char16_t c;
|
2003-07-01 09:11:46 +04:00
|
|
|
for (cp = name; *cp != '\0'; ++cp)
|
|
|
|
{
|
|
|
|
c = *cp;
|
2010-03-08 18:45:00 +03:00
|
|
|
if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z'))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2003-07-01 09:11:46 +04:00
|
|
|
}
|
1999-12-03 06:40:30 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1999-12-03 06:40:30 +03:00
|
|
|
}
|
2010-03-08 18:45:00 +03:00
|
|
|
#endif
|
1999-12-03 06:40:30 +03:00
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
nsIScriptGlobalObject *
|
|
|
|
nsJSContext::GetGlobalObject()
|
1998-07-16 05:16:47 +04:00
|
|
|
{
|
2014-06-20 14:32:50 +04:00
|
|
|
// Note: this could probably be simplified somewhat more; see bug 974327
|
|
|
|
// comments 1 and 3.
|
|
|
|
if (!mWindowProxy) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-18 01:54:40 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:50 +04:00
|
|
|
MOZ_ASSERT(mGlobalObjectRef);
|
|
|
|
return mGlobalObjectRef;
|
1998-07-16 05:16:47 +04:00
|
|
|
}
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
nsresult
|
2010-07-16 02:16:29 +04:00
|
|
|
nsJSContext::InitContext()
|
1998-07-16 05:16:47 +04:00
|
|
|
{
|
2005-08-10 04:15:51 +04:00
|
|
|
// Make sure callers of this use
|
|
|
|
// WillInitializeContext/DidInitializeContext around this call.
|
|
|
|
NS_ENSURE_TRUE(!mIsInitialized, NS_ERROR_ALREADY_INITIALIZED);
|
|
|
|
|
2016-06-02 17:34:40 +03:00
|
|
|
// XXXbz Is there still a point to this function?
|
2010-07-16 02:16:29 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
nsresult
|
2013-05-12 09:17:42 +04:00
|
|
|
nsJSContext::SetProperty(JS::Handle<JSObject*> aTarget, const char* aPropName, nsISupports* aArgs)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
2014-07-18 15:58:10 +04:00
|
|
|
AutoJSAPI jsapi;
|
2016-03-10 03:02:25 +03:00
|
|
|
if (NS_WARN_IF(!jsapi.Init(GetGlobalObject()))) {
|
2014-07-18 15:58:10 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-03-10 03:02:25 +03:00
|
|
|
JSContext* cx = jsapi.cx();
|
2007-07-26 21:52:26 +04:00
|
|
|
|
2016-03-10 03:02:25 +03:00
|
|
|
JS::AutoValueVector args(cx);
|
2010-01-25 19:48:07 +03:00
|
|
|
|
2016-03-10 03:02:25 +03:00
|
|
|
JS::Rooted<JSObject*> global(cx, GetWindowProxy());
|
2012-03-11 12:50:22 +04:00
|
|
|
nsresult rv =
|
2014-02-11 14:59:15 +04:00
|
|
|
ConvertSupportsTojsvals(aArgs, global, args);
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-07-26 21:52:26 +04:00
|
|
|
// got the arguments, now attach them.
|
|
|
|
|
2014-02-11 14:59:15 +04:00
|
|
|
for (uint32_t i = 0; i < args.length(); ++i) {
|
2016-03-10 03:02:25 +03:00
|
|
|
if (!JS_WrapValue(cx, args[i])) {
|
2013-05-17 21:43:19 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-09-28 07:40:27 +04:00
|
|
|
}
|
2013-05-17 12:08:44 +04:00
|
|
|
}
|
2013-05-17 10:33:14 +04:00
|
|
|
|
2016-03-10 03:02:25 +03:00
|
|
|
JS::Rooted<JSObject*> array(cx, ::JS_NewArrayObject(cx, args));
|
2014-02-11 14:59:15 +04:00
|
|
|
if (!array) {
|
2013-10-26 20:19:05 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-05-17 21:43:19 +04:00
|
|
|
|
2016-03-10 03:02:25 +03:00
|
|
|
return JS_DefineProperty(cx, aTarget, aPropName, array, 0) ? NS_OK : NS_ERROR_FAILURE;
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-11 14:59:15 +04:00
|
|
|
nsJSContext::ConvertSupportsTojsvals(nsISupports* aArgs,
|
2013-05-02 13:12:46 +04:00
|
|
|
JS::Handle<JSObject*> aScope,
|
2014-02-11 14:59:15 +04:00
|
|
|
JS::AutoValueVector& aArgsOut)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2014-02-11 14:59:15 +04:00
|
|
|
// If the array implements nsIJSArgArray, copy the contents and return.
|
2006-06-13 07:07:47 +04:00
|
|
|
nsCOMPtr<nsIJSArgArray> fastArray = do_QueryInterface(aArgs);
|
2014-02-11 14:59:15 +04:00
|
|
|
if (fastArray) {
|
|
|
|
uint32_t argc;
|
|
|
|
JS::Value* argv;
|
|
|
|
rv = fastArray->GetArgs(&argc, reinterpret_cast<void **>(&argv));
|
|
|
|
if (NS_SUCCEEDED(rv) && !aArgsOut.append(argv, argc)) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2010-01-25 19:48:07 +03:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
// Take the slower path converting each item.
|
|
|
|
// Handle only nsIArray and nsIVariant. nsIArray is only needed for
|
|
|
|
// SetProperty('arguments', ...);
|
|
|
|
|
|
|
|
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
|
|
|
NS_ENSURE_TRUE(xpc, NS_ERROR_UNEXPECTED);
|
2013-05-22 20:05:24 +04:00
|
|
|
AutoJSContext cx;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
if (!aArgs)
|
|
|
|
return NS_OK;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t argCount;
|
2006-06-13 07:07:47 +04:00
|
|
|
// This general purpose function may need to convert an arg array
|
|
|
|
// (window.arguments, event-handler args) and a generic property.
|
|
|
|
nsCOMPtr<nsIArray> argsArray(do_QueryInterface(aArgs));
|
|
|
|
|
|
|
|
if (argsArray) {
|
|
|
|
rv = argsArray->GetLength(&argCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (argCount == 0)
|
|
|
|
return NS_OK;
|
2006-06-22 02:10:35 +04:00
|
|
|
} else {
|
2006-06-13 07:07:47 +04:00
|
|
|
argCount = 1; // the nsISupports which is not an array
|
2006-06-22 02:10:35 +04:00
|
|
|
}
|
2006-06-13 07:07:47 +04:00
|
|
|
|
2010-02-17 22:32:47 +03:00
|
|
|
// Use the caller's auto guards to release and unroot.
|
2014-02-11 14:59:15 +04:00
|
|
|
if (!aArgsOut.resize(argCount)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2010-01-25 19:48:07 +03:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
if (argsArray) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t argCtr = 0; argCtr < argCount && NS_SUCCEEDED(rv); argCtr++) {
|
2006-06-13 07:07:47 +04:00
|
|
|
nsCOMPtr<nsISupports> arg;
|
2014-04-28 18:53:00 +04:00
|
|
|
JS::MutableHandle<JS::Value> thisVal = aArgsOut[argCtr];
|
2006-06-22 02:10:35 +04:00
|
|
|
argsArray->QueryElementAt(argCtr, NS_GET_IID(nsISupports),
|
|
|
|
getter_AddRefs(arg));
|
|
|
|
if (!arg) {
|
2014-02-11 14:59:15 +04:00
|
|
|
thisVal.setNull();
|
2006-06-22 02:10:35 +04:00
|
|
|
continue;
|
|
|
|
}
|
2006-06-13 07:07:47 +04:00
|
|
|
nsCOMPtr<nsIVariant> variant(do_QueryInterface(arg));
|
2012-07-30 18:20:58 +04:00
|
|
|
if (variant != nullptr) {
|
2014-02-11 14:59:15 +04:00
|
|
|
rv = xpc->VariantToJS(cx, aScope, variant, thisVal);
|
2006-06-13 07:07:47 +04:00
|
|
|
} else {
|
|
|
|
// And finally, support the nsISupportsPrimitives supplied
|
|
|
|
// by the AppShell. It generally will pass only strings, but
|
|
|
|
// as we have code for handling all, we may as well use it.
|
2014-02-11 14:59:15 +04:00
|
|
|
rv = AddSupportsPrimitiveTojsvals(arg, thisVal.address());
|
2006-06-13 07:07:47 +04:00
|
|
|
if (rv == NS_ERROR_NO_INTERFACE) {
|
2007-07-26 21:52:26 +04:00
|
|
|
// something else - probably an event object or similar -
|
2006-06-13 07:07:47 +04:00
|
|
|
// just wrap it.
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2006-06-13 07:07:47 +04:00
|
|
|
// but first, check its not another nsISupportsPrimitive, as
|
|
|
|
// these are now deprecated for use with script contexts.
|
|
|
|
nsCOMPtr<nsISupportsPrimitive> prim(do_QueryInterface(arg));
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(prim == nullptr,
|
2006-06-13 07:07:47 +04:00
|
|
|
"Don't pass nsISupportsPrimitives - use nsIVariant!");
|
|
|
|
#endif
|
2014-04-10 08:58:41 +04:00
|
|
|
JSAutoCompartment ac(cx, aScope);
|
|
|
|
rv = nsContentUtils::WrapNative(cx, arg, thisVal);
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-30 00:06:17 +04:00
|
|
|
nsCOMPtr<nsIVariant> variant = do_QueryInterface(aArgs);
|
|
|
|
if (variant) {
|
2014-04-28 18:53:00 +04:00
|
|
|
rv = xpc->VariantToJS(cx, aScope, variant, aArgsOut[0]);
|
2011-10-30 00:06:17 +04:00
|
|
|
} else {
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_ERROR("Not an array, not an interface?");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 14:59:15 +04:00
|
|
|
return rv;
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This really should go into xpconnect somewhere...
|
|
|
|
nsresult
|
2013-04-12 02:52:10 +04:00
|
|
|
nsJSContext::AddSupportsPrimitiveTojsvals(nsISupports *aArg, JS::Value *aArgv)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aArg, "Empty arg");
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsPrimitive> argPrimitive(do_QueryInterface(aArg));
|
|
|
|
if (!argPrimitive)
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
|
2013-05-22 20:05:24 +04:00
|
|
|
AutoJSContext cx;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t type;
|
2006-06-13 07:07:47 +04:00
|
|
|
argPrimitive->GetType(&type);
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case nsISupportsPrimitive::TYPE_CSTRING : {
|
|
|
|
nsCOMPtr<nsISupportsCString> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString data;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(data);
|
|
|
|
|
2008-07-27 03:17:12 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
JSString *str = ::JS_NewStringCopyN(cx, data.get(), data.Length());
|
|
|
|
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2015-06-30 21:20:56 +03:00
|
|
|
aArgv->setString(str);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_STRING : {
|
|
|
|
nsCOMPtr<nsISupportsString> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsAutoString data;
|
|
|
|
|
|
|
|
p->GetData(data);
|
|
|
|
|
2014-07-22 08:43:21 +04:00
|
|
|
// cast is probably safe since wchar_t and char16_t are expected
|
2006-06-13 07:07:47 +04:00
|
|
|
// to be equivalent; both unsigned 16-bit entities
|
|
|
|
JSString *str =
|
2013-12-04 16:19:38 +04:00
|
|
|
::JS_NewUCStringCopyN(cx, data.get(), data.Length());
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2015-06-30 21:20:56 +03:00
|
|
|
aArgv->setString(str);
|
2006-06-13 07:07:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_PRBOOL : {
|
|
|
|
nsCOMPtr<nsISupportsPRBool> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool data;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2015-06-30 21:20:56 +03:00
|
|
|
aArgv->setBoolean(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_PRUINT8 : {
|
|
|
|
nsCOMPtr<nsISupportsPRUint8> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t data;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2015-07-01 07:10:04 +03:00
|
|
|
aArgv->setInt32(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_PRUINT16 : {
|
|
|
|
nsCOMPtr<nsISupportsPRUint16> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t data;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2015-07-01 07:10:04 +03:00
|
|
|
aArgv->setInt32(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_PRUINT32 : {
|
|
|
|
nsCOMPtr<nsISupportsPRUint32> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t data;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2015-07-01 07:10:04 +03:00
|
|
|
aArgv->setInt32(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_CHAR : {
|
|
|
|
nsCOMPtr<nsISupportsChar> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
char data;
|
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
|
|
|
JSString *str = ::JS_NewStringCopyN(cx, &data, 1);
|
|
|
|
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2015-06-30 21:20:56 +03:00
|
|
|
aArgv->setString(str);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_PRINT16 : {
|
|
|
|
nsCOMPtr<nsISupportsPRInt16> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t data;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2015-07-01 07:10:04 +03:00
|
|
|
aArgv->setInt32(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_PRINT32 : {
|
|
|
|
nsCOMPtr<nsISupportsPRInt32> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t data;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2015-07-01 07:10:04 +03:00
|
|
|
aArgv->setInt32(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_FLOAT : {
|
|
|
|
nsCOMPtr<nsISupportsFloat> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
float data;
|
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2012-08-02 04:59:47 +04:00
|
|
|
*aArgv = ::JS_NumberValue(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_DOUBLE : {
|
|
|
|
nsCOMPtr<nsISupportsDouble> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
double data;
|
|
|
|
|
|
|
|
p->GetData(&data);
|
|
|
|
|
2012-08-02 04:59:47 +04:00
|
|
|
*aArgv = ::JS_NumberValue(data);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_INTERFACE_POINTER : {
|
|
|
|
nsCOMPtr<nsISupportsInterfacePointer> p(do_QueryInterface(argPrimitive));
|
|
|
|
NS_ENSURE_TRUE(p, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> data;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIID *iid = nullptr;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
p->GetData(getter_AddRefs(data));
|
|
|
|
p->GetDataIID(&iid);
|
|
|
|
NS_ENSURE_TRUE(iid, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
AutoFree iidGuard(iid); // Free iid upon destruction.
|
|
|
|
|
2014-04-10 08:58:41 +04:00
|
|
|
JS::Rooted<JSObject*> scope(cx, GetWindowProxy());
|
2013-05-02 13:12:46 +04:00
|
|
|
JS::Rooted<JS::Value> v(cx);
|
2014-04-10 08:58:41 +04:00
|
|
|
JSAutoCompartment ac(cx, scope);
|
|
|
|
nsresult rv = nsContentUtils::WrapNative(cx, data, iid, &v);
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-08-14 23:00:24 +04:00
|
|
|
*aArgv = v;
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsISupportsPrimitive::TYPE_ID :
|
|
|
|
case nsISupportsPrimitive::TYPE_PRUINT64 :
|
|
|
|
case nsISupportsPrimitive::TYPE_PRINT64 :
|
|
|
|
case nsISupportsPrimitive::TYPE_PRTIME :
|
|
|
|
case nsISupportsPrimitive::TYPE_VOID : {
|
|
|
|
NS_WARNING("Unsupported primitive type used");
|
2015-06-30 04:36:44 +03:00
|
|
|
aArgv->setNull();
|
2006-06-13 07:07:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default : {
|
|
|
|
NS_WARNING("Unknown primitive type used");
|
2015-06-30 04:36:44 +03:00
|
|
|
aArgv->setNull();
|
2006-06-13 07:07:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-11 06:37:25 +04:00
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2004-05-11 06:37:25 +04:00
|
|
|
IsJProfAction(struct sigaction *action)
|
|
|
|
{
|
|
|
|
return (action->sa_sigaction &&
|
2011-11-08 09:34:40 +04:00
|
|
|
(action->sa_flags & (SA_RESTART | SA_SIGINFO)) == (SA_RESTART | SA_SIGINFO));
|
2004-05-11 06:37:25 +04:00
|
|
|
}
|
|
|
|
|
2006-12-12 18:47:47 +03:00
|
|
|
void NS_JProfStartProfiling();
|
|
|
|
void NS_JProfStopProfiling();
|
2011-11-08 09:34:40 +04:00
|
|
|
void NS_JProfClearCircular();
|
2006-12-12 18:47:47 +03:00
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2013-04-12 02:52:10 +04:00
|
|
|
JProfStartProfilingJS(JSContext *cx, unsigned argc, JS::Value *vp)
|
2006-12-12 18:47:47 +03:00
|
|
|
{
|
|
|
|
NS_JProfStartProfiling();
|
2013-08-02 11:41:57 +04:00
|
|
|
return true;
|
2006-12-12 18:47:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void NS_JProfStartProfiling()
|
2004-05-11 06:37:25 +04:00
|
|
|
{
|
|
|
|
// Figure out whether we're dealing with SIGPROF, SIGALRM, or
|
|
|
|
// SIGPOLL profiling (SIGALRM for JP_REALTIME, SIGPOLL for
|
|
|
|
// JP_RTC_HZ)
|
|
|
|
struct sigaction action;
|
|
|
|
|
2011-11-08 09:34:40 +04:00
|
|
|
// Must check ALRM before PROF since both are enabled for real-time
|
2012-07-30 18:20:58 +04:00
|
|
|
sigaction(SIGALRM, nullptr, &action);
|
2011-11-08 09:34:40 +04:00
|
|
|
//printf("SIGALRM: %p, flags = %x\n",action.sa_sigaction,action.sa_flags);
|
2004-05-11 06:37:25 +04:00
|
|
|
if (IsJProfAction(&action)) {
|
2011-11-08 09:34:40 +04:00
|
|
|
//printf("Beginning real-time jprof profiling.\n");
|
2004-05-11 06:37:25 +04:00
|
|
|
raise(SIGALRM);
|
2006-12-12 18:47:47 +03:00
|
|
|
return;
|
2004-05-11 06:37:25 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
sigaction(SIGPROF, nullptr, &action);
|
2011-11-08 09:34:40 +04:00
|
|
|
//printf("SIGPROF: %p, flags = %x\n",action.sa_sigaction,action.sa_flags);
|
2004-05-11 06:37:25 +04:00
|
|
|
if (IsJProfAction(&action)) {
|
2011-11-08 09:34:40 +04:00
|
|
|
//printf("Beginning process-time jprof profiling.\n");
|
2004-05-11 06:37:25 +04:00
|
|
|
raise(SIGPROF);
|
2006-12-12 18:47:47 +03:00
|
|
|
return;
|
2004-05-11 06:37:25 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
sigaction(SIGPOLL, nullptr, &action);
|
2011-11-08 09:34:40 +04:00
|
|
|
//printf("SIGPOLL: %p, flags = %x\n",action.sa_sigaction,action.sa_flags);
|
2004-05-11 06:37:25 +04:00
|
|
|
if (IsJProfAction(&action)) {
|
2011-11-08 09:34:40 +04:00
|
|
|
//printf("Beginning rtc-based jprof profiling.\n");
|
2004-05-11 06:37:25 +04:00
|
|
|
raise(SIGPOLL);
|
2006-12-12 18:47:47 +03:00
|
|
|
return;
|
2004-05-11 06:37:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Could not start jprof-profiling since JPROF_FLAGS was not set.\n");
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2013-04-12 02:52:10 +04:00
|
|
|
JProfStopProfilingJS(JSContext *cx, unsigned argc, JS::Value *vp)
|
2006-12-12 18:47:47 +03:00
|
|
|
{
|
|
|
|
NS_JProfStopProfiling();
|
2013-08-02 11:41:57 +04:00
|
|
|
return true;
|
2006-12-12 18:47:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NS_JProfStopProfiling()
|
2004-05-11 06:37:25 +04:00
|
|
|
{
|
|
|
|
raise(SIGUSR1);
|
2011-11-08 09:34:40 +04:00
|
|
|
//printf("Stopped jprof profiling.\n");
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2013-04-12 02:52:10 +04:00
|
|
|
JProfClearCircularJS(JSContext *cx, unsigned argc, JS::Value *vp)
|
2011-11-08 09:34:40 +04:00
|
|
|
{
|
|
|
|
NS_JProfClearCircular();
|
2013-08-02 11:41:57 +04:00
|
|
|
return true;
|
2011-11-08 09:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NS_JProfClearCircular()
|
|
|
|
{
|
|
|
|
raise(SIGUSR2);
|
|
|
|
//printf("cleared jprof buffer\n");
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:41:57 +04:00
|
|
|
static bool
|
2013-04-12 02:52:10 +04:00
|
|
|
JProfSaveCircularJS(JSContext *cx, unsigned argc, JS::Value *vp)
|
2011-11-08 09:34:40 +04:00
|
|
|
{
|
|
|
|
// Not ideal...
|
|
|
|
NS_JProfStopProfiling();
|
|
|
|
NS_JProfStartProfiling();
|
2013-08-02 11:41:57 +04:00
|
|
|
return true;
|
2004-05-11 06:37:25 +04:00
|
|
|
}
|
|
|
|
|
2013-04-23 01:15:49 +04:00
|
|
|
static const JSFunctionSpec JProfFunctions[] = {
|
2012-10-05 03:01:32 +04:00
|
|
|
JS_FS("JProfStartProfiling", JProfStartProfilingJS, 0, 0),
|
|
|
|
JS_FS("JProfStopProfiling", JProfStopProfilingJS, 0, 0),
|
|
|
|
JS_FS("JProfClearCircular", JProfClearCircularJS, 0, 0),
|
|
|
|
JS_FS("JProfSaveCircular", JProfSaveCircularJS, 0, 0),
|
|
|
|
JS_FS_END
|
2004-05-11 06:37:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* defined(MOZ_JPROF) */
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
nsresult
|
2013-05-12 09:17:42 +04:00
|
|
|
nsJSContext::InitClasses(JS::Handle<JSObject*> aGlobalObj)
|
1998-07-16 05:16:47 +04:00
|
|
|
{
|
2014-06-11 20:31:24 +04:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-19 11:21:14 +04:00
|
|
|
jsapi.Init();
|
2014-06-11 20:31:24 +04:00
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
JSAutoCompartment ac(cx, aGlobalObj);
|
2000-09-01 07:10:33 +04:00
|
|
|
|
2011-01-15 04:58:40 +03:00
|
|
|
// Attempt to initialize profiling functions
|
2013-05-22 20:05:24 +04:00
|
|
|
::JS_DefineProfilingFunctions(cx, aGlobalObj);
|
2011-01-15 04:58:40 +03:00
|
|
|
|
2004-05-11 06:37:25 +04:00
|
|
|
#ifdef MOZ_JPROF
|
|
|
|
// Attempt to initialize JProf functions
|
2013-05-22 20:05:24 +04:00
|
|
|
::JS_DefineFunctions(cx, aGlobalObj, JProfFunctions);
|
2004-05-11 06:37:25 +04:00
|
|
|
#endif
|
|
|
|
|
2014-06-06 12:06:26 +04:00
|
|
|
return NS_OK;
|
1998-07-16 05:16:47 +04:00
|
|
|
}
|
|
|
|
|
2005-07-31 00:57:07 +04:00
|
|
|
void
|
|
|
|
nsJSContext::WillInitializeContext()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInitialized = false;
|
2005-07-31 00:57:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSContext::DidInitializeContext()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInitialized = true;
|
2005-07-31 00:57:07 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
1998-12-30 05:46:36 +03:00
|
|
|
nsJSContext::IsContextInitialized()
|
|
|
|
{
|
2004-02-10 01:48:53 +03:00
|
|
|
return mIsInitialized;
|
1998-12-30 05:46:36 +03:00
|
|
|
}
|
|
|
|
|
2013-01-15 15:46:35 +04:00
|
|
|
bool
|
|
|
|
nsJSContext::GetProcessingScriptTag()
|
|
|
|
{
|
|
|
|
return mProcessingScriptTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSContext::SetProcessingScriptTag(bool aFlag)
|
|
|
|
{
|
|
|
|
mProcessingScriptTag = aFlag;
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:53:23 +04:00
|
|
|
void
|
|
|
|
FullGCTimerFired(nsITimer* aTimer, void* aClosure)
|
|
|
|
{
|
2014-04-26 00:21:04 +04:00
|
|
|
nsJSContext::KillFullGCTimer();
|
2014-10-23 20:59:36 +04:00
|
|
|
MOZ_ASSERT(!aClosure, "Don't pass a closure to FullGCTimerFired");
|
|
|
|
nsJSContext::GarbageCollectNow(JS::gcreason::FULL_GC_TIMER,
|
2012-07-01 01:16:32 +04:00
|
|
|
nsJSContext::IncrementalGC);
|
2012-05-09 22:53:23 +04:00
|
|
|
}
|
|
|
|
|
2007-10-23 01:42:25 +04:00
|
|
|
//static
|
|
|
|
void
|
2013-01-28 00:35:12 +04:00
|
|
|
nsJSContext::GarbageCollectNow(JS::gcreason::Reason aReason,
|
2012-07-01 01:16:32 +04:00
|
|
|
IsIncremental aIncremental,
|
2012-08-01 05:39:39 +04:00
|
|
|
IsShrinking aShrinking,
|
|
|
|
int64_t aSliceMillis)
|
2007-10-23 01:42:25 +04:00
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsJSContext", "GarbageCollectNow",
|
|
|
|
js::ProfileEntry::Category::GC);
|
2010-05-20 03:22:19 +04:00
|
|
|
|
2012-08-01 05:39:39 +04:00
|
|
|
MOZ_ASSERT_IF(aSliceMillis, aIncremental == IncrementalGC);
|
|
|
|
|
2011-02-17 02:47:12 +03:00
|
|
|
KillGCTimer();
|
2011-12-27 15:59:29 +04:00
|
|
|
KillShrinkGCBuffersTimer();
|
2008-02-25 20:47:25 +03:00
|
|
|
|
2011-02-17 02:47:12 +03:00
|
|
|
// Reset sPendingLoadCount in case the timer that fired was a
|
|
|
|
// timer we scheduled due to a normal GC timer firing while
|
|
|
|
// documents were loading. If this happens we're waiting for a
|
|
|
|
// document that is taking a long time to load, and we effectively
|
|
|
|
// ignore the fact that the currently loading documents are still
|
|
|
|
// loading and move on as if they weren't.
|
|
|
|
sPendingLoadCount = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
sLoadingInProgress = false;
|
2007-10-23 01:42:25 +04:00
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
if (!nsContentUtils::XPConnect() || !sRuntime) {
|
2012-05-09 22:53:23 +04:00
|
|
|
return;
|
2011-02-19 02:14:21 +03:00
|
|
|
}
|
2012-07-01 01:16:32 +04:00
|
|
|
|
2012-07-01 01:18:10 +04:00
|
|
|
if (sCCLockedOut && aIncremental == IncrementalGC) {
|
|
|
|
// We're in the middle of incremental GC. Do another slice.
|
2016-07-07 10:55:41 +03:00
|
|
|
JS::PrepareForIncrementalGC(sContext);
|
2016-07-07 10:55:45 +03:00
|
|
|
JS::IncrementalGCSlice(sContext, aReason, aSliceMillis);
|
2012-07-01 01:18:10 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-24 12:40:02 +03:00
|
|
|
JSGCInvocationKind gckind = aShrinking == ShrinkingGC ? GC_SHRINK : GC_NORMAL;
|
2016-02-19 02:21:48 +03:00
|
|
|
|
|
|
|
if (sNeedsFullGC || aReason != JS::gcreason::CC_WAITING) {
|
|
|
|
sNeedsFullGC = false;
|
2016-07-07 10:55:41 +03:00
|
|
|
JS::PrepareForFullGC(sContext);
|
2016-02-19 02:21:48 +03:00
|
|
|
} else {
|
|
|
|
CycleCollectedJSRuntime::Get()->PrepareWaitingZonesForGC();
|
|
|
|
}
|
|
|
|
|
2012-07-01 01:16:32 +04:00
|
|
|
if (aIncremental == IncrementalGC) {
|
2016-07-07 10:55:45 +03:00
|
|
|
JS::StartIncrementalGC(sContext, gckind, aReason, aSliceMillis);
|
2012-07-01 01:16:32 +04:00
|
|
|
} else {
|
2016-07-07 10:55:41 +03:00
|
|
|
JS::GCForReason(sContext, gckind, aReason);
|
2012-07-01 01:16:32 +04:00
|
|
|
}
|
2007-10-23 01:42:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-27 15:59:29 +04:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::ShrinkGCBuffersNow()
|
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsJSContext", "ShrinkGCBuffersNow",
|
|
|
|
js::ProfileEntry::Category::GC);
|
2011-12-27 15:59:29 +04:00
|
|
|
|
|
|
|
KillShrinkGCBuffersTimer();
|
|
|
|
|
2016-07-07 10:55:45 +03:00
|
|
|
JS::ShrinkGCBuffers(sContext);
|
2011-12-27 15:59:29 +04:00
|
|
|
}
|
|
|
|
|
2013-01-01 00:54:37 +04:00
|
|
|
static void
|
|
|
|
FinishAnyIncrementalGC()
|
|
|
|
{
|
2016-01-15 01:03:11 +03:00
|
|
|
PROFILER_LABEL_FUNC(js::ProfileEntry::Category::GC);
|
|
|
|
|
2013-01-01 00:54:37 +04:00
|
|
|
if (sCCLockedOut) {
|
|
|
|
// We're in the middle of an incremental GC, so finish it.
|
2016-07-07 10:55:41 +03:00
|
|
|
JS::PrepareForIncrementalGC(sContext);
|
2016-07-07 10:55:45 +03:00
|
|
|
JS::FinishIncrementalGC(sContext, JS::gcreason::CC_FORCED);
|
2013-01-01 00:54:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-15 14:30:39 +04:00
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
FireForgetSkippable(uint32_t aSuspected, bool aRemoveChildless)
|
2012-07-15 14:30:39 +04:00
|
|
|
{
|
|
|
|
PRTime startTime = PR_Now();
|
2013-01-01 00:54:37 +04:00
|
|
|
FinishAnyIncrementalGC();
|
2013-07-27 14:48:45 +04:00
|
|
|
bool earlyForgetSkippable =
|
|
|
|
sCleanupsSinceLastGC < NS_MAJOR_FORGET_SKIPPABLE_CALLS;
|
|
|
|
nsCycleCollector_forgetSkippable(aRemoveChildless, earlyForgetSkippable);
|
2012-07-15 14:30:39 +04:00
|
|
|
sPreviousSuspectedCount = nsCycleCollector_suspectedCount();
|
|
|
|
++sCleanupsSinceLastGC;
|
|
|
|
PRTime delta = PR_Now() - startTime;
|
|
|
|
if (sMinForgetSkippableTime > delta) {
|
|
|
|
sMinForgetSkippableTime = delta;
|
|
|
|
}
|
|
|
|
if (sMaxForgetSkippableTime < delta) {
|
|
|
|
sMaxForgetSkippableTime = delta;
|
|
|
|
}
|
|
|
|
sTotalForgetSkippableTime += delta;
|
|
|
|
sRemovedPurples += (aSuspected - sPreviousSuspectedCount);
|
|
|
|
++sForgetSkippableBeforeCC;
|
|
|
|
}
|
|
|
|
|
2013-01-01 00:55:07 +04:00
|
|
|
MOZ_ALWAYS_INLINE
|
|
|
|
static uint32_t
|
2013-12-31 21:20:21 +04:00
|
|
|
TimeBetween(TimeStamp start, TimeStamp end)
|
2013-01-01 00:55:07 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(end >= start);
|
2013-12-31 21:20:21 +04:00
|
|
|
return (uint32_t) ((end - start).ToMilliseconds());
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
TimeUntilNow(TimeStamp start)
|
|
|
|
{
|
|
|
|
if (start.IsNull()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return TimeBetween(start, TimeStamp::Now());
|
2013-01-01 00:55:07 +04:00
|
|
|
}
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
struct CycleCollectorStats
|
|
|
|
{
|
2016-03-02 02:15:26 +03:00
|
|
|
MOZ_CONSTEXPR CycleCollectorStats() :
|
|
|
|
mMaxGCDuration(0), mRanSyncForgetSkippable(false), mSuspected(0),
|
|
|
|
mMaxSkippableDuration(0), mMaxSliceTime(0), mMaxSliceTimeSinceClear(0),
|
|
|
|
mTotalSliceTime(0), mAnyLockedOut(false), mExtraForgetSkippableCalls(0) {}
|
|
|
|
|
2014-06-15 03:43:45 +04:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mMaxSliceTimeSinceClear = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
void Clear()
|
|
|
|
{
|
2013-12-31 21:20:21 +04:00
|
|
|
mBeginSliceTime = TimeStamp();
|
2014-03-06 22:54:37 +04:00
|
|
|
mEndSliceTime = TimeStamp();
|
2013-12-31 21:20:21 +04:00
|
|
|
mBeginTime = TimeStamp();
|
2013-11-21 02:35:16 +04:00
|
|
|
mMaxGCDuration = 0;
|
|
|
|
mRanSyncForgetSkippable = false;
|
|
|
|
mSuspected = 0;
|
|
|
|
mMaxSkippableDuration = 0;
|
2013-12-31 21:20:21 +04:00
|
|
|
mMaxSliceTime = 0;
|
2014-01-08 05:33:47 +04:00
|
|
|
mTotalSliceTime = 0;
|
2013-11-21 02:35:16 +04:00
|
|
|
mAnyLockedOut = false;
|
2014-01-01 23:00:35 +04:00
|
|
|
mExtraForgetSkippableCalls = 0;
|
2013-11-21 02:35:16 +04:00
|
|
|
}
|
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
void PrepareForCycleCollectionSlice(int32_t aExtraForgetSkippableCalls = 0);
|
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
void FinishCycleCollectionSlice()
|
|
|
|
{
|
2014-03-05 04:21:48 +04:00
|
|
|
if (mBeginSliceTime.IsNull()) {
|
|
|
|
// We already called this method from EndCycleCollectionCallback for this slice.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-06 22:54:37 +04:00
|
|
|
mEndSliceTime = TimeStamp::Now();
|
|
|
|
uint32_t sliceTime = TimeBetween(mBeginSliceTime, mEndSliceTime);
|
2013-12-31 21:20:21 +04:00
|
|
|
mMaxSliceTime = std::max(mMaxSliceTime, sliceTime);
|
2014-06-15 03:43:45 +04:00
|
|
|
mMaxSliceTimeSinceClear = std::max(mMaxSliceTimeSinceClear, sliceTime);
|
2014-01-08 05:33:47 +04:00
|
|
|
mTotalSliceTime += sliceTime;
|
2014-03-05 04:21:48 +04:00
|
|
|
mBeginSliceTime = TimeStamp();
|
2014-01-01 23:00:35 +04:00
|
|
|
MOZ_ASSERT(mExtraForgetSkippableCalls == 0, "Forget to reset extra forget skippable calls?");
|
2013-12-31 21:20:21 +04:00
|
|
|
}
|
|
|
|
|
2014-01-01 23:00:35 +04:00
|
|
|
void RunForgetSkippable();
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
// Time the current slice began, including any GC finishing.
|
2013-12-31 21:20:21 +04:00
|
|
|
TimeStamp mBeginSliceTime;
|
2013-11-21 02:35:16 +04:00
|
|
|
|
2014-03-06 22:54:37 +04:00
|
|
|
// Time the previous slice of the current CC ended.
|
|
|
|
TimeStamp mEndSliceTime;
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
// Time the current cycle collection began.
|
2013-12-31 21:20:21 +04:00
|
|
|
TimeStamp mBeginTime;
|
2013-11-21 02:35:16 +04:00
|
|
|
|
|
|
|
// The longest GC finishing duration for any slice of the current CC.
|
|
|
|
uint32_t mMaxGCDuration;
|
|
|
|
|
|
|
|
// True if we ran sync forget skippable in any slice of the current CC.
|
|
|
|
bool mRanSyncForgetSkippable;
|
|
|
|
|
|
|
|
// Number of suspected objects at the start of the current CC.
|
|
|
|
uint32_t mSuspected;
|
|
|
|
|
|
|
|
// The longest duration spent on sync forget skippable in any slice of the
|
2013-12-31 21:20:21 +04:00
|
|
|
// current CC.
|
2013-11-21 02:35:16 +04:00
|
|
|
uint32_t mMaxSkippableDuration;
|
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
// The longest pause of any slice in the current CC.
|
|
|
|
uint32_t mMaxSliceTime;
|
|
|
|
|
2014-06-15 03:43:45 +04:00
|
|
|
// The longest slice time since ClearMaxCCSliceTime() was called.
|
|
|
|
uint32_t mMaxSliceTimeSinceClear;
|
|
|
|
|
2014-01-08 05:33:47 +04:00
|
|
|
// The total amount of time spent actually running the current CC.
|
|
|
|
uint32_t mTotalSliceTime;
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
// True if we were locked out by the GC in any slice of the current CC.
|
|
|
|
bool mAnyLockedOut;
|
2014-01-01 23:00:35 +04:00
|
|
|
|
|
|
|
int32_t mExtraForgetSkippableCalls;
|
2013-11-21 02:35:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
CycleCollectorStats gCCStats;
|
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
void
|
|
|
|
CycleCollectorStats::PrepareForCycleCollectionSlice(int32_t aExtraForgetSkippableCalls)
|
2013-11-21 02:35:17 +04:00
|
|
|
{
|
2013-12-31 21:20:21 +04:00
|
|
|
mBeginSliceTime = TimeStamp::Now();
|
2011-02-17 02:47:12 +03:00
|
|
|
|
2013-01-01 00:55:07 +04:00
|
|
|
// Before we begin the cycle collection, make sure there is no active GC.
|
2013-11-21 02:35:16 +04:00
|
|
|
if (sCCLockedOut) {
|
2013-12-31 21:20:21 +04:00
|
|
|
mAnyLockedOut = true;
|
2013-11-21 02:35:16 +04:00
|
|
|
FinishAnyIncrementalGC();
|
2014-03-05 04:21:48 +04:00
|
|
|
uint32_t gcTime = TimeBetween(mBeginSliceTime, TimeStamp::Now());
|
2013-12-31 21:20:21 +04:00
|
|
|
mMaxGCDuration = std::max(mMaxGCDuration, gcTime);
|
2013-11-21 02:35:16 +04:00
|
|
|
}
|
2012-01-31 00:06:18 +04:00
|
|
|
|
2014-01-01 23:00:35 +04:00
|
|
|
mExtraForgetSkippableCalls = aExtraForgetSkippableCalls;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CycleCollectorStats::RunForgetSkippable()
|
|
|
|
{
|
2013-01-01 00:55:07 +04:00
|
|
|
// Run forgetSkippable synchronously to reduce the size of the CC graph. This
|
|
|
|
// is particularly useful if we recently finished a GC.
|
2014-01-01 23:00:35 +04:00
|
|
|
if (mExtraForgetSkippableCalls >= 0) {
|
|
|
|
TimeStamp beginForgetSkippable = TimeStamp::Now();
|
2013-11-21 02:35:16 +04:00
|
|
|
bool ranSyncForgetSkippable = false;
|
2013-07-27 14:48:45 +04:00
|
|
|
while (sCleanupsSinceLastGC < NS_MAJOR_FORGET_SKIPPABLE_CALLS) {
|
2012-07-15 14:30:39 +04:00
|
|
|
FireForgetSkippable(nsCycleCollector_suspectedCount(), false);
|
2013-01-01 00:55:07 +04:00
|
|
|
ranSyncForgetSkippable = true;
|
2012-05-03 20:17:01 +04:00
|
|
|
}
|
2012-01-31 00:06:18 +04:00
|
|
|
|
2014-01-01 23:00:35 +04:00
|
|
|
for (int32_t i = 0; i < mExtraForgetSkippableCalls; ++i) {
|
2013-11-21 02:35:16 +04:00
|
|
|
FireForgetSkippable(nsCycleCollector_suspectedCount(), false);
|
|
|
|
ranSyncForgetSkippable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ranSyncForgetSkippable) {
|
2013-12-31 21:20:21 +04:00
|
|
|
mMaxSkippableDuration =
|
2014-01-01 23:00:35 +04:00
|
|
|
std::max(mMaxSkippableDuration, TimeUntilNow(beginForgetSkippable));
|
2013-12-31 21:20:21 +04:00
|
|
|
mRanSyncForgetSkippable = true;
|
2013-11-21 02:35:16 +04:00
|
|
|
}
|
|
|
|
|
2012-01-31 00:06:18 +04:00
|
|
|
}
|
2014-01-01 23:00:35 +04:00
|
|
|
mExtraForgetSkippableCalls = 0;
|
2013-11-21 02:35:17 +04:00
|
|
|
}
|
2012-05-03 20:17:01 +04:00
|
|
|
|
2013-11-21 02:35:17 +04:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::CycleCollectNow(nsICycleCollectorListener *aListener,
|
|
|
|
int32_t aExtraForgetSkippableCalls)
|
|
|
|
{
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsJSContext", "CycleCollectNow",
|
|
|
|
js::ProfileEntry::Category::CC);
|
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
gCCStats.PrepareForCycleCollectionSlice(aExtraForgetSkippableCalls);
|
2013-11-21 02:35:17 +04:00
|
|
|
nsCycleCollector_collect(aListener);
|
2013-12-31 21:20:21 +04:00
|
|
|
gCCStats.FinishCycleCollectionSlice();
|
2013-11-21 02:35:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
void
|
2014-03-05 04:21:48 +04:00
|
|
|
nsJSContext::RunCycleCollectorSlice()
|
2013-11-21 02:35:17 +04:00
|
|
|
{
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-21 02:35:16 +04:00
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsJSContext", "RunCycleCollectorSlice",
|
|
|
|
js::ProfileEntry::Category::CC);
|
2013-12-22 18:58:19 +04:00
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
gCCStats.PrepareForCycleCollectionSlice();
|
2014-03-06 22:54:37 +04:00
|
|
|
|
|
|
|
// Decide how long we want to budget for this slice. By default,
|
|
|
|
// use an unlimited budget.
|
2015-08-11 18:42:24 +03:00
|
|
|
js::SliceBudget budget = js::SliceBudget::unlimited();
|
2014-03-06 22:54:37 +04:00
|
|
|
|
|
|
|
if (sIncrementalCC) {
|
|
|
|
if (gCCStats.mBeginTime.IsNull()) {
|
|
|
|
// If no CC is in progress, use the standard slice time.
|
2014-11-06 12:14:00 +03:00
|
|
|
budget = js::SliceBudget(js::TimeBudget(kICCSliceBudget));
|
2014-03-06 22:54:37 +04:00
|
|
|
} else {
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
|
|
|
|
|
|
// Only run a limited slice if we're within the max running time.
|
|
|
|
if (TimeBetween(gCCStats.mBeginTime, now) < kMaxICCDuration) {
|
|
|
|
float sliceMultiplier = std::max(TimeBetween(gCCStats.mEndSliceTime, now) / (float)kICCIntersliceDelay, 1.0f);
|
2014-11-06 12:14:00 +03:00
|
|
|
budget = js::SliceBudget(js::TimeBudget(kICCSliceBudget * sliceMultiplier));
|
2014-03-06 22:54:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 14:47:51 +03:00
|
|
|
nsCycleCollector_collectSlice(budget, sDidPaintAfterPreviousICCSlice);
|
|
|
|
sDidPaintAfterPreviousICCSlice = false;
|
2014-03-06 22:54:37 +04:00
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
gCCStats.FinishCycleCollectionSlice();
|
2013-12-19 09:22:55 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 22:58:39 +04:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::RunCycleCollectorWorkSlice(int64_t aWorkBudget)
|
|
|
|
{
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsJSContext", "RunCycleCollectorWorkSlice",
|
|
|
|
js::ProfileEntry::Category::CC);
|
2014-05-13 22:58:39 +04:00
|
|
|
|
|
|
|
gCCStats.PrepareForCycleCollectionSlice();
|
2014-11-06 12:14:00 +03:00
|
|
|
|
|
|
|
js::SliceBudget budget = js::SliceBudget(js::WorkBudget(aWorkBudget));
|
|
|
|
nsCycleCollector_collectSlice(budget);
|
|
|
|
|
2014-05-13 22:58:39 +04:00
|
|
|
gCCStats.FinishCycleCollectionSlice();
|
|
|
|
}
|
|
|
|
|
2014-06-15 03:43:45 +04:00
|
|
|
void
|
|
|
|
nsJSContext::ClearMaxCCSliceTime()
|
|
|
|
{
|
|
|
|
gCCStats.mMaxSliceTimeSinceClear = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsJSContext::GetMaxCCSliceTimeSinceClear()
|
|
|
|
{
|
|
|
|
return gCCStats.mMaxSliceTimeSinceClear;
|
|
|
|
}
|
|
|
|
|
2013-12-21 18:35:08 +04:00
|
|
|
static void
|
|
|
|
ICCTimerFired(nsITimer* aTimer, void* aClosure)
|
|
|
|
{
|
|
|
|
if (sDidShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore ICC timer fires during IGC. Running ICC during an IGC will cause us
|
|
|
|
// to synchronously finish the GC, which is bad.
|
|
|
|
|
|
|
|
if (sCCLockedOut) {
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
if (sCCLockedOutTime == 0) {
|
|
|
|
sCCLockedOutTime = now;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (now - sCCLockedOutTime < NS_MAX_CC_LOCKEDOUT_TIME) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:21:48 +04:00
|
|
|
nsJSContext::RunCycleCollectorSlice();
|
2013-12-21 18:35:08 +04:00
|
|
|
}
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::BeginCycleCollectionCallback()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
gCCStats.mBeginTime = gCCStats.mBeginSliceTime.IsNull() ? TimeStamp::Now() : gCCStats.mBeginSliceTime;
|
2013-11-21 02:35:16 +04:00
|
|
|
gCCStats.mSuspected = nsCycleCollector_suspectedCount();
|
|
|
|
|
|
|
|
KillCCTimer();
|
2013-12-21 18:35:08 +04:00
|
|
|
|
2014-01-01 23:00:35 +04:00
|
|
|
gCCStats.RunForgetSkippable();
|
|
|
|
|
2013-12-21 18:35:08 +04:00
|
|
|
MOZ_ASSERT(!sICCTimer, "Tried to create a new ICC timer when one already existed.");
|
|
|
|
|
2014-11-13 18:11:55 +03:00
|
|
|
// Create an ICC timer even if ICC is globally disabled, because we could be manually triggering
|
|
|
|
// an incremental collection, and we want to be sure to finish it.
|
2013-12-21 18:35:08 +04:00
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sICCTimer);
|
|
|
|
if (sICCTimer) {
|
2015-09-10 10:50:51 +03:00
|
|
|
sICCTimer->InitWithNamedFuncCallback(ICCTimerFired, nullptr,
|
|
|
|
kICCIntersliceDelay,
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK,
|
|
|
|
"ICCTimerFired");
|
2013-12-21 18:35:08 +04:00
|
|
|
}
|
2013-11-21 02:35:16 +04:00
|
|
|
}
|
|
|
|
|
2014-05-16 21:11:40 +04:00
|
|
|
static_assert(NS_GC_DELAY > kMaxICCDuration, "A max duration ICC shouldn't reduce GC delay to 0");
|
|
|
|
|
2013-11-21 02:35:16 +04:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-06-27 19:10:09 +04:00
|
|
|
|
2013-12-21 18:35:08 +04:00
|
|
|
nsJSContext::KillICCTimer();
|
|
|
|
|
2014-03-05 04:21:48 +04:00
|
|
|
// Update timing information for the current slice before we log it, if
|
|
|
|
// we previously called PrepareForCycleCollectionSlice(). During shutdown
|
|
|
|
// CCs, this won't happen.
|
2013-12-31 21:20:21 +04:00
|
|
|
gCCStats.FinishCycleCollectionSlice();
|
|
|
|
|
2014-10-20 21:07:52 +04:00
|
|
|
sCCollectedWaitingForGC += aResults.mFreedGCed;
|
|
|
|
sCCollectedZonesWaitingForGC += aResults.mFreedJSZones;
|
2011-02-17 02:47:12 +03:00
|
|
|
|
2014-05-16 21:11:40 +04:00
|
|
|
TimeStamp endCCTimeStamp = TimeStamp::Now();
|
|
|
|
uint32_t ccNowDuration = TimeBetween(gCCStats.mBeginTime, endCCTimeStamp);
|
|
|
|
|
2014-02-03 19:31:11 +04:00
|
|
|
if (NeedsGCAfterCC()) {
|
2015-01-05 08:12:19 +03:00
|
|
|
PokeGC(JS::gcreason::CC_WAITING,
|
2014-05-16 21:11:40 +04:00
|
|
|
NS_GC_DELAY - std::min(ccNowDuration, kMaxICCDuration));
|
2010-11-07 22:07:59 +03:00
|
|
|
}
|
|
|
|
|
2014-02-18 18:58:40 +04:00
|
|
|
PRTime endCCTime;
|
|
|
|
if (sPostGCEventsToObserver) {
|
|
|
|
endCCTime = PR_Now();
|
|
|
|
}
|
2013-01-01 00:55:07 +04:00
|
|
|
|
|
|
|
// Log information about the CC via telemetry, JSON and the console.
|
2013-11-21 02:35:16 +04:00
|
|
|
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_FINISH_IGC, gCCStats.mAnyLockedOut);
|
|
|
|
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_SYNC_SKIPPABLE, gCCStats.mRanSyncForgetSkippable);
|
2013-01-01 00:55:07 +04:00
|
|
|
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_FULL, ccNowDuration);
|
2013-12-31 21:20:21 +04:00
|
|
|
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_MAX_PAUSE, gCCStats.mMaxSliceTime);
|
2012-01-21 00:02:18 +04:00
|
|
|
|
2013-12-31 21:20:21 +04:00
|
|
|
if (!sLastCCEndTime.IsNull()) {
|
2014-05-16 21:11:40 +04:00
|
|
|
// TimeBetween returns milliseconds, but we want to report seconds.
|
|
|
|
uint32_t timeBetween = TimeBetween(sLastCCEndTime, gCCStats.mBeginTime) / 1000;
|
2012-01-21 00:02:18 +04:00
|
|
|
Telemetry::Accumulate(Telemetry::CYCLE_COLLECTOR_TIME_BETWEEN, timeBetween);
|
|
|
|
}
|
2014-02-18 18:58:40 +04:00
|
|
|
sLastCCEndTime = endCCTimeStamp;
|
2012-01-21 00:02:18 +04:00
|
|
|
|
2012-02-11 03:30:20 +04:00
|
|
|
Telemetry::Accumulate(Telemetry::FORGET_SKIPPABLE_MAX,
|
|
|
|
sMaxForgetSkippableTime / PR_USEC_PER_MSEC);
|
|
|
|
|
2012-08-22 22:28:34 +04:00
|
|
|
PRTime delta = GetCollectionTimeDelta();
|
2011-11-10 01:32:17 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cleanups = sForgetSkippableBeforeCC ? sForgetSkippableBeforeCC : 1;
|
2012-09-28 10:57:33 +04:00
|
|
|
uint32_t minForgetSkippableTime = (sMinForgetSkippableTime == UINT32_MAX)
|
2012-07-13 23:13:52 +04:00
|
|
|
? 0 : sMinForgetSkippableTime;
|
2011-11-10 01:32:17 +04:00
|
|
|
|
2012-07-13 23:13:52 +04:00
|
|
|
if (sPostGCEventsToConsole) {
|
2012-06-27 19:10:09 +04:00
|
|
|
nsCString mergeMsg;
|
2013-11-21 02:35:16 +04:00
|
|
|
if (aResults.mMergedZones) {
|
2012-06-27 19:10:09 +04:00
|
|
|
mergeMsg.AssignLiteral(" merged");
|
|
|
|
}
|
|
|
|
|
2012-05-23 00:10:37 +04:00
|
|
|
nsCString gcMsg;
|
2013-11-21 02:35:16 +04:00
|
|
|
if (aResults.mForcedGC) {
|
2012-05-23 00:10:37 +04:00
|
|
|
gcMsg.AssignLiteral(", forced a GC");
|
2012-02-24 08:16:37 +04:00
|
|
|
}
|
|
|
|
|
2012-01-31 00:06:18 +04:00
|
|
|
NS_NAMED_MULTILINE_LITERAL_STRING(kFmt,
|
2016-02-22 20:37:50 +03:00
|
|
|
MOZ_UTF16("CC(T+%.1f)[%s] max pause: %lums, total time: %lums, slices: %lu, suspected: %lu, visited: %lu RCed and %lu%s GCed, collected: %lu RCed and %lu GCed (%lu|%lu|%lu waiting for GC)%s\n")
|
2013-11-21 02:35:16 +04:00
|
|
|
MOZ_UTF16("ForgetSkippable %lu times before CC, min: %lu ms, max: %lu ms, avg: %lu ms, total: %lu ms, max sync: %lu ms, removed: %lu"));
|
2011-02-17 02:47:12 +03:00
|
|
|
nsString msg;
|
2011-11-10 01:32:17 +04:00
|
|
|
msg.Adopt(nsTextFormatter::smprintf(kFmt.get(), double(delta) / PR_USEC_PER_SEC,
|
2016-02-22 20:37:50 +03:00
|
|
|
ProcessNameForCollectorLog(),
|
2014-01-08 05:33:47 +04:00
|
|
|
gCCStats.mMaxSliceTime, gCCStats.mTotalSliceTime,
|
2014-05-07 04:25:26 +04:00
|
|
|
aResults.mNumSlices, gCCStats.mSuspected,
|
2013-11-21 02:35:16 +04:00
|
|
|
aResults.mVisitedRefCounted, aResults.mVisitedGCed, mergeMsg.get(),
|
|
|
|
aResults.mFreedRefCounted, aResults.mFreedGCed,
|
2014-10-20 21:07:52 +04:00
|
|
|
sCCollectedWaitingForGC, sCCollectedZonesWaitingForGC, sLikelyShortLivingObjectsNeedingGC,
|
2013-03-07 22:53:19 +04:00
|
|
|
gcMsg.get(),
|
2012-01-31 00:06:18 +04:00
|
|
|
sForgetSkippableBeforeCC,
|
2012-07-13 23:13:52 +04:00
|
|
|
minForgetSkippableTime / PR_USEC_PER_MSEC,
|
2012-01-31 00:06:18 +04:00
|
|
|
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
|
|
|
|
(sTotalForgetSkippableTime / cleanups) /
|
|
|
|
PR_USEC_PER_MSEC,
|
|
|
|
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
|
2013-11-21 02:35:16 +04:00
|
|
|
gCCStats.mMaxSkippableDuration, sRemovedPurples));
|
2011-02-17 02:47:12 +03:00
|
|
|
nsCOMPtr<nsIConsoleService> cs =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (cs) {
|
|
|
|
cs->LogStringMessage(msg.get());
|
|
|
|
}
|
2012-07-13 23:13:52 +04:00
|
|
|
}
|
2012-03-06 03:33:24 +04:00
|
|
|
|
2012-10-02 23:27:31 +04:00
|
|
|
if (sPostGCEventsToObserver) {
|
2012-03-06 03:33:24 +04:00
|
|
|
NS_NAMED_MULTILINE_LITERAL_STRING(kJSONFmt,
|
2013-09-18 07:43:21 +04:00
|
|
|
MOZ_UTF16("{ \"timestamp\": %llu, ")
|
2014-02-17 16:16:23 +04:00
|
|
|
MOZ_UTF16("\"duration\": %lu, ")
|
|
|
|
MOZ_UTF16("\"max_slice_pause\": %lu, ")
|
|
|
|
MOZ_UTF16("\"total_slice_pause\": %lu, ")
|
|
|
|
MOZ_UTF16("\"max_finish_gc_duration\": %lu, ")
|
|
|
|
MOZ_UTF16("\"max_sync_skippable_duration\": %lu, ")
|
2013-09-18 07:43:21 +04:00
|
|
|
MOZ_UTF16("\"suspected\": %lu, ")
|
|
|
|
MOZ_UTF16("\"visited\": { ")
|
|
|
|
MOZ_UTF16("\"RCed\": %lu, ")
|
|
|
|
MOZ_UTF16("\"GCed\": %lu }, ")
|
|
|
|
MOZ_UTF16("\"collected\": { ")
|
|
|
|
MOZ_UTF16("\"RCed\": %lu, ")
|
|
|
|
MOZ_UTF16("\"GCed\": %lu }, ")
|
|
|
|
MOZ_UTF16("\"waiting_for_gc\": %lu, ")
|
2014-10-20 21:07:52 +04:00
|
|
|
MOZ_UTF16("\"zones_waiting_for_gc\": %lu, ")
|
2013-09-18 07:43:21 +04:00
|
|
|
MOZ_UTF16("\"short_living_objects_waiting_for_gc\": %lu, ")
|
|
|
|
MOZ_UTF16("\"forced_gc\": %d, ")
|
|
|
|
MOZ_UTF16("\"forget_skippable\": { ")
|
|
|
|
MOZ_UTF16("\"times_before_cc\": %lu, ")
|
|
|
|
MOZ_UTF16("\"min\": %lu, ")
|
|
|
|
MOZ_UTF16("\"max\": %lu, ")
|
|
|
|
MOZ_UTF16("\"avg\": %lu, ")
|
|
|
|
MOZ_UTF16("\"total\": %lu, ")
|
|
|
|
MOZ_UTF16("\"removed\": %lu } ")
|
|
|
|
MOZ_UTF16("}"));
|
2012-03-06 03:33:24 +04:00
|
|
|
nsString json;
|
2013-12-31 21:20:21 +04:00
|
|
|
json.Adopt(nsTextFormatter::smprintf(kJSONFmt.get(), endCCTime, ccNowDuration,
|
2014-01-08 05:33:47 +04:00
|
|
|
gCCStats.mMaxSliceTime,
|
|
|
|
gCCStats.mTotalSliceTime,
|
|
|
|
gCCStats.mMaxGCDuration,
|
2013-11-21 02:35:16 +04:00
|
|
|
gCCStats.mMaxSkippableDuration,
|
|
|
|
gCCStats.mSuspected,
|
2013-11-21 02:35:16 +04:00
|
|
|
aResults.mVisitedRefCounted, aResults.mVisitedGCed,
|
|
|
|
aResults.mFreedRefCounted, aResults.mFreedGCed,
|
2012-03-17 03:36:26 +04:00
|
|
|
sCCollectedWaitingForGC,
|
2014-10-20 21:07:52 +04:00
|
|
|
sCCollectedZonesWaitingForGC,
|
2013-03-07 22:53:19 +04:00
|
|
|
sLikelyShortLivingObjectsNeedingGC,
|
2013-11-21 02:35:16 +04:00
|
|
|
aResults.mForcedGC,
|
2012-03-17 03:36:26 +04:00
|
|
|
sForgetSkippableBeforeCC,
|
2012-07-13 23:13:52 +04:00
|
|
|
minForgetSkippableTime / PR_USEC_PER_MSEC,
|
2012-03-17 03:36:26 +04:00
|
|
|
sMaxForgetSkippableTime / PR_USEC_PER_MSEC,
|
|
|
|
(sTotalForgetSkippableTime / cleanups) /
|
|
|
|
PR_USEC_PER_MSEC,
|
|
|
|
sTotalForgetSkippableTime / PR_USEC_PER_MSEC,
|
|
|
|
sRemovedPurples));
|
2012-03-06 03:33:24 +04:00
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
2012-07-30 18:20:58 +04:00
|
|
|
observerService->NotifyObservers(nullptr, "cycle-collection-statistics", json.get());
|
2012-03-06 03:33:24 +04:00
|
|
|
}
|
2009-07-08 19:08:22 +04:00
|
|
|
}
|
2013-01-01 00:55:07 +04:00
|
|
|
|
|
|
|
// Update global state to indicate we have just run a cycle collection.
|
2012-09-28 10:57:33 +04:00
|
|
|
sMinForgetSkippableTime = UINT32_MAX;
|
2012-01-31 00:06:18 +04:00
|
|
|
sMaxForgetSkippableTime = 0;
|
|
|
|
sTotalForgetSkippableTime = 0;
|
|
|
|
sRemovedPurples = 0;
|
|
|
|
sForgetSkippableBeforeCC = 0;
|
2012-02-27 18:49:59 +04:00
|
|
|
sNeedsFullCC = false;
|
2013-08-22 01:02:12 +04:00
|
|
|
sNeedsGCAfterCC = false;
|
2013-11-21 02:35:16 +04:00
|
|
|
gCCStats.Clear();
|
2009-07-08 19:08:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-01 05:39:39 +04:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
InterSliceGCTimerFired(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
2014-04-26 00:21:04 +04:00
|
|
|
nsJSContext::KillInterSliceGCTimer();
|
2013-01-28 00:35:12 +04:00
|
|
|
nsJSContext::GarbageCollectNow(JS::gcreason::INTER_SLICE_GC,
|
2012-08-01 05:39:39 +04:00
|
|
|
nsJSContext::IncrementalGC,
|
|
|
|
nsJSContext::NonShrinkingGC,
|
|
|
|
NS_INTERSLICE_GC_BUDGET);
|
|
|
|
}
|
|
|
|
|
2009-02-12 15:06:59 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
GCTimerFired(nsITimer *aTimer, void *aClosure)
|
2001-11-27 12:46:38 +03:00
|
|
|
{
|
2014-04-26 00:21:04 +04:00
|
|
|
nsJSContext::KillGCTimer();
|
2012-01-25 22:59:55 +04:00
|
|
|
uintptr_t reason = reinterpret_cast<uintptr_t>(aClosure);
|
2013-01-28 00:35:12 +04:00
|
|
|
nsJSContext::GarbageCollectNow(static_cast<JS::gcreason::Reason>(reason),
|
2014-05-20 23:50:59 +04:00
|
|
|
nsJSContext::IncrementalGC);
|
2011-02-17 02:47:12 +03:00
|
|
|
}
|
2007-01-26 04:19:31 +03:00
|
|
|
|
2011-12-27 15:59:29 +04:00
|
|
|
void
|
|
|
|
ShrinkGCBuffersTimerFired(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
2014-04-26 00:21:04 +04:00
|
|
|
nsJSContext::KillShrinkGCBuffersTimer();
|
2011-12-27 15:59:29 +04:00
|
|
|
nsJSContext::ShrinkGCBuffersNow();
|
|
|
|
}
|
|
|
|
|
2015-02-24 12:40:02 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
ShrinkingGCTimerFired(nsITimer* aTimer, void* aClosure)
|
|
|
|
{
|
|
|
|
nsJSContext::KillShrinkingGCTimer();
|
2015-04-13 18:42:41 +03:00
|
|
|
sIsCompactingOnUserInactive = true;
|
2015-02-24 12:40:02 +03:00
|
|
|
nsJSContext::GarbageCollectNow(JS::gcreason::USER_INACTIVE,
|
|
|
|
nsJSContext::IncrementalGC,
|
|
|
|
nsJSContext::ShrinkingGC);
|
|
|
|
}
|
|
|
|
|
2012-03-06 01:48:33 +04:00
|
|
|
static bool
|
2012-08-22 19:56:38 +04:00
|
|
|
ShouldTriggerCC(uint32_t aSuspected)
|
2011-02-17 02:47:12 +03:00
|
|
|
{
|
2012-03-06 01:48:33 +04:00
|
|
|
return sNeedsFullCC ||
|
|
|
|
aSuspected > NS_CC_PURPLE_LIMIT ||
|
2012-07-15 14:30:39 +04:00
|
|
|
(aSuspected > NS_CC_FORCED_PURPLE_LIMIT &&
|
2013-12-31 21:20:21 +04:00
|
|
|
TimeUntilNow(sLastCCEndTime) > NS_CC_FORCED);
|
2012-03-06 01:48:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CCTimerFired(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
2012-03-09 03:37:13 +04:00
|
|
|
if (sDidShutdown) {
|
2012-02-18 02:35:20 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-03-09 03:37:13 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t ccDelay = NS_CC_DELAY;
|
2012-03-09 03:37:13 +04:00
|
|
|
if (sCCLockedOut) {
|
2014-05-16 21:11:40 +04:00
|
|
|
ccDelay = NS_CC_DELAY / 3;
|
2012-07-16 01:37:09 +04:00
|
|
|
|
2012-03-09 03:37:13 +04:00
|
|
|
PRTime now = PR_Now();
|
|
|
|
if (sCCLockedOutTime == 0) {
|
2013-01-08 15:11:01 +04:00
|
|
|
// Reset sCCTimerFireCount so that we run forgetSkippable
|
|
|
|
// often enough before CC. Because of reduced ccDelay
|
|
|
|
// forgetSkippable will be called just a few times.
|
|
|
|
// NS_MAX_CC_LOCKEDOUT_TIME limit guarantees that we end up calling
|
|
|
|
// forgetSkippable and CycleCollectNow eventually.
|
|
|
|
sCCTimerFireCount = 0;
|
2012-03-09 03:37:13 +04:00
|
|
|
sCCLockedOutTime = now;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (now - sCCLockedOutTime < NS_MAX_CC_LOCKEDOUT_TIME) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 00:06:18 +04:00
|
|
|
++sCCTimerFireCount;
|
2012-03-06 01:48:33 +04:00
|
|
|
|
|
|
|
// During early timer fires, we only run forgetSkippable. During the first
|
|
|
|
// late timer fire, we decide if we are going to have a second and final
|
2014-03-05 04:21:48 +04:00
|
|
|
// late timer fire, where we may begin to run the CC. Should run at least one
|
|
|
|
// early timer fire to allow cleanup before the CC.
|
|
|
|
int32_t numEarlyTimerFires = std::max((int32_t)ccDelay / NS_CC_SKIPPABLE_DELAY - 2, 1);
|
2012-03-06 01:48:33 +04:00
|
|
|
bool isLateTimerFire = sCCTimerFireCount > numEarlyTimerFires;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t suspected = nsCycleCollector_suspectedCount();
|
2012-03-06 01:48:33 +04:00
|
|
|
if (isLateTimerFire && ShouldTriggerCC(suspected)) {
|
|
|
|
if (sCCTimerFireCount == numEarlyTimerFires + 1) {
|
2012-07-15 14:30:39 +04:00
|
|
|
FireForgetSkippable(suspected, true);
|
2012-03-06 01:48:33 +04:00
|
|
|
if (ShouldTriggerCC(nsCycleCollector_suspectedCount())) {
|
|
|
|
// Our efforts to avoid a CC have failed, so we return to let the
|
|
|
|
// timer fire once more to trigger a CC.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We are in the final timer fire and still meet the conditions for
|
2014-01-01 23:00:35 +04:00
|
|
|
// triggering a CC. Let RunCycleCollectorSlice finish the current IGC, if
|
|
|
|
// any because that will allow us to include the GC time in the CC pause.
|
2014-03-05 04:21:48 +04:00
|
|
|
nsJSContext::RunCycleCollectorSlice();
|
2012-01-31 00:06:18 +04:00
|
|
|
}
|
2014-11-12 22:33:50 +03:00
|
|
|
} else if (((sPreviousSuspectedCount + 100) <= suspected) ||
|
|
|
|
(sCleanupsSinceLastGC < NS_MAJOR_FORGET_SKIPPABLE_CALLS)) {
|
|
|
|
// Only do a forget skippable if there are more than a few new objects
|
|
|
|
// or we're doing the initial forget skippables.
|
2013-01-01 00:54:37 +04:00
|
|
|
FireForgetSkippable(suspected, false);
|
2012-03-06 01:48:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isLateTimerFire) {
|
2014-05-16 21:11:40 +04:00
|
|
|
ccDelay = NS_CC_DELAY;
|
2012-07-16 01:37:09 +04:00
|
|
|
|
2012-03-06 01:48:33 +04:00
|
|
|
// We have either just run the CC or decided we don't want to run the CC
|
|
|
|
// next time, so kill the timer.
|
|
|
|
sPreviousSuspectedCount = 0;
|
|
|
|
nsJSContext::KillCCTimer();
|
2012-01-31 00:06:18 +04:00
|
|
|
}
|
|
|
|
}
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2012-01-31 00:06:18 +04:00
|
|
|
// static
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-05-03 20:17:01 +04:00
|
|
|
nsJSContext::CleanupsSinceLastGC()
|
2012-01-31 00:06:18 +04:00
|
|
|
{
|
2012-05-03 20:17:01 +04:00
|
|
|
return sCleanupsSinceLastGC;
|
2001-11-27 12:46:38 +03:00
|
|
|
}
|
1998-07-16 05:16:47 +04:00
|
|
|
|
2007-01-11 03:02:58 +03:00
|
|
|
// static
|
2001-11-27 12:46:38 +03:00
|
|
|
void
|
2007-01-11 03:02:58 +03:00
|
|
|
nsJSContext::LoadStart()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
sLoadingInProgress = true;
|
2007-01-11 03:02:58 +03:00
|
|
|
++sPendingLoadCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2007-10-21 20:46:54 +04:00
|
|
|
nsJSContext::LoadEnd()
|
2007-01-11 03:02:58 +03:00
|
|
|
{
|
2011-02-17 02:47:12 +03:00
|
|
|
if (!sLoadingInProgress)
|
|
|
|
return;
|
|
|
|
|
2007-01-11 03:02:58 +03:00
|
|
|
// sPendingLoadCount is not a well managed load counter (and doesn't
|
|
|
|
// need to be), so make sure we don't make it wrap backwards here.
|
|
|
|
if (sPendingLoadCount > 0) {
|
|
|
|
--sPendingLoadCount;
|
2011-02-17 02:47:12 +03:00
|
|
|
return;
|
2007-01-11 03:02:58 +03:00
|
|
|
}
|
|
|
|
|
2015-01-05 08:12:19 +03:00
|
|
|
// Its probably a good idea to GC soon since we have finished loading.
|
2011-10-17 18:59:28 +04:00
|
|
|
sLoadingInProgress = false;
|
2015-01-05 08:12:19 +03:00
|
|
|
PokeGC(JS::gcreason::LOAD_END);
|
2007-01-11 03:02:58 +03:00
|
|
|
}
|
|
|
|
|
2014-04-26 00:21:04 +04:00
|
|
|
// Only trigger expensive timers when they have been checked a number of times.
|
|
|
|
static bool
|
|
|
|
ReadyToTriggerExpensiveCollectorTimer()
|
|
|
|
{
|
|
|
|
bool ready = kPokesBetweenExpensiveCollectorTriggers < ++sExpensiveCollectorPokes;
|
|
|
|
if (ready) {
|
|
|
|
sExpensiveCollectorPokes = 0;
|
|
|
|
}
|
|
|
|
return ready;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check all of the various collector timers and see if they are waiting to fire.
|
|
|
|
// For the synchronous collector timers, sGCTimer and sCCTimer, we only want to trigger
|
|
|
|
// the collection occasionally, because they are expensive. The incremental collector
|
|
|
|
// timers, sInterSliceGCTimer and sICCTimer, are fast and need to be run many times, so
|
|
|
|
// always run their corresponding timer.
|
|
|
|
|
2014-10-23 20:59:36 +04:00
|
|
|
// This does not check sFullGCTimer, as that's an even more expensive collection we run
|
2014-04-26 00:21:04 +04:00
|
|
|
// on a long timer.
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsJSContext::RunNextCollectorTimer()
|
|
|
|
{
|
|
|
|
if (sShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sGCTimer) {
|
|
|
|
if (ReadyToTriggerExpensiveCollectorTimer()) {
|
|
|
|
GCTimerFired(nullptr, reinterpret_cast<void *>(JS::gcreason::DOM_WINDOW_UTILS));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sInterSliceGCTimer) {
|
|
|
|
InterSliceGCTimerFired(nullptr, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the CC timers after the GC timers, because the CC timers won't do
|
|
|
|
// anything if a GC is in progress.
|
|
|
|
MOZ_ASSERT(!sCCLockedOut, "Don't check the CC timers if the CC is locked out.");
|
|
|
|
|
|
|
|
if (sCCTimer) {
|
|
|
|
if (ReadyToTriggerExpensiveCollectorTimer()) {
|
|
|
|
CCTimerFired(nullptr, nullptr);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sICCTimer) {
|
|
|
|
ICCTimerFired(nullptr, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 15:06:59 +03:00
|
|
|
// static
|
2007-01-11 03:02:58 +03:00
|
|
|
void
|
2015-01-05 08:12:19 +03:00
|
|
|
nsJSContext::PokeGC(JS::gcreason::Reason aReason, int aDelay)
|
1998-07-16 05:16:47 +04:00
|
|
|
{
|
2016-02-19 02:21:48 +03:00
|
|
|
sNeedsFullGC = sNeedsFullGC || aReason != JS::gcreason::CC_WAITING;
|
|
|
|
|
2015-01-05 08:12:19 +03:00
|
|
|
if (sGCTimer || sInterSliceGCTimer || sShuttingDown) {
|
2005-12-06 08:48:46 +03:00
|
|
|
// There's already a timer for GC'ing, just return
|
2001-11-27 12:46:38 +03:00
|
|
|
return;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
}
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2013-08-22 01:02:12 +04:00
|
|
|
if (sCCTimer) {
|
|
|
|
// Make sure CC is called...
|
|
|
|
sNeedsFullCC = true;
|
|
|
|
// and GC after it.
|
|
|
|
sNeedsGCAfterCC = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:21:48 +04:00
|
|
|
if (sICCTimer) {
|
|
|
|
// Make sure GC is called after the current CC completes.
|
|
|
|
// No need to set sNeedsFullCC because we are currently running a CC.
|
|
|
|
sNeedsGCAfterCC = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sGCTimer);
|
2001-11-27 12:46:38 +03:00
|
|
|
|
|
|
|
if (!sGCTimer) {
|
2011-05-28 03:53:01 +04:00
|
|
|
// Failed to create timer (probably because we're in XPCOM shutdown)
|
2001-11-27 12:46:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool first = true;
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2015-09-10 10:50:51 +03:00
|
|
|
sGCTimer->InitWithNamedFuncCallback(GCTimerFired,
|
|
|
|
reinterpret_cast<void *>(aReason),
|
|
|
|
aDelay
|
|
|
|
? aDelay
|
|
|
|
: (first
|
|
|
|
? NS_FIRST_GC_DELAY
|
|
|
|
: NS_GC_DELAY),
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"GCTimerFired");
|
2011-10-17 18:59:28 +04:00
|
|
|
first = false;
|
1998-07-16 05:16:47 +04:00
|
|
|
}
|
|
|
|
|
2011-12-27 15:59:29 +04:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsJSContext::PokeShrinkGCBuffers()
|
|
|
|
{
|
2013-01-22 23:17:48 +04:00
|
|
|
if (sShrinkGCBuffersTimer || sShuttingDown) {
|
2011-12-27 15:59:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sShrinkGCBuffersTimer);
|
|
|
|
|
|
|
|
if (!sShrinkGCBuffersTimer) {
|
|
|
|
// Failed to create timer (probably because we're in XPCOM shutdown)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-10 10:50:51 +03:00
|
|
|
sShrinkGCBuffersTimer->InitWithNamedFuncCallback(ShrinkGCBuffersTimerFired,
|
|
|
|
nullptr,
|
|
|
|
NS_SHRINK_GC_BUFFERS_DELAY,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"ShrinkGCBuffersTimerFired");
|
2011-12-27 15:59:29 +04:00
|
|
|
}
|
|
|
|
|
2015-02-24 12:40:02 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsJSContext::PokeShrinkingGC()
|
|
|
|
{
|
|
|
|
if (sShrinkingGCTimer || sShuttingDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sShrinkingGCTimer);
|
|
|
|
|
|
|
|
if (!sShrinkingGCTimer) {
|
|
|
|
// Failed to create timer (probably because we're in XPCOM shutdown)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-10 10:50:51 +03:00
|
|
|
sShrinkingGCTimer->InitWithNamedFuncCallback(ShrinkingGCTimerFired, nullptr,
|
|
|
|
sCompactOnUserInactiveDelay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"ShrinkingGCTimerFired");
|
2015-02-24 12:40:02 +03:00
|
|
|
}
|
|
|
|
|
2011-02-17 02:47:12 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsJSContext::MaybePokeCC()
|
|
|
|
{
|
2013-12-21 18:35:08 +04:00
|
|
|
if (sCCTimer || sICCTimer || sShuttingDown || !sHasRunGC) {
|
2011-02-17 02:47:12 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-15 14:30:39 +04:00
|
|
|
if (ShouldTriggerCC(nsCycleCollector_suspectedCount())) {
|
2012-01-31 00:06:18 +04:00
|
|
|
sCCTimerFireCount = 0;
|
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sCCTimer);
|
|
|
|
if (!sCCTimer) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-09 21:30:58 +04:00
|
|
|
// We can kill some objects before running forgetSkippable.
|
|
|
|
nsCycleCollector_dispatchDeferredDeletion();
|
|
|
|
|
2015-09-10 10:50:51 +03:00
|
|
|
sCCTimer->InitWithNamedFuncCallback(CCTimerFired, nullptr,
|
|
|
|
NS_CC_SKIPPABLE_DELAY,
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK,
|
|
|
|
"CCTimerFired");
|
2011-02-17 02:47:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::KillGCTimer()
|
|
|
|
{
|
|
|
|
if (sGCTimer) {
|
|
|
|
sGCTimer->Cancel();
|
|
|
|
NS_RELEASE(sGCTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:53:23 +04:00
|
|
|
void
|
|
|
|
nsJSContext::KillFullGCTimer()
|
|
|
|
{
|
|
|
|
if (sFullGCTimer) {
|
|
|
|
sFullGCTimer->Cancel();
|
|
|
|
NS_RELEASE(sFullGCTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 08:27:59 +04:00
|
|
|
void
|
|
|
|
nsJSContext::KillInterSliceGCTimer()
|
|
|
|
{
|
|
|
|
if (sInterSliceGCTimer) {
|
|
|
|
sInterSliceGCTimer->Cancel();
|
|
|
|
NS_RELEASE(sInterSliceGCTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-27 15:59:29 +04:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::KillShrinkGCBuffersTimer()
|
|
|
|
{
|
|
|
|
if (sShrinkGCBuffersTimer) {
|
|
|
|
sShrinkGCBuffersTimer->Cancel();
|
|
|
|
NS_RELEASE(sShrinkGCBuffersTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-24 12:40:02 +03:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::KillShrinkingGCTimer()
|
|
|
|
{
|
|
|
|
if (sShrinkingGCTimer) {
|
|
|
|
sShrinkingGCTimer->Cancel();
|
|
|
|
NS_RELEASE(sShrinkingGCTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 02:47:12 +03:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::KillCCTimer()
|
|
|
|
{
|
2012-03-09 03:37:13 +04:00
|
|
|
sCCLockedOutTime = 0;
|
2011-02-17 02:47:12 +03:00
|
|
|
if (sCCTimer) {
|
|
|
|
sCCTimer->Cancel();
|
|
|
|
NS_RELEASE(sCCTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 18:35:08 +04:00
|
|
|
//static
|
|
|
|
void
|
|
|
|
nsJSContext::KillICCTimer()
|
|
|
|
{
|
|
|
|
sCCLockedOutTime = 0;
|
|
|
|
|
|
|
|
if (sICCTimer) {
|
|
|
|
sICCTimer->Cancel();
|
|
|
|
NS_RELEASE(sICCTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class NotifyGCEndRunnable : public Runnable
|
2012-03-06 03:33:24 +04:00
|
|
|
{
|
|
|
|
nsString mMessage;
|
|
|
|
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit NotifyGCEndRunnable(const nsString& aMessage) : mMessage(aMessage) {}
|
2012-03-06 03:33:24 +04:00
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NotifyGCEndRunnable::Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (!observerService) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-22 08:43:21 +04:00
|
|
|
const char16_t oomMsg[3] = { '{', '}', 0 };
|
|
|
|
const char16_t *toSend = mMessage.get() ? mMessage.get() : oomMsg;
|
2012-07-30 18:20:58 +04:00
|
|
|
observerService->NotifyObservers(nullptr, "garbage-collection-statistics", toSend);
|
2012-03-06 03:33:24 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-03 18:01:35 +04:00
|
|
|
static void
|
2013-01-28 00:35:12 +04:00
|
|
|
DOMGCSliceCallback(JSRuntime *aRt, JS::GCProgress aProgress, const JS::GCDescription &aDesc)
|
2011-11-10 01:32:17 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "GCs must run on the main thread");
|
2011-02-17 02:47:12 +03:00
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
switch (aProgress) {
|
|
|
|
case JS::GC_CYCLE_BEGIN: {
|
|
|
|
// Prevent cycle collections and shrinking during incremental GC.
|
|
|
|
sCCLockedOut = true;
|
|
|
|
|
|
|
|
nsJSContext::KillShrinkGCBuffersTimer();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case JS::GC_CYCLE_END: {
|
|
|
|
PRTime delta = GetCollectionTimeDelta();
|
|
|
|
|
|
|
|
if (sPostGCEventsToConsole) {
|
2016-02-22 20:37:50 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(kFmt, "GC(T+%.1f)[%s] ");
|
2015-01-05 04:46:49 +03:00
|
|
|
nsString prefix, gcstats;
|
2015-05-20 19:14:29 +03:00
|
|
|
gcstats.Adopt(aDesc.formatSummaryMessage(aRt));
|
2015-01-05 04:46:49 +03:00
|
|
|
prefix.Adopt(nsTextFormatter::smprintf(kFmt.get(),
|
2016-02-22 20:37:50 +03:00
|
|
|
double(delta) / PR_USEC_PER_SEC,
|
|
|
|
ProcessNameForCollectorLog()));
|
2015-01-05 04:46:49 +03:00
|
|
|
nsString msg = prefix + gcstats;
|
|
|
|
nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (cs) {
|
|
|
|
cs->LogStringMessage(msg.get());
|
|
|
|
}
|
2012-07-13 23:13:52 +04:00
|
|
|
}
|
2012-03-17 03:36:26 +04:00
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
if (sPostGCEventsToObserver) {
|
|
|
|
nsString json;
|
|
|
|
json.Adopt(aDesc.formatJSON(aRt, PR_Now()));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NotifyGCEndRunnable> notify = new NotifyGCEndRunnable(json);
|
2015-01-05 04:46:49 +03:00
|
|
|
NS_DispatchToMainThread(notify);
|
|
|
|
}
|
2011-02-17 02:47:12 +03:00
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
sCCLockedOut = false;
|
2015-04-13 18:42:41 +03:00
|
|
|
sIsCompactingOnUserInactive = false;
|
2015-01-05 04:46:49 +03:00
|
|
|
|
|
|
|
// May need to kill the inter-slice GC timer
|
|
|
|
nsJSContext::KillInterSliceGCTimer();
|
|
|
|
|
|
|
|
sCCollectedWaitingForGC = 0;
|
|
|
|
sCCollectedZonesWaitingForGC = 0;
|
|
|
|
sLikelyShortLivingObjectsNeedingGC = 0;
|
|
|
|
sCleanupsSinceLastGC = 0;
|
|
|
|
sNeedsFullCC = true;
|
|
|
|
sHasRunGC = true;
|
|
|
|
nsJSContext::MaybePokeCC();
|
|
|
|
|
|
|
|
if (aDesc.isCompartment_) {
|
|
|
|
if (!sFullGCTimer && !sShuttingDown) {
|
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sFullGCTimer);
|
2015-09-10 10:50:51 +03:00
|
|
|
sFullGCTimer->InitWithNamedFuncCallback(FullGCTimerFired,
|
|
|
|
nullptr,
|
|
|
|
NS_FULL_GC_DELAY,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"FullGCTimerFired");
|
2015-01-05 04:46:49 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsJSContext::KillFullGCTimer();
|
2016-02-19 02:21:48 +03:00
|
|
|
}
|
2015-01-05 04:46:49 +03:00
|
|
|
|
2016-02-19 02:21:48 +03:00
|
|
|
if (aDesc.invocationKind_ == GC_NORMAL) {
|
|
|
|
nsJSContext::PokeShrinkGCBuffers();
|
2015-01-05 04:46:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldTriggerCC(nsCycleCollector_suspectedCount())) {
|
|
|
|
nsCycleCollector_dispatchDeferredDeletion();
|
|
|
|
}
|
2012-01-31 00:06:18 +04:00
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
break;
|
2013-01-22 23:17:48 +04:00
|
|
|
}
|
2012-02-18 02:35:20 +04:00
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
case JS::GC_SLICE_BEGIN:
|
|
|
|
break;
|
2012-03-09 03:37:13 +04:00
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
case JS::GC_SLICE_END:
|
|
|
|
|
|
|
|
// The GC has more work to do, so schedule another GC slice.
|
|
|
|
nsJSContext::KillInterSliceGCTimer();
|
|
|
|
if (!sShuttingDown) {
|
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &sInterSliceGCTimer);
|
2015-09-10 10:50:51 +03:00
|
|
|
sInterSliceGCTimer->InitWithNamedFuncCallback(InterSliceGCTimerFired,
|
|
|
|
nullptr,
|
|
|
|
NS_INTERSLICE_GC_DELAY,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"InterSliceGCTimerFired");
|
2012-05-09 22:53:23 +04:00
|
|
|
}
|
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
if (ShouldTriggerCC(nsCycleCollector_suspectedCount())) {
|
|
|
|
nsCycleCollector_dispatchDeferredDeletion();
|
|
|
|
}
|
2005-04-26 05:23:53 +04:00
|
|
|
|
2015-05-20 19:14:29 +03:00
|
|
|
if (sPostGCEventsToConsole) {
|
|
|
|
nsString gcstats;
|
|
|
|
gcstats.Adopt(aDesc.formatSliceMessage(aRt));
|
|
|
|
nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (cs) {
|
|
|
|
cs->LogStringMessage(gcstats.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unexpected GCProgress value");
|
2013-07-27 14:48:45 +04:00
|
|
|
}
|
|
|
|
|
2015-01-05 04:46:49 +03:00
|
|
|
if (sPrevGCSliceCallback) {
|
2012-02-18 02:35:20 +04:00
|
|
|
(*sPrevGCSliceCallback)(aRt, aProgress, aDesc);
|
2015-01-05 04:46:49 +03:00
|
|
|
}
|
|
|
|
|
2000-05-15 08:21:04 +04:00
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2013-09-05 01:06:55 +04:00
|
|
|
void
|
|
|
|
nsJSContext::SetWindowProxy(JS::Handle<JSObject*> aWindowProxy)
|
|
|
|
{
|
2013-09-05 01:06:56 +04:00
|
|
|
mWindowProxy = aWindowProxy;
|
2013-09-05 01:06:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
nsJSContext::GetWindowProxy()
|
|
|
|
{
|
2013-09-09 07:28:48 +04:00
|
|
|
JSObject* windowProxy = GetWindowProxyPreserveColor();
|
|
|
|
if (windowProxy) {
|
|
|
|
JS::ExposeObjectToActiveJS(windowProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return windowProxy;
|
2013-09-05 01:06:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
nsJSContext::GetWindowProxyPreserveColor()
|
|
|
|
{
|
2013-09-05 01:06:56 +04:00
|
|
|
return mWindowProxy;
|
2013-09-05 01:06:55 +04:00
|
|
|
}
|
|
|
|
|
2013-03-07 22:53:19 +04:00
|
|
|
void
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated()
|
|
|
|
{
|
|
|
|
++sLikelyShortLivingObjectsNeedingGC;
|
|
|
|
}
|
|
|
|
|
2004-06-09 22:36:25 +04:00
|
|
|
void
|
2013-08-20 03:24:29 +04:00
|
|
|
mozilla::dom::StartupJSEnvironment()
|
2004-06-09 22:36:25 +04:00
|
|
|
{
|
|
|
|
// initialize all our statics, so that we can restart XPCOM
|
2015-02-24 12:40:02 +03:00
|
|
|
sGCTimer = sShrinkingGCTimer = sFullGCTimer = sCCTimer = sICCTimer = nullptr;
|
2012-02-18 02:35:20 +04:00
|
|
|
sCCLockedOut = false;
|
2012-03-09 03:37:13 +04:00
|
|
|
sCCLockedOutTime = 0;
|
2013-12-31 21:20:21 +04:00
|
|
|
sLastCCEndTime = TimeStamp();
|
2013-01-31 02:46:37 +04:00
|
|
|
sHasRunGC = false;
|
2007-01-11 03:02:58 +03:00
|
|
|
sPendingLoadCount = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
sLoadingInProgress = false;
|
2011-03-01 01:44:22 +03:00
|
|
|
sCCollectedWaitingForGC = 0;
|
2014-10-20 21:07:52 +04:00
|
|
|
sCCollectedZonesWaitingForGC = 0;
|
2013-03-07 22:53:19 +04:00
|
|
|
sLikelyShortLivingObjectsNeedingGC = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
sPostGCEventsToConsole = false;
|
2012-02-27 18:49:59 +04:00
|
|
|
sNeedsFullCC = false;
|
2016-02-19 02:21:48 +03:00
|
|
|
sNeedsFullGC = false;
|
2013-08-22 01:02:12 +04:00
|
|
|
sNeedsGCAfterCC = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
gNameSpaceManager = nullptr;
|
|
|
|
sRuntime = nullptr;
|
2016-07-07 10:55:41 +03:00
|
|
|
sContext = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
sIsInitialized = false;
|
|
|
|
sDidShutdown = false;
|
2013-01-22 23:17:48 +04:00
|
|
|
sShuttingDown = false;
|
2004-06-09 22:36:25 +04:00
|
|
|
sContextCount = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
sSecurityManager = nullptr;
|
2014-06-15 03:43:45 +04:00
|
|
|
gCCStats.Init();
|
2014-04-26 00:21:04 +04:00
|
|
|
sExpensiveCollectorPokes = 0;
|
2004-06-09 22:36:25 +04:00
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void
|
2009-07-09 16:16:26 +04:00
|
|
|
SetMemoryHighWaterMarkPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t highwatermark = Preferences::GetInt(aPrefName, 128);
|
2010-12-03 01:38:00 +03:00
|
|
|
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_MAX_MALLOC_BYTES,
|
2010-12-03 01:38:00 +03:00
|
|
|
highwatermark * 1024L * 1024L);
|
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void
|
2010-12-03 01:38:00 +03:00
|
|
|
SetMemoryMaxPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t pref = Preferences::GetInt(aPrefName, -1);
|
2011-01-12 20:35:36 +03:00
|
|
|
// handle overflow and negative pref values
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t max = (pref <= 0 || pref >= 0x1000) ? -1 : (uint32_t)pref * 1024 * 1024;
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_MAX_BYTES, max);
|
2009-07-09 16:16:26 +04:00
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void
|
2011-01-10 09:57:21 +03:00
|
|
|
SetMemoryGCModePrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
2012-04-04 13:15:10 +04:00
|
|
|
bool enableCompartmentGC = Preferences::GetBool("javascript.options.mem.gc_per_compartment");
|
|
|
|
bool enableIncrementalGC = Preferences::GetBool("javascript.options.mem.gc_incremental");
|
2012-02-18 02:35:20 +04:00
|
|
|
JSGCMode mode;
|
|
|
|
if (enableIncrementalGC) {
|
|
|
|
mode = JSGC_MODE_INCREMENTAL;
|
|
|
|
} else if (enableCompartmentGC) {
|
|
|
|
mode = JSGC_MODE_COMPARTMENT;
|
|
|
|
} else {
|
|
|
|
mode = JSGC_MODE_GLOBAL;
|
|
|
|
}
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_MODE, mode);
|
2012-02-18 02:35:20 +04:00
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void
|
2012-02-18 02:35:20 +04:00
|
|
|
SetMemoryGCSliceTimePrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t pref = Preferences::GetInt(aPrefName, -1);
|
2012-02-18 02:35:20 +04:00
|
|
|
// handle overflow and negative pref values
|
|
|
|
if (pref > 0 && pref < 100000)
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_SLICE_TIME_BUDGET, pref);
|
2011-01-10 09:57:21 +03:00
|
|
|
}
|
|
|
|
|
2015-02-02 17:39:34 +03:00
|
|
|
static void
|
|
|
|
SetMemoryGCCompactingPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
|
|
|
bool pref = Preferences::GetBool(aPrefName);
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_COMPACTING_ENABLED, pref);
|
2015-02-02 17:39:34 +03:00
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void
|
2012-07-11 22:09:53 +04:00
|
|
|
SetMemoryGCPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t pref = Preferences::GetInt(aPrefName, -1);
|
2012-07-11 22:09:53 +04:00
|
|
|
// handle overflow and negative pref values
|
2013-06-27 10:40:17 +04:00
|
|
|
if (pref >= 0 && pref < 10000)
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, (JSGCParamKey)(intptr_t)aClosure, pref);
|
2012-07-11 22:09:53 +04:00
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void
|
2012-07-11 22:09:53 +04:00
|
|
|
SetMemoryGCDynamicHeapGrowthPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
|
|
|
bool pref = Preferences::GetBool(aPrefName);
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_DYNAMIC_HEAP_GROWTH, pref);
|
2012-07-11 22:09:53 +04:00
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void
|
2012-07-11 22:09:53 +04:00
|
|
|
SetMemoryGCDynamicMarkSlicePrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
|
|
|
bool pref = Preferences::GetBool(aPrefName);
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_DYNAMIC_MARK_SLICE, pref);
|
2012-07-11 22:09:53 +04:00
|
|
|
}
|
|
|
|
|
2016-04-01 00:26:30 +03:00
|
|
|
static void
|
|
|
|
SetMemoryGCRefreshFrameSlicesEnabledPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
|
|
|
bool pref = Preferences::GetBool(aPrefName);
|
2016-07-07 10:55:41 +03:00
|
|
|
JS_SetGCParameter(sContext, JSGC_REFRESH_FRAME_SLICES_ENABLED, pref);
|
2016-04-01 00:26:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-22 19:14:36 +04:00
|
|
|
static void
|
|
|
|
SetIncrementalCCPrefChangedCallback(const char* aPrefName, void* aClosure)
|
|
|
|
{
|
|
|
|
bool pref = Preferences::GetBool(aPrefName);
|
|
|
|
sIncrementalCC = pref;
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:31:30 +04:00
|
|
|
static bool
|
|
|
|
AsmJSCacheOpenEntryForRead(JS::Handle<JSObject*> aGlobal,
|
2014-07-22 08:43:21 +04:00
|
|
|
const char16_t* aBegin,
|
|
|
|
const char16_t* aLimit,
|
2013-12-03 23:31:30 +04:00
|
|
|
size_t* aSize,
|
|
|
|
const uint8_t** aMemory,
|
|
|
|
intptr_t *aHandle)
|
|
|
|
{
|
2014-05-13 13:58:00 +04:00
|
|
|
nsIPrincipal* principal =
|
|
|
|
nsJSPrincipals::get(JS_GetCompartmentPrincipals(js::GetObjectCompartment(aGlobal)));
|
2013-12-03 23:31:30 +04:00
|
|
|
return asmjscache::OpenEntryForRead(principal, aBegin, aLimit, aSize, aMemory,
|
|
|
|
aHandle);
|
|
|
|
}
|
|
|
|
|
2014-10-23 02:28:07 +04:00
|
|
|
static JS::AsmJSCacheResult
|
2013-12-03 23:31:30 +04:00
|
|
|
AsmJSCacheOpenEntryForWrite(JS::Handle<JSObject*> aGlobal,
|
2014-03-06 00:47:10 +04:00
|
|
|
bool aInstalled,
|
2014-07-22 08:43:21 +04:00
|
|
|
const char16_t* aBegin,
|
|
|
|
const char16_t* aEnd,
|
2013-12-03 23:31:30 +04:00
|
|
|
size_t aSize,
|
|
|
|
uint8_t** aMemory,
|
|
|
|
intptr_t* aHandle)
|
|
|
|
{
|
2014-05-13 13:58:00 +04:00
|
|
|
nsIPrincipal* principal =
|
|
|
|
nsJSPrincipals::get(JS_GetCompartmentPrincipals(js::GetObjectCompartment(aGlobal)));
|
2014-03-06 00:47:10 +04:00
|
|
|
return asmjscache::OpenEntryForWrite(principal, aInstalled, aBegin, aEnd,
|
|
|
|
aSize, aMemory, aHandle);
|
2013-12-03 23:31:30 +04:00
|
|
|
}
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
void
|
|
|
|
nsJSContext::EnsureStatics()
|
1998-07-16 05:16:47 +04:00
|
|
|
{
|
2004-06-09 22:36:25 +04:00
|
|
|
if (sIsInitialized) {
|
2013-08-20 03:24:29 +04:00
|
|
|
if (!nsContentUtils::XPConnect()) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
return;
|
2000-06-20 07:45:21 +04:00
|
|
|
}
|
|
|
|
|
2008-09-06 03:26:04 +04:00
|
|
|
nsresult rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID,
|
|
|
|
&sSecurityManager);
|
2013-08-20 03:24:29 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2008-09-06 03:26:04 +04:00
|
|
|
|
2015-06-27 04:44:14 +03:00
|
|
|
sRuntime = xpc::GetJSRuntime();
|
|
|
|
if (!sRuntime) {
|
2013-08-20 03:24:29 +04:00
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2016-07-07 10:55:41 +03:00
|
|
|
sContext = JS_GetContext(sRuntime);
|
|
|
|
|
2001-06-05 05:00:48 +04:00
|
|
|
// Let's make sure that our main thread is the same as the xpcom main thread.
|
2013-08-20 03:24:29 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2001-06-05 05:00:48 +04:00
|
|
|
|
2016-07-07 10:55:45 +03:00
|
|
|
sPrevGCSliceCallback = JS::SetGCSliceCallback(sContext, DOMGCSliceCallback);
|
2000-05-15 08:21:04 +04:00
|
|
|
|
2013-11-19 01:49:53 +04:00
|
|
|
// Set up the asm.js cache callbacks
|
2014-12-17 03:30:39 +03:00
|
|
|
static const JS::AsmJSCacheOps asmJSCacheOps = {
|
2013-12-03 23:31:30 +04:00
|
|
|
AsmJSCacheOpenEntryForRead,
|
2013-11-19 01:49:53 +04:00
|
|
|
asmjscache::CloseEntryForRead,
|
2013-12-03 23:31:30 +04:00
|
|
|
AsmJSCacheOpenEntryForWrite,
|
2016-01-01 08:19:20 +03:00
|
|
|
asmjscache::CloseEntryForWrite
|
2013-11-19 01:49:53 +04:00
|
|
|
};
|
2016-07-07 10:55:41 +03:00
|
|
|
JS::SetAsmJSCacheOps(sContext, &asmJSCacheOps);
|
2013-11-19 01:49:53 +04:00
|
|
|
|
2001-06-05 05:00:48 +04:00
|
|
|
// Set these global xpconnect options...
|
2013-02-20 23:49:51 +04:00
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryHighWaterMarkPrefChangedCallback,
|
|
|
|
"javascript.options.mem.high_water_mark");
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryMaxPrefChangedCallback,
|
|
|
|
"javascript.options.mem.max");
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCModePrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_per_compartment");
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCModePrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_incremental");
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCSliceTimePrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_incremental_slice_ms");
|
|
|
|
|
2015-02-02 17:39:34 +03:00
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCCompactingPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_compacting");
|
|
|
|
|
2013-02-20 23:49:51 +04:00
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_high_frequency_time_limit_ms",
|
|
|
|
(void *)JSGC_HIGH_FREQUENCY_TIME_LIMIT);
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCDynamicMarkSlicePrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_dynamic_mark_slice");
|
|
|
|
|
2016-04-01 00:26:30 +03:00
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCRefreshFrameSlicesEnabledPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_refresh_frame_slices_enabled");
|
|
|
|
|
2013-02-20 23:49:51 +04:00
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCDynamicHeapGrowthPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_dynamic_heap_growth");
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_low_frequency_heap_growth",
|
|
|
|
(void *)JSGC_LOW_FREQUENCY_HEAP_GROWTH);
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_high_frequency_heap_growth_min",
|
|
|
|
(void *)JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN);
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_high_frequency_heap_growth_max",
|
|
|
|
(void *)JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX);
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_high_frequency_low_limit_mb",
|
|
|
|
(void *)JSGC_HIGH_FREQUENCY_LOW_LIMIT);
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_high_frequency_high_limit_mb",
|
|
|
|
(void *)JSGC_HIGH_FREQUENCY_HIGH_LIMIT);
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_allocation_threshold_mb",
|
|
|
|
(void *)JSGC_ALLOCATION_THRESHOLD);
|
2013-06-21 05:06:53 +04:00
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_decommit_threshold_mb",
|
|
|
|
(void *)JSGC_DECOMMIT_THRESHOLD);
|
|
|
|
|
2013-12-22 19:14:36 +04:00
|
|
|
Preferences::RegisterCallbackAndCall(SetIncrementalCCPrefChangedCallback,
|
|
|
|
"dom.cycle_collector.incremental");
|
|
|
|
|
2014-07-16 13:01:20 +04:00
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_min_empty_chunk_count",
|
|
|
|
(void *)JSGC_MIN_EMPTY_CHUNK_COUNT);
|
|
|
|
|
|
|
|
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
|
|
|
|
"javascript.options.mem.gc_max_empty_chunk_count",
|
|
|
|
(void *)JSGC_MAX_EMPTY_CHUNK_COUNT);
|
|
|
|
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2013-08-20 03:24:29 +04:00
|
|
|
if (!obs) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2007-10-23 01:42:25 +04:00
|
|
|
|
2011-07-07 22:27:07 +04:00
|
|
|
Preferences::AddBoolVarCache(&sGCOnMemoryPressure,
|
|
|
|
"javascript.options.gc_on_memory_pressure",
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2011-07-07 22:27:07 +04:00
|
|
|
|
2015-02-24 12:40:02 +03:00
|
|
|
Preferences::AddBoolVarCache(&sCompactOnUserInactive,
|
|
|
|
"javascript.options.compact_on_user_inactive",
|
|
|
|
true);
|
|
|
|
|
2015-07-30 13:03:06 +03:00
|
|
|
Preferences::AddUintVarCache(&sCompactOnUserInactiveDelay,
|
|
|
|
"javascript.options.compact_on_user_inactive_delay",
|
|
|
|
NS_DEAULT_INACTIVE_GC_DELAY);
|
|
|
|
|
2016-06-02 17:34:39 +03:00
|
|
|
Preferences::AddBoolVarCache(&sPostGCEventsToConsole,
|
|
|
|
JS_OPTIONS_DOT_STR "mem.log");
|
|
|
|
Preferences::AddBoolVarCache(&sPostGCEventsToObserver,
|
|
|
|
JS_OPTIONS_DOT_STR "mem.notify");
|
|
|
|
|
2013-01-22 23:17:48 +04:00
|
|
|
nsIObserver* observer = new nsJSEnvironmentObserver();
|
|
|
|
obs->AddObserver(observer, "memory-pressure", false);
|
2015-02-24 12:40:02 +03:00
|
|
|
obs->AddObserver(observer, "user-interaction-inactive", false);
|
|
|
|
obs->AddObserver(observer, "user-interaction-active", false);
|
2013-01-22 23:17:48 +04:00
|
|
|
obs->AddObserver(observer, "quit-application", false);
|
2014-10-22 19:57:32 +04:00
|
|
|
obs->AddObserver(observer, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2007-11-07 00:47:35 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
sIsInitialized = true;
|
1998-07-16 05:16:47 +04:00
|
|
|
}
|
|
|
|
|
2014-11-27 14:47:51 +03:00
|
|
|
void
|
|
|
|
nsJSContext::NotifyDidPaint()
|
|
|
|
{
|
|
|
|
sDidPaintAfterPreviousICCSlice = true;
|
|
|
|
}
|
|
|
|
|
2007-11-13 13:35:49 +03:00
|
|
|
nsScriptNameSpaceManager*
|
2013-08-20 03:24:29 +04:00
|
|
|
mozilla::dom::GetNameSpaceManager()
|
2007-11-13 13:35:49 +03:00
|
|
|
{
|
|
|
|
if (sDidShutdown)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-11-13 13:35:49 +03:00
|
|
|
|
|
|
|
if (!gNameSpaceManager) {
|
|
|
|
gNameSpaceManager = new nsScriptNameSpaceManager;
|
2010-11-17 01:09:50 +03:00
|
|
|
NS_ADDREF(gNameSpaceManager);
|
2007-11-13 13:35:49 +03:00
|
|
|
|
|
|
|
nsresult rv = gNameSpaceManager->Init();
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2007-11-13 13:35:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return gNameSpaceManager;
|
|
|
|
}
|
|
|
|
|
2015-04-28 19:25:55 +03:00
|
|
|
nsScriptNameSpaceManager*
|
|
|
|
mozilla::dom::PeekNameSpaceManager()
|
|
|
|
{
|
|
|
|
return gNameSpaceManager;
|
|
|
|
}
|
|
|
|
|
2008-09-11 17:20:56 +04:00
|
|
|
void
|
2013-08-20 03:24:29 +04:00
|
|
|
mozilla::dom::ShutdownJSEnvironment()
|
1998-07-16 05:16:47 +04:00
|
|
|
{
|
2013-01-22 23:17:48 +04:00
|
|
|
KillTimers();
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2010-11-17 01:09:50 +03:00
|
|
|
NS_IF_RELEASE(gNameSpaceManager);
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2002-05-03 07:02:07 +04:00
|
|
|
if (!sContextCount) {
|
|
|
|
// We're being shutdown, and there are no more contexts
|
2015-06-27 04:44:14 +03:00
|
|
|
// alive, release the security manager.
|
2003-04-18 00:21:00 +04:00
|
|
|
NS_IF_RELEASE(sSecurityManager);
|
2001-11-27 12:46:38 +03:00
|
|
|
}
|
2002-05-03 07:02:07 +04:00
|
|
|
|
2013-01-22 23:17:48 +04:00
|
|
|
sShuttingDown = true;
|
2011-10-17 18:59:28 +04:00
|
|
|
sDidShutdown = true;
|
1998-07-16 05:16:47 +04:00
|
|
|
}
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
// A fast-array class for JS. This class supports both nsIJSScriptArray and
|
|
|
|
// nsIArray. If it is JS itself providing and consuming this class, all work
|
|
|
|
// can be done via nsIJSScriptArray, and avoid the conversion of elements
|
|
|
|
// to/from nsISupports.
|
|
|
|
// When consumed by non-JS (eg, another script language), conversion is done
|
|
|
|
// on-the-fly.
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsJSArgArray final : public nsIJSArgArray {
|
2006-06-13 07:07:47 +04:00
|
|
|
public:
|
2015-06-05 12:23:00 +03:00
|
|
|
nsJSArgArray(JSContext *aContext, uint32_t argc, const JS::Value* argv,
|
2013-04-12 02:52:10 +04:00
|
|
|
nsresult *prv);
|
2014-07-11 21:19:00 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
// nsISupports
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2007-10-29 16:45:07 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsJSArgArray,
|
|
|
|
nsIJSArgArray)
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
// nsIArray
|
|
|
|
NS_DECL_NSIARRAY
|
|
|
|
|
|
|
|
// nsIJSArgArray
|
2015-03-21 19:28:04 +03:00
|
|
|
nsresult GetArgs(uint32_t* argc, void** argv) override;
|
2007-03-08 14:17:16 +03:00
|
|
|
|
|
|
|
void ReleaseJSObjects();
|
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
protected:
|
2014-07-11 21:19:00 +04:00
|
|
|
~nsJSArgArray();
|
2006-06-13 07:07:47 +04:00
|
|
|
JSContext *mContext;
|
2013-06-18 14:00:37 +04:00
|
|
|
JS::Heap<JS::Value> *mArgv;
|
2012-12-05 13:19:33 +04:00
|
|
|
uint32_t mArgc;
|
2006-06-13 07:07:47 +04:00
|
|
|
};
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2015-06-05 12:23:00 +03:00
|
|
|
nsJSArgArray::nsJSArgArray(JSContext *aContext, uint32_t argc,
|
|
|
|
const JS::Value* argv, nsresult *prv)
|
|
|
|
: mContext(aContext)
|
|
|
|
, mArgv(nullptr)
|
|
|
|
, mArgc(argc)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
|
|
|
// copy the array - we don't know its lifetime, and ours is tied to xpcom
|
2013-06-18 14:00:37 +04:00
|
|
|
// refcounting.
|
2012-12-05 13:19:33 +04:00
|
|
|
if (argc) {
|
2013-06-18 14:00:37 +04:00
|
|
|
mArgv = new (fallible) JS::Heap<JS::Value>[argc];
|
2012-12-05 13:19:33 +04:00
|
|
|
if (!mArgv) {
|
|
|
|
*prv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return;
|
|
|
|
}
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
2007-09-19 04:26:39 +04:00
|
|
|
|
2007-10-29 16:45:07 +03:00
|
|
|
// Callers are allowed to pass in a null argv even for argc > 0. They can
|
|
|
|
// then use GetArgs to initialize the values.
|
|
|
|
if (argv) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < argc; ++i)
|
2006-06-13 07:07:47 +04:00
|
|
|
mArgv[i] = argv[i];
|
|
|
|
}
|
2007-10-31 13:52:22 +03:00
|
|
|
|
2012-11-13 05:15:00 +04:00
|
|
|
if (argc > 0) {
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2012-11-13 05:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*prv = NS_OK;
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
2005-08-10 04:15:51 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
nsJSArgArray::~nsJSArgArray()
|
2007-03-08 14:17:16 +03:00
|
|
|
{
|
|
|
|
ReleaseJSObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSArgArray::ReleaseJSObjects()
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
2012-12-05 13:19:33 +04:00
|
|
|
if (mArgv) {
|
2013-06-18 14:00:37 +04:00
|
|
|
delete [] mArgv;
|
2012-12-05 13:19:33 +04:00
|
|
|
}
|
|
|
|
if (mArgc > 0) {
|
|
|
|
mArgc = 0;
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-12-05 13:19:33 +04:00
|
|
|
}
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 21:42:36 +04:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
// QueryInterface implementation for nsJSArgArray
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSArgArray)
|
|
|
|
|
2010-11-08 18:02:49 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSArgArray)
|
2007-03-08 14:17:16 +03:00
|
|
|
tmp->ReleaseJSObjects();
|
2010-11-08 18:02:49 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSArgArray)
|
2007-10-29 16:45:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSArgArray)
|
2013-05-27 15:50:49 +04:00
|
|
|
if (tmp->mArgv) {
|
|
|
|
for (uint32_t i = 0; i < tmp->mArgc; ++i) {
|
2016-02-22 21:11:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mArgv[i])
|
|
|
|
}
|
2007-03-08 14:17:16 +03:00
|
|
|
}
|
2007-10-29 16:45:07 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2007-03-08 14:17:16 +03:00
|
|
|
|
2007-04-25 20:35:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSArgArray)
|
2006-06-13 07:07:47 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIArray)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIJSArgArray)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIJSArgArray)
|
|
|
|
NS_INTERFACE_MAP_END
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2011-03-06 14:11:31 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsJSArgArray)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsJSArgArray)
|
2001-11-27 12:46:38 +03:00
|
|
|
|
2006-06-13 07:07:47 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJSArgArray::GetArgs(uint32_t *argc, void **argv)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
2012-12-05 13:19:33 +04:00
|
|
|
*argv = (void *)mArgv;
|
|
|
|
*argc = mArgc;
|
2006-06-13 07:07:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIArray impl
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsJSArgArray::GetLength(uint32_t *aLength)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
2012-12-05 13:19:33 +04:00
|
|
|
*aLength = mArgc;
|
2006-06-13 07:07:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsJSArgArray::QueryElementAt(uint32_t index, const nsIID & uuid, void * *result)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
2012-12-05 13:19:33 +04:00
|
|
|
if (index >= mArgc)
|
2006-06-13 07:07:47 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (uuid.Equals(NS_GET_IID(nsIVariant)) || uuid.Equals(NS_GET_IID(nsISupports))) {
|
2014-01-15 23:39:08 +04:00
|
|
|
// Have to copy a Heap into a Rooted to work with it.
|
|
|
|
JS::Rooted<JS::Value> val(mContext, mArgv[index]);
|
|
|
|
return nsContentUtils::XPConnect()->JSToVariant(mContext, val,
|
2006-06-13 07:07:47 +04:00
|
|
|
(nsIVariant **)result);
|
|
|
|
}
|
|
|
|
NS_WARNING("nsJSArgArray only handles nsIVariant");
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
1998-07-16 05:16:47 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsJSArgArray::IndexOf(uint32_t startIndex, nsISupports *element, uint32_t *_retval)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsJSArgArray::Enumerate(nsISimpleEnumerator **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The factory function
|
2015-06-05 12:23:00 +03:00
|
|
|
nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t argc,
|
|
|
|
const JS::Value* argv, nsIJSArgArray **aArray)
|
2006-06-13 07:07:47 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2015-06-05 12:23:00 +03:00
|
|
|
nsCOMPtr<nsIJSArgArray> ret = new nsJSArgArray(aContext, argc, argv, &rv);
|
2006-06-13 07:07:47 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-07-11 21:19:00 +04:00
|
|
|
ret.forget(aArray);
|
|
|
|
return NS_OK;
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|