| 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 NurseryAllocableProxyHandler { |
| 23 |
public: |
| 24 |
explicit constexpr DeadObjectProxy() |
| 25 |
: NurseryAllocableProxyHandler(&family) {} |
| 26 |
|
| 27 |
/* Standard internal methods. */ |
| 28 |
virtual bool getOwnPropertyDescriptor( |
| 29 |
JSContext* cx, JS::HandleObject wrapper, JS::HandleId id, |
| 30 |
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) |
| 31 |
const override; |
| 32 |
virtual bool defineProperty(JSContext* cx, JS::HandleObject wrapper, |
| 33 |
JS::HandleId id, |
| 34 |
JS::Handle<JS::PropertyDescriptor> desc, |
| 35 |
JS::ObjectOpResult& result) const override; |
| 36 |
virtual bool ownPropertyKeys(JSContext* cx, JS::HandleObject wrapper, |
| 37 |
JS::MutableHandleIdVector props) const override; |
| 38 |
virtual bool delete_(JSContext* cx, JS::HandleObject wrapper, JS::HandleId id, |
| 39 |
JS::ObjectOpResult& result) const override; |
| 40 |
virtual bool getPrototype(JSContext* cx, JS::HandleObject proxy, |
| 41 |
JS::MutableHandleObject protop) const override; |
| 42 |
virtual bool getPrototypeIfOrdinary( |
| 43 |
JSContext* cx, JS::HandleObject proxy, bool* isOrdinary, |
| 44 |
JS::MutableHandleObject protop) const override; |
| 45 |
virtual bool preventExtensions(JSContext* cx, JS::HandleObject proxy, |
| 46 |
JS::ObjectOpResult& result) const override; |
| 47 |
virtual bool isExtensible(JSContext* cx, JS::HandleObject proxy, |
| 48 |
bool* extensible) const override; |
| 49 |
virtual bool call(JSContext* cx, JS::HandleObject proxy, |
| 50 |
const JS::CallArgs& args) const override; |
| 51 |
virtual bool construct(JSContext* cx, JS::HandleObject proxy, |
| 52 |
const JS::CallArgs& args) const override; |
| 53 |
|
| 54 |
/* SpiderMonkey extensions. */ |
| 55 |
// BaseProxyHandler::enumerate will throw by calling ownKeys. |
| 56 |
virtual bool nativeCall(JSContext* cx, JS::IsAcceptableThis test, |
| 57 |
JS::NativeImpl impl, |
| 58 |
const JS::CallArgs& args) const override; |
| 59 |
virtual bool getBuiltinClass(JSContext* cx, JS::HandleObject proxy, |
| 60 |
ESClass* cls) const override; |
| 61 |
virtual bool isArray(JSContext* cx, JS::HandleObject proxy, |
| 62 |
JS::IsArrayAnswer* answer) const override; |
| 63 |
virtual const char* className(JSContext* cx, |
| 64 |
JS::HandleObject proxy) const override; |
| 65 |
virtual JSString* fun_toString(JSContext* cx, JS::HandleObject proxy, |
| 66 |
bool isToSource) const override; |
| 67 |
virtual RegExpShared* regexp_toShared(JSContext* cx, |
| 68 |
JS::HandleObject proxy) const override; |
| 69 |
|
| 70 |
// Use the regular paths for private values |
| 71 |
virtual bool useProxyExpandoObjectForPrivateFields() const override { |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
virtual bool isCallable(JSObject* obj) const override { |
| 76 |
return flags(obj) & DeadObjectProxyIsCallable; |
| 77 |
} |
| 78 |
virtual bool isConstructor(JSObject* obj) const override { |
| 79 |
return flags(obj) & DeadObjectProxyIsConstructor; |
| 80 |
} |
| 81 |
|
| 82 |
virtual bool finalizeInBackground(const JS::Value& priv) const override { |
| 83 |
return priv.toInt32() & DeadObjectProxyIsBackgroundFinalized; |
| 84 |
} |
| 85 |
|
| 86 |
static const DeadObjectProxy singleton; |
| 87 |
static const char family; |
| 88 |
|
| 89 |
private: |
| 90 |
static int32_t flags(JSObject* obj) { return GetProxyPrivate(obj).toInt32(); } |
| 91 |
}; |
| 92 |
|
| 93 |
bool IsDeadProxyObject(const JSObject* obj); |
| 94 |
|
| 95 |
JS::Value DeadProxyTargetValue(JSObject* obj); |
| 96 |
|
| 97 |
JSObject* NewDeadProxyObject(JSContext* cx, JSObject* origObj = nullptr); |
| 98 |
|
| 99 |
} /* namespace js */ |
| 100 |
|
| 101 |
#endif /* proxy_DeadObjectProxy_h */ |