1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/ipc/JavaScriptParent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=4 sw=4 et tw=80: 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#ifndef mozilla_jsipc_JavaScriptParent__ 1.12 +#define mozilla_jsipc_JavaScriptParent__ 1.13 + 1.14 +#include "JavaScriptShared.h" 1.15 +#include "mozilla/jsipc/PJavaScriptParent.h" 1.16 +#include "js/Class.h" 1.17 + 1.18 +#ifdef XP_WIN 1.19 +#undef GetClassName 1.20 +#undef GetClassInfo 1.21 +#endif 1.22 + 1.23 +namespace mozilla { 1.24 +namespace jsipc { 1.25 + 1.26 +class JavaScriptParent 1.27 + : public PJavaScriptParent, 1.28 + public JavaScriptShared 1.29 +{ 1.30 + public: 1.31 + JavaScriptParent(); 1.32 + 1.33 + bool init(); 1.34 + 1.35 + public: 1.36 + // Fundamental proxy traps. These are required. 1.37 + // (The traps should be in the same order like js/src/jsproxy.h) 1.38 + bool preventExtensions(JSContext *cx, JS::HandleObject proxy); 1.39 + bool getPropertyDescriptor(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, 1.40 + JS::MutableHandle<JSPropertyDescriptor> desc); 1.41 + bool getOwnPropertyDescriptor(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, 1.42 + JS::MutableHandle<JSPropertyDescriptor> desc); 1.43 + bool defineProperty(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, 1.44 + JS::MutableHandle<JSPropertyDescriptor> desc); 1.45 + bool getOwnPropertyNames(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props); 1.46 + bool delete_(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp); 1.47 + bool enumerate(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props); 1.48 + 1.49 + // Derived proxy traps. Implementing these is useful for perfomance. 1.50 + bool has(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp); 1.51 + bool hasOwn(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp); 1.52 + bool get(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver, 1.53 + JS::HandleId id, JS::MutableHandleValue vp); 1.54 + bool set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver, 1.55 + JS::HandleId id, bool strict, JS::MutableHandleValue vp); 1.56 + bool keys(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props); 1.57 + // We use "iterate" provided by the base class here. 1.58 + 1.59 + // SpiderMonkey Extensions. 1.60 + bool isExtensible(JSContext *cx, JS::HandleObject proxy, bool *extensible); 1.61 + bool call(JSContext *cx, JS::HandleObject proxy, const JS::CallArgs &args); 1.62 + bool objectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValue); 1.63 + const char* className(JSContext *cx, JS::HandleObject proxy); 1.64 + 1.65 + virtual void ActorDestroy(ActorDestroyReason why); 1.66 + 1.67 + void decref(); 1.68 + void incref(); 1.69 + 1.70 + bool active() { return !inactive_; } 1.71 + 1.72 + void drop(JSObject *obj); 1.73 + 1.74 + static bool IsCPOW(JSObject *obj); 1.75 + 1.76 + static nsresult InstanceOf(JSObject *obj, const nsID *id, bool *bp); 1.77 + nsresult instanceOf(JSObject *obj, const nsID *id, bool *bp); 1.78 + 1.79 + /* 1.80 + * Check that |obj| is a DOM wrapper whose prototype chain contains 1.81 + * |prototypeID| at depth |depth|. 1.82 + */ 1.83 + static bool DOMInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp); 1.84 + bool domInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp); 1.85 + 1.86 + mozilla::ipc::IProtocol* 1.87 + CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx) MOZ_OVERRIDE; 1.88 + 1.89 + protected: 1.90 + JSObject *unwrap(JSContext *cx, ObjectId objId); 1.91 + 1.92 + private: 1.93 + bool makeId(JSContext *cx, JSObject *obj, ObjectId *idp); 1.94 + bool getPropertyNames(JSContext *cx, JS::HandleObject proxy, uint32_t flags, 1.95 + JS::AutoIdVector &props); 1.96 + ObjectId idOf(JSObject *obj); 1.97 + 1.98 + // Catastrophic IPC failure. 1.99 + bool ipcfail(JSContext *cx); 1.100 + 1.101 + // Check whether a return status is okay, and if not, propagate its error. 1.102 + bool ok(JSContext *cx, const ReturnStatus &status); 1.103 + 1.104 + private: 1.105 + uintptr_t refcount_; 1.106 + bool inactive_; 1.107 +}; 1.108 + 1.109 +} // jsipc 1.110 +} // mozilla 1.111 + 1.112 +#endif // mozilla_jsipc_JavaScriptWrapper_h__ 1.113 +