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(const QString &fileName, |
12 | const QString &sourceCode, |
13 | AST::FunctionExpression *ast, |
14 | Compiler::Module *module) |
15 | { |
16 | _module = module; |
17 | _module->fileName = fileName; |
18 | _module->finalUrl = fileName; |
19 | _context = nullptr; |
20 | |
21 | Compiler::ScanFunctions scan(this, sourceCode, Compiler::ContextType::Global); |
22 | // fake a global environment |
23 | scan.enterEnvironment(node: nullptr, compilationMode: Compiler::ContextType::Function, name: QString()); |
24 | scan(ast); |
25 | scan.leaveEnvironment(); |
26 | |
27 | if (hasError()) |
28 | return; |
29 | |
30 | int index = defineFunction(name: ast->name.toString(), ast, formals: ast->formals, body: ast->body); |
31 | _module->rootContext = _module->functions.at(i: index); |
32 | } |
33 | |
34 | void RuntimeCodegen::throwSyntaxError(const SourceLocation &loc, const QString &detail) |
35 | { |
36 | if (hasError()) |
37 | return; |
38 | |
39 | Codegen::throwSyntaxError(loc, detail); |
40 | engine->throwSyntaxError(message: detail, fileName: _module->fileName, lineNumber: loc.startLine, column: loc.startColumn); |
41 | } |
42 | |
43 | void RuntimeCodegen::throwReferenceError(const SourceLocation &loc, const QString &detail) |
44 | { |
45 | if (hasError()) |
46 | return; |
47 | |
48 | Codegen::throwReferenceError(loc, detail); |
49 | engine->throwReferenceError(value: detail, fileName: _module->fileName, lineNumber: loc.startLine, column: loc.startColumn); |
50 | } |
51 | |
52 | |