aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-01 22:19:57 +0200
committerLars Knoll <lars.knoll@qt.io>2018-08-02 20:25:24 +0000
commit2291588304b6c057ad8fe0551aa76f33a4055917 (patch)
treef1a2e0fae9d31531744c5a0fc6093736cdeb8f7a
parent245cb6b6a3e5a04dc43a3c4ce15831f68309e97f (diff)
Fix writing to properties of primitive data
In strict mode, this should throw a type error and not do an implicit toObject conversion. Change-Id: I7b8cdf1125978b9d9a047d9da84f23b547cb4a75 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/jsruntime/qv4lookup.cpp3
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp19
-rw-r--r--src/qml/jsruntime/qv4symbol_p.h2
-rw-r--r--tests/auto/qml/ecmascripttests/TestExpectations1
4 files changed, 20 insertions, 5 deletions
diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp
index daa5b2dfbd..95a431bd9b 100644
--- a/src/qml/jsruntime/qv4lookup.cpp
+++ b/src/qml/jsruntime/qv4lookup.cpp
@@ -511,6 +511,9 @@ bool Lookup::setterGeneric(Lookup *l, ExecutionEngine *engine, Value &object, co
if (object.isObject())
return l->resolveSetter(engine, static_cast<Object *>(&object), value);
+ if (engine->currentStackFrame->v4Function->isStrict())
+ return false;
+
Scope scope(engine);
ScopedObject o(scope, RuntimeHelpers::convertToObject(scope.engine, object));
if (!o) // type error
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 7839db8e01..abfc3e730b 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -579,7 +579,14 @@ void Runtime::method_storeProperty(ExecutionEngine *engine, const Value &object,
Scope scope(engine);
QV4::Function *v4Function = engine->currentStackFrame->v4Function;
ScopedString name(scope, v4Function->compilationUnit->runtimeStrings[nameIndex]);
- ScopedObject o(scope, object.toObject(engine));
+ ScopedObject o(scope, object);
+ if (!o) {
+ if (v4Function->isStrict()) {
+ engine->throwTypeError();
+ return;
+ }
+ o = object.toObject(engine);
+ }
if ((!o || !o->put(name, value)) && v4Function->isStrict())
engine->throwTypeError();
}
@@ -664,7 +671,15 @@ ReturnedValue Runtime::method_loadElement(ExecutionEngine *engine, const Value &
static Q_NEVER_INLINE bool setElementFallback(ExecutionEngine *engine, const Value &object, const Value &index, const Value &value)
{
Scope scope(engine);
- ScopedObject o(scope, object.toObject(engine));
+ ScopedObject o(scope, object);
+ if (!o) {
+ if (engine->currentStackFrame->v4Function->isStrict()) {
+ engine->throwTypeError();
+ return false;
+ }
+
+ o = object.toObject(engine);
+ }
if (engine->hasException)
return false;
diff --git a/src/qml/jsruntime/qv4symbol_p.h b/src/qml/jsruntime/qv4symbol_p.h
index 46fa2979f8..cb60f748de 100644
--- a/src/qml/jsruntime/qv4symbol_p.h
+++ b/src/qml/jsruntime/qv4symbol_p.h
@@ -116,8 +116,6 @@ struct SymbolObject : Object
Q_MANAGED_TYPE(SymbolObject)
V4_INTERNALCLASS(SymbolObject)
V4_PROTOTYPE(symbolPrototype)
-
- static bool virtualPut(Managed *, PropertyKey, const Value &, Value *) { return false; }
};
}
diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations
index 5ddfc02b44..d5d347548a 100644
--- a/tests/auto/qml/ecmascripttests/TestExpectations
+++ b/tests/auto/qml/ecmascripttests/TestExpectations
@@ -459,7 +459,6 @@ built-ins/Number/prototype/toPrecision/return-values.js fails
built-ins/Number/string-binary-literal.js fails
built-ins/Number/string-hex-literal-invalid.js fails
built-ins/Number/string-octal-literal.js fails
-built-ins/Object/assign/Target-Symbol.js fails
built-ins/Object/assign/source-own-prop-desc-missing.js fails
built-ins/Object/create/15.2.3.5-4-14.js strictFails
built-ins/Object/create/15.2.3.5-4-37.js strictFails