| 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 builtin_TestingUtility_h |
| 8 |
#define builtin_TestingUtility_h |
| 9 |
|
| 10 |
#include "js/experimental/JSStencil.h" // JS::Stencil |
| 11 |
#include "js/RootingAPI.h" // JS::Handle, JS::MutableHandle |
| 12 |
#include "js/Utility.h" // JS::UniqueChars |
| 13 |
|
| 14 |
struct JSContext; |
| 15 |
class JSObject; |
| 16 |
class JSString; |
| 17 |
|
| 18 |
namespace JS { |
| 19 |
class JS_PUBLIC_API CompileOptions; |
| 20 |
} |
| 21 |
|
| 22 |
namespace js { |
| 23 |
|
| 24 |
class FrontendContext; |
| 25 |
class ScriptSource; |
| 26 |
|
| 27 |
namespace frontend { |
| 28 |
struct CompilationStencil; |
| 29 |
} // namespace frontend |
| 30 |
|
| 31 |
// Populate `options` fields from `opt` object. |
| 32 |
// |
| 33 |
// `opts` can have the following properties: |
| 34 |
// * isRunOnce (boolean): options.isRunOnce |
| 35 |
// * noScriptRval (boolean): options.noScriptRval |
| 36 |
// * fileName (string): options.filename_ |
| 37 |
// enabled only when `fileNameBytes` is given, and |
| 38 |
// `fileNameBytes` is initialized to the filename bytes |
| 39 |
// * skipFileNameValidation (boolean): options.skipFileNameValidation_ |
| 40 |
// * lineNumber (number): options.lineno |
| 41 |
// * columnNumber (number): options.column |
| 42 |
// * sourceIsLazy (boolean): options.sourceIsLazy |
| 43 |
// * forceFullParse (boolean): options.forceFullParse_ |
| 44 |
[[nodiscard]] bool ParseCompileOptions(JSContext* cx, |
| 45 |
JS::CompileOptions& options, |
| 46 |
JS::Handle<JSObject*> opts, |
| 47 |
JS::UniqueChars* fileNameBytes); |
| 48 |
|
| 49 |
[[nodiscard]] bool ParseSourceOptions( |
| 50 |
JSContext* cx, JS::Handle<JSObject*> opts, |
| 51 |
JS::MutableHandle<JSString*> displayURL, |
| 52 |
JS::MutableHandle<JSString*> sourceMapURL); |
| 53 |
|
| 54 |
[[nodiscard]] bool SetSourceOptions(JSContext* cx, FrontendContext* fc, |
| 55 |
ScriptSource* source, |
| 56 |
JS::Handle<JSString*> displayURL, |
| 57 |
JS::Handle<JSString*> sourceMapURL); |
| 58 |
|
| 59 |
JSObject* CreateScriptPrivate(JSContext* cx, |
| 60 |
JS::Handle<JSString*> path = nullptr); |
| 61 |
|
| 62 |
[[nodiscard]] bool ParseDebugMetadata( |
| 63 |
JSContext* cx, JS::Handle<JSObject*> opts, |
| 64 |
JS::MutableHandle<JS::Value> privateValue, |
| 65 |
JS::MutableHandle<JSString*> elementAttributeName); |
| 66 |
|
| 67 |
[[nodiscard]] JS::UniqueChars StringToLocale(JSContext* cx, |
| 68 |
JS::Handle<JSObject*> callee, |
| 69 |
JS::Handle<JSString*> str_); |
| 70 |
|
| 71 |
// Validate the option for lazy-parsing agrees between the current global and |
| 72 |
// the stencil. |
| 73 |
bool ValidateLazinessOfStencilAndGlobal(JSContext* cx, |
| 74 |
const JS::Stencil* stencil); |
| 75 |
|
| 76 |
bool ValidateModuleCompileOptions(JSContext* cx, JS::CompileOptions& options); |
| 77 |
|
| 78 |
} /* namespace js */ |
| 79 |
|
| 80 |
#endif /* builtin_TestingUtility_h */ |