mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 22:53:04 +00:00
06f122f425
- Bug 1176004 - Make jstest's unix task runner a generator; r=sfink (03def3308) - Bug 1175708 - Followup to fix windows jstests.py bustage on a CLOSED TREE; r=meow (b291f8cd0) - Bug 1175636 - Do not spawn a watchdog for each test on Windows; r=sfink (c87370ba8) - Bug 1141283 - Compensate for stackwalk duration and sleep overhead when determining sampler sleep time. r=BenWa (cf155667f) - Bug 1172186 - Make the profiler build standalone. r=mstange (324ec7283) - Bug 1176028 - Use the jstest's task generator directly; r=sfink (6dac9eb7a) - Bug 1176064 - Do processing of the jstest's skiplist inline; r=sfink (af6dd9d06) - Bug 1165054 - Fix inbound bustage due to missing explicit on single arg constructor r=me (b29da4afe) - Bug 1182092 - Try harder to filter out template shapes with indexed properties when making unboxed objects, r=jandem. (2540ff768) - Bug 1180299 - Implement ScopeExit for running actions at the end of a scope, r=Waldo (dd40bb356) - Bug 1180536 - Use mozilla::ScopeExit to clean up Debugger::addDebugge#eGlobal's consistency on failure; r=sfink (3bec89179) - Bug 1170216 - When using the slow-and-standard path in js::SetIntegrityLevel, don't manually call setNonwritableArrayLength afterwards. r=Waldo. (563a26f28) - Bug 1171036 - Change GetLengthProperty slow path to use ToLengthClamped instead of ToUint32. r=Waldo. (c0431c393) - Bug 1170307 - Inline the common path of NonNullObject; use it instead of ReportObjectRequired in the Debugger. r=shu. (ff70c4e1c) - Bug 1167883 - Avoid huge stack frames and stack overflow issues with MSVC PGO builds. r=nbp (a02cdc599) - Bug 1181063 - Use mozilla::IsNaN and mozilla::IsInfinite in Simulator-vixl.cpp. r=Waldo, r=sstangl (552a22923) - Bug 1181152 - Make Trampoline-mips.cpp compile with clang. r=rankov (d3308f445) - Bug 1181581 - Fix some typos in comments. r=jandem (79c5de477) - Bug 1175714 - Watch for baseline frame values with nursery types during OSR, r=jandem. (765346890)
225 lines
7.1 KiB
C++
225 lines
7.1 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
* vim: set ts=8 sw=4 et 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/. */
|
|
|
|
#ifndef mozilla_jsipc_JavaScriptShared_h__
|
|
#define mozilla_jsipc_JavaScriptShared_h__
|
|
|
|
#include "mozilla/dom/DOMTypes.h"
|
|
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
|
#include "mozilla/jsipc/PJavaScript.h"
|
|
#include "nsJSUtils.h"
|
|
|
|
namespace mozilla {
|
|
namespace jsipc {
|
|
|
|
class ObjectId {
|
|
public:
|
|
// Use 47 bits at most, to be safe, since jsval privates are encoded as
|
|
// doubles. See bug 1065811 comment 12 for an explanation.
|
|
static const size_t SERIAL_NUMBER_BITS = 47;
|
|
static const size_t FLAG_BITS = 1;
|
|
static const uint64_t SERIAL_NUMBER_MAX = (uint64_t(1) << SERIAL_NUMBER_BITS) - 1;
|
|
|
|
explicit ObjectId(uint64_t serialNumber, bool hasXrayWaiver)
|
|
: serialNumber_(serialNumber), hasXrayWaiver_(hasXrayWaiver)
|
|
{
|
|
if (MOZ_UNLIKELY(serialNumber == 0 || serialNumber > SERIAL_NUMBER_MAX))
|
|
MOZ_CRASH("Bad CPOW Id");
|
|
}
|
|
|
|
bool operator==(const ObjectId& other) const {
|
|
bool equal = serialNumber() == other.serialNumber();
|
|
MOZ_ASSERT_IF(equal, hasXrayWaiver() == other.hasXrayWaiver());
|
|
return equal;
|
|
}
|
|
|
|
bool isNull() { return !serialNumber_; }
|
|
|
|
uint64_t serialNumber() const { return serialNumber_; }
|
|
bool hasXrayWaiver() const { return hasXrayWaiver_; }
|
|
uint64_t serialize() const {
|
|
MOZ_ASSERT(serialNumber(), "Don't send a null ObjectId over IPC");
|
|
return uint64_t((serialNumber() << FLAG_BITS) | ((hasXrayWaiver() ? 1 : 0) << 0));
|
|
}
|
|
|
|
static ObjectId nullId() { return ObjectId(); }
|
|
static ObjectId deserialize(uint64_t data) {
|
|
return ObjectId(data >> FLAG_BITS, data & 1);
|
|
}
|
|
|
|
private:
|
|
ObjectId() : serialNumber_(0), hasXrayWaiver_(false) {}
|
|
|
|
uint64_t serialNumber_ : SERIAL_NUMBER_BITS;
|
|
bool hasXrayWaiver_ : 1;
|
|
};
|
|
|
|
class JavaScriptShared;
|
|
|
|
// DefaultHasher<T> requires that T coerce to an integral type. We could make
|
|
// ObjectId do that, but doing so would weaken our type invariants, so we just
|
|
// reimplement it manually.
|
|
struct ObjectIdHasher
|
|
{
|
|
typedef ObjectId Lookup;
|
|
static js::HashNumber hash(const Lookup& l) {
|
|
return l.serialize();
|
|
}
|
|
static bool match(const ObjectId& k, const ObjectId& l) {
|
|
return k == l;
|
|
}
|
|
static void rekey(ObjectId& k, const ObjectId& newKey) {
|
|
k = newKey;
|
|
}
|
|
};
|
|
|
|
// Map ids -> JSObjects
|
|
class IdToObjectMap
|
|
{
|
|
typedef js::HashMap<ObjectId, JS::Heap<JSObject*>, ObjectIdHasher, js::SystemAllocPolicy> Table;
|
|
|
|
public:
|
|
IdToObjectMap();
|
|
|
|
bool init();
|
|
void trace(JSTracer* trc);
|
|
void sweep();
|
|
|
|
bool add(ObjectId id, JSObject* obj);
|
|
JSObject* find(ObjectId id);
|
|
void remove(ObjectId id);
|
|
|
|
void clear();
|
|
bool empty() const;
|
|
|
|
private:
|
|
Table table_;
|
|
};
|
|
|
|
// Map JSObjects -> ids
|
|
class ObjectToIdMap
|
|
{
|
|
typedef js::PointerHasher<JSObject*, 3> Hasher;
|
|
typedef js::HashMap<JSObject*, ObjectId, Hasher, js::SystemAllocPolicy> Table;
|
|
|
|
public:
|
|
explicit ObjectToIdMap(JSRuntime* rt);
|
|
~ObjectToIdMap();
|
|
|
|
bool init();
|
|
void trace(JSTracer* trc);
|
|
void sweep();
|
|
|
|
bool add(JSContext* cx, JSObject* obj, ObjectId id);
|
|
ObjectId find(JSObject* obj);
|
|
void remove(JSObject* obj);
|
|
void clear();
|
|
|
|
private:
|
|
static void keyMarkCallback(JSTracer* trc, JSObject* key, void* data);
|
|
|
|
JSRuntime* rt_;
|
|
Table table_;
|
|
};
|
|
|
|
class Logging;
|
|
|
|
class JavaScriptShared : public CPOWManager
|
|
{
|
|
public:
|
|
explicit JavaScriptShared(JSRuntime* rt);
|
|
virtual ~JavaScriptShared();
|
|
|
|
bool init();
|
|
|
|
void decref();
|
|
void incref();
|
|
|
|
bool Unwrap(JSContext* cx, const InfallibleTArray<CpowEntry>& aCpows, JS::MutableHandleObject objp);
|
|
bool Wrap(JSContext* cx, JS::HandleObject aObj, InfallibleTArray<CpowEntry>* outCpows);
|
|
|
|
protected:
|
|
bool toVariant(JSContext* cx, JS::HandleValue from, JSVariant* to);
|
|
bool fromVariant(JSContext* cx, const JSVariant& from, JS::MutableHandleValue to);
|
|
|
|
bool toJSIDVariant(JSContext* cx, JS::HandleId from, JSIDVariant* to);
|
|
bool fromJSIDVariant(JSContext* cx, const JSIDVariant& from, JS::MutableHandleId to);
|
|
|
|
bool toSymbolVariant(JSContext* cx, JS::Symbol* sym, SymbolVariant* symVarp);
|
|
JS::Symbol* fromSymbolVariant(JSContext* cx, SymbolVariant symVar);
|
|
|
|
bool fromDescriptor(JSContext* cx, JS::Handle<JSPropertyDescriptor> desc,
|
|
PPropertyDescriptor* out);
|
|
bool toDescriptor(JSContext* cx, const PPropertyDescriptor& in,
|
|
JS::MutableHandle<JSPropertyDescriptor> out);
|
|
|
|
bool toObjectOrNullVariant(JSContext* cx, JSObject* obj, ObjectOrNullVariant* objVarp);
|
|
JSObject* fromObjectOrNullVariant(JSContext* cx, ObjectOrNullVariant objVar);
|
|
|
|
bool convertIdToGeckoString(JSContext* cx, JS::HandleId id, nsString* to);
|
|
bool convertGeckoStringToId(JSContext* cx, const nsString& from, JS::MutableHandleId id);
|
|
|
|
virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp) = 0;
|
|
virtual JSObject* fromObjectVariant(JSContext* cx, ObjectVariant objVar) = 0;
|
|
|
|
static void ConvertID(const nsID& from, JSIID* to);
|
|
static void ConvertID(const JSIID& from, nsID* to);
|
|
|
|
JSObject* findCPOWById(const ObjectId& objId) {
|
|
return cpows_.find(objId);
|
|
}
|
|
JSObject* findObjectById(JSContext* cx, const ObjectId& objId);
|
|
|
|
static bool LoggingEnabled() { return sLoggingEnabled; }
|
|
static bool StackLoggingEnabled() { return sStackLoggingEnabled; }
|
|
|
|
friend class Logging;
|
|
|
|
virtual bool isParent() = 0;
|
|
|
|
virtual JSObject* scopeForTargetObjects() = 0;
|
|
|
|
protected:
|
|
JSRuntime* rt_;
|
|
uintptr_t refcount_;
|
|
|
|
IdToObjectMap objects_;
|
|
IdToObjectMap cpows_;
|
|
|
|
uint64_t nextSerialNumber_;
|
|
|
|
// CPOW references can be weak, and any object we store in a map may be
|
|
// GCed (at which point the CPOW will report itself "dead" to the owner).
|
|
// This means that we don't want to store any js::Wrappers in the CPOW map,
|
|
// because CPOW will die if the wrapper is GCed, even if the underlying
|
|
// object is still alive.
|
|
//
|
|
// This presents a tricky situation for Xray waivers, since they're normally
|
|
// represented as a special same-compartment wrapper. We have to strip them
|
|
// off before putting them in the id-to-object and object-to-id maps, so we
|
|
// need a way of distinguishing them at lookup-time.
|
|
//
|
|
// For the id-to-object map, we encode waiver-or-not information into the id
|
|
// itself, which lets us do the right thing when accessing the object.
|
|
//
|
|
// For the object-to-id map, we just keep two maps, one for each type.
|
|
ObjectToIdMap unwaivedObjectIds_;
|
|
ObjectToIdMap waivedObjectIds_;
|
|
ObjectToIdMap& objectIdMap(bool waiver) {
|
|
return waiver ? waivedObjectIds_ : unwaivedObjectIds_;
|
|
}
|
|
|
|
static bool sLoggingInitialized;
|
|
static bool sLoggingEnabled;
|
|
static bool sStackLoggingEnabled;
|
|
};
|
|
|
|
} // namespace jsipc
|
|
} // namespace mozilla
|
|
|
|
#endif
|