Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=99: */
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/. */
7 #ifndef __ChromeObjectWrapper_h__
8 #define __ChromeObjectWrapper_h__
10 #include "mozilla/Attributes.h"
12 #include "FilteringWrapper.h"
14 namespace xpc {
16 struct ExposedPropertiesOnly;
18 // When chrome JS objects are exposed to content, they get a ChromeObjectWrapper.
19 //
20 // The base filtering wrapper here does most of the work for us. We define a
21 // custom class here to introduce custom behavior with respect to the prototype
22 // chain.
23 #define ChromeObjectWrapperBase \
24 FilteringWrapper<js::CrossCompartmentSecurityWrapper, ExposedPropertiesOnly>
26 class ChromeObjectWrapper : public ChromeObjectWrapperBase
27 {
28 public:
29 ChromeObjectWrapper() : ChromeObjectWrapperBase(0) {}
31 /* Custom traps. */
32 virtual bool getPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> wrapper,
33 JS::Handle<jsid> id,
34 JS::MutableHandle<JSPropertyDescriptor> desc) MOZ_OVERRIDE;
35 virtual bool has(JSContext *cx, JS::Handle<JSObject*> wrapper,
36 JS::Handle<jsid> id, bool *bp) MOZ_OVERRIDE;
37 virtual bool get(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> receiver,
38 JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) MOZ_OVERRIDE;
40 virtual bool objectClassIs(JS::Handle<JSObject*> obj, js::ESClassValue classValue,
41 JSContext *cx) MOZ_OVERRIDE;
43 virtual bool enter(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
44 js::Wrapper::Action act, bool *bp) MOZ_OVERRIDE;
46 // NB: One might think we'd need to implement enumerate(), keys(), iterate(),
47 // and getPropertyNames() here. However, ES5 built-in properties aren't
48 // enumerable (and SpiderMonkey's implementation seems to match the spec
49 // modulo Error.prototype.fileName and Error.prototype.lineNumber). Since
50 // we're only remapping the prototypes of standard objects, there would
51 // never be anything more to enumerate up the prototype chain. So we can
52 // atually skip these.
54 static ChromeObjectWrapper singleton;
55 };
57 } /* namespace xpc */
59 #endif /* __ChromeObjectWrapper_h__ */