Line data Source code
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/. */
6 :
7 : #include "jsapi.h"
8 : #include "jswrapper.h"
9 :
10 : #include "jsatominlines.h"
11 :
12 : using namespace js;
13 :
14 : template <class Base>
15 : bool
16 0 : SecurityWrapper<Base>::enter(JSContext* cx, HandleObject wrapper, HandleId id,
17 : Wrapper::Action act, bool mayThrow, bool* bp) const
18 : {
19 0 : ReportAccessDenied(cx);
20 0 : *bp = false;
21 0 : return false;
22 : }
23 :
24 : template <class Base>
25 : bool
26 0 : SecurityWrapper<Base>::nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
27 : const CallArgs& args) const
28 : {
29 0 : ReportAccessDenied(cx);
30 0 : return false;
31 : }
32 :
33 : template <class Base>
34 : bool
35 0 : SecurityWrapper<Base>::setPrototype(JSContext* cx, HandleObject wrapper, HandleObject proto,
36 : ObjectOpResult& result) const
37 : {
38 0 : ReportAccessDenied(cx);
39 0 : return false;
40 : }
41 :
42 : template <class Base>
43 : bool
44 0 : SecurityWrapper<Base>::setImmutablePrototype(JSContext* cx, HandleObject wrapper,
45 : bool* succeeded) const
46 : {
47 0 : ReportAccessDenied(cx);
48 0 : return false;
49 : }
50 :
51 : template <class Base>
52 : bool
53 0 : SecurityWrapper<Base>::preventExtensions(JSContext* cx, HandleObject wrapper,
54 : ObjectOpResult& result) const
55 : {
56 : // Just like BaseProxyHandler, SecurityWrappers claim by default to always
57 : // be extensible, so as not to leak information about the state of the
58 : // underlying wrapped thing.
59 0 : return result.fail(JSMSG_CANT_CHANGE_EXTENSIBILITY);
60 : }
61 :
62 : template <class Base>
63 : bool
64 0 : SecurityWrapper<Base>::isExtensible(JSContext* cx, HandleObject wrapper, bool* extensible) const
65 : {
66 : // See above.
67 0 : *extensible = true;
68 0 : return true;
69 : }
70 :
71 : template <class Base>
72 : bool
73 0 : SecurityWrapper<Base>::getBuiltinClass(JSContext* cx, HandleObject wrapper,
74 : ESClass* cls) const
75 : {
76 0 : *cls = ESClass::Other;
77 0 : return true;
78 : }
79 :
80 : template <class Base>
81 : bool
82 0 : SecurityWrapper<Base>::isArray(JSContext* cx, HandleObject obj, JS::IsArrayAnswer* answer) const
83 : {
84 : // This should ReportAccessDenied(cx), but bug 849730 disagrees. :-(
85 0 : *answer = JS::IsArrayAnswer::NotArray;
86 0 : return true;
87 : }
88 :
89 : template <class Base>
90 : RegExpShared*
91 0 : SecurityWrapper<Base>::regexp_toShared(JSContext* cx, HandleObject obj) const
92 : {
93 0 : return Base::regexp_toShared(cx, obj);
94 : }
95 :
96 : template <class Base>
97 : bool
98 0 : SecurityWrapper<Base>::boxedValue_unbox(JSContext* cx, HandleObject obj, MutableHandleValue vp) const
99 : {
100 0 : vp.setUndefined();
101 0 : return true;
102 : }
103 :
104 : template <class Base>
105 : bool
106 0 : SecurityWrapper<Base>::defineProperty(JSContext* cx, HandleObject wrapper, HandleId id,
107 : Handle<PropertyDescriptor> desc,
108 : ObjectOpResult& result) const
109 : {
110 0 : if (desc.getter() || desc.setter()) {
111 0 : RootedValue idVal(cx, IdToValue(id));
112 0 : JSString* str = ValueToSource(cx, idVal);
113 0 : if (!str)
114 0 : return false;
115 0 : AutoStableStringChars chars(cx);
116 0 : const char16_t* prop = nullptr;
117 0 : if (str->ensureFlat(cx) && chars.initTwoByte(cx, str))
118 0 : prop = chars.twoByteChars();
119 0 : JS_ReportErrorNumberUC(cx, GetErrorMessage, nullptr,
120 : JSMSG_ACCESSOR_DEF_DENIED, prop);
121 0 : return false;
122 : }
123 :
124 0 : return Base::defineProperty(cx, wrapper, id, desc, result);
125 : }
126 :
127 : template <class Base>
128 : bool
129 0 : SecurityWrapper<Base>::watch(JSContext* cx, HandleObject proxy,
130 : HandleId id, HandleObject callable) const
131 : {
132 0 : ReportAccessDenied(cx);
133 0 : return false;
134 : }
135 :
136 : template <class Base>
137 : bool
138 0 : SecurityWrapper<Base>::unwatch(JSContext* cx, HandleObject proxy,
139 : HandleId id) const
140 : {
141 0 : ReportAccessDenied(cx);
142 0 : return false;
143 : }
144 :
145 :
146 : template class js::SecurityWrapper<Wrapper>;
147 : template class js::SecurityWrapper<CrossCompartmentWrapper>;
|