| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 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 "NamespaceImports.h" |
| 8 |
|
| 9 |
#include "js/friend/ErrorMessages.h" // JSMSG_* |
| 10 |
#include "js/Wrapper.h" |
| 11 |
#include "vm/JSObject.h" |
| 12 |
#include "vm/StringType.h" |
| 13 |
|
| 14 |
using namespace js; |
| 15 |
|
| 16 |
template <class Base> |
| 17 |
bool SecurityWrapper<Base>::enter(JSContext* cx, HandleObject wrapper, |
| 18 |
HandleId id, Wrapper::Action act, |
| 19 |
bool mayThrow, bool* bp) const { |
| 20 |
ReportAccessDenied(cx); |
| 21 |
*bp = false; |
| 22 |
return false; |
| 23 |
} |
| 24 |
|
| 25 |
template <class Base> |
| 26 |
bool SecurityWrapper<Base>::nativeCall(JSContext* cx, IsAcceptableThis test, |
| 27 |
NativeImpl impl, |
| 28 |
const CallArgs& args) const { |
| 29 |
ReportAccessDenied(cx); |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
template <class Base> |
| 34 |
bool SecurityWrapper<Base>::setPrototype(JSContext* cx, HandleObject wrapper, |
| 35 |
HandleObject proto, |
| 36 |
ObjectOpResult& result) const { |
| 37 |
ReportAccessDenied(cx); |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
template <class Base> |
| 42 |
bool SecurityWrapper<Base>::setImmutablePrototype(JSContext* cx, |
| 43 |
HandleObject wrapper, |
| 44 |
bool* succeeded) const { |
| 45 |
ReportAccessDenied(cx); |
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
template <class Base> |
| 50 |
bool SecurityWrapper<Base>::preventExtensions(JSContext* cx, |
| 51 |
HandleObject wrapper, |
| 52 |
ObjectOpResult& result) const { |
| 53 |
// Just like BaseProxyHandler, SecurityWrappers claim by default to always |
| 54 |
// be extensible, so as not to leak information about the state of the |
| 55 |
// underlying wrapped thing. |
| 56 |
return result.fail(JSMSG_CANT_CHANGE_EXTENSIBILITY); |
| 57 |
} |
| 58 |
|
| 59 |
template <class Base> |
| 60 |
bool SecurityWrapper<Base>::isExtensible(JSContext* cx, HandleObject wrapper, |
| 61 |
bool* extensible) const { |
| 62 |
// See above. |
| 63 |
*extensible = true; |
| 64 |
return true; |
| 65 |
} |
| 66 |
|
| 67 |
template <class Base> |
| 68 |
bool SecurityWrapper<Base>::getBuiltinClass(JSContext* cx, HandleObject wrapper, |
| 69 |
ESClass* cls) const { |
| 70 |
*cls = ESClass::Other; |
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
template <class Base> |
| 75 |
bool SecurityWrapper<Base>::isArray(JSContext* cx, HandleObject obj, |
| 76 |
JS::IsArrayAnswer* answer) const { |
| 77 |
// This should ReportAccessDenied(cx), but bug 849730 disagrees. :-( |
| 78 |
*answer = JS::IsArrayAnswer::NotArray; |
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
template <class Base> |
| 83 |
RegExpShared* SecurityWrapper<Base>::regexp_toShared(JSContext* cx, |
| 84 |
HandleObject obj) const { |
| 85 |
return Base::regexp_toShared(cx, obj); |
| 86 |
} |
| 87 |
|
| 88 |
template <class Base> |
| 89 |
bool SecurityWrapper<Base>::boxedValue_unbox(JSContext* cx, HandleObject obj, |
| 90 |
MutableHandleValue vp) const { |
| 91 |
vp.setUndefined(); |
| 92 |
return true; |
| 93 |
} |
| 94 |
|
| 95 |
template <class Base> |
| 96 |
bool SecurityWrapper<Base>::defineProperty(JSContext* cx, HandleObject wrapper, |
| 97 |
HandleId id, |
| 98 |
Handle<PropertyDescriptor> desc, |
| 99 |
ObjectOpResult& result) const { |
| 100 |
if (desc.isAccessorDescriptor()) { |
| 101 |
return Throw(cx, id, JSMSG_ACCESSOR_DEF_DENIED); |
| 102 |
} |
| 103 |
|
| 104 |
return Base::defineProperty(cx, wrapper, id, desc, result); |
| 105 |
} |
| 106 |
|
| 107 |
template class js::SecurityWrapper<Wrapper>; |
| 108 |
template class js::SecurityWrapper<CrossCompartmentWrapper>; |