Skip to content

Commit 6e5c8d1

Browse files
author
Caio Marcelo de Oliveira Filho
committed
QDeclarativeObjectScriptClass: do not handle valueOf()
The obj.valueOf() is called in situations that we convert an object to a number. It is called implicitly by V8 (see DefaultNumber() in runtime.js for example), and when it hits our ScriptClass code the frame doesn't look like the way we expect (no DeclarativeContext available in the Caller scope chain). The problem happen in callQtInvokables, in tests that expect numbers and we pass the an object instead. This was the only case I've found which v8::Context::GetCallerContext (an extension in our branch of v8) isn't enough for the purpose of providing the top context in the previous frame. Avoiding valueOf() is OK for now. Last but not least, tst_qdeclarativeecmascript does not segfault anymore. Reviewed-by: Olivier Goffart
1 parent 7ed51aa commit 6e5c8d1

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/declarative/qml/qdeclarativeobjectscriptclass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ QDeclarativeObjectScriptClass::QDeclarativeObjectScriptClass(QDeclarativeEngine
9393
m_destroyId = createPersistentIdentifier(QLatin1String("destroy"));
9494
m_toString = scriptEngine->newFunction(tostring);
9595
m_toStringId = createPersistentIdentifier(QLatin1String("toString"));
96+
m_valueOfId = createPersistentIdentifier(QLatin1String("valueOf"));
9697
}
9798

9899
QDeclarativeObjectScriptClass::~QDeclarativeObjectScriptClass()
@@ -160,7 +161,7 @@ QDeclarativeObjectScriptClass::queryProperty(QObject *obj, const Identifier &nam
160161
name == m_toStringId.identifier)
161162
return QScriptClass::HandlesReadAccess;
162163

163-
if (!obj)
164+
if (name == m_valueOfId.identifier || !obj)
164165
return 0;
165166

166167
QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine);

src/declarative/qml/qdeclarativeobjectscriptclass_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeObjectScriptClass : public QScriptDeclarativ
150150

151151
PersistentIdentifier m_destroyId;
152152
PersistentIdentifier m_toStringId;
153+
PersistentIdentifier m_valueOfId;
153154
QScriptValue m_destroy;
154155
QScriptValue m_toString;
155156

0 commit comments

Comments
 (0)