2013-04-16 20:47:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2015-02-10 18:58:18 +00:00
|
|
|
#ifndef js_Proxy_h
|
|
|
|
#define js_Proxy_h
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2013-08-27 22:10:28 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
|
2011-10-04 14:06:54 +00:00
|
|
|
#include "jsfriendapi.h"
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2013-08-27 04:39:38 +00:00
|
|
|
#include "js/CallNonGenericMethod.h"
|
2013-08-29 00:20:24 +00:00
|
|
|
#include "js/Class.h"
|
2013-08-27 04:39:38 +00:00
|
|
|
|
2010-05-24 21:33:03 +00:00
|
|
|
namespace js {
|
|
|
|
|
2013-08-29 00:20:24 +00:00
|
|
|
using JS::AutoIdVector;
|
|
|
|
using JS::CallArgs;
|
2015-02-17 17:58:43 +00:00
|
|
|
using JS::Handle;
|
2013-08-29 00:20:24 +00:00
|
|
|
using JS::HandleId;
|
|
|
|
using JS::HandleObject;
|
|
|
|
using JS::HandleValue;
|
|
|
|
using JS::IsAcceptableThis;
|
|
|
|
using JS::MutableHandle;
|
|
|
|
using JS::MutableHandleObject;
|
|
|
|
using JS::MutableHandleValue;
|
|
|
|
using JS::NativeImpl;
|
2015-01-30 17:37:07 +00:00
|
|
|
using JS::ObjectOpResult;
|
2013-08-29 00:20:24 +00:00
|
|
|
using JS::PrivateValue;
|
2016-01-28 10:28:04 +00:00
|
|
|
using JS::PropertyDescriptor;
|
2013-08-29 00:20:24 +00:00
|
|
|
using JS::Value;
|
|
|
|
|
2017-03-27 09:38:29 +00:00
|
|
|
class RegExpShared;
|
2017-03-27 09:38:29 +00:00
|
|
|
|
2012-07-17 16:54:41 +00:00
|
|
|
class JS_FRIEND_API(Wrapper);
|
2012-06-28 02:10:37 +00:00
|
|
|
|
2012-07-08 17:04:14 +00:00
|
|
|
/*
|
2014-10-08 17:09:08 +00:00
|
|
|
* A proxy is a JSObject with highly customizable behavior. ES6 specifies a
|
|
|
|
* single kind of proxy, but the customization mechanisms we use to implement
|
|
|
|
* ES6 Proxy objects are also useful wherever an object with weird behavior is
|
|
|
|
* wanted. Proxies are used to implement:
|
2012-07-08 17:04:14 +00:00
|
|
|
*
|
2014-10-08 17:09:08 +00:00
|
|
|
* - the scope objects used by the Debugger's frame.eval() method
|
|
|
|
* (see js::GetDebugScopeForFunction)
|
2012-07-08 17:04:14 +00:00
|
|
|
*
|
2014-10-08 17:09:08 +00:00
|
|
|
* - the khuey hack, whereby a whole compartment can be blown away
|
|
|
|
* even if other compartments hold references to objects in it
|
|
|
|
* (see js::NukeCrossCompartmentWrappers)
|
2012-07-08 17:04:14 +00:00
|
|
|
*
|
2014-10-08 17:09:08 +00:00
|
|
|
* - XPConnect security wrappers, which protect chrome from malicious content
|
|
|
|
* (js/xpconnect/wrappers)
|
2013-12-13 20:01:30 +00:00
|
|
|
*
|
2014-10-08 17:09:08 +00:00
|
|
|
* - DOM objects with special property behavior, like named getters
|
|
|
|
* (dom/bindings/Codegen.py generates these proxies from WebIDL)
|
|
|
|
*
|
|
|
|
* - semi-transparent use of objects that live in other processes
|
|
|
|
* (CPOWs, implemented in js/ipc)
|
|
|
|
*
|
|
|
|
* ### Proxies and internal methods
|
|
|
|
*
|
2016-03-24 20:03:55 +00:00
|
|
|
* ES2016 specifies 13 internal methods. The runtime semantics of just
|
2016-02-09 23:12:24 +00:00
|
|
|
* about everything a script can do to an object is specified in terms
|
|
|
|
* of these internal methods. For example:
|
2014-10-08 17:09:08 +00:00
|
|
|
*
|
|
|
|
* JS code ES6 internal method that gets called
|
|
|
|
* --------------------------- --------------------------------
|
|
|
|
* obj.prop obj.[[Get]](obj, "prop")
|
|
|
|
* "prop" in obj obj.[[HasProperty]]("prop")
|
|
|
|
* new obj() obj.[[Construct]](<empty argument List>)
|
|
|
|
*
|
|
|
|
* With regard to the implementation of these internal methods, there are three
|
|
|
|
* very different kinds of object in SpiderMonkey.
|
|
|
|
*
|
2014-12-17 21:55:32 +00:00
|
|
|
* 1. Native objects' internal methods are implemented in vm/NativeObject.cpp,
|
|
|
|
* with duplicate (but functionally identical) implementations scattered
|
|
|
|
* through the ICs and JITs.
|
2014-10-08 17:09:08 +00:00
|
|
|
*
|
|
|
|
* 2. Certain non-native objects have internal methods that are implemented as
|
|
|
|
* magical js::ObjectOps hooks. We're trying to get rid of these.
|
2014-12-17 21:55:32 +00:00
|
|
|
*
|
2014-10-08 17:09:08 +00:00
|
|
|
* 3. All other objects are proxies. A proxy's internal methods are
|
|
|
|
* implemented in C++, as the virtual methods of a C++ object stored on the
|
|
|
|
* proxy, known as its handler.
|
|
|
|
*
|
|
|
|
* This means that just about anything you do to a proxy will end up going
|
|
|
|
* through a C++ virtual method call. Possibly several. There's no reason the
|
|
|
|
* JITs and ICs can't specialize for particular proxies, based on the handler;
|
|
|
|
* but currently we don't do much of this, so the virtual method overhead
|
|
|
|
* typically is actually incurred.
|
|
|
|
*
|
|
|
|
* ### The proxy handler hierarchy
|
|
|
|
*
|
|
|
|
* A major use case for proxies is to forward each internal method call to
|
|
|
|
* another object, known as its target. The target can be an arbitrary JS
|
|
|
|
* object. Not every proxy has the notion of a target, however.
|
2013-12-13 20:01:30 +00:00
|
|
|
*
|
2012-07-08 17:04:14 +00:00
|
|
|
* To minimize code duplication, a set of abstract proxy handler classes is
|
2014-10-08 17:09:08 +00:00
|
|
|
* provided, from which other handlers may inherit. These abstract classes are
|
|
|
|
* organized in the following hierarchy:
|
2012-07-08 17:04:14 +00:00
|
|
|
*
|
2014-10-08 17:09:08 +00:00
|
|
|
* BaseProxyHandler
|
|
|
|
* |
|
2016-05-04 00:29:10 +00:00
|
|
|
* Wrapper // has a target, can be unwrapped to reveal
|
|
|
|
* | // target (see js::CheckedUnwrap)
|
2014-10-08 17:09:08 +00:00
|
|
|
* |
|
|
|
|
* CrossCompartmentWrapper // target is in another compartment;
|
|
|
|
* // implements membrane between compartments
|
|
|
|
*
|
|
|
|
* Example: Some DOM objects (including all the arraylike DOM objects) are
|
|
|
|
* implemented as proxies. Since these objects don't need to forward operations
|
|
|
|
* to any underlying JS object, DOMJSProxyHandler directly subclasses
|
|
|
|
* BaseProxyHandler.
|
|
|
|
*
|
|
|
|
* Gecko's security wrappers are examples of cross-compartment wrappers.
|
|
|
|
*
|
|
|
|
* ### Proxy prototype chains
|
|
|
|
*
|
|
|
|
* In addition to the normal methods, there are two models for proxy prototype
|
|
|
|
* chains.
|
|
|
|
*
|
|
|
|
* 1. Proxies can use the standard prototype mechanism used throughout the
|
|
|
|
* engine. To do so, simply pass a prototype to NewProxyObject() at
|
|
|
|
* creation time. All prototype accesses will then "just work" to treat the
|
|
|
|
* proxy as a "normal" object.
|
|
|
|
*
|
|
|
|
* 2. A proxy can implement more complicated prototype semantics (if, for
|
|
|
|
* example, it wants to delegate the prototype lookup to a wrapped object)
|
|
|
|
* by passing Proxy::LazyProto as the prototype at create time. This
|
2015-02-05 22:36:50 +00:00
|
|
|
* guarantees that the getPrototype() handler method will be called every
|
2014-10-08 17:09:08 +00:00
|
|
|
* time the object's prototype chain is accessed.
|
|
|
|
*
|
2015-02-05 22:36:50 +00:00
|
|
|
* This system is implemented with two methods: {get,set}Prototype. The
|
|
|
|
* default implementation of setPrototype throws a TypeError. Since it is
|
2014-10-08 17:09:08 +00:00
|
|
|
* not possible to create an object without a sense of prototype chain,
|
2015-02-05 22:36:50 +00:00
|
|
|
* handlers must implement getPrototype if opting in to the dynamic
|
2014-10-08 17:09:08 +00:00
|
|
|
* prototype system.
|
2012-07-08 17:04:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BaseProxyHandler is the most generic kind of proxy handler. It does not make
|
|
|
|
* any assumptions about the target. Consequently, it does not provide any
|
2014-10-08 17:09:08 +00:00
|
|
|
* default implementation for most methods. As a convenience, a few high-level
|
|
|
|
* methods, like get() and set(), are given default implementations that work by
|
|
|
|
* calling the low-level methods, like getOwnPropertyDescriptor().
|
2013-12-05 20:58:20 +00:00
|
|
|
*
|
2014-10-08 17:09:08 +00:00
|
|
|
* Important: If you add a method here, you should probably also add a
|
|
|
|
* Proxy::foo entry point with an AutoEnterPolicy. If you don't, you need an
|
|
|
|
* explicit override for the method in SecurityWrapper. See bug 945826 comment 0.
|
2012-07-08 17:04:14 +00:00
|
|
|
*/
|
2013-03-23 02:43:03 +00:00
|
|
|
class JS_FRIEND_API(BaseProxyHandler)
|
|
|
|
{
|
2014-08-28 00:09:06 +00:00
|
|
|
/*
|
|
|
|
* Sometimes it's desirable to designate groups of proxy handlers as "similar".
|
|
|
|
* For this, we use the notion of a "family": A consumer-provided opaque pointer
|
|
|
|
* that designates the larger group to which this proxy belongs.
|
|
|
|
*
|
|
|
|
* If it will never be important to differentiate this proxy from others as
|
|
|
|
* part of a distinct group, nullptr may be used instead.
|
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
const void* mFamily;
|
2014-04-25 20:07:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Proxy handlers can use mHasPrototype to request the following special
|
|
|
|
* treatment from the JS engine:
|
|
|
|
*
|
|
|
|
* - When mHasPrototype is true, the engine never calls these methods:
|
|
|
|
* getPropertyDescriptor, has, set, enumerate, iterate. Instead, for
|
2014-10-08 17:09:08 +00:00
|
|
|
* these operations, it calls the "own" methods like
|
2014-10-09 03:01:55 +00:00
|
|
|
* getOwnPropertyDescriptor, hasOwn, defineProperty,
|
|
|
|
* getOwnEnumerablePropertyKeys, etc., and consults the prototype chain
|
|
|
|
* if needed.
|
2014-04-25 20:07:18 +00:00
|
|
|
*
|
|
|
|
* - When mHasPrototype is true, the engine calls handler->get() only if
|
|
|
|
* handler->hasOwn() says an own property exists on the proxy. If not,
|
|
|
|
* it consults the prototype chain.
|
|
|
|
*
|
|
|
|
* This is useful because it frees the ProxyHandler from having to implement
|
|
|
|
* any behavior having to do with the prototype chain.
|
|
|
|
*/
|
2012-08-10 11:55:55 +00:00
|
|
|
bool mHasPrototype;
|
2014-01-29 21:07:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* All proxies indicate whether they have any sort of interesting security
|
|
|
|
* policy that might prevent the caller from doing something it wants to
|
|
|
|
* the object. In the case of wrappers, this distinction is used to
|
|
|
|
* determine whether the caller may strip off the wrapper if it so desires.
|
|
|
|
*/
|
|
|
|
bool mHasSecurityPolicy;
|
|
|
|
|
2010-05-19 02:21:43 +00:00
|
|
|
public:
|
2016-07-08 21:39:53 +00:00
|
|
|
explicit constexpr BaseProxyHandler(const void* aFamily, bool aHasPrototype = false,
|
2014-08-28 20:47:16 +00:00
|
|
|
bool aHasSecurityPolicy = false)
|
|
|
|
: mFamily(aFamily),
|
|
|
|
mHasPrototype(aHasPrototype),
|
|
|
|
mHasSecurityPolicy(aHasSecurityPolicy)
|
|
|
|
{ }
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2014-06-27 11:44:04 +00:00
|
|
|
bool hasPrototype() const {
|
2012-08-10 11:55:55 +00:00
|
|
|
return mHasPrototype;
|
|
|
|
}
|
|
|
|
|
2014-06-27 11:44:04 +00:00
|
|
|
bool hasSecurityPolicy() const {
|
2014-01-29 21:07:13 +00:00
|
|
|
return mHasSecurityPolicy;
|
2013-02-25 21:54:18 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
inline const void* family() const {
|
2012-06-28 02:10:37 +00:00
|
|
|
return mFamily;
|
2012-06-29 22:59:42 +00:00
|
|
|
}
|
2013-08-11 05:20:36 +00:00
|
|
|
static size_t offsetOfFamily() {
|
|
|
|
return offsetof(BaseProxyHandler, mFamily);
|
|
|
|
}
|
2012-06-28 02:10:37 +00:00
|
|
|
|
2016-09-11 09:15:23 +00:00
|
|
|
virtual bool finalizeInBackground(const Value& priv) const {
|
2013-02-21 10:19:17 +00:00
|
|
|
/*
|
|
|
|
* Called on creation of a proxy to determine whether its finalize
|
|
|
|
* method can be finalized on the background thread.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-04 18:50:12 +00:00
|
|
|
virtual bool canNurseryAllocate() const {
|
|
|
|
/*
|
|
|
|
* Nursery allocation is allowed if and only if it is safe to not
|
|
|
|
* run |finalize| when the ProxyObject dies.
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 17:09:08 +00:00
|
|
|
/* Policy enforcement methods.
|
2013-02-25 21:54:18 +00:00
|
|
|
*
|
|
|
|
* enter() allows the policy to specify whether the caller may perform |act|
|
|
|
|
* on the proxy's |id| property. In the case when |act| is CALL, |id| is
|
2017-02-02 17:48:49 +00:00
|
|
|
* generally JSID_VOID. The |mayThrow| parameter indicates whether a
|
|
|
|
* handler that wants to throw custom exceptions when denying should do so
|
|
|
|
* or not.
|
2013-02-25 21:54:18 +00:00
|
|
|
*
|
|
|
|
* The |act| parameter to enter() specifies the action being performed.
|
2014-10-08 17:09:08 +00:00
|
|
|
* If |bp| is false, the method suggests that the caller throw (though it
|
2013-02-25 21:54:18 +00:00
|
|
|
* may still decide to squelch the error).
|
2014-02-13 18:54:07 +00:00
|
|
|
*
|
|
|
|
* We make these OR-able so that assertEnteredPolicy can pass a union of them.
|
2014-07-30 19:23:03 +00:00
|
|
|
* For example, get{,Own}PropertyDescriptor is invoked by calls to ::get()
|
|
|
|
* ::set(), in addition to being invoked on its own, so there are several
|
|
|
|
* valid Actions that could have been entered.
|
2013-02-25 21:54:18 +00:00
|
|
|
*/
|
2014-02-13 18:54:07 +00:00
|
|
|
typedef uint32_t Action;
|
2014-02-17 20:59:03 +00:00
|
|
|
enum {
|
|
|
|
NONE = 0x00,
|
|
|
|
GET = 0x01,
|
|
|
|
SET = 0x02,
|
|
|
|
CALL = 0x04,
|
2014-07-30 19:23:03 +00:00
|
|
|
ENUMERATE = 0x08,
|
|
|
|
GET_PROPERTY_DESCRIPTOR = 0x10
|
2014-02-17 20:59:03 +00:00
|
|
|
};
|
2014-02-13 18:54:07 +00:00
|
|
|
|
2017-02-02 17:48:49 +00:00
|
|
|
virtual bool enter(JSContext* cx, HandleObject wrapper, HandleId id, Action act, bool mayThrow,
|
2015-03-28 22:22:11 +00:00
|
|
|
bool* bp) const;
|
2013-02-25 21:54:18 +00:00
|
|
|
|
2014-10-08 17:09:08 +00:00
|
|
|
/* Standard internal methods. */
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2016-01-28 10:28:04 +00:00
|
|
|
MutableHandle<PropertyDescriptor> desc) const = 0;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
2016-01-28 10:28:04 +00:00
|
|
|
Handle<PropertyDescriptor> desc,
|
2015-03-28 22:22:11 +00:00
|
|
|
ObjectOpResult& result) const = 0;
|
|
|
|
virtual bool ownPropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const = 0;
|
|
|
|
virtual bool delete_(JSContext* cx, HandleObject proxy, HandleId id,
|
|
|
|
ObjectOpResult& result) const = 0;
|
2015-02-04 16:20:04 +00:00
|
|
|
|
2014-10-08 17:09:08 +00:00
|
|
|
/*
|
|
|
|
* These methods are standard, but the engine does not normally call them.
|
|
|
|
* They're opt-in. See "Proxy prototype chains" above.
|
|
|
|
*
|
2015-02-05 22:36:50 +00:00
|
|
|
* getPrototype() crashes if called. setPrototype() throws a TypeError.
|
2014-10-08 17:09:08 +00:00
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool getPrototype(JSContext* cx, HandleObject proxy, MutableHandleObject protop) const;
|
|
|
|
virtual bool setPrototype(JSContext* cx, HandleObject proxy, HandleObject proto,
|
|
|
|
ObjectOpResult& result) const;
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2016-02-23 21:42:30 +00:00
|
|
|
/* Non-standard but conceptual kin to {g,s}etPrototype, so these live here. */
|
|
|
|
virtual bool getPrototypeIfOrdinary(JSContext* cx, HandleObject proxy, bool* isOrdinary,
|
2016-04-30 02:59:40 +00:00
|
|
|
MutableHandleObject protop) const = 0;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool setImmutablePrototype(JSContext* cx, HandleObject proxy, bool* succeeded) const;
|
2014-09-23 20:03:40 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool preventExtensions(JSContext* cx, HandleObject proxy,
|
|
|
|
ObjectOpResult& result) const = 0;
|
|
|
|
virtual bool isExtensible(JSContext* cx, HandleObject proxy, bool* extensible) const = 0;
|
2014-10-21 18:40:04 +00:00
|
|
|
|
2014-10-08 17:09:08 +00:00
|
|
|
/*
|
|
|
|
* These standard internal methods are implemented, as a convenience, so
|
|
|
|
* that ProxyHandler subclasses don't have to provide every single method.
|
|
|
|
*
|
|
|
|
* The base-class implementations work by calling getPropertyDescriptor().
|
|
|
|
* They do not follow any standard. When in doubt, override them.
|
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const;
|
2015-09-17 22:14:33 +00:00
|
|
|
virtual bool get(JSContext* cx, HandleObject proxy, HandleValue receiver,
|
2014-06-27 11:44:06 +00:00
|
|
|
HandleId id, MutableHandleValue vp) const;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool set(JSContext* cx, HandleObject proxy, HandleId id, HandleValue v,
|
|
|
|
HandleValue receiver, ObjectOpResult& result) const;
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2014-10-08 17:09:08 +00:00
|
|
|
/*
|
|
|
|
* [[Call]] and [[Construct]] are standard internal methods but according
|
|
|
|
* to the spec, they are not present on every object.
|
|
|
|
*
|
|
|
|
* SpiderMonkey never calls a proxy's call()/construct() internal method
|
|
|
|
* unless isCallable()/isConstructor() returns true for that proxy.
|
|
|
|
*
|
|
|
|
* BaseProxyHandler::isCallable()/isConstructor() always return false, and
|
|
|
|
* BaseProxyHandler::call()/construct() crash if called. So if you're
|
|
|
|
* creating a kind of that is never callable, you don't have to override
|
|
|
|
* anything, but otherwise you probably want to override all four.
|
|
|
|
*/
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool call(JSContext* cx, HandleObject proxy, const CallArgs& args) const;
|
|
|
|
virtual bool construct(JSContext* cx, HandleObject proxy, const CallArgs& args) const;
|
2014-10-08 17:09:08 +00:00
|
|
|
|
|
|
|
/* SpiderMonkey extensions. */
|
2017-06-29 04:00:43 +00:00
|
|
|
virtual JSObject* enumerate(JSContext* cx, HandleObject proxy) const;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool getPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
2016-01-28 10:28:04 +00:00
|
|
|
MutableHandle<PropertyDescriptor> desc) const;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool hasOwn(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const;
|
|
|
|
virtual bool getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject proxy,
|
|
|
|
AutoIdVector& props) const;
|
2015-08-27 19:18:37 +00:00
|
|
|
virtual bool nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
|
|
|
|
const CallArgs& args) const;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool hasInstance(JSContext* cx, HandleObject proxy, MutableHandleValue v, bool* bp) const;
|
2015-08-29 04:55:40 +00:00
|
|
|
virtual bool getBuiltinClass(JSContext* cx, HandleObject proxy,
|
2016-06-29 22:04:56 +00:00
|
|
|
ESClass* cls) const;
|
2015-08-23 08:10:24 +00:00
|
|
|
virtual bool isArray(JSContext* cx, HandleObject proxy, JS::IsArrayAnswer* answer) const;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual const char* className(JSContext* cx, HandleObject proxy) const;
|
2017-07-25 11:22:11 +00:00
|
|
|
virtual JSString* fun_toString(JSContext* cx, HandleObject proxy, bool isToSource) const;
|
2017-07-11 09:31:12 +00:00
|
|
|
virtual RegExpShared* regexp_toShared(JSContext* cx, HandleObject proxy) const;
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool boxedValue_unbox(JSContext* cx, HandleObject proxy, MutableHandleValue vp) const;
|
|
|
|
virtual void trace(JSTracer* trc, JSObject* proxy) const;
|
|
|
|
virtual void finalize(JSFreeOp* fop, JSObject* proxy) const;
|
2017-09-19 11:31:30 +00:00
|
|
|
virtual size_t objectMoved(JSObject* proxy, JSObject* old) const;
|
2012-10-09 01:22:47 +00:00
|
|
|
|
2014-09-10 22:52:36 +00:00
|
|
|
// Allow proxies, wrappers in particular, to specify callability at runtime.
|
2015-03-28 22:22:11 +00:00
|
|
|
// Note: These do not take const JSObject*, but they do in spirit.
|
2014-09-10 22:52:36 +00:00
|
|
|
// We are not prepared to do this, as there's little const correctness
|
|
|
|
// in the external APIs that handle proxies.
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool isCallable(JSObject* obj) const;
|
|
|
|
virtual bool isConstructor(JSObject* obj) const;
|
2014-09-10 22:52:36 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual bool getElements(JSContext* cx, HandleObject proxy, uint32_t begin, uint32_t end,
|
|
|
|
ElementAdder* adder) const;
|
2013-12-05 19:07:24 +00:00
|
|
|
|
2013-08-22 05:26:57 +00:00
|
|
|
/* See comment for weakmapKeyDelegateOp in js/Class.h. */
|
2015-03-28 22:22:11 +00:00
|
|
|
virtual JSObject* weakmapKeyDelegate(JSObject* proxy) const;
|
2014-06-27 11:44:06 +00:00
|
|
|
virtual bool isScripted() const { return false; }
|
2010-05-19 02:21:43 +00:00
|
|
|
};
|
|
|
|
|
2018-04-20 11:07:14 +00:00
|
|
|
extern JS_FRIEND_DATA(const js::Class) ProxyClass;
|
2013-08-27 04:39:37 +00:00
|
|
|
|
2015-03-11 23:54:11 +00:00
|
|
|
inline bool IsProxy(const JSObject* obj)
|
2011-10-04 14:06:54 +00:00
|
|
|
{
|
2014-02-01 08:30:44 +00:00
|
|
|
return GetObjectClass(obj)->isProxy();
|
2011-10-04 14:06:54 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 20:24:51 +00:00
|
|
|
namespace detail {
|
2014-10-17 23:57:52 +00:00
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Proxy objects store a pointer to the reserved slots (ProxyReservedSlots*).
|
|
|
|
// The ProxyValueArray and the private slot can be accessed using
|
|
|
|
// ProxyValueArray::fromReservedSlots or ProxyDataLayout::values.
|
|
|
|
//
|
|
|
|
// Storing a pointer to ProxyReservedSlots instead of ProxyValueArray has a
|
|
|
|
// number of advantages. In particular, it means js::GetReservedSlot and
|
|
|
|
// js::SetReservedSlot can be used with both proxies and native objects. This
|
|
|
|
// works because the ProxyReservedSlots* pointer is stored where native objects
|
|
|
|
// store their dynamic slots pointer.
|
|
|
|
|
|
|
|
struct ProxyReservedSlots
|
|
|
|
{
|
|
|
|
Value slots[1];
|
|
|
|
|
|
|
|
static inline int offsetOfPrivateSlot();
|
|
|
|
|
2018-01-12 11:47:19 +00:00
|
|
|
static inline int offsetOfSlot(size_t slot) {
|
|
|
|
return offsetof(ProxyReservedSlots, slots[0]) + slot * sizeof(Value);
|
|
|
|
}
|
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
void init(size_t nreserved) {
|
|
|
|
for (size_t i = 0; i < nreserved; i++)
|
|
|
|
slots[i] = JS::UndefinedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyReservedSlots(const ProxyReservedSlots&) = delete;
|
|
|
|
void operator=(const ProxyReservedSlots&) = delete;
|
|
|
|
};
|
2014-10-17 23:57:52 +00:00
|
|
|
|
|
|
|
struct ProxyValueArray
|
|
|
|
{
|
|
|
|
Value privateSlot;
|
2017-04-28 12:12:28 +00:00
|
|
|
ProxyReservedSlots reservedSlots;
|
2014-10-17 23:57:52 +00:00
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
void init(size_t nreserved) {
|
|
|
|
privateSlot = JS::UndefinedValue();
|
|
|
|
reservedSlots.init(nreserved);
|
2014-10-17 23:57:52 +00:00
|
|
|
}
|
2017-02-22 20:16:04 +00:00
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
static size_t sizeOf(size_t nreserved) {
|
|
|
|
return offsetOfReservedSlots() + nreserved * sizeof(Value);
|
|
|
|
}
|
|
|
|
static MOZ_ALWAYS_INLINE ProxyValueArray* fromReservedSlots(ProxyReservedSlots* slots) {
|
|
|
|
uintptr_t p = reinterpret_cast<uintptr_t>(slots);
|
|
|
|
return reinterpret_cast<ProxyValueArray*>(p - offsetOfReservedSlots());
|
|
|
|
}
|
|
|
|
static size_t offsetOfReservedSlots() {
|
|
|
|
return offsetof(ProxyValueArray, reservedSlots);
|
2017-02-22 20:16:04 +00:00
|
|
|
}
|
2017-04-28 12:12:28 +00:00
|
|
|
|
|
|
|
ProxyValueArray(const ProxyValueArray&) = delete;
|
|
|
|
void operator=(const ProxyValueArray&) = delete;
|
2014-10-17 23:57:52 +00:00
|
|
|
};
|
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
/* static */ inline int
|
|
|
|
ProxyReservedSlots::offsetOfPrivateSlot()
|
|
|
|
{
|
|
|
|
return -int(ProxyValueArray::offsetOfReservedSlots()) + offsetof(ProxyValueArray, privateSlot);
|
|
|
|
}
|
|
|
|
|
2014-10-17 23:57:52 +00:00
|
|
|
// All proxies share the same data layout. Following the object's shape and
|
|
|
|
// type, the proxy has a ProxyDataLayout structure with a pointer to an array
|
|
|
|
// of values and the proxy's handler. This is designed both so that proxies can
|
|
|
|
// be easily swapped with other objects (via RemapWrapper) and to mimic the
|
|
|
|
// layout of other objects (proxies and other objects have the same size) so
|
|
|
|
// that common code can access either type of object.
|
|
|
|
//
|
|
|
|
// See GetReservedOrProxyPrivateSlot below.
|
|
|
|
struct ProxyDataLayout
|
|
|
|
{
|
2017-04-28 12:12:28 +00:00
|
|
|
ProxyReservedSlots* reservedSlots;
|
2015-03-28 22:22:11 +00:00
|
|
|
const BaseProxyHandler* handler;
|
2017-04-28 12:12:28 +00:00
|
|
|
|
|
|
|
MOZ_ALWAYS_INLINE ProxyValueArray* values() const {
|
|
|
|
return ProxyValueArray::fromReservedSlots(reservedSlots);
|
|
|
|
}
|
2014-10-17 23:57:52 +00:00
|
|
|
};
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
const uint32_t ProxyDataOffset = 2 * sizeof(void*);
|
2014-10-17 23:57:52 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
inline ProxyDataLayout*
|
|
|
|
GetProxyDataLayout(JSObject* obj)
|
2014-10-17 23:57:52 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsProxy(obj));
|
2015-03-28 22:22:11 +00:00
|
|
|
return reinterpret_cast<ProxyDataLayout*>(reinterpret_cast<uint8_t*>(obj) + ProxyDataOffset);
|
2014-10-17 23:57:52 +00:00
|
|
|
}
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2016-03-24 20:24:51 +00:00
|
|
|
inline const ProxyDataLayout*
|
|
|
|
GetProxyDataLayout(const JSObject* obj)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsProxy(obj));
|
|
|
|
return reinterpret_cast<const ProxyDataLayout*>(reinterpret_cast<const uint8_t*>(obj) +
|
|
|
|
ProxyDataOffset);
|
|
|
|
}
|
2018-04-20 08:09:52 +00:00
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetValueInProxy(Value* slot, const Value& value);
|
|
|
|
|
|
|
|
inline void
|
|
|
|
SetProxyReservedSlotUnchecked(JSObject* obj, size_t n, const Value& extra)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(n < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj)));
|
|
|
|
|
|
|
|
Value* vp = &GetProxyDataLayout(obj)->reservedSlots->slots[n];
|
|
|
|
|
|
|
|
// Trigger a barrier before writing the slot.
|
|
|
|
if (vp->isGCThing() || extra.isGCThing())
|
|
|
|
SetValueInProxy(vp, extra);
|
|
|
|
else
|
|
|
|
*vp = extra;
|
|
|
|
}
|
|
|
|
|
2016-03-24 20:24:51 +00:00
|
|
|
} // namespace detail
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
inline const BaseProxyHandler*
|
2016-03-24 20:24:51 +00:00
|
|
|
GetProxyHandler(const JSObject* obj)
|
2010-05-19 02:21:43 +00:00
|
|
|
{
|
2016-03-24 20:24:51 +00:00
|
|
|
return detail::GetProxyDataLayout(obj)->handler;
|
2010-05-19 02:21:43 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
inline const Value&
|
2016-03-24 20:24:51 +00:00
|
|
|
GetProxyPrivate(const JSObject* obj)
|
2010-05-19 02:21:43 +00:00
|
|
|
{
|
2017-04-28 12:12:28 +00:00
|
|
|
return detail::GetProxyDataLayout(obj)->values()->privateSlot;
|
2010-05-19 02:21:43 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
inline JSObject*
|
|
|
|
GetProxyTargetObject(JSObject* obj)
|
2012-05-17 11:19:37 +00:00
|
|
|
{
|
|
|
|
return GetProxyPrivate(obj).toObjectOrNull();
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
inline const Value&
|
2017-04-28 12:12:28 +00:00
|
|
|
GetProxyReservedSlot(const JSObject* obj, size_t n)
|
2010-09-20 21:48:01 +00:00
|
|
|
{
|
2017-04-28 12:12:28 +00:00
|
|
|
MOZ_ASSERT(n < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj)));
|
|
|
|
return detail::GetProxyDataLayout(obj)->reservedSlots->slots[n];
|
2010-09-20 21:48:01 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:03:53 +00:00
|
|
|
inline void
|
2015-03-28 22:22:11 +00:00
|
|
|
SetProxyHandler(JSObject* obj, const BaseProxyHandler* handler)
|
2012-04-26 04:03:53 +00:00
|
|
|
{
|
2016-03-24 20:24:51 +00:00
|
|
|
detail::GetProxyDataLayout(obj)->handler = handler;
|
2012-04-26 04:03:53 +00:00
|
|
|
}
|
|
|
|
|
2010-09-20 21:48:01 +00:00
|
|
|
inline void
|
2017-04-28 12:12:28 +00:00
|
|
|
SetProxyReservedSlot(JSObject* obj, size_t n, const Value& extra)
|
2010-09-20 21:48:01 +00:00
|
|
|
{
|
2018-02-16 11:40:04 +00:00
|
|
|
MOZ_ASSERT_IF(gc::detail::ObjectIsMarkedBlack(obj), JS::ValueIsNotGray(extra));
|
2018-04-20 08:09:52 +00:00
|
|
|
detail::SetProxyReservedSlotUnchecked(obj, n, extra);
|
2010-09-20 21:48:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
inline void
|
|
|
|
SetProxyPrivate(JSObject* obj, const Value& value)
|
2014-04-25 20:07:18 +00:00
|
|
|
{
|
2018-02-16 11:40:04 +00:00
|
|
|
MOZ_ASSERT_IF(gc::detail::ObjectIsMarkedBlack(obj), JS::ValueIsNotGray(value));
|
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
Value* vp = &detail::GetProxyDataLayout(obj)->values()->privateSlot;
|
2014-04-25 20:07:18 +00:00
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
// Trigger a barrier before writing the slot.
|
|
|
|
if (vp->isGCThing() || value.isGCThing())
|
2018-04-20 08:09:52 +00:00
|
|
|
detail::SetValueInProxy(vp, value);
|
2017-04-28 12:12:28 +00:00
|
|
|
else
|
|
|
|
*vp = value;
|
2014-10-17 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 12:12:28 +00:00
|
|
|
inline bool
|
|
|
|
IsScriptedProxy(const JSObject* obj)
|
2014-10-17 23:57:52 +00:00
|
|
|
{
|
2017-04-28 12:12:28 +00:00
|
|
|
return IsProxy(obj) && GetProxyHandler(obj)->isScripted();
|
2014-10-17 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
2013-10-04 11:29:35 +00:00
|
|
|
class MOZ_STACK_CLASS ProxyOptions {
|
2014-01-30 01:20:16 +00:00
|
|
|
protected:
|
|
|
|
/* protected constructor for subclass */
|
2015-02-10 15:29:28 +00:00
|
|
|
explicit ProxyOptions(bool singletonArg, bool lazyProtoArg = false)
|
2014-01-30 01:20:16 +00:00
|
|
|
: singleton_(singletonArg),
|
2015-02-10 15:29:28 +00:00
|
|
|
lazyProto_(lazyProtoArg),
|
2018-04-20 11:07:14 +00:00
|
|
|
clasp_(&ProxyClass)
|
2014-01-30 01:20:16 +00:00
|
|
|
{}
|
|
|
|
|
2013-10-04 11:29:35 +00:00
|
|
|
public:
|
2014-01-30 01:20:16 +00:00
|
|
|
ProxyOptions() : singleton_(false),
|
2015-02-10 15:29:28 +00:00
|
|
|
lazyProto_(false),
|
2018-04-20 11:07:14 +00:00
|
|
|
clasp_(&ProxyClass)
|
2013-10-04 11:29:35 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool singleton() const { return singleton_; }
|
2015-03-28 22:22:11 +00:00
|
|
|
ProxyOptions& setSingleton(bool flag) {
|
2013-10-04 11:29:35 +00:00
|
|
|
singleton_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-10 15:29:28 +00:00
|
|
|
bool lazyProto() const { return lazyProto_; }
|
2015-03-28 22:22:11 +00:00
|
|
|
ProxyOptions& setLazyProto(bool flag) {
|
2015-02-10 15:29:28 +00:00
|
|
|
lazyProto_ = flag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
const Class* clasp() const {
|
2014-01-30 01:20:16 +00:00
|
|
|
return clasp_;
|
|
|
|
}
|
2015-03-28 22:22:11 +00:00
|
|
|
ProxyOptions& setClass(const Class* claspArg) {
|
2014-01-30 01:20:16 +00:00
|
|
|
clasp_ = claspArg;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-10-04 11:29:35 +00:00
|
|
|
private:
|
|
|
|
bool singleton_;
|
2015-02-10 15:29:28 +00:00
|
|
|
bool lazyProto_;
|
2015-03-28 22:22:11 +00:00
|
|
|
const Class* clasp_;
|
2013-03-27 00:51:55 +00:00
|
|
|
};
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JS_FRIEND_API(JSObject*)
|
|
|
|
NewProxyObject(JSContext* cx, const BaseProxyHandler* handler, HandleValue priv,
|
|
|
|
JSObject* proto, const ProxyOptions& options = ProxyOptions());
|
2013-03-27 00:51:55 +00:00
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
JSObject*
|
2016-09-11 09:15:22 +00:00
|
|
|
RenewProxyObject(JSContext* cx, JSObject* obj, BaseProxyHandler* handler, const Value& priv);
|
2012-09-12 00:14:24 +00:00
|
|
|
|
2013-02-25 21:54:18 +00:00
|
|
|
class JS_FRIEND_API(AutoEnterPolicy)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef BaseProxyHandler::Action Action;
|
2018-04-12 19:15:26 +00:00
|
|
|
AutoEnterPolicy(JSContext* cx, const BaseProxyHandler* handler,
|
|
|
|
HandleObject wrapper, HandleId id, Action act, bool mayThrow)
|
2013-12-06 23:03:08 +00:00
|
|
|
#ifdef JS_DEBUG
|
2018-04-12 19:15:26 +00:00
|
|
|
: context(nullptr)
|
2013-02-25 21:54:18 +00:00
|
|
|
#endif
|
2013-02-25 21:54:18 +00:00
|
|
|
{
|
2017-02-02 17:48:49 +00:00
|
|
|
allow = handler->hasSecurityPolicy() ? handler->enter(cx, wrapper, id, act, mayThrow, &rv)
|
2014-01-29 21:07:13 +00:00
|
|
|
: true;
|
2014-02-13 18:54:07 +00:00
|
|
|
recordEnter(cx, wrapper, id, act);
|
2013-03-18 04:44:41 +00:00
|
|
|
// 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.
|
2013-08-29 00:20:24 +00:00
|
|
|
if (!allow && !rv && mayThrow)
|
|
|
|
reportErrorIfExceptionIsNotPending(cx, id);
|
2013-02-25 21:54:18 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 21:54:18 +00:00
|
|
|
virtual ~AutoEnterPolicy() { recordLeave(); }
|
2013-02-25 21:54:18 +00:00
|
|
|
inline bool allowed() { return allow; }
|
2014-10-01 17:17:51 +00:00
|
|
|
inline bool returnValue() { MOZ_ASSERT(!allowed()); return rv; }
|
2013-02-25 21:54:18 +00:00
|
|
|
|
|
|
|
protected:
|
2013-02-25 21:54:18 +00:00
|
|
|
// no-op constructor for subclass
|
|
|
|
AutoEnterPolicy()
|
2013-12-06 23:03:08 +00:00
|
|
|
#ifdef JS_DEBUG
|
2018-04-12 19:15:26 +00:00
|
|
|
: context(nullptr)
|
|
|
|
, enteredAction(BaseProxyHandler::NONE)
|
2013-02-25 21:54:18 +00:00
|
|
|
#endif
|
2018-04-12 19:15:26 +00:00
|
|
|
{}
|
2015-03-28 22:22:11 +00:00
|
|
|
void reportErrorIfExceptionIsNotPending(JSContext* cx, jsid id);
|
2013-02-25 21:54:18 +00:00
|
|
|
bool allow;
|
|
|
|
bool rv;
|
2013-02-25 21:54:18 +00:00
|
|
|
|
2013-12-06 23:03:08 +00:00
|
|
|
#ifdef JS_DEBUG
|
2015-03-28 22:22:11 +00:00
|
|
|
JSContext* context;
|
2013-03-21 12:56:58 +00:00
|
|
|
mozilla::Maybe<HandleObject> enteredProxy;
|
|
|
|
mozilla::Maybe<HandleId> enteredId;
|
2014-02-13 18:54:07 +00:00
|
|
|
Action enteredAction;
|
|
|
|
|
2013-02-25 21:54:18 +00:00
|
|
|
// NB: We explicitly don't track the entered action here, because sometimes
|
2014-10-08 17:09:08 +00:00
|
|
|
// set() methods do an implicit get() during their implementation, leading
|
|
|
|
// to spurious assertions.
|
2015-03-28 22:22:11 +00:00
|
|
|
AutoEnterPolicy* prev;
|
|
|
|
void recordEnter(JSContext* cx, HandleObject proxy, HandleId id, Action act);
|
2013-02-25 21:54:18 +00:00
|
|
|
void recordLeave();
|
|
|
|
|
2015-03-28 22:22:11 +00:00
|
|
|
friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext* cx, JSObject* proxy, jsid id, Action act);
|
2013-02-25 21:54:18 +00:00
|
|
|
#else
|
2015-03-28 22:22:11 +00:00
|
|
|
inline void recordEnter(JSContext* cx, JSObject* proxy, jsid id, Action act) {}
|
2013-02-25 21:54:18 +00:00
|
|
|
inline void recordLeave() {}
|
|
|
|
#endif
|
|
|
|
|
2016-12-28 23:58:01 +00:00
|
|
|
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;
|
2013-02-25 21:54:18 +00:00
|
|
|
};
|
|
|
|
|
2013-12-06 23:03:08 +00:00
|
|
|
#ifdef JS_DEBUG
|
2013-02-25 21:54:18 +00:00
|
|
|
class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy {
|
|
|
|
public:
|
2015-03-28 22:22:11 +00:00
|
|
|
AutoWaivePolicy(JSContext* cx, HandleObject proxy, HandleId id,
|
2014-02-13 18:54:07 +00:00
|
|
|
BaseProxyHandler::Action act)
|
2013-02-25 21:54:18 +00:00
|
|
|
{
|
|
|
|
allow = true;
|
2014-02-13 18:54:07 +00:00
|
|
|
recordEnter(cx, proxy, id, act);
|
2013-02-25 21:54:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
class JS_FRIEND_API(AutoWaivePolicy) {
|
2014-02-13 18:54:07 +00:00
|
|
|
public:
|
2015-03-28 22:22:11 +00:00
|
|
|
AutoWaivePolicy(JSContext* cx, HandleObject proxy, HandleId id,
|
2014-02-13 18:54:07 +00:00
|
|
|
BaseProxyHandler::Action act)
|
|
|
|
{}
|
2013-02-25 21:54:18 +00:00
|
|
|
};
|
2013-02-25 21:54:18 +00:00
|
|
|
#endif
|
2013-02-25 21:54:18 +00:00
|
|
|
|
2014-02-13 18:54:07 +00:00
|
|
|
#ifdef JS_DEBUG
|
|
|
|
extern JS_FRIEND_API(void)
|
2015-03-28 22:22:11 +00:00
|
|
|
assertEnteredPolicy(JSContext* cx, JSObject* obj, jsid id,
|
2014-02-13 18:54:07 +00:00
|
|
|
BaseProxyHandler::Action act);
|
|
|
|
#else
|
2015-03-28 22:22:11 +00:00
|
|
|
inline void assertEnteredPolicy(JSContext* cx, JSObject* obj, jsid id,
|
2014-02-13 18:54:07 +00:00
|
|
|
BaseProxyHandler::Action act)
|
2014-08-18 19:20:39 +00:00
|
|
|
{}
|
2014-02-13 18:54:07 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-29 12:41:49 +00:00
|
|
|
extern JS_FRIEND_DATA(const js::ClassOps) ProxyClassOps;
|
|
|
|
extern JS_FRIEND_DATA(const js::ClassExtension) ProxyClassExtension;
|
|
|
|
extern JS_FRIEND_DATA(const js::ObjectOps) ProxyObjectOps;
|
|
|
|
|
|
|
|
template <unsigned Flags>
|
|
|
|
constexpr unsigned
|
|
|
|
CheckProxyFlags()
|
|
|
|
{
|
|
|
|
// 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(((Flags >> JSCLASS_RESERVED_SLOTS_SHIFT) & JSCLASS_RESERVED_SLOTS_MASK) > 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((offsetof(js::detail::ProxyValueArray, reservedSlots) / sizeof(Value)) +
|
|
|
|
((Flags >> JSCLASS_RESERVED_SLOTS_SHIFT) & JSCLASS_RESERVED_SLOTS_MASK)
|
|
|
|
<= shadow::Object::MAX_FIXED_SLOTS,
|
|
|
|
"ProxyValueArray size must not exceed max JSObject size");
|
2017-07-01 00:31:41 +00:00
|
|
|
|
|
|
|
// 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.");
|
2017-04-29 12:41:49 +00:00
|
|
|
return Flags;
|
|
|
|
}
|
|
|
|
|
2017-09-19 11:31:30 +00:00
|
|
|
#define PROXY_CLASS_DEF(name, flags) \
|
2017-04-29 12:41:49 +00:00
|
|
|
{ \
|
|
|
|
name, \
|
|
|
|
js::Class::NON_NATIVE | \
|
|
|
|
JSCLASS_IS_PROXY | \
|
|
|
|
JSCLASS_DELAY_METADATA_BUILDER | \
|
|
|
|
js::CheckProxyFlags<flags>(), \
|
|
|
|
&js::ProxyClassOps, \
|
|
|
|
JS_NULL_CLASS_SPEC, \
|
2017-09-19 11:31:30 +00:00
|
|
|
&js::ProxyClassExtension, \
|
2017-04-29 12:41:49 +00:00
|
|
|
&js::ProxyObjectOps \
|
|
|
|
}
|
|
|
|
|
2015-02-27 15:08:15 +00:00
|
|
|
} /* namespace js */
|
2010-05-19 02:21:43 +00:00
|
|
|
|
2015-02-10 18:58:18 +00:00
|
|
|
#endif /* js_Proxy_h */
|