Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/js/ipc/JavaScriptChild.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=4 sw=4 et tw=80:
3
 *
4
 * This Source Code Form is subject to the terms of the Mozilla Public
5
 * License, v. 2.0. If a copy of the MPL was not distributed with this
6
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8
#include "JavaScriptChild.h"
9
#include "mozilla/dom/ContentChild.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/ipc/MessageChannel.h"
12
#include "nsContentUtils.h"
13
#include "xpcprivate.h"
14
#include "jsfriendapi.h"
15
#include "AccessCheck.h"
16
17
using namespace JS;
18
using namespace mozilla;
19
using namespace mozilla::jsipc;
20
21
using mozilla::AutoSafeJSContext;
22
23
static void
24
UpdateChildWeakPointersBeforeSweepingZoneGroup(JSContext* cx, void* data)
25
0
{
26
0
    static_cast<JavaScriptChild*>(data)->updateWeakPointers();
27
0
}
28
29
static void
30
TraceChild(JSTracer* trc, void* data)
31
0
{
32
0
    static_cast<JavaScriptChild*>(data)->trace(trc);
33
0
}
34
35
JavaScriptChild::~JavaScriptChild()
36
0
{
37
0
    JSContext* cx = dom::danger::GetJSContext();
38
0
    JS_RemoveWeakPointerZonesCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup);
39
0
    JS_RemoveExtraGCRootsTracer(cx, TraceChild, this);
40
0
}
41
42
bool
43
JavaScriptChild::init()
44
0
{
45
0
    JSContext* cx = dom::danger::GetJSContext();
46
0
    JS_AddWeakPointerZonesCallback(cx, UpdateChildWeakPointersBeforeSweepingZoneGroup, this);
47
0
    JS_AddExtraGCRootsTracer(cx, TraceChild, this);
48
0
    return true;
49
0
}
50
51
void
52
JavaScriptChild::trace(JSTracer* trc)
53
0
{
54
0
    objects_.trace(trc, strongReferenceObjIdMinimum_);
55
0
}
56
57
void
58
JavaScriptChild::updateWeakPointers()
59
0
{
60
0
    objects_.sweep();
61
0
    unwaivedObjectIds_.sweep();
62
0
    waivedObjectIds_.sweep();
63
0
}
64
65
JSObject*
66
JavaScriptChild::scopeForTargetObjects()
67
0
{
68
0
    // CPOWs from the parent need to point into the child's privileged junk
69
0
    // scope so that they can benefit from XrayWrappers in the child.
70
0
    return xpc::PrivilegedJunkScope();
71
0
}
72
73
mozilla::ipc::IPCResult
74
JavaScriptChild::RecvDropTemporaryStrongReferences(const uint64_t& upToObjId)
75
0
{
76
0
    strongReferenceObjIdMinimum_ = upToObjId + 1;
77
0
    return IPC_OK();
78
0
}
79
80
PJavaScriptChild*
81
mozilla::jsipc::NewJavaScriptChild()
82
0
{
83
0
    JavaScriptChild* child = new JavaScriptChild();
84
0
    if (!child->init()) {
85
0
        delete child;
86
0
        return nullptr;
87
0
    }
88
0
    return child;
89
0
}
90
91
void
92
mozilla::jsipc::ReleaseJavaScriptChild(PJavaScriptChild* child)
93
0
{
94
0
    static_cast<JavaScriptChild*>(child)->decref();
95
0
}