src/script/bridge/qscriptvariant.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    27 #include "../api/qscriptengine.h"
    27 #include "../api/qscriptengine.h"
    28 #include "../api/qscriptengine_p.h"
    28 #include "../api/qscriptengine_p.h"
    29 
    29 
    30 #include "Error.h"
    30 #include "Error.h"
    31 #include "PrototypeFunction.h"
    31 #include "PrototypeFunction.h"
       
    32 #include "JSFunction.h"
       
    33 #include "NativeFunctionWrapper.h"
    32 #include "JSString.h"
    34 #include "JSString.h"
    33 
    35 
    34 namespace JSC
    36 namespace JSC
    35 {
    37 {
    36 QT_USE_NAMESPACE
    38 QT_USE_NAMESPACE
   117     const QVariant &v = static_cast<QVariantDelegate*>(delegate)->value();
   119     const QVariant &v = static_cast<QVariantDelegate*>(delegate)->value();
   118     JSC::UString result;
   120     JSC::UString result;
   119     JSC::JSValue value = variantProtoFuncValueOf(exec, callee, thisValue, args);
   121     JSC::JSValue value = variantProtoFuncValueOf(exec, callee, thisValue, args);
   120     if (value.isObject()) {
   122     if (value.isObject()) {
   121         result = v.toString();
   123         result = v.toString();
   122         if (result.isEmpty() && !v.canConvert(QVariant::String)) {
   124         if (result.isEmpty() && !v.canConvert(QVariant::String))
   123             result = "QVariant(";
   125             result = QString::fromLatin1("QVariant(%0)").arg(QString::fromLatin1(v.typeName()));
   124             result += v.typeName();
       
   125             result += ")";
       
   126         }
       
   127     } else {
   126     } else {
   128         result = value.toString(exec);
   127         result = value.toString(exec);
   129     }
   128     }
   130     return JSC::jsString(exec, result);
   129     return JSC::jsString(exec, result);
   131 }
   130 }
   132 
   131 
   133 bool QVariantDelegate::compareToObject(QScriptObject *, JSC::ExecState *exec, JSC::JSObject *o2)
   132 bool QVariantDelegate::compareToObject(QScriptObject *, JSC::ExecState *exec, JSC::JSObject *o2)
   134 {
   133 {
   135     const QVariant &variant1 = value();
   134     const QVariant &variant1 = value();
   136     return variant1 == scriptEngineFromExec(exec)->scriptValueFromJSCValue(o2).toVariant();
   135     return variant1 == QScriptEnginePrivate::toVariant(exec, o2);
   137 }
   136 }
   138 
   137 
   139 QVariantPrototype::QVariantPrototype(JSC::ExecState* exec, WTF::PassRefPtr<JSC::Structure> structure,
   138 QVariantPrototype::QVariantPrototype(JSC::ExecState* exec, WTF::PassRefPtr<JSC::Structure> structure,
   140                                      JSC::Structure* prototypeFunctionStructure)
   139                                      JSC::Structure* prototypeFunctionStructure)
   141     : QScriptObject(structure)
   140     : QScriptObject(structure)
   142 {
   141 {
   143     setDelegate(new QVariantDelegate(QVariant()));
   142     setDelegate(new QVariantDelegate(QVariant()));
   144 
   143 
   145     putDirectFunction(exec, new (exec) JSC::PrototypeFunction(exec, prototypeFunctionStructure, 0, exec->propertyNames().toString, variantProtoFuncToString), JSC::DontEnum);
   144     putDirectFunction(exec, new (exec) JSC::NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().toString, variantProtoFuncToString), JSC::DontEnum);
   146     putDirectFunction(exec, new (exec) JSC::PrototypeFunction(exec, prototypeFunctionStructure, 0, exec->propertyNames().valueOf, variantProtoFuncValueOf), JSC::DontEnum);
   145     putDirectFunction(exec, new (exec) JSC::NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().valueOf, variantProtoFuncValueOf), JSC::DontEnum);
   147 }
   146 }
   148 
   147 
   149 
   148 
   150 } // namespace QScript
   149 } // namespace QScript
   151 
   150