зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1259580 - Hide as many Proxy details as possible behind a detail namespace; r=efaust
--HG-- extra : rebase_source : 9acd8f66646e5104579cde751a85175a365c9662
This commit is contained in:
Родитель
172b7c970b
Коммит
6ab8c8ca99
|
@ -427,6 +427,7 @@ inline bool IsProxy(const JSObject* obj)
|
|||
return GetObjectClass(obj)->isProxy();
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
const uint32_t PROXY_EXTRA_SLOTS = 2;
|
||||
|
||||
// Layout of the values stored by a proxy. Note that API clients require the
|
||||
|
@ -463,7 +464,6 @@ struct ProxyDataLayout
|
|||
|
||||
const uint32_t ProxyDataOffset = 2 * sizeof(void*);
|
||||
|
||||
// This method should only be used internally and by the accessors below.
|
||||
inline ProxyDataLayout*
|
||||
GetProxyDataLayout(JSObject* obj)
|
||||
{
|
||||
|
@ -471,16 +471,25 @@ GetProxyDataLayout(JSObject* obj)
|
|||
return reinterpret_cast<ProxyDataLayout*>(reinterpret_cast<uint8_t*>(obj) + ProxyDataOffset);
|
||||
}
|
||||
|
||||
inline const BaseProxyHandler*
|
||||
GetProxyHandler(JSObject* obj)
|
||||
inline const ProxyDataLayout*
|
||||
GetProxyDataLayout(const JSObject* obj)
|
||||
{
|
||||
return GetProxyDataLayout(obj)->handler;
|
||||
MOZ_ASSERT(IsProxy(obj));
|
||||
return reinterpret_cast<const ProxyDataLayout*>(reinterpret_cast<const uint8_t*>(obj) +
|
||||
ProxyDataOffset);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
inline const BaseProxyHandler*
|
||||
GetProxyHandler(const JSObject* obj)
|
||||
{
|
||||
return detail::GetProxyDataLayout(obj)->handler;
|
||||
}
|
||||
|
||||
inline const Value&
|
||||
GetProxyPrivate(JSObject* obj)
|
||||
GetProxyPrivate(const JSObject* obj)
|
||||
{
|
||||
return GetProxyDataLayout(obj)->values->privateSlot;
|
||||
return detail::GetProxyDataLayout(obj)->values->privateSlot;
|
||||
}
|
||||
|
||||
inline JSObject*
|
||||
|
@ -490,16 +499,16 @@ GetProxyTargetObject(JSObject* obj)
|
|||
}
|
||||
|
||||
inline const Value&
|
||||
GetProxyExtra(JSObject* obj, size_t n)
|
||||
GetProxyExtra(const JSObject* obj, size_t n)
|
||||
{
|
||||
MOZ_ASSERT(n < PROXY_EXTRA_SLOTS);
|
||||
return GetProxyDataLayout(obj)->values->extraSlots[n];
|
||||
MOZ_ASSERT(n < detail::PROXY_EXTRA_SLOTS);
|
||||
return detail::GetProxyDataLayout(obj)->values->extraSlots[n];
|
||||
}
|
||||
|
||||
inline void
|
||||
SetProxyHandler(JSObject* obj, const BaseProxyHandler* handler)
|
||||
{
|
||||
GetProxyDataLayout(obj)->handler = handler;
|
||||
detail::GetProxyDataLayout(obj)->handler = handler;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
|
@ -508,8 +517,8 @@ SetValueInProxy(Value* slot, const Value& value);
|
|||
inline void
|
||||
SetProxyExtra(JSObject* obj, size_t n, const Value& extra)
|
||||
{
|
||||
MOZ_ASSERT(n < PROXY_EXTRA_SLOTS);
|
||||
Value* vp = &GetProxyDataLayout(obj)->values->extraSlots[n];
|
||||
MOZ_ASSERT(n < detail::PROXY_EXTRA_SLOTS);
|
||||
Value* vp = &detail::GetProxyDataLayout(obj)->values->extraSlots[n];
|
||||
|
||||
// Trigger a barrier before writing the slot.
|
||||
if (vp->isMarkable() || extra.isMarkable())
|
||||
|
@ -519,13 +528,13 @@ SetProxyExtra(JSObject* obj, size_t n, const Value& extra)
|
|||
}
|
||||
|
||||
inline bool
|
||||
IsScriptedProxy(JSObject* obj)
|
||||
IsScriptedProxy(const JSObject* obj)
|
||||
{
|
||||
return IsProxy(obj) && GetProxyHandler(obj)->isScripted();
|
||||
}
|
||||
|
||||
inline const Value&
|
||||
GetReservedOrProxyPrivateSlot(JSObject* obj, size_t slot)
|
||||
GetReservedOrProxyPrivateSlot(const JSObject* obj, size_t slot)
|
||||
{
|
||||
MOZ_ASSERT(slot == 0);
|
||||
MOZ_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj)) || IsProxy(obj));
|
||||
|
|
|
@ -1123,7 +1123,7 @@ CopyProxyObject(JSContext* cx, Handle<ProxyObject*> from, Handle<ProxyObject*> t
|
|||
}
|
||||
|
||||
RootedValue v(cx);
|
||||
for (size_t n = 0; n < PROXY_EXTRA_SLOTS; n++) {
|
||||
for (size_t n = 0; n < js::detail::PROXY_EXTRA_SLOTS; n++) {
|
||||
v = GetProxyExtra(from, n);
|
||||
if (!cx->compartment()->wrap(cx, &v))
|
||||
return false;
|
||||
|
|
|
@ -344,8 +344,8 @@ JSObject::create(js::ExclusiveContext* cx, js::gc::AllocKind kind, js::gc::Initi
|
|||
shape->slotSpan(), clasp);
|
||||
} else if (group->clasp()->isProxy()) {
|
||||
// Proxy objects overlay the |slots| field with a ProxyValueArray.
|
||||
MOZ_ASSERT(sizeof(js::ProxyValueArray) % sizeof(js::HeapSlot) == 0);
|
||||
nDynamicSlots = sizeof(js::ProxyValueArray) / sizeof(js::HeapSlot);
|
||||
MOZ_ASSERT(sizeof(js::detail::ProxyValueArray) % sizeof(js::HeapSlot) == 0);
|
||||
nDynamicSlots = sizeof(js::detail::ProxyValueArray) / sizeof(js::HeapSlot);
|
||||
}
|
||||
|
||||
JSObject* obj = js::Allocate<JSObject>(cx, kind, nDynamicSlots, heap, clasp);
|
||||
|
|
|
@ -653,7 +653,7 @@ js::proxy_Finalize(FreeOp* fop, JSObject* obj)
|
|||
|
||||
MOZ_ASSERT(obj->is<ProxyObject>());
|
||||
obj->as<ProxyObject>().handler()->finalize(fop, obj);
|
||||
js_free(GetProxyDataLayout(obj)->values);
|
||||
js_free(detail::GetProxyDataLayout(obj)->values);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -51,7 +51,7 @@ ProxyObject::New(JSContext* cx, const BaseProxyHandler* handler, HandleValue pri
|
|||
return nullptr;
|
||||
|
||||
Rooted<ProxyObject*> proxy(cx, &obj->as<ProxyObject>());
|
||||
new (proxy->data.values) ProxyValueArray;
|
||||
new (proxy->data.values) detail::ProxyValueArray;
|
||||
proxy->data.handler = handler;
|
||||
proxy->setCrossCompartmentPrivate(priv);
|
||||
|
||||
|
@ -79,7 +79,7 @@ void
|
|||
ProxyObject::nuke(const BaseProxyHandler* handler)
|
||||
{
|
||||
setSameCompartmentPrivate(NullValue());
|
||||
for (size_t i = 0; i < PROXY_EXTRA_SLOTS; i++)
|
||||
for (size_t i = 0; i < detail::PROXY_EXTRA_SLOTS; i++)
|
||||
SetProxyExtra(this, i, NullValue());
|
||||
|
||||
/* Restore the handler as requested after nuking. */
|
||||
|
|
|
@ -19,12 +19,12 @@ class ProxyObject : public JSObject
|
|||
HeapPtrShape shape;
|
||||
|
||||
// GetProxyDataLayout computes the address of this field.
|
||||
ProxyDataLayout data;
|
||||
detail::ProxyDataLayout data;
|
||||
|
||||
void static_asserts() {
|
||||
static_assert(sizeof(ProxyObject) == sizeof(JSObject_Slots0),
|
||||
"proxy object size must match GC thing size");
|
||||
static_assert(offsetof(ProxyObject, data) == ProxyDataOffset,
|
||||
static_assert(offsetof(ProxyObject, data) == detail::ProxyDataOffset,
|
||||
"proxy object layout must match shadow interface");
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class ProxyObject : public JSObject
|
|||
void setSameCompartmentPrivate(const Value& priv);
|
||||
|
||||
HeapValue* slotOfPrivate() {
|
||||
return reinterpret_cast<HeapValue*>(&GetProxyDataLayout(this)->values->privateSlot);
|
||||
return reinterpret_cast<HeapValue*>(&detail::GetProxyDataLayout(this)->values->privateSlot);
|
||||
}
|
||||
|
||||
JSObject* target() const {
|
||||
|
@ -62,8 +62,8 @@ class ProxyObject : public JSObject
|
|||
return offsetof(ProxyObject, data.handler);
|
||||
}
|
||||
static size_t offsetOfExtraSlotInValues(size_t slot) {
|
||||
MOZ_ASSERT(slot < PROXY_EXTRA_SLOTS);
|
||||
return offsetof(ProxyValueArray, extraSlots) + slot * sizeof(Value);
|
||||
MOZ_ASSERT(slot < detail::PROXY_EXTRA_SLOTS);
|
||||
return offsetof(detail::ProxyValueArray, extraSlots) + slot * sizeof(Value);
|
||||
}
|
||||
|
||||
const Value& extra(size_t n) const {
|
||||
|
@ -76,8 +76,8 @@ class ProxyObject : public JSObject
|
|||
|
||||
private:
|
||||
HeapValue* slotOfExtra(size_t n) {
|
||||
MOZ_ASSERT(n < PROXY_EXTRA_SLOTS);
|
||||
return reinterpret_cast<HeapValue*>(&GetProxyDataLayout(this)->values->extraSlots[n]);
|
||||
MOZ_ASSERT(n < detail::PROXY_EXTRA_SLOTS);
|
||||
return reinterpret_cast<HeapValue*>(&detail::GetProxyDataLayout(this)->values->extraSlots[n]);
|
||||
}
|
||||
|
||||
static bool isValidProxyClass(const Class* clasp) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче