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 frontend_BytecodeCompilation_h
8 #define frontend_BytecodeCompilation_h
9 
10 #include "mozilla/Assertions.h"  // MOZ_ASSERT
11 #include "mozilla/Attributes.h"  // MOZ_MUST_USE, MOZ_STACK_CLASS
12 #include "mozilla/Maybe.h"       // mozilla::Maybe, mozilla::Nothing
13 #include "mozilla/Utf8.h"        // mozilla::Utf8Unit
14 
15 #include <stddef.h>  // size_t
16 #include <stdint.h>  // uint32_t
17 
18 #include "jstypes.h"  // JS_PUBLIC_API
19 
20 #include "frontend/CompilationInfo.h"
21 #include "frontend/ParseContext.h"  // js::frontend::UsedNameTracker
22 #include "frontend/SharedContext.h"  // js::frontend::Directives, js::frontend::{,Eval,Global}SharedContext
23 #include "js/CompileOptions.h"  // JS::ReadOnlyCompileOptions
24 #include "js/RootingAPI.h"      // JS::{,Mutable}Handle, JS::Rooted
25 #include "js/SourceText.h"      // JS::SourceText
26 #include "vm/JSScript.h"  // js::{FunctionAsync,Generator}Kind, js::BaseScript, JSScript, js::ScriptSource, js::ScriptSourceObject
27 #include "vm/Scope.h"     // js::ScopeKind
28 
29 class JS_PUBLIC_API JSFunction;
30 class JS_PUBLIC_API JSObject;
31 
32 namespace js {
33 
34 namespace frontend {
35 
36 struct BytecodeEmitter;
37 class EitherParser;
38 
39 template <typename Unit>
40 class SourceAwareCompiler;
41 template <typename Unit>
42 class ScriptCompiler;
43 template <typename Unit>
44 class ModuleCompiler;
45 template <typename Unit>
46 class StandaloneFunctionCompiler;
47 
48 extern JSScript* CompileGlobalScript(CompilationInfo& compilationInfo,
49                                      GlobalSharedContext& globalsc,
50                                      JS::SourceText<char16_t>& srcBuf);
51 
52 extern JSScript* CompileGlobalScript(CompilationInfo& compilationInfo,
53                                      GlobalSharedContext& globalsc,
54                                      JS::SourceText<mozilla::Utf8Unit>& srcBuf);
55 
56 extern JSScript* CompileEvalScript(CompilationInfo& compilationInfo,
57                                    EvalSharedContext& evalsc,
58                                    JS::SourceText<char16_t>& srcBuf);
59 
60 extern MOZ_MUST_USE bool CompileLazyFunction(JSContext* cx,
61                                              JS::Handle<BaseScript*> lazy,
62                                              const char16_t* units,
63                                              size_t length);
64 
65 extern MOZ_MUST_USE bool CompileLazyFunction(JSContext* cx,
66                                              JS::Handle<BaseScript*> lazy,
67                                              const mozilla::Utf8Unit* units,
68                                              size_t length);
69 
70 }  // namespace frontend
71 
72 }  // namespace js
73 
74 #endif  // frontend_BytecodeCompilation_h
75