v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
rewriter.h
Go to the documentation of this file.
1// Copyright 2011 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_PARSING_REWRITER_H_
6#define V8_PARSING_REWRITER_H_
7
8#include <optional>
9
10#include "src/base/macros.h"
12
13namespace v8::internal {
14
15class AstValueFactory;
16class Isolate;
17class ParseInfo;
18class Parser;
19class DeclarationScope;
20class Scope;
21class Statement;
22class VariableProxy;
23
24class Rewriter {
25 public:
26 // Rewrite top-level code (ECMA 262 "programs") so as to conservatively
27 // include an assignment of the value of the last statement in the code to
28 // a compiler-generated temporary variable wherever needed.
29 //
30 // Assumes code has been parsed and scopes have been analyzed. Mutates the
31 // AST, so the AST should not continue to be used in the case of failure.
32 V8_EXPORT_PRIVATE static bool Rewrite(ParseInfo* info,
33 bool* out_has_stack_overflow);
34
35 // Helper that does the actual re-writing. Extracted so REPL scripts can
36 // rewrite the body but then use the ".result" VariableProxy to resolve
37 // the async promise that is the result of running a REPL script.
38 // Returns std::nullopt in case something went wrong.
39 static std::optional<VariableProxy*> RewriteBody(
40 ParseInfo* info, Scope* scope, ZonePtrList<Statement>* body,
41 bool* out_has_stack_overflow);
42};
43
44} // namespace v8::internal
45
46#endif // V8_PARSING_REWRITER_H_
static V8_EXPORT_PRIVATE bool Rewrite(ParseInfo *info, bool *out_has_stack_overflow)
Definition rewriter.cc:386
static std::optional< VariableProxy * > RewriteBody(ParseInfo *info, Scope *scope, ZonePtrList< Statement > *body, bool *out_has_stack_overflow)
Definition rewriter.cc:406
#define V8_EXPORT_PRIVATE
Definition macros.h:460