JSOracleChild.cpp (1620B)
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 "mozilla/dom/JSOracleChild.h" 8 9 #include "mozilla/ClearOnShutdown.h" 10 #include "mozilla/dom/JSValidatorChild.h" 11 #include "mozilla/dom/PJSValidatorChild.h" 12 #include "mozilla/ipc/Endpoint.h" 13 14 using namespace mozilla::dom; 15 16 static mozilla::StaticRefPtr<JSOracleChild> sOracleSingletonChild; 17 18 static mozilla::StaticAutoPtr<JSFrontendContextHolder> sJSFrontendContextHolder; 19 20 /* static */ 21 void JSFrontendContextHolder::MaybeInit() { 22 if (!sJSFrontendContextHolder) { 23 sJSFrontendContextHolder = new JSFrontendContextHolder(); 24 ClearOnShutdown(&sJSFrontendContextHolder); 25 } 26 } 27 28 /* static */ 29 JS::FrontendContext* JSOracleChild::JSFrontendContext() { 30 MOZ_ASSERT(sJSFrontendContextHolder); 31 return sJSFrontendContextHolder->mFc; 32 } 33 34 JSOracleChild* JSOracleChild::GetSingleton() { 35 MOZ_ASSERT(NS_IsMainThread()); 36 if (!sOracleSingletonChild) { 37 sOracleSingletonChild = new JSOracleChild(); 38 ClearOnShutdown(&sOracleSingletonChild); 39 } 40 return sOracleSingletonChild; 41 } 42 43 already_AddRefed<PJSValidatorChild> JSOracleChild::AllocPJSValidatorChild() { 44 return MakeAndAddRef<JSValidatorChild>(); 45 } 46 47 void JSOracleChild::Start(Endpoint<PJSOracleChild>&& aEndpoint) { 48 DebugOnly<bool> ok = std::move(aEndpoint).Bind(this); 49 JSFrontendContextHolder::MaybeInit(); 50 MOZ_ASSERT(ok); 51 }