Proxy.h (5219B)
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_Proxy_h 8 #define proxy_Proxy_h 9 10 #include "NamespaceImports.h" 11 12 #include "js/Array.h" // JS::IsArrayAnswer 13 #include "js/Class.h" 14 15 namespace js { 16 17 /* 18 * Dispatch point for handlers that executes the appropriate C++ or scripted 19 * traps. 20 * 21 * Important: All proxy methods need either (a) an AutoEnterPolicy in their 22 * Proxy::foo entry point below or (b) an override in SecurityWrapper. See bug 23 * 945826 comment 0. 24 */ 25 class Proxy { 26 public: 27 /* Standard internal methods. */ 28 static bool getOwnPropertyDescriptor( 29 JSContext* cx, HandleObject proxy, HandleId id, 30 MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc); 31 static bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id, 32 Handle<JS::PropertyDescriptor> desc, 33 ObjectOpResult& result); 34 static bool ownPropertyKeys(JSContext* cx, HandleObject proxy, 35 MutableHandleIdVector props); 36 static bool delete_(JSContext* cx, HandleObject proxy, HandleId id, 37 ObjectOpResult& result); 38 static bool enumerate(JSContext* cx, HandleObject proxy, 39 MutableHandleIdVector props); 40 static bool isExtensible(JSContext* cx, HandleObject proxy, bool* extensible); 41 static bool preventExtensions(JSContext* cx, HandleObject proxy, 42 ObjectOpResult& result); 43 static bool getPrototype(JSContext* cx, HandleObject proxy, 44 MutableHandleObject protop); 45 static bool setPrototype(JSContext* cx, HandleObject proxy, 46 HandleObject proto, ObjectOpResult& result); 47 static bool getPrototypeIfOrdinary(JSContext* cx, HandleObject proxy, 48 bool* isOrdinary, 49 MutableHandleObject protop); 50 static bool setImmutablePrototype(JSContext* cx, HandleObject proxy, 51 bool* succeeded); 52 static bool has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp); 53 static bool get(JSContext* cx, HandleObject proxy, HandleValue receiver, 54 HandleId id, MutableHandleValue vp); 55 static bool getInternal(JSContext* cx, HandleObject proxy, 56 HandleValue receiver, HandleId id, 57 MutableHandleValue vp); 58 static bool set(JSContext* cx, HandleObject proxy, HandleId id, HandleValue v, 59 HandleValue receiver, ObjectOpResult& result); 60 static bool setInternal(JSContext* cx, HandleObject proxy, HandleId id, 61 HandleValue v, HandleValue receiver, 62 ObjectOpResult& result); 63 static bool call(JSContext* cx, HandleObject proxy, const CallArgs& args); 64 static bool construct(JSContext* cx, HandleObject proxy, 65 const CallArgs& args); 66 67 /* SpiderMonkey extensions. */ 68 static bool hasOwn(JSContext* cx, HandleObject proxy, HandleId id, bool* bp); 69 static bool getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject proxy, 70 MutableHandleIdVector props); 71 static bool nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl, 72 const CallArgs& args); 73 static bool getBuiltinClass(JSContext* cx, HandleObject proxy, ESClass* cls); 74 static bool isArray(JSContext* cx, HandleObject proxy, 75 JS::IsArrayAnswer* answer); 76 static const char* className(JSContext* cx, HandleObject proxy); 77 static JSString* fun_toString(JSContext* cx, HandleObject proxy, 78 bool isToSource); 79 static RegExpShared* regexp_toShared(JSContext* cx, HandleObject proxy); 80 static bool boxedValue_unbox(JSContext* cx, HandleObject proxy, 81 MutableHandleValue vp); 82 83 static bool getElements(JSContext* cx, HandleObject obj, uint32_t begin, 84 uint32_t end, ElementAdder* adder); 85 86 static void trace(JSTracer* trc, JSObject* obj); 87 }; 88 89 size_t proxy_ObjectMoved(JSObject* obj, JSObject* old); 90 91 // These functions are used by JIT code 92 93 bool ProxyHas(JSContext* cx, HandleObject proxy, HandleValue idVal, 94 bool* result); 95 96 bool ProxyHasOwn(JSContext* cx, HandleObject proxy, HandleValue idVal, 97 bool* result); 98 99 bool ProxyGetProperty(JSContext* cx, HandleObject proxy, HandleId id, 100 MutableHandleValue vp); 101 102 bool ProxyGetPropertyByValue(JSContext* cx, HandleObject proxy, 103 HandleValue idVal, MutableHandleValue vp); 104 105 bool ProxySetProperty(JSContext* cx, HandleObject proxy, HandleId id, 106 HandleValue val, bool strict); 107 108 bool ProxySetPropertyByValue(JSContext* cx, HandleObject proxy, 109 HandleValue idVal, HandleValue val, bool strict); 110 } /* namespace js */ 111 112 #endif /* proxy_Proxy_h */