aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/compiler/qv4compileddata.cpp8
-rw-r--r--src/qml/jsruntime/qv4module.cpp19
2 files changed, 24 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 52db3100fc..798bfe921e 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -469,9 +469,11 @@ const Value *CompilationUnit::resolveExportRecursively(QV4::String *exportName,
if (auto localExport = lookupNameInExportTable(data->localExportEntryTable(), data->localExportEntryTableSize, exportName)) {
ScopedString localName(scope, runtimeStrings[localExport->localName]);
uint index = m_module->scope->internalClass->find(localName->toPropertyKey());
- if (index < UINT_MAX)
- return &m_module->scope->locals[index];
- return nullptr;
+ if (index >= UINT_MAX)
+ return nullptr;
+ if (index >= m_module->scope->locals.size)
+ return imports[index - m_module->scope->locals.size];
+ return &m_module->scope->locals[index];
}
if (auto indirectExport = lookupNameInExportTable(data->indirectExportEntryTable(), data->indirectExportEntryTableSize, exportName)) {
diff --git a/src/qml/jsruntime/qv4module.cpp b/src/qml/jsruntime/qv4module.cpp
index 4a7d0c19c4..e8e84ac965 100644
--- a/src/qml/jsruntime/qv4module.cpp
+++ b/src/qml/jsruntime/qv4module.cpp
@@ -44,6 +44,7 @@
#include <private/qv4vme_moth_p.h>
#include <private/qv4context_p.h>
#include <private/qv4symbol_p.h>
+#include <private/qv4identifiertable_p.h>
using namespace QV4;
@@ -70,6 +71,24 @@ void Heap::Module::init(ExecutionEngine *engine, CompiledData::CompilationUnit *
scope->nArgs = 0;
Scope valueScope(engine);
+
+ // It's possible for example to re-export an import, for example:
+ // import * as foo from "./bar.js"
+ // export { foo }
+ // Since we don't add imports to the locals, it won't be found typically.
+ // Except now we add imports at the end of the internal class in the index
+ // space past the locals, so that resolveExport can find it.
+ {
+ Scoped<QV4::InternalClass> ic(valueScope, scope->internalClass);
+
+ for (uint i = 0; i < unit->data->importEntryTableSize; ++i) {
+ const CompiledData::ImportEntry &import = unit->data->importEntryTable()[i];
+ ic = ic->addMember(engine->identifierTable->asPropertyKey(unit->runtimeStrings[import.localName]), Attr_NotConfigurable);
+ }
+ scope->internalClass.set(engine, ic->d());
+ }
+
+
Scoped<QV4::Module> This(valueScope, this);
ScopedString name(valueScope, engine->newString(QStringLiteral("Module")));
This->insertMember(engine->symbol_toStringTag(), name, Attr_ReadOnly);