Files
palemoon27/dom/base/nsWrapperCache.cpp
T
roytam1 96a96c469e import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1212298 - Use inner script instead of outer script in CodeGenerator::visitCallDirectEval. r=shu (cee3f366a6)
- Bug 1233331 - CodeGenerator: Properly indent IonScript::New. r=jandem (6d110c45a3)
- Bug 1233331 - CodeGenerator: Prepare the invalidation of the recompileInfo as soon as the contraints are recorded. r=jandem (679d22dd8e)
- Bug 1238417 - Part 1: Fix wrong rebase for _SetCanonicalName call on RegExpToString. r=till (31ee926189)
- Bug 1238417 - Part 2: Fix argument count of RegExpMatcher and RegExpTester. r=till (9dc5dcadd5)
- Bug 1238417 - Part 4: Enable recover instruction for RegExpMatcher and RegExpTester. r=h4writer (5479b238ac)
- Bug 1238417 - Part 5: Add RegExpMatcher to MustCloneRegExp optimization. r=h4writer (554905fa3a)
- Bug 1238417 - Part 6: Make RegExpMatcher and RegExpTester movable. r=h4writer (72091090ee)
- Bug 1238417 - Part 7: Add comment for OutOfLineRegExpMatcher and OutOfLineRegExpTester. r=nbp (f5e4519728)
- Bug 1238630 - Fix unicode surrogate pair handling in RegExp. r=h4writer (d4c1e1d49d)
- Bug 1236600 - Properly pre-barrier sets to inline TypedObject Any-type Elements. (r=jandem) (1f23bb6d61)
- Bug 1149245 - Make DeserializedEdgeRange re-use its referents edge vector; r=vporof (ea861bfd43)
- Bug 1235631 - Odin: remove change-heap support (r=bbouvier) (940a0d58bc)
- Bug 1231224 part 11 - Add missing OOM checks in Module::setProfilingEnabled. r=luke (0d264fa46b)
- Bug 1234402 - Crash on OOM in AlternativeGenerationList constructor. r=bbouvier (baa7b3da17)
- Bug 1231224 part 12 - Use InfallibleVector in irregexp code to avoid MOZ_WARN_UNUSED_RESULT warnings. r=luke (72ac897dab)
- Bug 1231224 part 13 - Add OOM checks to Statistics::initialize. r=jonco (5033150018)
- Bug 1237508 - Odin: remove function index from Export (r=bbouvier) (d368ef7f85)
- Bug 1236541 - Odin: when enabling profiling, only patch actual callsites (r=bbouvie) (713dbcc45c)
- Bug 1235046 - Optimize JIT-code poisoning to be fast with W^X. r=bhackett (25972b36a9)
- Bug 1215479 - Turn on W^X JIT code by default. r=luke (82c4b94315)
- Bug 1235868 - Change nonWritableJITCode to ifdefs. r=jandem (4dee262ff4)
- Bug 1237508 - Add missing #include to fix non-unified builds (r=me) (327242e706)
- Bug 1236530 - Make ExecutableAllocator::reprotectRegion fallible and handle in asm.js (r=jandem) (9444127563)
- Bug 1229399: Make initialization of asm.js local variables closer to wasm; r=luke (732d40b42c)
- Bug 1229399: Store line/column info in the FuncIR rather than the bytecode stream; r=luke (483faefbdd)
- Bug 1235989 - Add a null check for filename in ModuleValidator::finish. r=luke (abc62aa437)
- Bug 1235041 - Cast value to uint64_t in order to prevent int overflow when value is greater than 2^12. r=jonco (ef754091ea)
- Bug 1182369 - Remove js/Class.h include from nsWrapperCache.h. - r=bz (cc7b3c856b)
- Bug 1231964 - Move CC participant code that touches JS out of mozglue. r=smaug (100fceeb2b)
- Bug 1120016 - Allocate short lived JS wrappers in the Nursery, r=mccr8,terrence (2a17a5484d)
- Bug 1235277 - Define MOZ_FALLTHROUGH_ASSERT to workaround -Wunreachable-code warnings about MOZ_FALLTHROUGH in debug builds. r=botond (262589e609)
- Bug 1247679, part 1 - Make ClearJSHolder publicly inherit from TraceCallbacks. r=smaug (1a3543fd31)
- Bug 1235598 - Part 1: Add better SpiderMonkey API support for tracing in C++; r=sfinxk (f23bf81919)
- Bug 1235598 - Part 2: Use TraceEdge exclusively in Gecko; r=smaug (a3ad4d0ef7)
2023-08-02 11:49:15 +08:00

153 lines
4.2 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/Class.h"
#include "js/Proxy.h"
#include "mozilla/dom/DOMJSProxyHandler.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/HoldDropJSObjects.h"
#include "nsCycleCollectionTraversalCallback.h"
#include "nsCycleCollector.h"
using namespace mozilla;
using namespace mozilla::dom;
#ifdef DEBUG
/* static */ bool
nsWrapperCache::HasJSObjectMovedOp(JSObject* aWrapper)
{
return js::HasObjectMovedOp(aWrapper);
}
#endif
void
nsWrapperCache::HoldJSObjects(void* aScriptObjectHolder,
nsScriptObjectTracer* aTracer)
{
cyclecollector::HoldJSObjectsImpl(aScriptObjectHolder, aTracer);
if (mWrapper && !JS::ObjectIsTenured(mWrapper)) {
CycleCollectedJSRuntime::Get()->NurseryWrapperPreserved(mWrapper);
}
}
void
nsWrapperCache::SetWrapperJSObject(JSObject* aWrapper)
{
mWrapper = aWrapper;
UnsetWrapperFlags(kWrapperFlagsMask & ~WRAPPER_IS_NOT_DOM_BINDING);
if (aWrapper && !JS::ObjectIsTenured(aWrapper)) {
CycleCollectedJSRuntime::Get()->NurseryWrapperAdded(this);
}
}
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