From a29ab499a4822014d34d6e9e988600fdb6d60a0d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 14 Aug 2018 15:43:19 +0200 Subject: Fix explicit export of imported variables Instead of using a re-export, it's also possible to write import { foo } from "./bar.js" and then export it again export { foo } Typically exported variables are referenced from the locals, but since we don't add imports to the locals, we need another way of locating them. This patch uses the index space after the locals in the internal class for imports, so that after we've identifier the export in the local export entry table, we can use the local name to search in the internal class and find imports past the locals. Change-Id: I58ab79ad3df1bbc1b972f0a2771d9ca1268de27b Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4module.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/qml/jsruntime/qv4module.cpp') 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 #include #include +#include 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 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 This(valueScope, this); ScopedString name(valueScope, engine->newString(QStringLiteral("Module"))); This->insertMember(engine->symbol_toStringTag(), name, Attr_ReadOnly); -- cgit v1.2.3