Bug 1782289 [wpt PR 35277] - Move mojojs support out of fedcm-helper.js, a=testonly
[gecko.git] / ipc / testshell / XPCShellEnvironment.h
blobb479ec85b62d52ded05f82a4eb3256af7a257fee
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
6 #define _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
8 #include "base/basictypes.h"
10 #include <string>
11 #include <stdio.h>
13 #include "nsCOMPtr.h"
14 #include "nsDebug.h"
15 #include "nsString.h"
16 #include "nsJSPrincipals.h"
17 #include "nsContentUtils.h"
18 #include "js/RootingAPI.h"
19 #include "js/TypeDecls.h"
21 struct JSPrincipals;
23 namespace mozilla {
24 namespace ipc {
26 class XPCShellEnvironment {
27 public:
28 static XPCShellEnvironment* CreateEnvironment();
29 ~XPCShellEnvironment();
31 void ProcessFile(JSContext* cx, const char* filename, FILE* file,
32 bool forceTTY);
33 bool EvaluateString(const nsAString& aString, nsString* aResult = nullptr);
35 JSPrincipals* GetPrincipal() {
36 return nsJSPrincipals::get(nsContentUtils::GetSystemPrincipal());
39 JSObject* GetGlobalObject() { return mGlobalHolder; }
41 void SetIsQuitting() { mQuitting = true; }
42 bool IsQuitting() { return mQuitting; }
44 protected:
45 XPCShellEnvironment();
46 bool Init();
48 private:
49 JS::PersistentRooted<JSObject*> mGlobalHolder;
51 bool mQuitting;
54 } /* namespace ipc */
55 } /* namespace mozilla */
57 #endif /* _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ */