js/ipc/JavaScriptParent.h

branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
equal deleted inserted replaced
-1:000000000000 0:450eefbd0623
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=80:
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8 #ifndef mozilla_jsipc_JavaScriptParent__
9 #define mozilla_jsipc_JavaScriptParent__
10
11 #include "JavaScriptShared.h"
12 #include "mozilla/jsipc/PJavaScriptParent.h"
13 #include "js/Class.h"
14
15 #ifdef XP_WIN
16 #undef GetClassName
17 #undef GetClassInfo
18 #endif
19
20 namespace mozilla {
21 namespace jsipc {
22
23 class JavaScriptParent
24 : public PJavaScriptParent,
25 public JavaScriptShared
26 {
27 public:
28 JavaScriptParent();
29
30 bool init();
31
32 public:
33 // Fundamental proxy traps. These are required.
34 // (The traps should be in the same order like js/src/jsproxy.h)
35 bool preventExtensions(JSContext *cx, JS::HandleObject proxy);
36 bool getPropertyDescriptor(JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
37 JS::MutableHandle<JSPropertyDescriptor> desc);
38 bool getOwnPropertyDescriptor(JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
39 JS::MutableHandle<JSPropertyDescriptor> desc);
40 bool defineProperty(JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
41 JS::MutableHandle<JSPropertyDescriptor> desc);
42 bool getOwnPropertyNames(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props);
43 bool delete_(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp);
44 bool enumerate(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props);
45
46 // Derived proxy traps. Implementing these is useful for perfomance.
47 bool has(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp);
48 bool hasOwn(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp);
49 bool get(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver,
50 JS::HandleId id, JS::MutableHandleValue vp);
51 bool set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver,
52 JS::HandleId id, bool strict, JS::MutableHandleValue vp);
53 bool keys(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props);
54 // We use "iterate" provided by the base class here.
55
56 // SpiderMonkey Extensions.
57 bool isExtensible(JSContext *cx, JS::HandleObject proxy, bool *extensible);
58 bool call(JSContext *cx, JS::HandleObject proxy, const JS::CallArgs &args);
59 bool objectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValue);
60 const char* className(JSContext *cx, JS::HandleObject proxy);
61
62 virtual void ActorDestroy(ActorDestroyReason why);
63
64 void decref();
65 void incref();
66
67 bool active() { return !inactive_; }
68
69 void drop(JSObject *obj);
70
71 static bool IsCPOW(JSObject *obj);
72
73 static nsresult InstanceOf(JSObject *obj, const nsID *id, bool *bp);
74 nsresult instanceOf(JSObject *obj, const nsID *id, bool *bp);
75
76 /*
77 * Check that |obj| is a DOM wrapper whose prototype chain contains
78 * |prototypeID| at depth |depth|.
79 */
80 static bool DOMInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp);
81 bool domInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp);
82
83 mozilla::ipc::IProtocol*
84 CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
85
86 protected:
87 JSObject *unwrap(JSContext *cx, ObjectId objId);
88
89 private:
90 bool makeId(JSContext *cx, JSObject *obj, ObjectId *idp);
91 bool getPropertyNames(JSContext *cx, JS::HandleObject proxy, uint32_t flags,
92 JS::AutoIdVector &props);
93 ObjectId idOf(JSObject *obj);
94
95 // Catastrophic IPC failure.
96 bool ipcfail(JSContext *cx);
97
98 // Check whether a return status is okay, and if not, propagate its error.
99 bool ok(JSContext *cx, const ReturnStatus &status);
100
101 private:
102 uintptr_t refcount_;
103 bool inactive_;
104 };
105
106 } // jsipc
107 } // mozilla
108
109 #endif // mozilla_jsipc_JavaScriptWrapper_h__
110

mercurial