aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4codegen.cpp
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-12-05 09:19:06 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-12-07 11:32:23 +0100
commit4fec5c428e580d0f2622bbe878349899e5f93c62 (patch)
treee5bc6c0231ed79b8066cdee6de9bcbac1c3a3c50 /src/qml/compiler/qv4codegen.cpp
parentb55b3692f6cc57f8a7ef972388504b5133331ceb (diff)
parent64ee4968b46019b8e4cb7523a6e41833fc4cf665 (diff)
Merge remote-tracking branch 'origin/5.12.0' into 5.12
Conflicts: src/qml/jsruntime/qv4script.cpp src/qml/parser/qqmljslexer.cpp Change-Id: I82252a8c504a4b77c45f4f8efe849ff9acb949fd
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r--src/qml/compiler/qv4codegen.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 8ec730a33d..f570af4819 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -102,6 +102,62 @@ Codegen::Codegen(QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict)
jsUnitGenerator->codeGeneratorName = QStringLiteral("moth");
}
+const char *globalNames[] = {
+ "isNaN",
+ "parseFloat",
+ "String",
+ "EvalError",
+ "URIError",
+ "Math",
+ "encodeURIComponent",
+ "RangeError",
+ "eval",
+ "isFinite",
+ "ReferenceError",
+ "Infinity",
+ "Function",
+ "RegExp",
+ "Number",
+ "parseInt",
+ "Object",
+ "decodeURI",
+ "TypeError",
+ "Boolean",
+ "encodeURI",
+ "NaN",
+ "Error",
+ "decodeURIComponent",
+ "Date",
+ "Array",
+ "Symbol",
+ "escape",
+ "unescape",
+ "SyntaxError",
+ "undefined",
+ "JSON",
+ "ArrayBuffer",
+ "SharedArrayBuffer",
+ "DataView",
+ "Int8Array",
+ "Uint8Array",
+ "Uint8ClampedArray",
+ "Int16Array",
+ "Uint16Array",
+ "Int32Array",
+ "Uint32Array",
+ "Float32Array",
+ "Float64Array",
+ "WeakSet",
+ "Set",
+ "WeakMap",
+ "Map",
+ "Reflect",
+ "Proxy",
+ "Atomics",
+ "Promise",
+ nullptr
+};
+
void Codegen::generateFromProgram(const QString &fileName,
const QString &finalUrl,
const QString &sourceCode,
@@ -118,6 +174,18 @@ void Codegen::generateFromProgram(const QString &fileName,
_module->fileName = fileName;
_module->finalUrl = finalUrl;
+ if (contextType == ContextType::ScriptImportedByQML) {
+ // the global object is frozen, so we know that members of it are
+ // pointing to the global object. This is important so that references
+ // to Math etc. do not go through the expensive path in the context wrapper
+ // that tries to see whether we have a matching type
+ //
+ // Since this can be called from the loader thread we can't get the list
+ // directly from the engine, so let's hardcode the most important ones here
+ for (const char **g = globalNames; *g != nullptr; ++g)
+ m_globalNames << QString::fromLatin1(*g);
+ }
+
ScanFunctions scan(this, sourceCode, contextType);
scan(node);
@@ -2336,6 +2404,8 @@ Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs, co
Reference r = Reference::fromName(this, name);
r.global = useFastLookups && (resolved.type == Context::ResolvedName::Global);
+ if (!r.global && m_globalNames.contains(name))
+ r.global = true;
return r;
}