Files
palemoon27/dom/base/nsWrapperCache.cpp
T
roytam1 6885f7ffc2 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1185749 - Implement a DynamicTraceable HashMap subclass that can be used with Rooted; r=jonco (3f84bdb30)
- Bug 1186609 - Implement a DynamicTraceable Vector subclass for use with Rooted; r=sfink (fa5b47e5b)
- Bug 1155985 - Set FieldInto::mType just before storing to reserved slot. r=jonco, a=abillings (34dbc3ca0)
- Bug 1156295 - Refactor GC rooting in StructType::DefineInternal() r=terrence (ec40a1701)
- Bug 1185755 - Use Rooted to simplify FieldInfoHash rooting; r=jonco (8dc66d7cd)
- Bug 1189072 - Make DefaultTracer for struct types call T::trace; r=fitzgen (96f79bc6f)
- Bug 1149294 - Part 1: Don't trace permanent atoms and well known symbols that are owned by a parent JSRuntime inside SimpeEdgeVectorTracer; r=terrence (7ce049a33)
- Bug 1149294 - Part 2: expose ChromeUtils and HeapSnapshot to workers; r=bholley (5737cd923)
- Bug 1147679 - Use PR_GetFileInfo64 when deserializing heap snapshots; r=jimb (1ce8cd241)
- Bug 1147680 - Use PR_MemMap when deserializing heap snapshots; r=jimb (04e5a370d)
- Bug 1149294 - Part 3: Split thread-safe methods on ChromeUtils out in to a new (4967637e2)
- Bug 1173829. Fix some compile issues in code generated by bindings codegen for non-concrete interfaces. r=peterv (3e0f93640)
- Bug 1170274 - A better string parser for nsGenericHTMLElement::GetURIListAttr, r=ehsan (8c1595d29)
- Bug 1170274 - patch 2 - A better string parser for nsGenericHTMLElement::GetURIListAttr, r=ehsan CLOSED TREE (5626d631f)
- Bug 1096550 - Update content scale when swapping remote tabs between windows. r=roc. (ed974edf4)
- Bug 1180017: Give GCCellPtr is<T> and as<T> methods, replacing isFoo and toFoo methods. Fix callers. r=terrence (b95645bbb)
- pointer style (a46b905fe)
- pointer style (cb548fd44)
- Bug 1151182 - Fix type for JSOP_THROWMSG documentation comment. r=efaust (f9bce9df7)
- Bug 1077318 - Part 2: Fix the order of include in AsmJSModule.cpp. r=evilpie (a61716e33)
- Bug 1155006: Fix unified build sensitivities in js/src. r=shu (b0f166ec9)
- Bug 988463 - Add in support for tracelogging on ARM. r=h4writer (10345729b)
- Bug 1190077 - Move RDTSC and prmjtime.* to vm/Time.*. r=nbp (b72c1f366)
2021-04-27 09:19:42 +08:00

129 lines
3.6 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsWrapperCacheInlines.h"
#include "js/Proxy.h"
#include "mozilla/dom/DOMJSProxyHandler.h"
#include "mozilla/HoldDropJSObjects.h"
#include "nsCycleCollectionTraversalCallback.h"
#include "nsCycleCollector.h"
using namespace mozilla;
using namespace mozilla::dom;
/* static */ void
nsWrapperCache::HoldJSObjects(void* aScriptObjectHolder,
nsScriptObjectTracer* aTracer)
{
cyclecollector::HoldJSObjectsImpl(aScriptObjectHolder, aTracer);
}
void
nsWrapperCache::ReleaseWrapper(void* aScriptObjectHolder)
{
if (PreservingWrapper()) {
// PreserveWrapper puts new DOM bindings in the JS holders hash, but they
// can also be in the DOM expando hash, so we need to try to remove them
// from both here.
JSObject* obj = GetWrapperPreserveColor();
if (IsDOMBinding() && obj && js::IsProxy(obj)) {
DOMProxyHandler::GetAndClearExpandoObject(obj);
}
SetPreservingWrapper(false);
cyclecollector::DropJSObjectsImpl(aScriptObjectHolder);
}
}
#ifdef DEBUG
class DebugWrapperTraversalCallback : public nsCycleCollectionTraversalCallback
{
public:
explicit DebugWrapperTraversalCallback(JSObject* aWrapper)
: mFound(false)
, mWrapper(aWrapper)
{
mFlags = WANT_ALL_TRACES;
}
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt aRefCount,
const char* aObjName)
{
}
NS_IMETHOD_(void) DescribeGCedNode(bool aIsMarked,
const char* aObjName,
uint64_t aCompartmentAddress)
{
}
NS_IMETHOD_(void) NoteJSObject(JSObject* aChild)
{
if (aChild == mWrapper) {
mFound = true;
}
}
NS_IMETHOD_(void) NoteJSScript(JSScript* aChild)
{
}
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild)
{
}
NS_IMETHOD_(void) NoteNativeChild(void* aChild,
nsCycleCollectionParticipant* aHelper)
{
}
NS_IMETHOD_(void) NoteNextEdgeName(const char* aName)
{
}
bool mFound;
private:
JSObject* mWrapper;
};
static void
DebugWrapperTraceCallback(JS::GCCellPtr aPtr, const char* aName, void* aClosure)
{
DebugWrapperTraversalCallback* callback =
static_cast<DebugWrapperTraversalCallback*>(aClosure);
if (aPtr.is<JSObject>()) {
callback->NoteJSObject(&aPtr.as<JSObject>());
}
}
void
nsWrapperCache::CheckCCWrapperTraversal(void* aScriptObjectHolder,
nsScriptObjectTracer* aTracer)
{
JSObject* wrapper = GetWrapper();
if (!wrapper) {
return;
}
DebugWrapperTraversalCallback callback(wrapper);
// The CC traversal machinery cannot trigger GC; however, the analysis cannot
// see through the COM layer, so we use a suppression to help it.
JS::AutoSuppressGCAnalysis suppress;
aTracer->Traverse(aScriptObjectHolder, callback);
MOZ_ASSERT(callback.mFound,
"Cycle collection participant didn't traverse to preserved "
"wrapper! This will probably crash.");
callback.mFound = false;
aTracer->Trace(aScriptObjectHolder,
TraceCallbackFunc(DebugWrapperTraceCallback), &callback);
MOZ_ASSERT(callback.mFound,
"Cycle collection participant didn't trace preserved wrapper! "
"This will probably crash.");
}
#endif // DEBUG