/work/obj-fuzz/dist/include/js/Transcoding.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | /* |
7 | | * Structures and functions for transcoding compiled scripts and functions to |
8 | | * and from memory. |
9 | | */ |
10 | | |
11 | | #ifndef js_Transcoding_h |
12 | | #define js_Transcoding_h |
13 | | |
14 | | #include "mozilla/Range.h" // mozilla::Range |
15 | | #include "mozilla/Vector.h" // mozilla::Vector |
16 | | |
17 | | #include <stddef.h> // size_t |
18 | | #include <stdint.h> // uint8_t, uint32_t |
19 | | |
20 | | #include "js/RootingAPI.h" // JS::Handle, JS::MutableHandle |
21 | | |
22 | | struct JSContext; |
23 | | class JSFunction; |
24 | | class JSObject; |
25 | | class JSScript; |
26 | | |
27 | | namespace JS { |
28 | | |
29 | | using TranscodeBuffer = mozilla::Vector<uint8_t>; |
30 | | using TranscodeRange = mozilla::Range<uint8_t>; |
31 | | |
32 | | struct TranscodeSource final |
33 | | { |
34 | | TranscodeSource(const TranscodeRange& range_, const char* file, uint32_t line) |
35 | | : range(range_), filename(file), lineno(line) |
36 | 0 | {} |
37 | | |
38 | | const TranscodeRange range; |
39 | | const char* filename; |
40 | | const uint32_t lineno; |
41 | | }; |
42 | | |
43 | | using TranscodeSources = mozilla::Vector<TranscodeSource>; |
44 | | |
45 | | enum TranscodeResult : uint8_t |
46 | | { |
47 | | // Successful encoding / decoding. |
48 | | TranscodeResult_Ok = 0, |
49 | | |
50 | | // A warning message, is set to the message out-param. |
51 | | TranscodeResult_Failure = 0x10, |
52 | | TranscodeResult_Failure_BadBuildId = TranscodeResult_Failure | 0x1, |
53 | | TranscodeResult_Failure_RunOnceNotSupported = TranscodeResult_Failure | 0x2, |
54 | | TranscodeResult_Failure_AsmJSNotSupported = TranscodeResult_Failure | 0x3, |
55 | | TranscodeResult_Failure_BadDecode = TranscodeResult_Failure | 0x4, |
56 | | TranscodeResult_Failure_WrongCompileOption = TranscodeResult_Failure | 0x5, |
57 | | TranscodeResult_Failure_NotInterpretedFun = TranscodeResult_Failure | 0x6, |
58 | | |
59 | | // There is a pending exception on the context. |
60 | | TranscodeResult_Throw = 0x20 |
61 | | }; |
62 | | |
63 | | extern JS_PUBLIC_API(TranscodeResult) |
64 | | EncodeScript(JSContext* cx, TranscodeBuffer& buffer, Handle<JSScript*> script); |
65 | | |
66 | | extern JS_PUBLIC_API(TranscodeResult) |
67 | | EncodeInterpretedFunction(JSContext* cx, TranscodeBuffer& buffer, Handle<JSObject*> funobj); |
68 | | |
69 | | extern JS_PUBLIC_API(TranscodeResult) |
70 | | DecodeScript(JSContext* cx, TranscodeBuffer& buffer, MutableHandle<JSScript*> scriptp, |
71 | | size_t cursorIndex = 0); |
72 | | |
73 | | extern JS_PUBLIC_API(TranscodeResult) |
74 | | DecodeScript(JSContext* cx, const TranscodeRange& range, MutableHandle<JSScript*> scriptp); |
75 | | |
76 | | extern JS_PUBLIC_API(TranscodeResult) |
77 | | DecodeInterpretedFunction(JSContext* cx, TranscodeBuffer& buffer, MutableHandle<JSFunction*> funp, |
78 | | size_t cursorIndex = 0); |
79 | | |
80 | | // Register an encoder on the given script source, such that all functions can |
81 | | // be encoded as they are parsed. This strategy is used to avoid blocking the |
82 | | // main thread in a non-interruptible way. |
83 | | // |
84 | | // The |script| argument of |StartIncrementalEncoding| and |
85 | | // |FinishIncrementalEncoding| should be the top-level script returned either as |
86 | | // an out-param of any of the |Compile| functions, or the result of |
87 | | // |FinishOffThreadScript|. |
88 | | // |
89 | | // The |buffer| argument of |FinishIncrementalEncoding| is used for appending |
90 | | // the encoded bytecode into the buffer. If any of these functions failed, the |
91 | | // content of |buffer| would be undefined. |
92 | | extern JS_PUBLIC_API(bool) |
93 | | StartIncrementalEncoding(JSContext* cx, Handle<JSScript*> script); |
94 | | |
95 | | extern JS_PUBLIC_API(bool) |
96 | | FinishIncrementalEncoding(JSContext* cx, Handle<JSScript*> script, TranscodeBuffer& buffer); |
97 | | |
98 | | } // namespace JS |
99 | | |
100 | | #endif /* js_Transcoding_h */ |