Bug 588735 - Mirror glass caption buttons for rtl windows. r=roc, a=blocking-betaN.
[mozilla-central.git] / js / src / jswrapper.h
blobab34106517d341398210ba488cf332c3510d492b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
18 * May 28, 2008.
20 * The Initial Developer of the Original Code is
21 * Mozilla Foundation
22 * Portions created by the Initial Developer are Copyright (C) 2010
23 * the Initial Developer. All Rights Reserved.
25 * Contributor(s):
26 * Andreas Gal <gal@mozilla.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef jswrapper_h___
43 #define jswrapper_h___
45 #include "jsapi.h"
46 #include "jsproxy.h"
48 /* No-op wrapper handler base class. */
49 class JSWrapper : public js::JSProxyHandler {
50 uintN mFlags;
51 public:
52 uintN flags() const { return mFlags; }
54 explicit JS_FRIEND_API(JSWrapper(uintN flags));
56 typedef enum { PermitObjectAccess, PermitPropertyAccess, DenyAccess } Permission;
58 JS_FRIEND_API(virtual ~JSWrapper());
60 /* ES5 Harmony fundamental wrapper traps. */
61 virtual JS_FRIEND_API(bool) getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
62 js::PropertyDescriptor *desc);
63 virtual JS_FRIEND_API(bool) getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
64 js::PropertyDescriptor *desc);
65 virtual JS_FRIEND_API(bool) defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
66 js::PropertyDescriptor *desc);
67 virtual JS_FRIEND_API(bool) getOwnPropertyNames(JSContext *cx, JSObject *wrapper,
68 js::AutoIdVector &props);
69 virtual JS_FRIEND_API(bool) delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
70 virtual JS_FRIEND_API(bool) enumerate(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props);
71 virtual JS_FRIEND_API(bool) fix(JSContext *cx, JSObject *wrapper, js::Value *vp);
73 /* ES5 Harmony derived wrapper traps. */
74 virtual JS_FRIEND_API(bool) has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
75 virtual JS_FRIEND_API(bool) hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
76 virtual JS_FRIEND_API(bool) get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id,
77 js::Value *vp);
78 virtual JS_FRIEND_API(bool) set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id,
79 js::Value *vp);
80 virtual JS_FRIEND_API(bool) enumerateOwn(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props);
81 virtual JS_FRIEND_API(bool) iterate(JSContext *cx, JSObject *wrapper, uintN flags, js::Value *vp);
83 /* Spidermonkey extensions. */
84 virtual JS_FRIEND_API(bool) call(JSContext *cx, JSObject *wrapper, uintN argc, js::Value *vp);
85 virtual JS_FRIEND_API(bool) construct(JSContext *cx, JSObject *wrapper,
86 uintN argc, js::Value *argv, js::Value *rval);
87 virtual JS_FRIEND_API(JSString *) obj_toString(JSContext *cx, JSObject *wrapper);
88 virtual JS_FRIEND_API(JSString *) fun_toString(JSContext *cx, JSObject *wrapper, uintN indent);
90 virtual JS_FRIEND_API(void) trace(JSTracer *trc, JSObject *wrapper);
92 /* Policy enforcement traps. */
93 virtual JS_FRIEND_API(bool) enter(JSContext *cx, JSObject *wrapper, jsid id, bool set);
94 virtual JS_FRIEND_API(void) leave(JSContext *cx, JSObject *wrapper);
96 static JS_FRIEND_API(JSWrapper) singleton;
98 static JS_FRIEND_API(JSObject *) New(JSContext *cx, JSObject *obj,
99 JSObject *proto, JSObject *parent,
100 JSWrapper *handler);
102 static inline JSObject *wrappedObject(JSObject *wrapper) {
103 return wrapper->getProxyPrivate().toObjectOrNull();
107 /* Base class for all cross compartment wrapper handlers. */
108 class JS_FRIEND_API(JSCrossCompartmentWrapper) : public JSWrapper {
109 public:
110 JSCrossCompartmentWrapper(uintN flags);
112 virtual ~JSCrossCompartmentWrapper();
114 /* ES5 Harmony fundamental wrapper traps. */
115 virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
116 js::PropertyDescriptor *desc);
117 virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
118 js::PropertyDescriptor *desc);
119 virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
120 js::PropertyDescriptor *desc);
121 virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props);
122 virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
123 virtual bool enumerate(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props);
125 /* ES5 Harmony derived wrapper traps. */
126 virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
127 virtual bool hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
128 virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, js::Value *vp);
129 virtual bool set(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, js::Value *vp);
130 virtual bool enumerateOwn(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props);
131 virtual bool iterate(JSContext *cx, JSObject *wrapper, uintN flags, js::Value *vp);
133 /* Spidermonkey extensions. */
134 virtual bool call(JSContext *cx, JSObject *wrapper, uintN argc, js::Value *vp);
135 virtual bool construct(JSContext *cx, JSObject *wrapper,
136 uintN argc, js::Value *argv, js::Value *rval);
137 virtual JSString *obj_toString(JSContext *cx, JSObject *wrapper);
138 virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, uintN indent);
140 static bool isCrossCompartmentWrapper(JSObject *obj);
142 static JSCrossCompartmentWrapper singleton;
145 namespace js {
147 class AutoCompartment
149 public:
150 JSContext * const context;
151 JSCompartment * const origin;
152 JSObject * const target;
153 JSCompartment * const destination;
154 private:
155 LazilyConstructed<FrameGuard> frame;
156 JSFrameRegs regs;
157 RegExpStatics statics;
158 AutoStringRooter input;
159 bool entered;
161 public:
162 AutoCompartment(JSContext *cx, JSObject *target);
163 ~AutoCompartment();
165 bool enter();
166 void leave();
168 private:
169 // Prohibit copying.
170 AutoCompartment(const AutoCompartment &);
171 AutoCompartment & operator=(const AutoCompartment &);
174 extern JSObject *
175 TransparentObjectWrapper(JSContext *cx, JSObject *obj, JSObject *wrappedProto, uintN flags);
179 #endif