2010-06-03 22:27:29 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99:
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
|
|
|
|
* May 28, 2008.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Andreas Gal <gal@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef jswrapper_h___
|
|
|
|
#define jswrapper_h___
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsproxy.h"
|
|
|
|
|
2011-09-09 03:29:15 +00:00
|
|
|
namespace js {
|
2010-09-26 03:05:36 +00:00
|
|
|
|
2010-06-03 22:27:29 +00:00
|
|
|
/* No-op wrapper handler base class. */
|
2011-09-09 03:29:15 +00:00
|
|
|
class JS_FRIEND_API(Wrapper) : public ProxyHandler
|
|
|
|
{
|
2010-07-02 20:54:53 +00:00
|
|
|
uintN mFlags;
|
2010-07-02 01:06:33 +00:00
|
|
|
public:
|
2010-07-02 20:54:53 +00:00
|
|
|
uintN flags() const { return mFlags; }
|
|
|
|
|
2011-09-09 03:29:15 +00:00
|
|
|
explicit Wrapper(uintN flags);
|
2010-07-02 20:54:53 +00:00
|
|
|
|
|
|
|
typedef enum { PermitObjectAccess, PermitPropertyAccess, DenyAccess } Permission;
|
|
|
|
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual ~Wrapper();
|
2010-06-03 22:27:29 +00:00
|
|
|
|
2010-07-02 20:54:53 +00:00
|
|
|
/* ES5 Harmony fundamental wrapper traps. */
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
2011-09-09 03:29:15 +00:00
|
|
|
PropertyDescriptor *desc);
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
2011-09-09 03:29:15 +00:00
|
|
|
PropertyDescriptor *desc);
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
2011-09-09 03:29:15 +00:00
|
|
|
PropertyDescriptor *desc);
|
|
|
|
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
|
|
|
|
virtual bool fix(JSContext *cx, JSObject *wrapper, Value *vp);
|
2010-07-02 20:54:53 +00:00
|
|
|
|
|
|
|
/* ES5 Harmony derived wrapper traps. */
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
|
|
|
|
virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp);
|
2011-02-09 19:31:40 +00:00
|
|
|
virtual bool set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, bool strict,
|
2011-09-09 03:29:15 +00:00
|
|
|
Value *vp);
|
|
|
|
virtual bool keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
|
|
|
|
virtual bool iterate(JSContext *cx, JSObject *wrapper, uintN flags, Value *vp);
|
2010-06-03 22:27:29 +00:00
|
|
|
|
|
|
|
/* Spidermonkey extensions. */
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool call(JSContext *cx, JSObject *wrapper, uintN argc, Value *vp);
|
|
|
|
virtual bool construct(JSContext *cx, JSObject *wrapper, uintN argc, Value *argv, Value *rval);
|
2011-09-09 04:06:41 +00:00
|
|
|
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp);
|
2010-11-10 23:56:00 +00:00
|
|
|
virtual JSType typeOf(JSContext *cx, JSObject *proxy);
|
2011-09-28 15:48:16 +00:00
|
|
|
virtual bool objectClassIs(JSObject *obj, ESClassValue classValue, JSContext *cx);
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual JSString *obj_toString(JSContext *cx, JSObject *wrapper);
|
|
|
|
virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, uintN indent);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp);
|
2010-07-02 20:54:53 +00:00
|
|
|
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual void trace(JSTracer *trc, JSObject *wrapper);
|
2010-07-02 20:54:53 +00:00
|
|
|
|
|
|
|
/* Policy enforcement traps. */
|
2010-09-17 21:54:40 +00:00
|
|
|
enum Action { GET, SET, CALL };
|
2011-01-30 02:48:30 +00:00
|
|
|
virtual bool enter(JSContext *cx, JSObject *wrapper, jsid id, Action act, bool *bp);
|
2010-10-10 22:36:04 +00:00
|
|
|
virtual void leave(JSContext *cx, JSObject *wrapper);
|
2010-06-03 22:27:29 +00:00
|
|
|
|
2011-09-09 03:29:15 +00:00
|
|
|
static Wrapper singleton;
|
2010-06-03 22:27:29 +00:00
|
|
|
|
2010-10-10 22:36:04 +00:00
|
|
|
static JSObject *New(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent,
|
2011-09-09 03:29:15 +00:00
|
|
|
Wrapper *handler);
|
2010-06-23 21:35:10 +00:00
|
|
|
|
2011-04-09 02:51:40 +00:00
|
|
|
static JSObject *wrappedObject(const JSObject *wrapper);
|
2011-09-09 03:29:15 +00:00
|
|
|
static Wrapper *wrapperHandler(const JSObject *wrapper);
|
2010-11-16 01:21:25 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
CROSS_COMPARTMENT = 1 << 0,
|
|
|
|
LAST_USED_FLAG = CROSS_COMPARTMENT
|
|
|
|
};
|
2010-09-20 21:48:01 +00:00
|
|
|
|
2010-10-10 22:36:04 +00:00
|
|
|
static void *getWrapperFamily();
|
2010-06-23 21:35:10 +00:00
|
|
|
};
|
|
|
|
|
2010-06-24 21:45:32 +00:00
|
|
|
/* Base class for all cross compartment wrapper handlers. */
|
2011-09-09 03:29:15 +00:00
|
|
|
class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper
|
|
|
|
{
|
2010-06-24 21:45:32 +00:00
|
|
|
public:
|
2011-09-09 03:29:15 +00:00
|
|
|
CrossCompartmentWrapper(uintN flags);
|
2010-06-25 22:58:09 +00:00
|
|
|
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual ~CrossCompartmentWrapper();
|
2010-06-24 21:45:32 +00:00
|
|
|
|
2010-07-02 20:54:53 +00:00
|
|
|
/* ES5 Harmony fundamental wrapper traps. */
|
2010-09-17 21:54:41 +00:00
|
|
|
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
2011-09-09 03:29:15 +00:00
|
|
|
PropertyDescriptor *desc);
|
2010-09-17 21:54:41 +00:00
|
|
|
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set,
|
2011-09-09 03:29:15 +00:00
|
|
|
PropertyDescriptor *desc);
|
2010-08-10 16:31:06 +00:00
|
|
|
virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
2011-09-09 03:29:15 +00:00
|
|
|
PropertyDescriptor *desc);
|
|
|
|
virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
|
2010-08-10 16:31:06 +00:00
|
|
|
virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
|
2010-07-02 20:54:53 +00:00
|
|
|
|
|
|
|
/* ES5 Harmony derived wrapper traps. */
|
2010-08-10 16:31:06 +00:00
|
|
|
virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
|
|
|
|
virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, Value *vp);
|
2011-02-09 19:31:40 +00:00
|
|
|
virtual bool set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, bool strict,
|
2011-09-09 03:29:15 +00:00
|
|
|
Value *vp);
|
|
|
|
virtual bool keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props);
|
|
|
|
virtual bool iterate(JSContext *cx, JSObject *wrapper, uintN flags, Value *vp);
|
2010-06-24 21:45:32 +00:00
|
|
|
|
|
|
|
/* Spidermonkey extensions. */
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool call(JSContext *cx, JSObject *wrapper, uintN argc, Value *vp);
|
|
|
|
virtual bool construct(JSContext *cx, JSObject *wrapper, uintN argc, Value *argv, Value *rval);
|
2011-09-09 04:06:41 +00:00
|
|
|
virtual bool nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs args);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool hasInstance(JSContext *cx, JSObject *wrapper, const Value *vp, bool *bp);
|
2010-08-10 16:31:06 +00:00
|
|
|
virtual JSString *obj_toString(JSContext *cx, JSObject *wrapper);
|
|
|
|
virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, uintN indent);
|
2011-09-09 03:29:15 +00:00
|
|
|
virtual bool defaultValue(JSContext *cx, JSObject *wrapper, JSType hint, Value *vp);
|
2010-06-24 21:45:32 +00:00
|
|
|
|
2011-07-08 00:31:24 +00:00
|
|
|
virtual void trace(JSTracer *trc, JSObject *wrapper);
|
|
|
|
|
2011-09-09 03:29:15 +00:00
|
|
|
static CrossCompartmentWrapper singleton;
|
2010-06-24 21:45:32 +00:00
|
|
|
};
|
|
|
|
|
2011-09-09 03:29:15 +00:00
|
|
|
/*
|
|
|
|
* A hacky class that lets a friend force a fake frame. We must already be
|
|
|
|
* in the compartment of |target| when we enter the forced frame.
|
|
|
|
*/
|
2011-05-02 22:47:10 +00:00
|
|
|
class JS_FRIEND_API(ForceFrame)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
JSContext * const context;
|
|
|
|
JSObject * const target;
|
|
|
|
private:
|
2011-06-07 23:43:18 +00:00
|
|
|
DummyFrameGuard *frame;
|
2011-05-02 22:47:10 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
ForceFrame(JSContext *cx, JSObject *target);
|
2011-05-24 15:45:36 +00:00
|
|
|
~ForceFrame();
|
2011-05-02 22:47:10 +00:00
|
|
|
bool enter();
|
|
|
|
};
|
|
|
|
|
2010-06-24 21:45:32 +00:00
|
|
|
extern JSObject *
|
2010-09-17 21:54:40 +00:00
|
|
|
TransparentObjectWrapper(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSObject *parent,
|
|
|
|
uintN flags);
|
2010-06-24 21:45:32 +00:00
|
|
|
|
2011-10-04 14:06:54 +00:00
|
|
|
JS_FRIEND_API(bool) IsWrapper(const JSObject *obj);
|
|
|
|
JS_FRIEND_API(JSObject *) UnwrapObject(JSObject *obj, uintN *flagsp = NULL);
|
|
|
|
bool IsCrossCompartmentWrapper(const JSObject *obj);
|
|
|
|
|
|
|
|
} /* namespace js */
|
2010-06-03 22:27:29 +00:00
|
|
|
|
|
|
|
#endif
|