Commit 91d07a69 authored by eric@webkit.org's avatar eric@webkit.org

2010-03-03 Jedrzej Nowacki <jedrzej.nowacki@nokia.com>

        Reviewed by Simon Hausmann.

        QScriptValue::isObject fix.

        Fix broken internal state evaluation from JSValue to JSNative / JSObject.
        New function was introduced which should take care about promoting
        JSValue state inside QScriptValuePrivate. It should be used instead of a
        direct JSC C API call.

        The bug exposed a weakness in autotest suite, as the QScriptValuePrivate
        is based on state machine with lazy state evaluation, there is a possibility
        that serial sequencial calls to the same public const function could return
        different results. The patch fix the issue.

        [Qt] Sometimes QScriptValue::isObject returns an incorrect value
        https://bugs.webkit.org/show_bug.cgi?id=35387

        * qt/api/qscriptvalue_p.h:
        (QScriptValuePrivate::isBool):
        (QScriptValuePrivate::isNumber):
        (QScriptValuePrivate::isNull):
        (QScriptValuePrivate::isString):
        (QScriptValuePrivate::isUndefined):
        (QScriptValuePrivate::isError):
        (QScriptValuePrivate::isObject):
        (QScriptValuePrivate::isFunction):
        (QScriptValuePrivate::call):
        (QScriptValuePrivate::refineJSValue):
        * qt/tests/qscriptvalue/tst_qscriptvalue_generated.cpp:
        (tst_QScriptValue::initScriptValues):
        (tst_QScriptValue::isValid_makeData):
        (tst_QScriptValue::isValid_test):
        (tst_QScriptValue::isBool_makeData):
        (tst_QScriptValue::isBool_test):
        (tst_QScriptValue::isBoolean_makeData):
        (tst_QScriptValue::isBoolean_test):
        (tst_QScriptValue::isNumber_makeData):
        (tst_QScriptValue::isNumber_test):
        (tst_QScriptValue::isFunction_test):
        (tst_QScriptValue::isNull_makeData):
        (tst_QScriptValue::isNull_test):
        (tst_QScriptValue::isString_makeData):
        (tst_QScriptValue::isString_test):
        (tst_QScriptValue::isUndefined_makeData):
        (tst_QScriptValue::isUndefined_test):
        (tst_QScriptValue::isObject_makeData):
        (tst_QScriptValue::isObject_test):
        (tst_QScriptValue::toString_makeData):
        (tst_QScriptValue::toString_test):
        (tst_QScriptValue::toNumber_makeData):
        (tst_QScriptValue::toNumber_test):
        (tst_QScriptValue::toBool_makeData):
        (tst_QScriptValue::toBool_test):
        (tst_QScriptValue::toBoolean_makeData):
        (tst_QScriptValue::toBoolean_test):
        (tst_QScriptValue::toInteger_makeData):
        (tst_QScriptValue::toInteger_test):
        (tst_QScriptValue::toInt32_makeData):
        (tst_QScriptValue::toInt32_test):
        (tst_QScriptValue::toUInt32_makeData):
        (tst_QScriptValue::toUInt32_test):
        (tst_QScriptValue::toUInt16_makeData):
        (tst_QScriptValue::toUInt16_test):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55502 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 70b14116
2010-03-03 Jedrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed by Simon Hausmann.
QScriptValue::isObject fix.
Fix broken internal state evaluation from JSValue to JSNative / JSObject.
New function was introduced which should take care about promoting
JSValue state inside QScriptValuePrivate. It should be used instead of a
direct JSC C API call.
The bug exposed a weakness in autotest suite, as the QScriptValuePrivate
is based on state machine with lazy state evaluation, there is a possibility
that serial sequencial calls to the same public const function could return
different results. The patch fix the issue.
[Qt] Sometimes QScriptValue::isObject returns an incorrect value
https://bugs.webkit.org/show_bug.cgi?id=35387
* qt/api/qscriptvalue_p.h:
(QScriptValuePrivate::isBool):
(QScriptValuePrivate::isNumber):
(QScriptValuePrivate::isNull):
(QScriptValuePrivate::isString):
(QScriptValuePrivate::isUndefined):
(QScriptValuePrivate::isError):
(QScriptValuePrivate::isObject):
(QScriptValuePrivate::isFunction):
(QScriptValuePrivate::call):
(QScriptValuePrivate::refineJSValue):
* qt/tests/qscriptvalue/tst_qscriptvalue_generated.cpp:
(tst_QScriptValue::initScriptValues):
(tst_QScriptValue::isValid_makeData):
(tst_QScriptValue::isValid_test):
(tst_QScriptValue::isBool_makeData):
(tst_QScriptValue::isBool_test):
(tst_QScriptValue::isBoolean_makeData):
(tst_QScriptValue::isBoolean_test):
(tst_QScriptValue::isNumber_makeData):
(tst_QScriptValue::isNumber_test):
(tst_QScriptValue::isFunction_test):
(tst_QScriptValue::isNull_makeData):
(tst_QScriptValue::isNull_test):
(tst_QScriptValue::isString_makeData):
(tst_QScriptValue::isString_test):
(tst_QScriptValue::isUndefined_makeData):
(tst_QScriptValue::isUndefined_test):
(tst_QScriptValue::isObject_makeData):
(tst_QScriptValue::isObject_test):
(tst_QScriptValue::toString_makeData):
(tst_QScriptValue::toString_test):
(tst_QScriptValue::toNumber_makeData):
(tst_QScriptValue::toNumber_test):
(tst_QScriptValue::toBool_makeData):
(tst_QScriptValue::toBool_test):
(tst_QScriptValue::toBoolean_makeData):
(tst_QScriptValue::toBoolean_test):
(tst_QScriptValue::toInteger_makeData):
(tst_QScriptValue::toInteger_test):
(tst_QScriptValue::toInt32_makeData):
(tst_QScriptValue::toInt32_test):
(tst_QScriptValue::toUInt32_makeData):
(tst_QScriptValue::toUInt32_test):
(tst_QScriptValue::toUInt16_makeData):
(tst_QScriptValue::toUInt16_test):
2010-03-03 Chao-ying Fu <fu@mips.com>
Reviewed by Gavin Barraclough.
......
......@@ -136,6 +136,7 @@ private:
inline void setValue(JSValueRef);
inline bool inherits(const char*);
inline States refinedJSValue();
inline bool isJSBased() const;
inline bool isNumberBased() const;
......@@ -325,7 +326,7 @@ bool QScriptValuePrivate::isBool()
case CBool:
return true;
case JSValue:
if (isObject())
if (refinedJSValue() != JSNative)
return false;
// Fall-through.
case JSNative:
......@@ -341,7 +342,7 @@ bool QScriptValuePrivate::isNumber()
case CNumber:
return true;
case JSValue:
if (isObject())
if (refinedJSValue() != JSNative)
return false;
// Fall-through.
case JSNative:
......@@ -357,7 +358,7 @@ bool QScriptValuePrivate::isNull()
case CSpecial:
return m_number == static_cast<int>(QScriptValue::NullValue);
case JSValue:
if (isObject())
if (refinedJSValue() != JSNative)
return false;
// Fall-through.
case JSNative:
......@@ -373,7 +374,7 @@ bool QScriptValuePrivate::isString()
case CString:
return true;
case JSValue:
if (isObject())
if (refinedJSValue() != JSNative)
return false;
// Fall-through.
case JSNative:
......@@ -389,7 +390,7 @@ bool QScriptValuePrivate::isUndefined()
case CSpecial:
return m_number == static_cast<int>(QScriptValue::UndefinedValue);
case JSValue:
if (isObject())
if (refinedJSValue() != JSNative)
return false;
// Fall-through.
case JSNative:
......@@ -403,7 +404,7 @@ bool QScriptValuePrivate::isError()
{
switch (m_state) {
case JSValue:
if (!isObject())
if (refinedJSValue() != JSObject)
return false;
// Fall-through.
case JSObject:
......@@ -416,14 +417,11 @@ bool QScriptValuePrivate::isError()
bool QScriptValuePrivate::isObject()
{
switch (m_state) {
case JSObject:
return true;
case JSValue:
m_object = JSValueToObject(context(), value(), /* exception */ 0);
if (!m_object)
return false;
m_state = JSObject;
return refinedJSValue() == JSObject;
case JSObject:
return true;
default:
return false;
}
......@@ -433,10 +431,8 @@ bool QScriptValuePrivate::isFunction()
{
switch (m_state) {
case JSValue:
m_object = JSValueToObject(context(), value(), /* exception */ 0);
if (!m_object)
if (refinedJSValue() != JSObject)
return false;
m_state = JSObject;
// Fall-through.
case JSObject:
return JSObjectIsFunction(context(), object());
......@@ -640,12 +636,8 @@ QScriptValuePrivate* QScriptValuePrivate::call(const QScriptValuePrivate*, const
{
switch (m_state) {
case JSValue:
m_object = JSValueToObject(context(), value(), /* exception */ 0);
if (!object()) {
m_state = JSValue;
if (refinedJSValue() != JSObject)
return new QScriptValuePrivate;
}
m_state = JSObject;
// Fall-through.
case JSObject:
{
......@@ -723,6 +715,24 @@ bool QScriptValuePrivate::inherits(const char* name)
return JSValueIsInstanceOfConstructor(context(), value(), JSValueToObject(context(), error, /* exception */ 0), /* exception */ 0);
}
/*!
\internal
Refines the state of this QScriptValuePrivate. Returns the new state.
*/
QScriptValuePrivate::States QScriptValuePrivate::refinedJSValue()
{
Q_ASSERT(m_state == JSValue);
if (!JSValueIsObject(context(), value())) {
m_state = JSNative;
} else {
m_state = JSObject;
// We are sure that value is an JSObject, so we can const_cast safely without
// calling JSC C API (JSValueToObject(context(), value(), /* exceptions */ 0)).
m_object = const_cast<JSObjectRef>(m_value);
}
return m_state;
}
/*!
\internal
Returns true if QSV have an engine associated.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment