js/xpconnect/wrappers/ChromeObjectWrapper.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/wrappers/ChromeObjectWrapper.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=99: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef __ChromeObjectWrapper_h__
    1.11 +#define __ChromeObjectWrapper_h__
    1.12 +
    1.13 +#include "mozilla/Attributes.h"
    1.14 +
    1.15 +#include "FilteringWrapper.h"
    1.16 +
    1.17 +namespace xpc {
    1.18 +
    1.19 +struct ExposedPropertiesOnly;
    1.20 +
    1.21 +// When chrome JS objects are exposed to content, they get a ChromeObjectWrapper.
    1.22 +//
    1.23 +// The base filtering wrapper here does most of the work for us. We define a
    1.24 +// custom class here to introduce custom behavior with respect to the prototype
    1.25 +// chain.
    1.26 +#define ChromeObjectWrapperBase \
    1.27 +  FilteringWrapper<js::CrossCompartmentSecurityWrapper, ExposedPropertiesOnly>
    1.28 +
    1.29 +class ChromeObjectWrapper : public ChromeObjectWrapperBase
    1.30 +{
    1.31 +  public:
    1.32 +    ChromeObjectWrapper() : ChromeObjectWrapperBase(0) {}
    1.33 +
    1.34 +    /* Custom traps. */
    1.35 +    virtual bool getPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> wrapper,
    1.36 +                                       JS::Handle<jsid> id,
    1.37 +                                       JS::MutableHandle<JSPropertyDescriptor> desc) MOZ_OVERRIDE;
    1.38 +    virtual bool has(JSContext *cx, JS::Handle<JSObject*> wrapper,
    1.39 +                     JS::Handle<jsid> id, bool *bp) MOZ_OVERRIDE;
    1.40 +    virtual bool get(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> receiver,
    1.41 +                     JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) MOZ_OVERRIDE;
    1.42 +
    1.43 +    virtual bool objectClassIs(JS::Handle<JSObject*> obj, js::ESClassValue classValue,
    1.44 +                               JSContext *cx) MOZ_OVERRIDE;
    1.45 +
    1.46 +    virtual bool enter(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
    1.47 +                       js::Wrapper::Action act, bool *bp) MOZ_OVERRIDE;
    1.48 +
    1.49 +    // NB: One might think we'd need to implement enumerate(), keys(), iterate(),
    1.50 +    // and getPropertyNames() here. However, ES5 built-in properties aren't
    1.51 +    // enumerable (and SpiderMonkey's implementation seems to match the spec
    1.52 +    // modulo Error.prototype.fileName and Error.prototype.lineNumber). Since
    1.53 +    // we're only remapping the prototypes of standard objects, there would
    1.54 +    // never be anything more to enumerate up the prototype chain. So we can
    1.55 +    // atually skip these.
    1.56 +
    1.57 +    static ChromeObjectWrapper singleton;
    1.58 +};
    1.59 +
    1.60 +} /* namespace xpc */
    1.61 +
    1.62 +#endif /* __ChromeObjectWrapper_h__ */

mercurial