JSOracleChild.h (1785B)
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 #ifndef mozilla_dom_JSOracleChild 8 #define mozilla_dom_JSOracleChild 9 10 #include "js/Initialization.h" 11 #include "js/experimental/CompileScript.h" 12 #include "js/experimental/JSStencil.h" 13 #include "jsapi.h" 14 #include "mozilla/dom/PJSOracleChild.h" 15 16 namespace mozilla::ipc { 17 class UtilityProcessParent; 18 } 19 20 namespace mozilla::dom { 21 struct JSFrontendContextHolder { 22 JSFrontendContextHolder() { 23 MOZ_RELEASE_ASSERT(JS_IsInitialized(), 24 "UtilityProcessChild::Init should have JS initialized"); 25 26 mFc = JS::NewFrontendContext(); 27 if (!mFc) { 28 MOZ_CRASH("Failed to create JS FrontendContext"); 29 return; 30 } 31 32 // See the comment in XPCJSContext::Initialize. 33 const size_t kDefaultStackQuota = 128 * sizeof(size_t) * 1024; 34 35 JS::SetNativeStackQuota(mFc, kDefaultStackQuota); 36 } 37 38 ~JSFrontendContextHolder() { 39 if (mFc) { 40 JS::DestroyFrontendContext(mFc); 41 } 42 } 43 44 static void MaybeInit(); 45 46 JS::FrontendContext* mFc; 47 }; 48 49 class PJSValidatorChild; 50 51 class JSOracleChild final : public PJSOracleChild { 52 public: 53 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(JSOracleChild, override); 54 55 already_AddRefed<PJSValidatorChild> AllocPJSValidatorChild(); 56 57 void Start(Endpoint<PJSOracleChild>&& aEndpoint); 58 59 static JS::FrontendContext* JSFrontendContext(); 60 61 private: 62 ~JSOracleChild() = default; 63 64 static JSOracleChild* GetSingleton(); 65 }; 66 } // namespace mozilla::dom 67 68 #endif // defined(mozilla_dom_JSOracleChild)