source: trunk/src/script/bridge/qscriptvariant.cpp@ 1123

Last change on this file since 1123 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtScript module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL-ONLY$
10** GNU Lesser General Public License Usage
11** This file may be used under the terms of the GNU Lesser
12** General Public License version 2.1 as published by the Free Software
13** Foundation and appearing in the file LICENSE.LGPL included in the
14** packaging of this file. Please review the following information to
15** ensure the GNU Lesser General Public License version 2.1 requirements
16** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17**
18** If you have questions regarding the use of this file, please contact
19** Nokia at [email protected].
20** $QT_END_LICENSE$
21**
22****************************************************************************/
23
24#include "config.h"
25#include "qscriptvariant_p.h"
26
27#include "../api/qscriptengine.h"
28#include "../api/qscriptengine_p.h"
29
30#include "Error.h"
31#include "PrototypeFunction.h"
32#include "JSFunction.h"
33#include "NativeFunctionWrapper.h"
34#include "JSString.h"
35
36namespace JSC
37{
38QT_USE_NAMESPACE
39ASSERT_CLASS_FITS_IN_CELL(QScript::QVariantPrototype);
40}
41
42QT_BEGIN_NAMESPACE
43
44namespace QScript
45{
46
47QVariantDelegate::QVariantDelegate(const QVariant &value)
48 : m_value(value)
49{
50}
51
52QVariantDelegate::~QVariantDelegate()
53{
54}
55
56QVariant &QVariantDelegate::value()
57{
58 return m_value;
59}
60
61void QVariantDelegate::setValue(const QVariant &value)
62{
63 m_value = value;
64}
65
66QScriptObjectDelegate::Type QVariantDelegate::type() const
67{
68 return Variant;
69}
70
71static JSC::JSValue JSC_HOST_CALL variantProtoFuncValueOf(JSC::ExecState *exec, JSC::JSObject*,
72 JSC::JSValue thisValue, const JSC::ArgList&)
73{
74 QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
75 thisValue = engine->toUsableValue(thisValue);
76 if (!thisValue.inherits(&QScriptObject::info))
77 return throwError(exec, JSC::TypeError);
78 QScriptObjectDelegate *delegate = static_cast<QScriptObject*>(JSC::asObject(thisValue))->delegate();
79 if (!delegate || (delegate->type() != QScriptObjectDelegate::Variant))
80 return throwError(exec, JSC::TypeError);
81 const QVariant &v = static_cast<QVariantDelegate*>(delegate)->value();
82 switch (v.type()) {
83 case QVariant::Invalid:
84 return JSC::jsUndefined();
85 case QVariant::String:
86 return JSC::jsString(exec, v.toString());
87
88 case QVariant::Int:
89 return JSC::jsNumber(exec, v.toInt());
90
91 case QVariant::Bool:
92 return JSC::jsBoolean(v.toBool());
93
94 case QVariant::Double:
95 return JSC::jsNumber(exec, v.toDouble());
96
97// case QVariant::Char:
98// return JSC::jsNumber(exec, v.toChar().unicode());
99
100 case QVariant::UInt:
101 return JSC::jsNumber(exec, v.toUInt());
102
103 default: