| # kjs Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# object.h

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    00006  *
    00007  *  This library is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU Lesser General Public
    00009  *  License as published by the Free Software Foundation; either
    00010  *  version 2 of the License, or (at your option) any later version.
    00011  *
    00012  *  This library is distributed in the hope that it will be useful,
    00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  *  Lesser General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU Lesser General Public License
    00018  *  along with this library; see the file COPYING.LIB.  If not, write to
    00019  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  *  Boston, MA 02111-1307, USA.
    00021  *
    00022  */
    00023
    00024
    00025 #ifndef _KJS_OBJECT_H_
    00026 #define _KJS_OBJECT_H_
    00027
    00028 // Objects
    00029
    00030 #include "value.h"
    00031 #include "types.h"
    00032
    00033 namespace KJS {
    00034
    00035   class ObjectImpPrivate;
    00036   class PropertyMap;
    00037   class HashTable;
    00038   class HashEntry;
    00039   class ListImp;
    00040
    00041   // ECMA 262-3 8.6.1
    00042   // Attributes (only applicable to the Object type)
    00043   enum Attribute { None       = 0,
    00044                    ReadOnly   = 1 << 1, // property can be only read, not written
    00045                    DontEnum   = 1 << 2, // property doesn't appear in (for .. in ..)
    00046                    DontDelete = 1 << 3, // property can't be deleted
    00047                    Internal   = 1 << 4, // an internal property, set to by pass checks
    00048                    Function   = 1 << 5 }; // property is a function - only used by static hashtables
    00049
    00053   struct ClassInfo {
    00057     const char* className;
    00062     const ClassInfo *parentClass;
    00066     const HashTable *propHashTable;
    00070     void *dummy;
    00071   };
    00072
    00076   class Object : public Value {
    00077   public:
    00078     Object();
    00079     explicit Object(ObjectImp *v);
    00080     Object(const Object &v);
    00081     virtual ~Object();          // TODO: make non-virtual
    00082
    00083     Object& operator=(const Object &v);
    00084
    00085     virtual const ClassInfo *classInfo() const; // TODO: make non-virtual
    00086     bool inherits(const ClassInfo *cinfo) const;
    00087
    00097     static Object dynamicCast(const Value &v);
    00098
    00107     Value prototype() const;
    00108
    00116     UString className() const;
    00117
    00130     Value get(ExecState *exec, const UString &propertyName) const;
    00131
    00141     void put(ExecState *exec, const UString &propertyName,
    00142              const Value &value, int attr = None);
    00143
    00154     bool canPut(ExecState *exec, const UString &propertyName) const;
    00155
    00166     bool hasProperty(ExecState *exec, const UString &propertyName) const;
    00167
    00179     bool deleteProperty(ExecState *exec, const UString &propertyName);
    00180
    00193     Value defaultValue(ExecState *exec, Type hint) const;
    00194
    00203     bool implementsConstruct() const;
    00204
    00230     Object construct(ExecState *exec, const List &args);
    00231
    00240     bool implementsCall() const;
    00241
    00242
    00260     Value call(ExecState *exec, Object &thisObj, const List &args);
    00261
    00270     bool implementsHasInstance() const;
    00271
    00281     Boolean hasInstance(ExecState *exec, const Value &value);
    00282
    00307     const List scope() const;
    00308     void setScope(const List &s);
    00309
    00326     List propList(ExecState *exec, bool recursive = true);
    00327
    00336     Value internalValue() const;
    00337
    00345     void setInternalValue(const Value &v);
    00346   };
    00347
    00348   class ObjectImp : public ValueImp {
    00349   public:
    00355     ObjectImp(const Object &proto);
    00356
    00362     ObjectImp();
    00363
    00364     virtual ~ObjectImp();
    00365
    00366     virtual void mark();
    00367
    00368     Type type() const;
    00369
    00403     virtual const ClassInfo *classInfo() const;
    00404
    00431     bool inherits(const ClassInfo *cinfo) const;
    00432
    00433     // internal properties (ECMA 262-3 8.6.2)
    00434
    00441     Value prototype() const;
    00442     void setPrototype(const Value &proto);
    00443
    00455     virtual UString className() const;
    00456
    00463     // [[Get]] - must be implemented by all Objects
    00464     virtual Value get(ExecState *exec, const UString &propertyName) const;
    00465
    00472     virtual void put(ExecState *exec, const UString &propertyName,
    00473                      const Value &value, int attr = None);
    00474
    00481     virtual bool canPut(ExecState *exec, const UString &propertyName) const;
    00482
    00489     virtual bool hasProperty(ExecState *exec,
    00490                              const UString &propertyName) const;
    00491
    00498     virtual bool deleteProperty(ExecState *exec,
    00499                                 const UString &propertyName);
    00500
    00506     void deleteAllProperties( ExecState * );
    00507
    00514     virtual Value defaultValue(ExecState *exec, Type hint) const;
    00515
    00516     virtual bool implementsConstruct() const;
    00522     virtual Object construct(ExecState *exec, const List &args);
    00523
    00524     virtual bool implementsCall() const;
    00530     virtual Value call(ExecState *exec, Object &thisObj,
    00531                        const List &args);
    00532
    00533     virtual bool implementsHasInstance() const;
    00539     virtual Boolean hasInstance(ExecState *exec, const Value &value);
    00540
    00546     const List scope() const;
    00547     void setScope(const List &s);
    00548
    00549     List propList(ExecState *exec, bool recursive = true);
    00550
    00551     Value internalValue() const;
    00552     void setInternalValue(const Value &v);
    00553
    00554     Value toPrimitive(ExecState *exec,
    00555                       Type preferredType = UnspecifiedType) const;
    00556     bool toBoolean(ExecState *exec) const;
    00557     double toNumber(ExecState *exec) const;
    00558     int toInteger(ExecState *exec) const;
    00559     int toInt32(ExecState *exec) const;
    00560     unsigned int toUInt32(ExecState *exec) const;
    00561     unsigned short toUInt16(ExecState *exec) const;
    00562     UString toString(ExecState *exec) const;
    00563     Object toObject(ExecState *exec) const;
    00564
    00565     ValueImp* getDirect(const UString& propertyName) const;
    00566   private:
    00567     const HashEntry* findPropertyHashEntry( const UString& propertyName ) const;
    00568     ObjectImpPrivate *_od;
    00569     PropertyMap *_prop;
    00570     ValueImp *_proto;
    00571     ValueImp *_internalValue;
    00572     ListImp *_scope;
    00573   };
    00574
    00579   enum ErrorType { GeneralError   = 0,
    00580                    EvalError      = 1,
    00581                    RangeError     = 2,
    00582                    ReferenceError = 3,
    00583                    SyntaxError    = 4,
    00584                    TypeError      = 5,
    00585                    URIError       = 6};
    00586
    00590   class Error {
    00591   public:
    00601     static Object create(ExecState *exec, ErrorType errtype = GeneralError,
    00602                          const char *message = 0, int lineno = -1,
    00603                          int sourceId = -1);
    00604
    00608     static const char * const * const errorNames;
    00609   };
    00610
    00611 } // namespace
    00612
    00613 #endif // _KJS_OBJECT_H_

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:08:33 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001