Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/js/ipc/WrapperOwner.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 * vim: set ts=8 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_WrapperOwner_h__
9
#define mozilla_jsipc_WrapperOwner_h__
10
11
#include "JavaScriptShared.h"
12
#include "mozilla/ipc/ProtocolUtils.h"
13
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
14
#include "js/Class.h"
15
#include "js/Proxy.h"
16
17
namespace mozilla {
18
namespace jsipc {
19
20
class WrapperOwner : public virtual JavaScriptShared
21
{
22
  public:
23
    typedef mozilla::ipc::IProtocol::ActorDestroyReason
24
           ActorDestroyReason;
25
26
    WrapperOwner();
27
28
    // Standard internal methods.
29
    // (The traps should be in the same order like js/Proxy.h)
30
    bool getOwnPropertyDescriptor(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
31
                                  JS::MutableHandle<JS::PropertyDescriptor> desc);
32
    bool defineProperty(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
33
                        JS::Handle<JS::PropertyDescriptor> desc,
34
                        JS::ObjectOpResult& result);
35
    bool ownPropertyKeys(JSContext* cx, JS::HandleObject proxy, JS::AutoIdVector& props);
36
    bool delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
37
                 JS::ObjectOpResult& result);
38
    bool preventExtensions(JSContext* cx, JS::HandleObject proxy, JS::ObjectOpResult& result);
39
    bool isExtensible(JSContext* cx, JS::HandleObject proxy, bool* extensible);
40
    bool has(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, bool* bp);
41
    bool get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue receiver,
42
             JS::HandleId id, JS::MutableHandleValue vp);
43
    bool set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue v,
44
             JS::HandleValue receiver, JS::ObjectOpResult& result);
45
    bool callOrConstruct(JSContext* cx, JS::HandleObject proxy, const JS::CallArgs& args,
46
                         bool construct);
47
48
    // SpiderMonkey extensions.
49
    bool hasOwn(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, bool* bp);
50
    bool getOwnEnumerablePropertyKeys(JSContext* cx, JS::HandleObject proxy,
51
                                      JS::AutoIdVector& props);
52
    bool hasInstance(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool* bp);
53
    bool getBuiltinClass(JSContext* cx, JS::HandleObject proxy, js::ESClass* cls);
54
    bool isArray(JSContext* cx, JS::HandleObject proxy, JS::IsArrayAnswer* answer);
55
    const char* className(JSContext* cx, JS::HandleObject proxy);
56
    bool getPrototype(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleObject protop);
57
    bool getPrototypeIfOrdinary(JSContext* cx, JS::HandleObject proxy, bool* isOrdinary,
58
                                JS::MutableHandleObject protop);
59
60
    js::RegExpShared* regexp_toShared(JSContext* cx, JS::HandleObject proxy);
61
62
    nsresult instanceOf(JSObject* obj, const nsID* id, bool* bp);
63
64
    bool toString(JSContext* cx, JS::HandleObject callee, JS::CallArgs& args);
65
    bool DOMQI(JSContext* cx, JS::HandleObject callee, JS::CallArgs& args);
66
67
    /*
68
     * Check that |obj| is a DOM wrapper whose prototype chain contains
69
     * |prototypeID| at depth |depth|.
70
     */
71
    bool domInstanceOf(JSContext* cx, JSObject* obj, int prototypeID, int depth, bool* bp);
72
73
0
    bool active() { return !inactive_; }
74
75
    virtual bool allowMessage(JSContext* cx) = 0;
76
77
    void drop(JSObject* obj);
78
    void updatePointer(JSObject* obj, const JSObject* old);
79
80
    virtual void ActorDestroy(ActorDestroyReason why);
81
82
    virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp) override;
83
    virtual JSObject* fromObjectVariant(JSContext* cx, const ObjectVariant& objVar) override;
84
    JSObject* fromRemoteObjectVariant(JSContext* cx, const RemoteObject& objVar);
85
    JSObject* fromLocalObjectVariant(JSContext* cx, const LocalObject& objVar);
86
87
  protected:
88
    ObjectId idOf(JSObject* obj);
89
90
  private:
91
    ObjectId idOfUnchecked(JSObject* obj);
92
93
    bool getPropertyKeys(JSContext* cx, JS::HandleObject proxy, uint32_t flags,
94
                         JS::AutoIdVector& props);
95
96
    // Catastrophic IPC failure.
97
    bool ipcfail(JSContext* cx);
98
99
    // Check whether a return status is okay, and if not, propagate its error.
100
    //
101
    // If 'status' might be a ReturnObjectOpResult, which is only possible for
102
    // a subset of the operations below, 'result' must be passed.
103
    bool ok(JSContext* cx, const ReturnStatus& status, JS::ObjectOpResult& result);
104
    bool ok(JSContext* cx, const ReturnStatus& status);
105
106
    bool inactive_;
107
108
    /*** Dummy call handlers ***/
109
  public:
110
    virtual bool SendDropObject(const ObjectId& objId) = 0;
111
    virtual bool SendPreventExtensions(const ObjectId& objId, ReturnStatus* rs) = 0;
112
    virtual bool SendGetOwnPropertyDescriptor(const ObjectId& objId,
113
                                              const JSIDVariant& id,
114
                                              ReturnStatus* rs,
115
                                              PPropertyDescriptor* out) = 0;
116
    virtual bool SendDefineProperty(const ObjectId& objId, const JSIDVariant& id,
117
                                    const PPropertyDescriptor& flags,
118
                                    ReturnStatus* rs) = 0;
119
    virtual bool SendDelete(const ObjectId& objId, const JSIDVariant& id,
120
                            ReturnStatus* rs) = 0;
121
122
    virtual bool SendHas(const ObjectId& objId, const JSIDVariant& id,
123
                         ReturnStatus* rs, bool* bp) = 0;
124
    virtual bool SendHasOwn(const ObjectId& objId, const JSIDVariant& id,
125
                            ReturnStatus* rs, bool* bp) = 0;
126
    virtual bool SendGet(const ObjectId& objId, const JSVariant& receiverVar,
127
                         const JSIDVariant& id,
128
                         ReturnStatus* rs, JSVariant* result) = 0;
129
    virtual bool SendSet(const ObjectId& objId, const JSIDVariant& id, const JSVariant& value,
130
                         const JSVariant& receiverVar, ReturnStatus* rs) = 0;
131
132
    virtual bool SendIsExtensible(const ObjectId& objId, ReturnStatus* rs,
133
                                  bool* result) = 0;
134
    virtual bool SendCallOrConstruct(const ObjectId& objId, const nsTArray<JSParam>& argv,
135
                                     const bool& construct, ReturnStatus* rs, JSVariant* result,
136
                                     nsTArray<JSParam>* outparams) = 0;
137
    virtual bool SendHasInstance(const ObjectId& objId, const JSVariant& v,
138
                                 ReturnStatus* rs, bool* bp) = 0;
139
    virtual bool SendGetBuiltinClass(const ObjectId& objId, ReturnStatus* rs,
140
                                     uint32_t* classValue) = 0;
141
    virtual bool SendIsArray(const ObjectId& objId, ReturnStatus* rs,
142
                             uint32_t* answer) = 0;
143
    virtual bool SendClassName(const ObjectId& objId, nsCString* result) = 0;
144
    virtual bool SendGetPrototype(const ObjectId& objId, ReturnStatus* rs, ObjectOrNullVariant* result) = 0;
145
    virtual bool SendGetPrototypeIfOrdinary(const ObjectId& objId, ReturnStatus* rs, bool* isOrdinary,
146
                                            ObjectOrNullVariant* result) = 0;
147
    virtual bool SendRegExpToShared(const ObjectId& objId, ReturnStatus* rs, nsString* source,
148
                                    uint32_t* flags) = 0;
149
150
    virtual bool SendGetPropertyKeys(const ObjectId& objId, const uint32_t& flags,
151
                                     ReturnStatus* rs, nsTArray<JSIDVariant>* ids) = 0;
152
    virtual bool SendInstanceOf(const ObjectId& objId, const JSIID& iid,
153
                                ReturnStatus* rs, bool* instanceof) = 0;
154
    virtual bool SendDOMInstanceOf(const ObjectId& objId, const int& prototypeID, const int& depth,
155
                                   ReturnStatus* rs, bool* instanceof) = 0;
156
};
157
158
} // namespace jsipc
159
} // namespace mozilla
160
161
#endif // mozilla_jsipc_WrapperOwner_h__