Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/js/xpconnect/wrappers/WaiveXrayWrapper.cpp
Line
Count
Source (jump to first uncovered line)
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 "WaiveXrayWrapper.h"
8
#include "WrapperFactory.h"
9
#include "jsapi.h"
10
11
using namespace JS;
12
13
namespace xpc {
14
15
static bool
16
WaiveAccessors(JSContext* cx, MutableHandle<PropertyDescriptor> desc)
17
0
{
18
0
    if (desc.hasGetterObject() && desc.getterObject()) {
19
0
        RootedValue v(cx, JS::ObjectValue(*desc.getterObject()));
20
0
        if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) {
21
0
            return false;
22
0
        }
23
0
        desc.setGetterObject(&v.toObject());
24
0
    }
25
0
26
0
    if (desc.hasSetterObject() && desc.setterObject()) {
27
0
        RootedValue v(cx, JS::ObjectValue(*desc.setterObject()));
28
0
        if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) {
29
0
            return false;
30
0
        }
31
0
        desc.setSetterObject(&v.toObject());
32
0
    }
33
0
    return true;
34
0
}
35
36
bool
37
WaiveXrayWrapper::getPropertyDescriptor(JSContext* cx, HandleObject wrapper, HandleId id,
38
                                        MutableHandle<PropertyDescriptor> desc) const
39
0
{
40
0
    return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, desc) &&
41
0
           WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc);
42
0
}
43
44
bool
45
WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext* cx, HandleObject wrapper, HandleId id,
46
                                           MutableHandle<PropertyDescriptor> desc) const
47
0
{
48
0
    return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc) &&
49
0
           WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc);
50
0
}
51
52
bool
53
WaiveXrayWrapper::get(JSContext* cx, HandleObject wrapper, HandleValue receiver, HandleId id,
54
                      MutableHandleValue vp) const
55
0
{
56
0
    return CrossCompartmentWrapper::get(cx, wrapper, receiver, id, vp) &&
57
0
           WrapperFactory::WaiveXrayAndWrap(cx, vp);
58
0
}
59
60
JSObject*
61
WaiveXrayWrapper::enumerate(JSContext* cx, HandleObject proxy) const
62
0
{
63
0
    RootedObject obj(cx, CrossCompartmentWrapper::enumerate(cx, proxy));
64
0
    if (!obj) {
65
0
        return nullptr;
66
0
    }
67
0
    if (!WrapperFactory::WaiveXrayAndWrap(cx, &obj)) {
68
0
        return nullptr;
69
0
    }
70
0
    return obj;
71
0
}
72
73
bool
74
WaiveXrayWrapper::call(JSContext* cx, HandleObject wrapper, const JS::CallArgs& args) const
75
0
{
76
0
    return CrossCompartmentWrapper::call(cx, wrapper, args) &&
77
0
           WrapperFactory::WaiveXrayAndWrap(cx, args.rval());
78
0
}
79
80
bool
81
WaiveXrayWrapper::construct(JSContext* cx, HandleObject wrapper, const JS::CallArgs& args) const
82
0
{
83
0
    return CrossCompartmentWrapper::construct(cx, wrapper, args) &&
84
0
           WrapperFactory::WaiveXrayAndWrap(cx, args.rval());
85
0
}
86
87
// NB: This is important as the other side of a handshake with FieldGetter. See
88
// nsXBLProtoImplField.cpp.
89
bool
90
WaiveXrayWrapper::nativeCall(JSContext* cx, JS::IsAcceptableThis test,
91
                             JS::NativeImpl impl, const JS::CallArgs& args) const
92
0
{
93
0
    return CrossCompartmentWrapper::nativeCall(cx, test, impl, args) &&
94
0
           WrapperFactory::WaiveXrayAndWrap(cx, args.rval());
95
0
}
96
97
bool
98
WaiveXrayWrapper::getPrototype(JSContext* cx, HandleObject wrapper, MutableHandleObject protop) const
99
0
{
100
0
    return CrossCompartmentWrapper::getPrototype(cx, wrapper, protop) &&
101
0
           (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop));
102
0
}
103
104
bool
105
WaiveXrayWrapper::getPrototypeIfOrdinary(JSContext* cx, HandleObject wrapper, bool* isOrdinary,
106
                                         MutableHandleObject protop) const
107
0
{
108
0
    return CrossCompartmentWrapper::getPrototypeIfOrdinary(cx, wrapper, isOrdinary, protop) &&
109
0
           (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop));
110
0
}
111
112
} // namespace xpc