Bumping manifests a=b2g-bump
[gecko.git] / js / ipc / JavaScriptChild.cpp
blobfafc74af9222caa4a551c77361a89b6568c34e79
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=80:
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/. */
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"
17 using namespace JS;
18 using namespace mozilla;
19 using namespace mozilla::jsipc;
21 using mozilla::AutoSafeJSContext;
23 static void
24 UpdateChildWeakPointersAfterGC(JSRuntime* rt, void* data)
26 static_cast<JavaScriptChild*>(data)->updateWeakPointers();
29 JavaScriptChild::JavaScriptChild(JSRuntime* rt)
30 : JavaScriptShared(rt),
31 JavaScriptBase<PJavaScriptChild>(rt)
35 JavaScriptChild::~JavaScriptChild()
37 JS_RemoveWeakPointerCallback(rt_, UpdateChildWeakPointersAfterGC);
40 bool
41 JavaScriptChild::init()
43 if (!WrapperOwner::init())
44 return false;
45 if (!WrapperAnswer::init())
46 return false;
48 JS_AddWeakPointerCallback(rt_, UpdateChildWeakPointersAfterGC, this);
49 return true;
52 void
53 JavaScriptChild::updateWeakPointers()
55 objects_.sweep();
56 unwaivedObjectIds_.sweep();
57 waivedObjectIds_.sweep();
60 JSObject*
61 JavaScriptChild::scopeForTargetObjects()
63 // CPOWs from the parent need to point into the child's privileged junk
64 // scope so that they can benefit from XrayWrappers in the child.
65 return xpc::PrivilegedJunkScope();