1 | // Copyright (C) 2017 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qv4engine_p.h" |
5 | #include "qv4runtimecodegen_p.h" |
6 | #include <private/qv4compilerscanfunctions_p.h> |
7 | |
8 | using namespace QV4; |
9 | using namespace QQmlJS; |
10 | |
11 | void RuntimeCodegen::generateFromFunctionExpression( |
12 | const QString &sourceCode, AST::FunctionExpression *ast, Compiler::Module *module) |
13 | { |
14 | _module = module; |
15 | _context = nullptr; |
16 | |
17 | Compiler::ScanFunctions scan(this, sourceCode, Compiler::ContextType::Global); |
18 | // fake a global environment |
19 | scan.enterEnvironment(node: nullptr, compilationMode: Compiler::ContextType::Function, name: QString()); |
20 | scan(ast); |
21 | scan.leaveEnvironment(); |
22 | |
23 | if (hasError()) |
24 | return; |
25 | |
26 | int index = defineFunction(name: ast->name.toString(), ast, formals: ast->formals, body: ast->body); |
27 | _module->rootContext = _module->functions.at(i: index); |
28 | } |
29 | |
30 | void RuntimeCodegen::throwSyntaxError(const SourceLocation &loc, const QString &detail) |
31 | { |
32 | if (hasError()) |
33 | return; |
34 | |
35 | Codegen::throwSyntaxError(loc, detail); |
36 | engine->throwSyntaxError(message: detail, fileName: _module->fileName, lineNumber: loc.startLine, column: loc.startColumn); |
37 | } |
38 | |
39 | void RuntimeCodegen::throwReferenceError(const SourceLocation &loc, const QString &detail) |
40 | { |
41 | if (hasError()) |
42 | return; |
43 | |
44 | Codegen::throwReferenceError(loc, detail); |
45 | engine->throwReferenceError(value: detail, fileName: _module->fileName, lineNumber: loc.startLine, column: loc.startColumn); |
46 | } |
47 | |
48 |