michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=99: */ 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 __ChromeObjectWrapper_h__ michael@0: #define __ChromeObjectWrapper_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include "FilteringWrapper.h" michael@0: michael@0: namespace xpc { michael@0: michael@0: struct ExposedPropertiesOnly; michael@0: michael@0: // When chrome JS objects are exposed to content, they get a ChromeObjectWrapper. michael@0: // michael@0: // The base filtering wrapper here does most of the work for us. We define a michael@0: // custom class here to introduce custom behavior with respect to the prototype michael@0: // chain. michael@0: #define ChromeObjectWrapperBase \ michael@0: FilteringWrapper michael@0: michael@0: class ChromeObjectWrapper : public ChromeObjectWrapperBase michael@0: { michael@0: public: michael@0: ChromeObjectWrapper() : ChromeObjectWrapperBase(0) {} michael@0: michael@0: /* Custom traps. */ michael@0: virtual bool getPropertyDescriptor(JSContext *cx, JS::Handle wrapper, michael@0: JS::Handle id, michael@0: JS::MutableHandle desc) MOZ_OVERRIDE; michael@0: virtual bool has(JSContext *cx, JS::Handle wrapper, michael@0: JS::Handle id, bool *bp) MOZ_OVERRIDE; michael@0: virtual bool get(JSContext *cx, JS::Handle wrapper, JS::Handle receiver, michael@0: JS::Handle id, JS::MutableHandle vp) MOZ_OVERRIDE; michael@0: michael@0: virtual bool objectClassIs(JS::Handle obj, js::ESClassValue classValue, michael@0: JSContext *cx) MOZ_OVERRIDE; michael@0: michael@0: virtual bool enter(JSContext *cx, JS::Handle wrapper, JS::Handle id, michael@0: js::Wrapper::Action act, bool *bp) MOZ_OVERRIDE; michael@0: michael@0: // NB: One might think we'd need to implement enumerate(), keys(), iterate(), michael@0: // and getPropertyNames() here. However, ES5 built-in properties aren't michael@0: // enumerable (and SpiderMonkey's implementation seems to match the spec michael@0: // modulo Error.prototype.fileName and Error.prototype.lineNumber). Since michael@0: // we're only remapping the prototypes of standard objects, there would michael@0: // never be anything more to enumerate up the prototype chain. So we can michael@0: // atually skip these. michael@0: michael@0: static ChromeObjectWrapper singleton; michael@0: }; michael@0: michael@0: } /* namespace xpc */ michael@0: michael@0: #endif /* __ChromeObjectWrapper_h__ */