Source code

Revision control

Other Tools

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