/* -*- 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/. */
/** * This is the base class for the various kinds of proxy objects. It's never * instantiated. * * Proxy objects use their shape primarily to record flags. Property * information, &c. is all dynamically computed. * * There is no class_ member to force specialization of JSObject::is<T>(). * The implementation in JSObject is incorrect for proxies since it doesn't * take account of the handler type.
*/ class ProxyObject : public JSObject { // GetProxyDataLayout computes the address of this field.
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) == detail::ProxyDataOffset, "proxy object layout must match shadow interface");
static_assert(offsetof(ProxyObject, data.reservedSlots) ==
offsetof(JS::shadow::Object, slots), "Proxy reservedSlots must overlay native object slots field");
}
// Proxies usually store their ProxyValueArray inline in the object. // There's one unfortunate exception: when a proxy is swapped with another // object, and the sizes don't match, we malloc the ProxyValueArray. void* inlineDataStart() const { return (void*)(uintptr_t(this) + sizeof(ProxyObject));
} bool usingInlineValueArray() const { return data.values() == inlineDataStart();
} void setInlineValueArray() {
data.reservedSlots =
&reinterpret_cast<detail::ProxyValueArray*>(inlineDataStart())
->reservedSlots;
}
// For use from JSObject::swap.
[[nodiscard]] bool prepareForSwap(JSContext* cx,
MutableHandleValueVector valuesOut);
[[nodiscard]] bool fixupAfterSwap(JSContext* cx, HandleValueVector values);
staticbool isValidProxyClass(const JSClass* clasp) { // Since we can take classes from the outside, make sure that they // are "sane". They have to quack enough like proxies for us to belive // they should be treated as such.
// Proxy classes are not allowed to have call or construct hooks directly. // Their callability is instead decided by handler()->isCallable(). return clasp->isProxyObject() && clasp->isTrace(ProxyObject::trace) &&
!clasp->getCall() && !clasp->getConstruct();
}
template <> inlinebool JSObject::is<js::ProxyObject>() const { // Note: this method is implemented in terms of the IsProxy() friend API // functions to ensure the implementations are tied together. // Note 2: this specialization isn't used for subclasses of ProxyObject // which must supply their own implementation. return js::IsProxy(this);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.