Changeset 61003 in webkit


Ignore:
Timestamp:
Jun 11, 2010 3:36:18 AM (14 years ago)
Author:
Simon Hausmann
Message:

[Qt] Explicit conversions from QtScript types to JSC opaque types were removed.
https://bugs.webkit.org/show_bug.cgi?id=40412

Patch by Jedrzej Nowacki <jedrzej.nowacki@nokia.com> on 2010-06-11
Reviewed by Simon Hausmann.

Conversion between a JSC C types and a QtScript private types, takes
main part of the source code. In most cases a mapping between the types
is one to one. New cast operators were added to simplify the code.

The QScriptValuePrivate could be casted to the JSValueRef and the JSObjectRef.
The QScriptEnginePrivate could be casted to the JSGlobalContext.
The QScriptProgramPrivate could be casted to the JSStringRef.

  • qt/api/qscriptengine_p.cpp:

(QScriptEnginePrivate::evaluate):
(QScriptEnginePrivate::newObject):
(QScriptEnginePrivate::globalObject):

  • qt/api/qscriptengine_p.h:

(QScriptEnginePrivate::operator JSGlobalContextRef):

  • qt/api/qscriptprogram_p.h:

(QScriptProgramPrivate::operator JSStringRef):

  • qt/api/qscriptsyntaxcheckresult.cpp:

(QScriptSyntaxCheckResultPrivate::~QScriptSyntaxCheckResultPrivate):
(QScriptSyntaxCheckResultPrivate::errorMessage):
(QScriptSyntaxCheckResultPrivate::errorLineNumber):

  • qt/api/qscriptvalue_p.h:

(QScriptValuePrivate::~QScriptValuePrivate):
(QScriptValuePrivate::QScriptValuePrivate):
(QScriptValuePrivate::isBool):
(QScriptValuePrivate::isNumber):
(QScriptValuePrivate::isNull):
(QScriptValuePrivate::isString):
(QScriptValuePrivate::isUndefined):
(QScriptValuePrivate::isFunction):
(QScriptValuePrivate::toString):
(QScriptValuePrivate::toNumber):
(QScriptValuePrivate::toBool):
(QScriptValuePrivate::toObject):
(QScriptValuePrivate::equals):
(QScriptValuePrivate::strictlyEquals):
(QScriptValuePrivate::instanceOf):
(QScriptValuePrivate::call):
(QScriptValuePrivate::operator JSValueRef):
(QScriptValuePrivate::operator JSObjectRef):
(QScriptValuePrivate::setValue):
(QScriptValuePrivate::inherits):
(QScriptValuePrivate::refinedJSValue):

Location:
trunk/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r61002 r61003  
     12010-06-11  Jedrzej Nowacki  <jedrzej.nowacki@nokia.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] Explicit conversions from QtScript types to JSC opaque types were removed.
     6        https://bugs.webkit.org/show_bug.cgi?id=40412
     7
     8        Conversion between a JSC C types and a QtScript private types, takes
     9        main part of the source code. In most cases a mapping between the types
     10        is one to one. New cast operators were added to simplify the code.
     11
     12        The QScriptValuePrivate could be casted to the JSValueRef and the JSObjectRef.
     13        The QScriptEnginePrivate could be casted to the JSGlobalContext.
     14        The QScriptProgramPrivate could be casted to the JSStringRef.
     15
     16        * qt/api/qscriptengine_p.cpp:
     17        (QScriptEnginePrivate::evaluate):
     18        (QScriptEnginePrivate::newObject):
     19        (QScriptEnginePrivate::globalObject):
     20        * qt/api/qscriptengine_p.h:
     21        (QScriptEnginePrivate::operator JSGlobalContextRef):
     22        * qt/api/qscriptprogram_p.h:
     23        (QScriptProgramPrivate::operator JSStringRef):
     24        * qt/api/qscriptsyntaxcheckresult.cpp:
     25        (QScriptSyntaxCheckResultPrivate::~QScriptSyntaxCheckResultPrivate):
     26        (QScriptSyntaxCheckResultPrivate::errorMessage):
     27        (QScriptSyntaxCheckResultPrivate::errorLineNumber):
     28        * qt/api/qscriptvalue_p.h:
     29        (QScriptValuePrivate::~QScriptValuePrivate):
     30        (QScriptValuePrivate::QScriptValuePrivate):
     31        (QScriptValuePrivate::isBool):
     32        (QScriptValuePrivate::isNumber):
     33        (QScriptValuePrivate::isNull):
     34        (QScriptValuePrivate::isString):
     35        (QScriptValuePrivate::isUndefined):
     36        (QScriptValuePrivate::isFunction):
     37        (QScriptValuePrivate::toString):
     38        (QScriptValuePrivate::toNumber):
     39        (QScriptValuePrivate::toBool):
     40        (QScriptValuePrivate::toObject):
     41        (QScriptValuePrivate::equals):
     42        (QScriptValuePrivate::strictlyEquals):
     43        (QScriptValuePrivate::instanceOf):
     44        (QScriptValuePrivate::call):
     45        (QScriptValuePrivate::operator JSValueRef):
     46        (QScriptValuePrivate::operator JSObjectRef):
     47        (QScriptValuePrivate::setValue):
     48        (QScriptValuePrivate::inherits):
     49        (QScriptValuePrivate::refinedJSValue):
     50
    1512010-05-31  Jocelyn Turcotte  <jocelyn.turcotte@nokia.com>
    252
  • trunk/JavaScriptCore/qt/api/qscriptengine_p.cpp

    r60583 r61003  
    7575    if (program->isNull())
    7676        return new QScriptValuePrivate;
    77     return new QScriptValuePrivate(this, evaluate(program->program(), program->file(), program->line()));
     77    return new QScriptValuePrivate(this, evaluate(*program, program->file(), program->line()));
    7878}
    7979
    8080QScriptValuePrivate* QScriptEnginePrivate::newObject() const
    8181{
    82     return new QScriptValuePrivate(this, JSObjectMake(context(), /* jsClass */ 0, /* userData */ 0));
     82    return new QScriptValuePrivate(this, JSObjectMake(m_context, /* jsClass */ 0, /* userData */ 0));
    8383}
    8484
    8585QScriptValuePrivate* QScriptEnginePrivate::globalObject() const
    8686{
    87     JSObjectRef globalObject = JSContextGetGlobalObject(context());
     87    JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
    8888    return new QScriptValuePrivate(this, globalObject, globalObject);
    8989}
  • trunk/JavaScriptCore/qt/api/qscriptengine_p.h

    r60583 r61003  
    6262    inline QScriptStringPrivate* toStringHandle(const QString& str) const;
    6363
    64     inline JSGlobalContextRef context() const;
     64    inline operator JSGlobalContextRef() const;
    6565private:
    6666    QScriptEngine* q_ptr;
     
    134134}
    135135
    136 JSGlobalContextRef QScriptEnginePrivate::context() const
     136QScriptEnginePrivate::operator JSGlobalContextRef() const
    137137{
     138    Q_ASSERT(this);
    138139    return m_context;
    139140}
  • trunk/JavaScriptCore/qt/api/qscriptprogram_p.h

    r56320 r61003  
    5353    inline bool operator!=(const QScriptProgramPrivate& other) const;
    5454
    55     inline JSStringRef program() const;
     55    inline operator JSStringRef() const;
    5656    inline JSStringRef file() const;
    5757    inline int line() const;
     
    123123}
    124124
    125 JSStringRef QScriptProgramPrivate::program() const { return m_program; }
     125QScriptProgramPrivate::operator JSStringRef() const
     126{
     127    return m_program;
     128}
     129
    126130JSStringRef QScriptProgramPrivate::file() const {return m_fileName; }
    127131int QScriptProgramPrivate::line() const { return m_line; }
  • trunk/JavaScriptCore/qt/api/qscriptsyntaxcheckresult.cpp

    r57626 r61003  
    120120{
    121121    if (m_exception)
    122         JSValueUnprotect(m_engine->context(), m_exception);
     122        JSValueUnprotect(*m_engine, m_exception);
    123123}
    124124
     
    128128        return QString();
    129129
    130     JSStringRef tmp = JSValueToStringCopy(m_engine->context(), m_exception, /* exception */ 0);
     130    JSStringRef tmp = JSValueToStringCopy(*m_engine, m_exception, /* exception */ 0);
    131131    QString message = QScriptConverter::toString(tmp);
    132132    JSStringRelease(tmp);
     
    140140    // m_exception is an instance of the Exception so it has "line" attribute.
    141141    JSStringRef lineAttrName = QScriptConverter::toString("line");
    142     JSValueRef line = JSObjectGetProperty(m_engine->context(),
     142    JSValueRef line = JSObjectGetProperty(*m_engine,
    143143                                          m_exception,
    144144                                          lineAttrName,
    145145                                          /* exceptions */0);
    146146    JSStringRelease(lineAttrName);
    147     return JSValueToNumber(m_engine->context(), line, /* exceptions */0);
     147    return JSValueToNumber(*m_engine, line, /* exceptions */0);
    148148}
  • trunk/JavaScriptCore/qt/api/qscriptvalue_p.h

    r60725 r61003  
    6060  Each state keep all necessary information to invoke all methods, if not it should be changed to
    6161  a proper state. Changed state shouldn't be reverted.
     62
     63  The QScriptValuePrivate use the JSC C API directly. The QSVP type is equal to combination of
     64  the JSValueRef and the JSObjectRef, and it could be automatically casted to these types by cast
     65  operators.
    6266*/
    6367
     
    115119    inline QScriptValuePrivate* call(const QScriptValuePrivate* , const QScriptValueList& args);
    116120
    117     inline JSGlobalContextRef context() const;
    118     inline JSValueRef value() const;
    119     inline JSObjectRef object() const;
     121    inline operator JSValueRef() const;
     122    inline operator JSObjectRef() const;
     123
    120124    inline QScriptEnginePrivate* engine() const;
    121125
     
    164168{
    165169    if (m_value)
    166         JSValueUnprotect(context(), m_value);
     170        JSValueUnprotect(*m_engine, m_value);
    167171}
    168172
     
    220224{
    221225    Q_ASSERT(engine);
    222     JSValueProtect(context(), m_value);
     226    JSValueProtect(*m_engine, m_value);
    223227}
    224228
     
    229233{
    230234    Q_ASSERT(engine);
    231     JSValueProtect(context(), m_value);
     235    JSValueProtect(*m_engine, m_value);
    232236}
    233237
     
    238242{
    239243    Q_ASSERT(engine);
    240     JSValueProtect(context(), m_value);
     244    JSValueProtect(*m_engine, m_value);
    241245}
    242246
     
    247251{
    248252    Q_ASSERT(engine);
    249     JSValueProtect(context(), m_value);
     253    JSValueProtect(*m_engine, m_value);
    250254}
    251255
     
    256260{
    257261    Q_ASSERT(engine);
    258     JSValueProtect(context(), m_value);
     262    JSValueProtect(*m_engine, m_value);
    259263}
    260264
     
    265269{
    266270    Q_ASSERT(engine);
    267     JSValueProtect(context(), m_value);
     271    JSValueProtect(*m_engine, m_value);
    268272}
    269273
     
    275279    Q_ASSERT(engine);
    276280    Q_ASSERT(value);
    277     JSValueProtect(context(), m_value);
     281    JSValueProtect(*m_engine, m_value);
    278282}
    279283
     
    287291    Q_ASSERT(value);
    288292    Q_ASSERT(object);
    289     JSValueProtect(context(), m_value);
     293    JSValueProtect(*m_engine, m_value);
    290294}
    291295
     
    302306        // Fall-through.
    303307    case JSPrimitive:
    304         return JSValueIsBoolean(context(), value());
     308        return JSValueIsBoolean(*m_engine, *this);
    305309    default:
    306310        return false;
     
    318322        // Fall-through.
    319323    case JSPrimitive:
    320         return JSValueIsNumber(context(), value());
     324        return JSValueIsNumber(*m_engine, *this);
    321325    default:
    322326        return false;
     
    334338        // Fall-through.
    335339    case JSPrimitive:
    336         return JSValueIsNull(context(), value());
     340        return JSValueIsNull(*m_engine, *this);
    337341    default:
    338342        return false;
     
    350354        // Fall-through.
    351355    case JSPrimitive:
    352         return JSValueIsString(context(), value());
     356        return JSValueIsString(*m_engine, *this);
    353357    default:
    354358        return false;
     
    366370        // Fall-through.
    367371    case JSPrimitive:
    368         return JSValueIsUndefined(context(), value());
     372        return JSValueIsUndefined(*m_engine, *this);
    369373    default:
    370374        return false;
     
    407411        // Fall-through.
    408412    case JSObject:
    409         return JSObjectIsFunction(context(), object());
     413        return JSObjectIsFunction(*m_engine, *this);
    410414    default:
    411415        return false;
     
    431435    case JSPrimitive:
    432436    case JSObject:
    433         JSRetainPtr<JSStringRef> ptr(Adopt, JSValueToStringCopy(context(), value(), /* exception */ 0));
     437        JSRetainPtr<JSStringRef> ptr(Adopt, JSValueToStringCopy(*m_engine, *this, /* exception */ 0));
    434438        return QScriptConverter::toString(ptr.get());
    435439    }
     
    445449    case JSPrimitive:
    446450    case JSObject:
    447         return JSValueToNumber(context(), value(), /* exception */ 0);
     451        return JSValueToNumber(*m_engine, *this, /* exception */ 0);
    448452    case CNumber:
    449453        return m_number;
     
    477481    case JSValue:
    478482    case JSPrimitive:
    479         return JSValueToBoolean(context(), value());
     483        return JSValueToBoolean(*m_engine, *this);
    480484    case JSObject:
    481485        return true;
     
    548552        {
    549553            // Exception can't occur here.
    550             JSObjectRef object = JSValueToObject(engine->context(), engine->makeJSValue(m_string), /* exception */ 0);
     554            JSObjectRef object = JSValueToObject(*engine, engine->makeJSValue(m_string), /* exception */ 0);
    551555            Q_ASSERT(object);
    552556            return new QScriptValuePrivate(engine, object, object);
     
    555559        {
    556560            // Exception can't occur here.
    557             JSObjectRef object = JSValueToObject(engine->context(), engine->makeJSValue(m_number), /* exception */ 0);
     561            JSObjectRef object = JSValueToObject(*engine, engine->makeJSValue(m_number), /* exception */ 0);
    558562            Q_ASSERT(object);
    559563            return new QScriptValuePrivate(engine, object, object);
     
    562566        {
    563567            // Exception can't occure here.
    564             JSObjectRef object = JSValueToObject(engine->context(), engine->makeJSValue(static_cast<bool>(m_number)), /* exception */ 0);
     568            JSObjectRef object = JSValueToObject(*engine, engine->makeJSValue(static_cast<bool>(m_number)), /* exception */ 0);
    565569            Q_ASSERT(object);
    566570            return new QScriptValuePrivate(engine, object, object);
     
    574578            if (engine != this->engine())
    575579                qWarning("QScriptEngine::toObject: cannot convert value created in a different engine");
    576             JSObjectRef object = JSValueToObject(context(), value(), /* exception */ 0);
     580            JSObjectRef object = JSValueToObject(*m_engine, *this, /* exception */ 0);
    577581            if (object)
    578582                return new QScriptValuePrivate(m_engine.constData(), object);
     
    632636    }
    633637
    634     return JSValueIsEqual(context(), value(), other->value(), /* exception */ 0);
     638    return JSValueIsEqual(*m_engine, *this, *other, /* exception */ 0);
    635639}
    636640
     
    641645        if (!other->isJSBased()) {
    642646            if (other->assignEngine(engine()))
    643                 return JSValueIsStrictEqual(context(), value(), other->value());
     647                return JSValueIsStrictEqual(*m_engine, *this, *other);
    644648            return false;
    645649        }
     
    648652            return false;
    649653        }
    650         return JSValueIsStrictEqual(context(), value(), other->value());
     654        return JSValueIsStrictEqual(*m_engine, *this, *other);
    651655    }
    652656    if (isStringBased()) {
     
    655659        if (other->isJSBased()) {
    656660            assignEngine(other->engine());
    657             return JSValueIsStrictEqual(context(), value(), other->value());
     661            return JSValueIsStrictEqual(*m_engine, *this, *other);
    658662        }
    659663    }
     
    663667        if (other->isJSBased()) {
    664668            assignEngine(other->engine());
    665             return JSValueIsStrictEqual(context(), value(), other->value());
     669            return JSValueIsStrictEqual(*m_engine, *this, *other);
    666670        }
    667671    }
     
    676680    if (!isJSBased() || !other->isObject())
    677681        return false;
    678     return JSValueIsInstanceOfConstructor(context(), value(), other->object(), /* exception */ 0);
     682    return JSValueIsInstanceOfConstructor(*m_engine, *this, *other, /* exception */ 0);
    679683}
    680684
     
    733737                    return new QScriptValuePrivate;
    734738                }
    735                 argv[j] = value->value();
     739                argv[j] = *value;
    736740            }
    737741
    738742            // Make the call
    739743            JSValueRef exception = 0;
    740             JSValueRef result = JSObjectCallAsFunction(context(), object(), /* thisObject */ 0, argc, argv.constData(), &exception);
     744            JSValueRef result = JSObjectCallAsFunction(*m_engine, *this, /* thisObject */ 0, argc, argv.constData(), &exception);
    741745            if (!result && exception)
    742746                return new QScriptValuePrivate(engine(), exception);
     
    757761}
    758762
    759 JSGlobalContextRef QScriptValuePrivate::context() const
    760 {
    761     Q_ASSERT(isJSBased());
    762     return m_engine->context();
    763 }
    764 
    765 JSValueRef QScriptValuePrivate::value() const
     763QScriptValuePrivate::operator JSValueRef() const
    766764{
    767765    Q_ASSERT(isJSBased());
     
    769767}
    770768
    771 JSObjectRef QScriptValuePrivate::object() const
     769QScriptValuePrivate::operator JSObjectRef() const
    772770{
    773771    Q_ASSERT(m_state == JSObject);
     
    778776{
    779777    if (m_value)
    780         JSValueUnprotect(context(), m_value);
     778        JSValueUnprotect(*m_engine, m_value);
    781779    if (value)
    782         JSValueProtect(context(), value);
     780        JSValueProtect(*m_engine, value);
    783781    m_value = value;
    784782}
     
    792790{
    793791    Q_ASSERT(isJSBased());
    794     JSObjectRef globalObject = JSContextGetGlobalObject(context());
     792    JSObjectRef globalObject = JSContextGetGlobalObject(*m_engine);
    795793    JSStringRef errorAttrName = QScriptConverter::toString(name);
    796     JSValueRef error = JSObjectGetProperty(context(), globalObject, errorAttrName, /* exception */ 0);
     794    JSValueRef error = JSObjectGetProperty(*m_engine, globalObject, errorAttrName, /* exception */ 0);
    797795    JSStringRelease(errorAttrName);
    798     return JSValueIsInstanceOfConstructor(context(), value(), JSValueToObject(context(), error, /* exception */ 0), /* exception */ 0);
     796    return JSValueIsInstanceOfConstructor(*m_engine, *this, JSValueToObject(*m_engine, error, /* exception */ 0), /* exception */ 0);
    799797}
    800798
     
    806804{
    807805    Q_ASSERT(m_state == JSValue);
    808     if (!JSValueIsObject(context(), value())) {
     806    if (!JSValueIsObject(*m_engine, *this)) {
    809807        m_state = JSPrimitive;
    810808    } else {
    811809        m_state = JSObject;
    812810        // We are sure that value is an JSObject, so we can const_cast safely without
    813         // calling JSC C API (JSValueToObject(context(), value(), /* exceptions */ 0)).
     811        // calling JSC C API (JSValueToObject(*m_engine, *this, /* exceptions */ 0)).
    814812        m_object = const_cast<JSObjectRef>(m_value);
    815813    }
Note: See TracChangeset for help on using the changeset viewer.