diff options
author | Simon Hausmann <[email protected]> | 2018-08-22 12:45:51 +0200 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2018-08-29 06:54:13 +0000 |
commit | 697564810f94ba32792ae714ca861e330bb4c657 (patch) | |
tree | 8f7f443edfe2662bf58177bef9d4dfe2bda58131 /src/qml/jsruntime/qv4module.cpp | |
parent | 16f18f68e37661f45047c913b9e6f9068dbc88a9 (diff) |
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 <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4module.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4module.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
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<const Module *>(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; |