diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-17 11:59:44 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-17 11:59:44 (GMT) |
commit | 869450c0f6f5cf654211f79d97d00e0d0058b49c (patch) | |
tree | 41e940e70397ca358483068fbfeae13b37cf33aa /src/script/api | |
parent | 55e4d1453f6ddbca69599047f5638ca2cd63bd0c (diff) | |
download | Qt-869450c0f6f5cf654211f79d97d00e0d0058b49c.zip Qt-869450c0f6f5cf654211f79d97d00e0d0058b49c.tar.gz Qt-869450c0f6f5cf654211f79d97d00e0d0058b49c.tar.bz2 |
implement cyclic prototype chain check
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index ec72818..2084ddb 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -840,9 +840,20 @@ void QScriptValue::setPrototype(const QScriptValue &prototype) "a different engine"); return; } - // ### check for cycle QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(d->engine); JSC::JSValue other = eng_p->scriptValueToJSCValue(prototype); + + // check for cycle + JSC::JSValue nextPrototypeValue = other; + while (nextPrototypeValue && nextPrototypeValue.isObject()) { + JSC::JSObject *nextPrototype = JSC::asObject(nextPrototypeValue); + if (nextPrototype == JSC::asObject(d->jscValue)) { + qWarning("QScriptValue::setPrototype() failed: cyclic prototype value"); + return; + } + nextPrototypeValue = nextPrototype->prototype(); + } + JSC::asObject(d->jscValue)->setPrototype(other); } |