2010-05-18 19:21:43 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99:
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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-18 19:21:43 -07:00
|
|
|
|
|
|
|
#ifndef jsproxy_h___
|
|
|
|
#define jsproxy_h___
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "jsfriendapi.h"
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2010-05-24 14:33:03 -07:00
|
|
|
namespace js {
|
|
|
|
|
2012-07-17 09:54:41 -07:00
|
|
|
class JS_FRIEND_API(Wrapper);
|
2012-06-27 19:10:37 -07:00
|
|
|
|
2012-07-08 10:04:14 -07:00
|
|
|
/*
|
|
|
|
* A proxy is a JSObject that implements generic behavior by providing custom
|
|
|
|
* implementations for each object trap. The implementation for each trap is
|
|
|
|
* provided by a C++ object stored on the proxy, known as its handler.
|
|
|
|
*
|
|
|
|
* A major use case for proxies is to forward each trap to another object,
|
|
|
|
* known as its target. The target can be an arbitrary C++ object. Not every
|
|
|
|
* proxy has the notion of a target, however.
|
|
|
|
*
|
|
|
|
* Proxy traps are grouped into fundamental and derived traps. Every proxy has
|
|
|
|
* to at least provide implementations for the fundamental traps, but the
|
2012-10-29 08:52:53 -07:00
|
|
|
* derived traps can be implemented in terms of the fundamental ones
|
|
|
|
* BaseProxyHandler provides implementations of the derived traps in terms of
|
|
|
|
* the (pure virtual) fundamental traps.
|
2012-07-08 10:04:14 -07:00
|
|
|
*
|
|
|
|
* To minimize code duplication, a set of abstract proxy handler classes is
|
|
|
|
* provided, from which other handlers may inherit. These abstract classes
|
|
|
|
* are organized in the following hierarchy:
|
|
|
|
*
|
|
|
|
* BaseProxyHandler
|
|
|
|
* |
|
|
|
|
* DirectProxyHandler
|
2012-10-29 08:52:53 -07:00
|
|
|
* |
|
|
|
|
* Wrapper
|
2012-07-08 10:04:14 -07: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
|
|
|
|
* default implementation for the fundamental traps. It does, however, implement
|
|
|
|
* the derived traps in terms of the fundamental ones. This allows consumers of
|
|
|
|
* this class to define any custom behavior they want.
|
|
|
|
*/
|
2012-05-17 04:19:37 -07:00
|
|
|
class JS_FRIEND_API(BaseProxyHandler) {
|
2010-06-24 14:45:32 -07:00
|
|
|
void *mFamily;
|
2012-08-10 04:55:55 -07:00
|
|
|
bool mHasPrototype;
|
2013-02-25 13:54:18 -08:00
|
|
|
bool mHasPolicy;
|
2012-08-10 04:55:55 -07:00
|
|
|
protected:
|
|
|
|
// Subclasses may set this in their constructor.
|
2013-02-17 22:56:32 -08:00
|
|
|
void setHasPrototype(bool aHasPrototype) { mHasPrototype = aHasPrototype; }
|
2013-02-25 13:54:18 -08:00
|
|
|
void setHasPolicy(bool aHasPolicy) { mHasPolicy = aHasPolicy; }
|
2012-08-10 04:55:55 -07:00
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
public:
|
2012-05-17 04:19:37 -07:00
|
|
|
explicit BaseProxyHandler(void *family);
|
|
|
|
virtual ~BaseProxyHandler();
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2012-08-10 04:55:55 -07:00
|
|
|
bool hasPrototype() {
|
|
|
|
return mHasPrototype;
|
|
|
|
}
|
|
|
|
|
2013-02-25 13:54:18 -08:00
|
|
|
bool hasPolicy() {
|
|
|
|
return mHasPolicy;
|
|
|
|
}
|
|
|
|
|
2012-06-27 19:10:37 -07:00
|
|
|
inline void *family() {
|
|
|
|
return mFamily;
|
2012-06-29 15:59:42 -07:00
|
|
|
}
|
2012-06-27 19:10:37 -07:00
|
|
|
|
|
|
|
virtual bool isOuterWindow() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-21 02:19:17 -08:00
|
|
|
virtual bool finalizeInBackground(HandleValue priv) {
|
|
|
|
/*
|
|
|
|
* Called on creation of a proxy to determine whether its finalize
|
|
|
|
* method can be finalized on the background thread.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-25 13:54:18 -08:00
|
|
|
/* Policy enforcement traps.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* generally JSID_VOID.
|
|
|
|
*
|
|
|
|
* The |act| parameter to enter() specifies the action being performed.
|
2013-02-25 13:54:18 -08:00
|
|
|
* If |bp| is false, the trap suggests that the caller throw (though it
|
|
|
|
* may still decide to squelch the error).
|
2013-02-25 13:54:18 -08:00
|
|
|
*/
|
|
|
|
enum Action {
|
|
|
|
GET,
|
|
|
|
SET,
|
|
|
|
CALL
|
|
|
|
};
|
|
|
|
virtual bool enter(JSContext *cx, JSObject *wrapper, jsid id, Action act,
|
|
|
|
bool *bp);
|
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
/* ES5 Harmony fundamental proxy traps. */
|
2012-07-08 10:04:14 -07:00
|
|
|
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id,
|
2013-01-03 13:31:36 -08:00
|
|
|
PropertyDescriptor *desc, unsigned flags) = 0;
|
2012-07-08 10:04:14 -07:00
|
|
|
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy,
|
2013-01-03 13:31:36 -08:00
|
|
|
jsid id, PropertyDescriptor *desc, unsigned flags) = 0;
|
2010-05-27 12:03:25 -07:00
|
|
|
virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id,
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyDescriptor *desc) = 0;
|
2012-07-08 10:04:14 -07:00
|
|
|
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy,
|
|
|
|
AutoIdVector &props) = 0;
|
2010-05-18 19:21:43 -07:00
|
|
|
virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) = 0;
|
2012-07-08 10:04:14 -07:00
|
|
|
virtual bool enumerate(JSContext *cx, JSObject *proxy,
|
|
|
|
AutoIdVector &props) = 0;
|
2010-05-18 19:21:43 -07:00
|
|
|
|
|
|
|
/* ES5 Harmony derived proxy traps. */
|
2010-09-20 14:48:01 -07:00
|
|
|
virtual bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
|
|
|
|
virtual bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
|
2012-07-08 10:04:14 -07:00
|
|
|
virtual bool get(JSContext *cx, JSObject *proxy, JSObject *receiver,
|
|
|
|
jsid id, Value *vp);
|
|
|
|
virtual bool set(JSContext *cx, JSObject *proxy, JSObject *receiver,
|
|
|
|
jsid id, bool strict, Value *vp);
|
2011-09-08 20:29:15 -07:00
|
|
|
virtual bool keys(JSContext *cx, JSObject *proxy, AutoIdVector &props);
|
2012-07-08 10:04:14 -07:00
|
|
|
virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags,
|
|
|
|
Value *vp);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
|
|
|
/* Spidermonkey extensions. */
|
2012-02-28 15:11:11 -08:00
|
|
|
virtual bool call(JSContext *cx, JSObject *proxy, unsigned argc, Value *vp);
|
|
|
|
virtual bool construct(JSContext *cx, JSObject *proxy, unsigned argc, Value *argv, Value *rval);
|
2012-07-03 17:44:22 -07:00
|
|
|
virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args);
|
2012-09-04 16:40:12 -07:00
|
|
|
virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp);
|
2011-09-28 08:48:16 -07:00
|
|
|
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx);
|
2010-09-20 14:48:01 -07:00
|
|
|
virtual JSString *obj_toString(JSContext *cx, JSObject *proxy);
|
2012-02-28 15:11:11 -08:00
|
|
|
virtual JSString *fun_toString(JSContext *cx, JSObject *proxy, unsigned indent);
|
2012-02-23 13:51:19 -08:00
|
|
|
virtual bool regexp_toShared(JSContext *cx, JSObject *proxy, RegExpGuard *g);
|
2011-09-08 20:29:15 -07:00
|
|
|
virtual bool defaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp);
|
2012-03-19 07:34:55 -07:00
|
|
|
virtual void finalize(JSFreeOp *fop, JSObject *proxy);
|
2011-11-04 09:19:00 -07:00
|
|
|
virtual bool getElementIfPresent(JSContext *cx, JSObject *obj, JSObject *receiver,
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t index, Value *vp, bool *present);
|
2012-09-26 09:49:20 -07:00
|
|
|
virtual bool getPrototypeOf(JSContext *cx, JSObject *proxy, JSObject **protop);
|
2012-10-08 18:22:47 -07:00
|
|
|
|
|
|
|
/* See comment for weakmapKeyDelegateOp in jsclass.h. */
|
|
|
|
virtual JSObject *weakmapKeyDelegate(JSObject *proxy);
|
2010-05-18 19:21:43 -07:00
|
|
|
};
|
|
|
|
|
2012-07-08 10:04:14 -07:00
|
|
|
/*
|
2012-10-29 08:52:53 -07:00
|
|
|
* DirectProxyHandler includes a notion of a target object. All traps are
|
|
|
|
* reimplemented such that they forward their behavior to the target. This
|
|
|
|
* allows consumers of this class to forward to another object as transparently
|
|
|
|
* and efficiently as possible.
|
2012-07-08 10:04:14 -07:00
|
|
|
*/
|
2012-10-29 08:52:53 -07:00
|
|
|
class JS_PUBLIC_API(DirectProxyHandler) : public BaseProxyHandler {
|
|
|
|
public:
|
|
|
|
explicit DirectProxyHandler(void *family);
|
2012-05-17 04:19:37 -07:00
|
|
|
|
|
|
|
/* ES5 Harmony fundamental proxy traps. */
|
|
|
|
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id,
|
2013-01-03 13:31:36 -08:00
|
|
|
PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE;
|
2012-05-17 04:19:37 -07:00
|
|
|
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy,
|
2013-01-03 13:31:36 -08:00
|
|
|
jsid id, PropertyDescriptor *desc,
|
|
|
|
unsigned flags) MOZ_OVERRIDE;
|
2012-05-17 04:19:37 -07:00
|
|
|
virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id,
|
|
|
|
PropertyDescriptor *desc) MOZ_OVERRIDE;
|
|
|
|
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy,
|
|
|
|
AutoIdVector &props) MOZ_OVERRIDE;
|
|
|
|
virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id,
|
|
|
|
bool *bp) MOZ_OVERRIDE;
|
|
|
|
virtual bool enumerate(JSContext *cx, JSObject *proxy,
|
|
|
|
AutoIdVector &props) MOZ_OVERRIDE;
|
|
|
|
|
2012-10-29 08:52:53 -07:00
|
|
|
/* ES5 Harmony derived proxy traps. */
|
|
|
|
virtual bool has(JSContext *cx, JSObject *proxy, jsid id,
|
|
|
|
bool *bp) MOZ_OVERRIDE;
|
|
|
|
virtual bool hasOwn(JSContext *cx, JSObject *proxy, jsid id,
|
|
|
|
bool *bp) MOZ_OVERRIDE;
|
|
|
|
virtual bool get(JSContext *cx, JSObject *proxy, JSObject *receiver,
|
|
|
|
jsid id, Value *vp) MOZ_OVERRIDE;
|
|
|
|
virtual bool set(JSContext *cx, JSObject *proxy, JSObject *receiver,
|
|
|
|
jsid id, bool strict, Value *vp) MOZ_OVERRIDE;
|
|
|
|
virtual bool keys(JSContext *cx, JSObject *proxy,
|
|
|
|
AutoIdVector &props) MOZ_OVERRIDE;
|
|
|
|
virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags,
|
|
|
|
Value *vp) MOZ_OVERRIDE;
|
|
|
|
|
2012-05-17 04:19:37 -07:00
|
|
|
/* Spidermonkey extensions. */
|
2012-07-03 17:44:22 -07:00
|
|
|
virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl,
|
|
|
|
CallArgs args) MOZ_OVERRIDE;
|
2012-09-04 16:40:12 -07:00
|
|
|
virtual bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v,
|
2012-05-17 04:19:37 -07:00
|
|
|
bool *bp) MOZ_OVERRIDE;
|
|
|
|
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue,
|
|
|
|
JSContext *cx) MOZ_OVERRIDE;
|
|
|
|
virtual JSString *obj_toString(JSContext *cx, JSObject *proxy) MOZ_OVERRIDE;
|
|
|
|
virtual JSString *fun_toString(JSContext *cx, JSObject *proxy,
|
|
|
|
unsigned indent) MOZ_OVERRIDE;
|
|
|
|
virtual bool regexp_toShared(JSContext *cx, JSObject *proxy,
|
|
|
|
RegExpGuard *g) MOZ_OVERRIDE;
|
|
|
|
virtual bool defaultValue(JSContext *cx, JSObject *obj, JSType hint,
|
|
|
|
Value *vp) MOZ_OVERRIDE;
|
2012-10-08 18:22:47 -07:00
|
|
|
virtual JSObject *weakmapKeyDelegate(JSObject *proxy);
|
2012-05-17 04:19:37 -07:00
|
|
|
};
|
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
/* Dispatch point for handlers that executes the appropriate C++ or scripted traps. */
|
2011-09-08 20:29:15 -07:00
|
|
|
class Proxy {
|
2010-05-18 19:21:43 -07:00
|
|
|
public:
|
|
|
|
/* ES5 Harmony fundamental proxy traps. */
|
2013-01-03 13:31:36 -08:00
|
|
|
static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id,
|
|
|
|
PropertyDescriptor *desc, unsigned flags);
|
|
|
|
static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, unsigned flags, jsid id,
|
|
|
|
Value *vp);
|
|
|
|
static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id,
|
|
|
|
PropertyDescriptor *desc, unsigned flags);
|
|
|
|
static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, unsigned flags, jsid id,
|
2010-09-17 14:54:41 -07:00
|
|
|
Value *vp);
|
2010-07-14 23:19:36 -07:00
|
|
|
static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc);
|
|
|
|
static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, const Value &v);
|
2011-09-08 20:29:15 -07:00
|
|
|
static bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, AutoIdVector &props);
|
2010-05-18 19:21:43 -07:00
|
|
|
static bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
|
2011-09-08 20:29:15 -07:00
|
|
|
static bool enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
|
|
|
/* ES5 Harmony derived proxy traps. */
|
|
|
|
static bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
|
|
|
|
static bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
|
2012-08-10 04:55:55 -07:00
|
|
|
static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, MutableHandleValue vp);
|
|
|
|
static bool getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver,
|
|
|
|
uint32_t index, MutableHandleValue vp, bool *present);
|
|
|
|
static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, bool strict,
|
|
|
|
MutableHandleValue vp);
|
2011-09-08 20:29:15 -07:00
|
|
|
static bool keys(JSContext *cx, JSObject *proxy, AutoIdVector &props);
|
2012-08-10 04:55:55 -07:00
|
|
|
static bool iterate(JSContext *cx, HandleObject proxy, unsigned flags, MutableHandleValue vp);
|
2010-06-23 14:35:10 -07:00
|
|
|
|
|
|
|
/* Spidermonkey extensions. */
|
2012-02-28 15:11:11 -08:00
|
|
|
static bool call(JSContext *cx, JSObject *proxy, unsigned argc, Value *vp);
|
|
|
|
static bool construct(JSContext *cx, JSObject *proxy, unsigned argc, Value *argv, Value *rval);
|
2012-07-03 17:44:22 -07:00
|
|
|
static bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args);
|
2012-09-04 16:40:12 -07:00
|
|
|
static bool hasInstance(JSContext *cx, HandleObject proxy, MutableHandleValue v, bool *bp);
|
2011-09-28 08:48:16 -07:00
|
|
|
static bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx);
|
2010-06-23 14:35:10 -07:00
|
|
|
static JSString *obj_toString(JSContext *cx, JSObject *proxy);
|
2012-02-28 15:11:11 -08:00
|
|
|
static JSString *fun_toString(JSContext *cx, JSObject *proxy, unsigned indent);
|
2012-02-23 13:51:19 -08:00
|
|
|
static bool regexp_toShared(JSContext *cx, JSObject *proxy, RegExpGuard *g);
|
2011-09-08 20:29:15 -07:00
|
|
|
static bool defaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp);
|
2012-09-26 09:49:20 -07:00
|
|
|
static bool getPrototypeOf(JSContext *cx, JSObject *proxy, JSObject **protop);
|
|
|
|
|
|
|
|
static JSObject * const LazyProto;
|
2010-05-18 19:21:43 -07:00
|
|
|
};
|
|
|
|
|
2012-02-21 10:31:27 -08:00
|
|
|
inline bool IsObjectProxyClass(const Class *clasp)
|
2011-10-04 07:06:54 -07:00
|
|
|
{
|
|
|
|
return clasp == &js::ObjectProxyClass || clasp == &js::OuterWindowProxyClass;
|
|
|
|
}
|
|
|
|
|
2012-02-21 10:31:27 -08:00
|
|
|
inline bool IsFunctionProxyClass(const Class *clasp)
|
2011-10-04 07:06:54 -07:00
|
|
|
{
|
|
|
|
return clasp == &js::FunctionProxyClass;
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:37:31 -07:00
|
|
|
inline bool IsObjectProxy(RawObject obj)
|
2012-02-21 10:31:27 -08:00
|
|
|
{
|
|
|
|
return IsObjectProxyClass(GetObjectClass(obj));
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:37:31 -07:00
|
|
|
inline bool IsFunctionProxy(RawObject obj)
|
2012-02-21 10:31:27 -08:00
|
|
|
{
|
|
|
|
return IsFunctionProxyClass(GetObjectClass(obj));
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:37:31 -07:00
|
|
|
inline bool IsProxy(RawObject obj)
|
2011-10-04 07:06:54 -07:00
|
|
|
{
|
2012-02-21 10:31:27 -08:00
|
|
|
Class *clasp = GetObjectClass(obj);
|
|
|
|
return IsObjectProxyClass(clasp) || IsFunctionProxyClass(clasp);
|
2011-10-04 07:06:54 -07:00
|
|
|
}
|
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
/* Shared between object and function proxies. */
|
2012-12-06 12:21:19 -08:00
|
|
|
/*
|
|
|
|
* NOTE: JSSLOT_PROXY_PRIVATE is 0, because that way slot 0 is usable by API
|
|
|
|
* clients for both proxy and non-proxy objects. So an API client that only
|
|
|
|
* needs to store one slot's worth of data doesn't need to branch on what sort
|
|
|
|
* of object it has.
|
|
|
|
*/
|
|
|
|
const uint32_t JSSLOT_PROXY_PRIVATE = 0;
|
|
|
|
const uint32_t JSSLOT_PROXY_HANDLER = 1;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
const uint32_t JSSLOT_PROXY_EXTRA = 2;
|
2010-05-18 19:21:43 -07:00
|
|
|
/* Function proxies only. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
const uint32_t JSSLOT_PROXY_CALL = 4;
|
|
|
|
const uint32_t JSSLOT_PROXY_CONSTRUCT = 5;
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2012-05-17 04:19:37 -07:00
|
|
|
inline BaseProxyHandler *
|
2012-07-23 13:37:31 -07:00
|
|
|
GetProxyHandler(RawObject obj)
|
2010-05-18 19:21:43 -07:00
|
|
|
{
|
2011-10-04 07:06:54 -07:00
|
|
|
JS_ASSERT(IsProxy(obj));
|
2012-05-17 04:19:37 -07:00
|
|
|
return (BaseProxyHandler *) GetReservedSlot(obj, JSSLOT_PROXY_HANDLER).toPrivate();
|
2010-05-18 19:21:43 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
inline const Value &
|
2012-07-23 13:37:31 -07:00
|
|
|
GetProxyPrivate(RawObject obj)
|
2010-05-18 19:21:43 -07:00
|
|
|
{
|
2011-10-04 07:06:54 -07:00
|
|
|
JS_ASSERT(IsProxy(obj));
|
|
|
|
return GetReservedSlot(obj, JSSLOT_PROXY_PRIVATE);
|
2010-05-18 19:21:43 -07:00
|
|
|
}
|
|
|
|
|
2012-05-17 04:19:37 -07:00
|
|
|
inline JSObject *
|
2012-07-23 13:37:31 -07:00
|
|
|
GetProxyTargetObject(RawObject obj)
|
2012-05-17 04:19:37 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(IsProxy(obj));
|
|
|
|
return GetProxyPrivate(obj).toObjectOrNull();
|
|
|
|
}
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
inline const Value &
|
2012-07-23 13:37:31 -07:00
|
|
|
GetProxyCall(RawObject obj)
|
2012-05-23 16:31:26 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(IsFunctionProxy(obj));
|
|
|
|
return GetReservedSlot(obj, JSSLOT_PROXY_CALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Value &
|
2012-07-23 13:37:31 -07:00
|
|
|
GetProxyExtra(RawObject obj, size_t n)
|
2010-09-20 14:48:01 -07:00
|
|
|
{
|
2011-10-04 07:06:54 -07:00
|
|
|
JS_ASSERT(IsProxy(obj));
|
2011-05-23 08:39:25 -07:00
|
|
|
return GetReservedSlot(obj, JSSLOT_PROXY_EXTRA + n);
|
2010-09-20 14:48:01 -07:00
|
|
|
}
|
|
|
|
|
2012-04-25 21:03:53 -07:00
|
|
|
inline void
|
2012-07-23 13:37:31 -07:00
|
|
|
SetProxyHandler(RawObject obj, BaseProxyHandler *handler)
|
2012-04-25 21:03:53 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(IsProxy(obj));
|
|
|
|
SetReservedSlot(obj, JSSLOT_PROXY_HANDLER, PrivateValue(handler));
|
|
|
|
}
|
|
|
|
|
2010-09-20 14:48:01 -07:00
|
|
|
inline void
|
2012-07-23 13:37:31 -07:00
|
|
|
SetProxyExtra(RawObject obj, size_t n, const Value &extra)
|
2010-09-20 14:48:01 -07:00
|
|
|
{
|
2011-10-04 07:06:54 -07:00
|
|
|
JS_ASSERT(IsProxy(obj));
|
2011-05-23 08:39:25 -07:00
|
|
|
JS_ASSERT(n <= 1);
|
|
|
|
SetReservedSlot(obj, JSSLOT_PROXY_EXTRA + n, extra);
|
2010-09-20 14:48:01 -07:00
|
|
|
}
|
|
|
|
|
2010-05-24 14:33:03 -07:00
|
|
|
JS_FRIEND_API(JSObject *)
|
2012-05-17 04:19:37 -07:00
|
|
|
NewProxyObject(JSContext *cx, BaseProxyHandler *handler, const Value &priv,
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject *proto, JSObject *parent,
|
2010-06-23 14:35:10 -07:00
|
|
|
JSObject *call = NULL, JSObject *construct = NULL);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2012-09-11 17:14:24 -07:00
|
|
|
JSObject *
|
|
|
|
RenewProxyObject(JSContext *cx, JSObject *obj, BaseProxyHandler *handler, Value priv);
|
|
|
|
|
2013-02-25 13:54:18 -08:00
|
|
|
class JS_FRIEND_API(AutoEnterPolicy)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef BaseProxyHandler::Action Action;
|
|
|
|
AutoEnterPolicy(JSContext *cx, BaseProxyHandler *handler,
|
|
|
|
JSObject *wrapper, jsid id, Action act, bool mayThrow)
|
2013-02-25 13:54:18 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
: context(NULL)
|
|
|
|
#endif
|
2013-02-25 13:54:18 -08:00
|
|
|
{
|
|
|
|
allow = handler->hasPolicy() ? handler->enter(cx, wrapper, id, act, &rv)
|
|
|
|
: true;
|
2013-02-25 13:54:18 -08:00
|
|
|
recordEnter(cx, wrapper, id);
|
2013-03-13 10:22:14 -07:00
|
|
|
if (!allow && !rv && mayThrow)
|
2013-02-25 13:54:18 -08:00
|
|
|
reportError(cx, id);
|
|
|
|
}
|
|
|
|
|
2013-02-25 13:54:18 -08:00
|
|
|
virtual ~AutoEnterPolicy() { recordLeave(); }
|
2013-02-25 13:54:18 -08:00
|
|
|
inline bool allowed() { return allow; }
|
|
|
|
inline bool returnValue() { JS_ASSERT(!allowed()); return rv; }
|
|
|
|
|
|
|
|
protected:
|
2013-02-25 13:54:18 -08:00
|
|
|
// no-op constructor for subclass
|
|
|
|
AutoEnterPolicy()
|
|
|
|
#ifdef DEBUG
|
|
|
|
: context(NULL)
|
|
|
|
#endif
|
|
|
|
{};
|
2013-02-25 13:54:18 -08:00
|
|
|
void reportError(JSContext *cx, jsid id);
|
|
|
|
bool allow;
|
|
|
|
bool rv;
|
2013-02-25 13:54:18 -08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSContext *context;
|
|
|
|
mozilla::Maybe<RootedObject> enteredProxy;
|
|
|
|
mozilla::Maybe<RootedId> enteredId;
|
|
|
|
// NB: We explicitly don't track the entered action here, because sometimes
|
|
|
|
// SET traps do an implicit GET during their implementation, leading to
|
|
|
|
// spurious assertions.
|
|
|
|
AutoEnterPolicy *prev;
|
|
|
|
void recordEnter(JSContext *cx, JSObject *proxy, jsid id);
|
|
|
|
void recordLeave();
|
|
|
|
|
|
|
|
friend JS_FRIEND_API(void) assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id);
|
|
|
|
#else
|
|
|
|
inline void recordEnter(JSContext *cx, JSObject *proxy, jsid id) {}
|
|
|
|
inline void recordLeave() {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
class JS_FRIEND_API(AutoWaivePolicy) : public AutoEnterPolicy {
|
|
|
|
public:
|
|
|
|
AutoWaivePolicy(JSContext *cx, JSObject *proxy, jsid id)
|
|
|
|
{
|
|
|
|
allow = true;
|
|
|
|
recordEnter(cx, proxy, id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
class JS_FRIEND_API(AutoWaivePolicy) {
|
|
|
|
public: AutoWaivePolicy(JSContext *cx, JSObject *proxy, jsid id) {};
|
2013-02-25 13:54:18 -08:00
|
|
|
};
|
2013-02-25 13:54:18 -08:00
|
|
|
#endif
|
2013-02-25 13:54:18 -08:00
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
} /* namespace js */
|
2010-05-24 14:33:03 -07:00
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2012-09-20 22:17:49 -07:00
|
|
|
js_InitProxyClass(JSContext *cx, JSHandleObject obj);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
|
|
|
#endif
|