File indexing completed on 2024-05-19 11:43:17

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
0003     Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
0004     Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
0005     Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #include "object_binding.h"
0024 
0025 #include <QArgument>
0026 #include <QDebug>
0027 
0028 
0029 using namespace KJSEmbed;
0030 
0031 const KJS::ClassInfo ObjectBinding::info = { "ObjectBinding", nullptr, nullptr, nullptr };
0032 
0033 ObjectBinding::~ObjectBinding()
0034 {
0035     if (m_owner == JSOwned) {
0036         m_value->cleanup();
0037     }
0038 
0039     delete m_value;
0040 }
0041 
0042 const char *ObjectBinding::typeName() const
0043 {
0044     return m_name;
0045 }
0046 
0047 KJS::UString ObjectBinding::toString(KJS::ExecState * /*exec*/) const
0048 {
0049     return KJS::UString(typeName());
0050 }
0051 
0052 KJS::UString ObjectBinding::className() const
0053 {
0054     return KJS::UString(typeName());
0055 }
0056 
0057 KJS::JSType ObjectBinding::type() const
0058 {
0059     return KJS::ObjectType;
0060 }
0061 
0062 ObjectBinding::Ownership ObjectBinding::ownership() const
0063 {
0064     return m_owner;
0065 }
0066 
0067 void ObjectBinding::setOwnership(ObjectBinding::Ownership owner)
0068 {
0069     m_owner = owner;
0070 }
0071 
0072 KJS::JSValue *callPointerName(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &/*args*/)
0073 {
0074     KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp<KJSEmbed::ObjectBinding>(exec,  self);
0075     if (imp) {
0076         return KJS::jsString(imp->typeName());
0077     }
0078     return KJS::jsNull();
0079 }
0080 
0081 KJS::JSValue *callPointerCast(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &/*args*/)
0082 {
0083     KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp<KJSEmbed::ObjectBinding>(exec,  self);
0084     if (imp) {
0085         return KJS::jsBoolean(false);
0086     }
0087     return KJS::jsNull();
0088 }
0089 
0090 KJS::JSValue *callPointerToString(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &/*args*/)
0091 {
0092     KJSEmbed::ObjectBinding *imp = KJSEmbed::extractBindingImp<KJSEmbed::ObjectBinding>(exec,  self);
0093     if (imp) {
0094         qDebug("Object to string");
0095         return KJS::jsString(imp->typeName());
0096     }
0097     return KJS::jsNull();
0098 }
0099 
0100 const Method ObjectFactory::ObjectMethods[] = {
0101     {"type", 0, KJS::DontDelete | KJS::ReadOnly, &callPointerName },
0102     {"cast", 1, KJS::DontDelete | KJS::ReadOnly, &callPointerCast },
0103     {"toString", 0, KJS::DontDelete | KJS::ReadOnly, &callPointerToString },
0104     {nullptr, 0, 0, nullptr }
0105 };
0106