From 697564810f94ba32792ae714ca861e330bb4c657 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 22 Aug 2018 12:45:51 +0200 Subject: Fix dead temporal zone checking in module namespaces Accessing uninitialized imports through the module namespace object should throw a reference error. Unfortunately we can't do this check on the caller side of the namespace object get, as we have no idea that we're talking to one. Therefore we must throw in the vtable methods. When checking via Reflect.has(), the properties should be reported as existing. This means providing a virtual hasProperty() in the module as well as changing Reflect::method_has to use the vtable method instead of doing a get (which would throw). Change-Id: Ic0ec51de3832c6a67044fc8f689ac534f349c1b6 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4module.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/qml/jsruntime/qv4module.cpp') diff --git a/src/qml/jsruntime/qv4module.cpp b/src/qml/jsruntime/qv4module.cpp index c892749a11..6b15637d49 100644 --- a/src/qml/jsruntime/qv4module.cpp +++ b/src/qml/jsruntime/qv4module.cpp @@ -109,8 +109,12 @@ ReturnedValue Module::virtualGet(const Managed *m, PropertyKey id, const Value * const Value *v = module->d()->unit->resolveExport(expectedName); if (hasProperty) *hasProperty = v != nullptr; - if (!v || v->isEmpty()) + if (!v) return Encode::undefined(); + if (v->isEmpty()) { + ScopedValue propName(scope, id.toStringOrSymbol(scope.engine)); + return scope.engine->throwReferenceError(propName); + } return v->asReturnedValue(); } @@ -129,10 +133,26 @@ PropertyAttributes Module::virtualGetOwnProperty(Managed *m, PropertyKey id, Pro return Attr_Invalid; } if (p) - p->value = v->asReturnedValue(); + p->value = v->isEmpty() ? Encode::undefined() : v->asReturnedValue(); + if (v->isEmpty()) { + ScopedValue propName(scope, id.toStringOrSymbol(scope.engine)); + scope.engine->throwReferenceError(propName); + } return Attr_Data | Attr_NotConfigurable; } +bool Module::virtualHasProperty(const Managed *m, PropertyKey id) +{ + if (id.isSymbol()) + return Object::virtualHasProperty(m, id); + + const Module *module = static_cast(m); + Scope scope(m->engine()); + ScopedString expectedName(scope, id.toStringOrSymbol(scope.engine)); + const Value *v = module->d()->unit->resolveExport(expectedName); + return v != nullptr; +} + bool Module::virtualPreventExtensions(Managed *) { return true; -- cgit v1.2.3