Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef proxy_DeadObjectProxy_h
8
#define proxy_DeadObjectProxy_h
9
10
#include "js/Proxy.h"
11
12
namespace js {
13
14
class ProxyObject;
15
16
enum DeadObjectProxyFlags {
17
DeadObjectProxyIsCallable = 1 << 0,
18
DeadObjectProxyIsConstructor = 1 << 1,
19
DeadObjectProxyIsBackgroundFinalized = 1 << 2
20
};
21
22
class DeadObjectProxy : public BaseProxyHandler {
23
public:
24
explicit constexpr DeadObjectProxy() : BaseProxyHandler(&family) {}
25
26
/* Standard internal methods. */
27
virtual bool getOwnPropertyDescriptor(
28
JSContext* cx, HandleObject wrapper, HandleId id,
29
MutableHandle<PropertyDescriptor> desc) const override;
30
virtual bool defineProperty(JSContext* cx, HandleObject wrapper, HandleId id,
31
Handle<PropertyDescriptor> desc,
32
ObjectOpResult& result) const override;
33
virtual bool ownPropertyKeys(JSContext* cx, HandleObject wrapper,
34
MutableHandleIdVector props) const override;
35
virtual bool delete_(JSContext* cx, HandleObject wrapper, HandleId id,
36
ObjectOpResult& result) const override;
37
virtual bool getPrototype(JSContext* cx, HandleObject proxy,
38
MutableHandleObject protop) const override;
39
virtual bool getPrototypeIfOrdinary(
40
JSContext* cx, HandleObject proxy, bool* isOrdinary,
41
MutableHandleObject protop) const override;
42
virtual bool preventExtensions(JSContext* cx, HandleObject proxy,
43
ObjectOpResult& result) const override;
44
virtual bool isExtensible(JSContext* cx, HandleObject proxy,
45
bool* extensible) const override;
46
virtual bool call(JSContext* cx, HandleObject proxy,
47
const CallArgs& args) const override;
48
virtual bool construct(JSContext* cx, HandleObject proxy,
49
const CallArgs& args) const override;
50
51
/* SpiderMonkey extensions. */
52
// BaseProxyHandler::enumerate will throw by calling ownKeys.
53
virtual bool nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
54
const CallArgs& args) const override;
55
virtual bool hasInstance(JSContext* cx, HandleObject proxy,
56
MutableHandleValue v, bool* bp) const override;
57
virtual bool getBuiltinClass(JSContext* cx, HandleObject proxy,
58
ESClass* cls) const override;
59
virtual bool isArray(JSContext* cx, HandleObject proxy,
60
JS::IsArrayAnswer* answer) const override;
61
virtual const char* className(JSContext* cx,
62
HandleObject proxy) const override;
63
virtual JSString* fun_toString(JSContext* cx, HandleObject proxy,
64
bool isToSource) const override;
65
virtual RegExpShared* regexp_toShared(JSContext* cx,
66
HandleObject proxy) const override;
67
68
virtual bool isCallable(JSObject* obj) const override {
69
return flags(obj) & DeadObjectProxyIsCallable;
70
}
71
virtual bool isConstructor(JSObject* obj) const override {
72
return flags(obj) & DeadObjectProxyIsConstructor;
73
}
74
75
virtual bool finalizeInBackground(const JS::Value& priv) const override {
76
return priv.toInt32() & DeadObjectProxyIsBackgroundFinalized;
77
}
78
79
static const DeadObjectProxy singleton;
80
static const char family;
81
82
private:
83
static int32_t flags(JSObject* obj) { return GetProxyPrivate(obj).toInt32(); }
84
};
85
86
bool IsDeadProxyObject(JSObject* obj);
87
88
Value DeadProxyTargetValue(ProxyObject* obj);
89
90
JSObject* NewDeadProxyObject(JSContext* cx, JSObject* origObj = nullptr);
91
92
enum class IsCallableFlag : bool { False, True };
93
enum class IsConstructorFlag : bool { False, True };
94
95
JSObject* NewDeadProxyObject(JSContext* cx, IsCallableFlag isCallable,
96
IsConstructorFlag isConstructor);
97
98
} /* namespace js */
99
100
#endif /* proxy_DeadObjectProxy_h */