michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=4 sw=4 et tw=80: michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_jsipc_JavaScriptParent__ michael@0: #define mozilla_jsipc_JavaScriptParent__ michael@0: michael@0: #include "JavaScriptShared.h" michael@0: #include "mozilla/jsipc/PJavaScriptParent.h" michael@0: #include "js/Class.h" michael@0: michael@0: #ifdef XP_WIN michael@0: #undef GetClassName michael@0: #undef GetClassInfo michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace jsipc { michael@0: michael@0: class JavaScriptParent michael@0: : public PJavaScriptParent, michael@0: public JavaScriptShared michael@0: { michael@0: public: michael@0: JavaScriptParent(); michael@0: michael@0: bool init(); michael@0: michael@0: public: michael@0: // Fundamental proxy traps. These are required. michael@0: // (The traps should be in the same order like js/src/jsproxy.h) michael@0: bool preventExtensions(JSContext *cx, JS::HandleObject proxy); michael@0: bool getPropertyDescriptor(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, michael@0: JS::MutableHandle desc); michael@0: bool getOwnPropertyDescriptor(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, michael@0: JS::MutableHandle desc); michael@0: bool defineProperty(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, michael@0: JS::MutableHandle desc); michael@0: bool getOwnPropertyNames(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props); michael@0: bool delete_(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp); michael@0: bool enumerate(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props); michael@0: michael@0: // Derived proxy traps. Implementing these is useful for perfomance. michael@0: bool has(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp); michael@0: bool hasOwn(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, bool *bp); michael@0: bool get(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver, michael@0: JS::HandleId id, JS::MutableHandleValue vp); michael@0: bool set(JSContext *cx, JS::HandleObject proxy, JS::HandleObject receiver, michael@0: JS::HandleId id, bool strict, JS::MutableHandleValue vp); michael@0: bool keys(JSContext *cx, JS::HandleObject proxy, JS::AutoIdVector &props); michael@0: // We use "iterate" provided by the base class here. michael@0: michael@0: // SpiderMonkey Extensions. michael@0: bool isExtensible(JSContext *cx, JS::HandleObject proxy, bool *extensible); michael@0: bool call(JSContext *cx, JS::HandleObject proxy, const JS::CallArgs &args); michael@0: bool objectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValue); michael@0: const char* className(JSContext *cx, JS::HandleObject proxy); michael@0: michael@0: virtual void ActorDestroy(ActorDestroyReason why); michael@0: michael@0: void decref(); michael@0: void incref(); michael@0: michael@0: bool active() { return !inactive_; } michael@0: michael@0: void drop(JSObject *obj); michael@0: michael@0: static bool IsCPOW(JSObject *obj); michael@0: michael@0: static nsresult InstanceOf(JSObject *obj, const nsID *id, bool *bp); michael@0: nsresult instanceOf(JSObject *obj, const nsID *id, bool *bp); michael@0: michael@0: /* michael@0: * Check that |obj| is a DOM wrapper whose prototype chain contains michael@0: * |prototypeID| at depth |depth|. michael@0: */ michael@0: static bool DOMInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp); michael@0: bool domInstanceOf(JSContext *cx, JSObject *obj, int prototypeID, int depth, bool *bp); michael@0: michael@0: mozilla::ipc::IProtocol* michael@0: CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: JSObject *unwrap(JSContext *cx, ObjectId objId); michael@0: michael@0: private: michael@0: bool makeId(JSContext *cx, JSObject *obj, ObjectId *idp); michael@0: bool getPropertyNames(JSContext *cx, JS::HandleObject proxy, uint32_t flags, michael@0: JS::AutoIdVector &props); michael@0: ObjectId idOf(JSObject *obj); michael@0: michael@0: // Catastrophic IPC failure. michael@0: bool ipcfail(JSContext *cx); michael@0: michael@0: // Check whether a return status is okay, and if not, propagate its error. michael@0: bool ok(JSContext *cx, const ReturnStatus &status); michael@0: michael@0: private: michael@0: uintptr_t refcount_; michael@0: bool inactive_; michael@0: }; michael@0: michael@0: } // jsipc michael@0: } // mozilla michael@0: michael@0: #endif // mozilla_jsipc_JavaScriptWrapper_h__ michael@0: