diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-22 12:45:51 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-29 06:54:13 +0000 |
commit | 697564810f94ba32792ae714ca861e330bb4c657 (patch) | |
tree | 8f7f443edfe2662bf58177bef9d4dfe2bda58131 | |
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 <lars.knoll@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4module.cpp | 24 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4module_p.h | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4reflect.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4typedarray.cpp | 7 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4typedarray_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/ecmascripttests/TestExpectations | 5 |
6 files changed, 32 insertions, 10 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; diff --git a/src/qml/jsruntime/qv4module_p.h b/src/qml/jsruntime/qv4module_p.h index bb004b3b44..073e0d1e54 100644 --- a/src/qml/jsruntime/qv4module_p.h +++ b/src/qml/jsruntime/qv4module_p.h @@ -77,6 +77,7 @@ struct Q_QML_EXPORT Module : public Object { static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); static PropertyAttributes virtualGetOwnProperty(Managed *m, PropertyKey id, Property *p); + static bool virtualHasProperty(const Managed *m, PropertyKey id); static bool virtualPreventExtensions(Managed *); static bool virtualDefineOwnProperty(Managed *, PropertyKey, const Property *, PropertyAttributes); static bool virtualPut(Managed *, PropertyKey, const Value &, Value *); diff --git a/src/qml/jsruntime/qv4reflect.cpp b/src/qml/jsruntime/qv4reflect.cpp index 3dc0956e0c..766a0c4592 100644 --- a/src/qml/jsruntime/qv4reflect.cpp +++ b/src/qml/jsruntime/qv4reflect.cpp @@ -200,9 +200,7 @@ ReturnedValue Reflect::method_has(const FunctionObject *f, const Value *, const if (scope.engine->hasException) return false; - bool hasProperty = false; - (void) o->get(name, nullptr, &hasProperty); - return Encode(hasProperty); + return Encode(o->hasProperty(name)); } ReturnedValue Reflect::method_isExtensible(const FunctionObject *f, const Value *, const Value *argv, int argc) diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index 7606af80cb..7492f8872d 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -467,6 +467,13 @@ ReturnedValue TypedArray::virtualGet(const Managed *m, PropertyKey id, const Val return a->d()->type->read(a->d()->buffer->data->data() + byteOffset); } +bool TypedArray::virtualHasProperty(const Managed *m, PropertyKey id) +{ + bool hasProperty = false; + virtualGet(m, id, nullptr, &hasProperty); + return hasProperty; +} + bool TypedArray::virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver) { if (!id.isArrayIndex()) diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h index d29599f31e..909334adb0 100644 --- a/src/qml/jsruntime/qv4typedarray_p.h +++ b/src/qml/jsruntime/qv4typedarray_p.h @@ -166,6 +166,7 @@ struct Q_QML_PRIVATE_EXPORT TypedArray : Object using Object::get; static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); + static bool virtualHasProperty(const Managed *m, PropertyKey id); static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); }; diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index fd372abaf1..9a7e09ca3c 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -1051,13 +1051,8 @@ language/global-code/script-decl-var.js fails language/identifiers/other_id_continue.js fails language/identifiers/other_id_start-escaped.js fails language/identifiers/other_id_start.js fails -language/module-code/namespace/internals/delete-exported-uninit.js strictFails language/module-code/namespace/internals/enumerate-binding-uninit.js strictFails -language/module-code/namespace/internals/get-own-property-str-found-uninit.js strictFails -language/module-code/namespace/internals/get-str-found-uninit.js strictFails -language/module-code/namespace/internals/object-hasOwnProperty-binding-uninit.js strictFails language/module-code/namespace/internals/object-keys-binding-uninit.js strictFails -language/module-code/namespace/internals/object-propertyIsEnumerable-binding-uninit.js strictFails language/statements/async-function/cptn-decl.js fails language/statements/async-function/declaration-returns-promise.js fails language/statements/async-function/evaluation-body.js fails |