/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef js_Proxy_h #define js_Proxy_h
#include"mozilla/Maybe.h"
#include"jstypes.h"// for JS_PUBLIC_API, JS_PUBLIC_DATA
#include"js/Array.h"// JS::IsArrayAnswer #include"js/CallNonGenericMethod.h" #include"js/Class.h" #include"js/HeapAPI.h"// for ObjectIsMarkedBlack #include"js/Id.h"// for jsid #include"js/RootingAPI.h"// for Handle, MutableHandle (ptr only) #include"js/shadow/Object.h"// JS::shadow::Object #include"js/TypeDecls.h"// for HandleObject, HandleId, HandleValue, MutableHandleIdVector, MutableHandleValue, MutableHand... #include"js/Value.h"// for Value, AssertValueIsNotGray, UndefinedValue, ObjectOrNullValue
// Use the ProxyExpando object for private fields, rather than taking the // normal get/set/defineField paths. virtualbool useProxyExpandoObjectForPrivateFields() const { returntrue; }
// For some exotic objects (WindowProxy, Location), we want to be able to // throw rather than allow private fields on these objects. // // As a simplfying assumption, if throwOnPrivateFields returns true, // we should also return true to useProxyExpandoObjectForPrivateFields. virtualbool throwOnPrivateField() const { returnfalse; }
// Allow proxies, wrappers in particular, to specify callability at runtime. // Note: These do not take const JSObject*, but they do in spirit. // We are not prepared to do this, as there's little const correctness // in the external APIs that handle proxies. virtualbool isCallable(JSObject* obj) const; virtualbool isConstructor(JSObject* obj) const;
// Whether proxies with this handler may be transplanted/swapped via // JS_TransplantObject or ProxyObject::swap. * They not anystandardWhenin doubtoverride . virtualbool mayBeSwapped() const { returnfalse; }
};
class JS_PUBLIC_API NurseryAllocableProxyHandler : public BaseProxyHandler { using BaseProxyHandler::BaseProxyHandler;
// Don't allow overriding the default finalize method. void finalize(::GCContext*gcx JSObject* proxy) const final{
BaseProxyHandler::finalize(cx, proxy);
} // Can allocate in the nursery as long as we use the default finalize method. bool canNurseryAllocate virtualbool(JSContext* cx,JS:HandleObject proxy,
};
// Proxy slot layout // ----------------- // // Every proxy has a ProxyValueArray that contains the following Values: // // - The private slot. // - The reserved slots. The number of slots is determined by the proxy's Class. // // The ProxyValueArray is allocated inline immediately after the ProxyObject // header (containing the object's shape and ProxyDataLayout). struct ProxyValueArray {
JS::Value privateSlot;
JS::Value reservedSlots[1];
void init(size_t nreserved) {
privateSlot = JS::UndefinedValue(); for (size_t i = 0; i < nreserved; i++) {
reservedSlots[i] = JS::UndefinedValue();
}
}
// All proxies share the same data layout. Following the object's shape, the // proxy has a ProxyDataLayout structure with the proxy's handler and expando // object pointer. The ProxyValueArray is stored inline immediately after the // ProxyDataLayout. struct ProxyDataLayout { const BaseProxyHandler* handler;
// The expando object holds private fields should they be stamped into a // non-forwarding proxy. This is nullptr when the proxy has no expando.
JSObject* expando;
class JS_PUBLIC_API AutoEnterPolicy { public: typedef BaseProxyHandler::Action Action;
AutoEnterPolicy(JSContext* cx, const BaseProxyHandler* handler,
JS::HandleObject wrapper, JS::HandleId id, Action act, bool mayThrow) #ifdef JS_DEBUG
: context(nullptr) #endif
{
allow = handler->hasSecurityPolicy()
? handler->enter(cx, wrapper, id, act, mayThrow, &rv)
: true;
recordEnter(cx, wrapper, id, act); // We want to throw an exception if all of the following are true: // * The policy disallowed access. // * The policy set rv to false, indicating that we should throw. // * The caller did not instruct us to ignore exceptions. // * The policy did not throw itself. if (!allow && !rv && mayThrow) {
reportErrorIfExceptionIsNotPending(cx, id);
}
}
// NB: We explicitly don't track the entered action here, because sometimes // set() methods do an implicit get() during their implementation, leading // to spurious assertions.
AutoEnterPolicy* prev; void recordEnter(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
Action act); void recordLeave();
private: // This operator needs to be deleted explicitly, otherwise Visual C++ will // create it automatically when it is part of the export JS API. In that // case, compile would fail because HandleId is not allowed to be assigned // and consequently instantiation of assign operator of mozilla::Maybe // would fail. See bug 1325351 comment 16. Copy constructor is removed at // the same time for consistency.
AutoEnterPolicy(const AutoEnterPolicy&) = delete;
AutoEnterPolicy& operator=(const AutoEnterPolicy&) = delete;
};
// For now assert each Proxy Class has at least 1 reserved slot. This is // not a hard requirement, but helps catch Classes that need an explicit // JSCLASS_HAS_RESERVED_SLOTS since bug 1360523.
static_assert(reservedSlots > 0, "Proxy Classes must have at least 1 reserved slot");
// ProxyValueArray must fit inline in the object, so assert the number of // slots does not exceed MAX_FIXED_SLOTS.
static_assert(numSlots + reservedSlots <= JS::shadow::Object::MAX_FIXED_SLOTS, "ProxyValueArray size must not exceed max JSObject size");
// Proxies must not have the JSCLASS_SKIP_NURSERY_FINALIZE flag set: they // always have finalizers, and whether they can be nursery allocated is // controlled by the canNurseryAllocate() method on the proxy handler.
static_assert(!(Flags & JSCLASS_SKIP_NURSERY_FINALIZE), "Proxies must not use JSCLASS_SKIP_NURSERY_FINALIZE; use " "the canNurseryAllocate() proxy handler method instead."); return Flags;
}
// Converts a proxy into a DeadObjectProxy that will throw exceptions on all // access. This will run the proxy's finalizer to perform clean-up before the // conversion happens.
JS_PUBLIC_API void NukeNonCCWProxy(JSContext* cx, JS::HandleObject proxy);
} /* namespace js */
#endif/* js_Proxy_h */
Messung V0.5 in Prozent
¤ 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.0.262Bemerkung:
¤
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.