kjs Library API Documentation

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 * Copyright (C) 2003 Apple Computer, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Library General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Library General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Library General Public License 00019 * along with this library; see the file COPYING.LIB. If not, write to 00020 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 * Boston, MA 02111-1307, USA. 00022 * 00023 */ 00024 00025 00026 #ifndef _KJS_OBJECT_H_ 00027 #define _KJS_OBJECT_H_ 00028 00029 // Objects 00030 00031 #include "value.h" 00032 #include "types.h" 00033 #include "reference_list.h" 00034 #include "identifier.h" 00035 #include "property_map.h" 00036 #include "scope_chain.h" 00037 00038 namespace KJS { 00039 00040 class ObjectImpPrivate; 00041 class PropertyMap; 00042 class HashTable; 00043 struct HashEntry; 00044 class ListImp; 00045 00046 // ECMA 262-3 8.6.1 00047 // Attributes (only applicable to the Object type) 00048 enum Attribute { None = 0, 00049 ReadOnly = 1 << 1, // property can be only read, not written 00050 DontEnum = 1 << 2, // property doesn't appear in (for .. in ..) 00051 DontDelete = 1 << 3, // property can't be deleted 00052 Internal = 1 << 4, // an internal property, set to by pass checks 00053 Function = 1 << 5 }; // property is a function - only used by static hashtables 00054 00058 struct ClassInfo { 00062 const char* className; 00067 const ClassInfo *parentClass; 00071 const HashTable *propHashTable; 00075 void *dummy; 00076 }; 00077 00081 class Object : public Value { 00082 public: 00083 Object() { } 00084 explicit Object(ObjectImp *v); 00085 00086 ObjectImp *imp() const; 00087 00088 const ClassInfo *classInfo() const; 00089 bool inherits(const ClassInfo *cinfo) const; 00090 00100 static Object dynamicCast(const Value &v); 00101 00110 Value prototype() const; 00111 00119 UString className() const; 00120 00133 Value get(ExecState *exec, const Identifier &propertyName) const; 00134 Value get(ExecState *exec, unsigned propertyName) const; 00135 00145 void put(ExecState *exec, const Identifier &propertyName, 00146 const Value &value, int attr = None); 00147 void put(ExecState *exec, unsigned propertyName, 00148 const Value &value, int attr = None); 00149 00160 bool canPut(ExecState *exec, const Identifier &propertyName) const; 00161 00172 bool hasProperty(ExecState *exec, const Identifier &propertyName) const; 00173 bool hasProperty(ExecState *exec, unsigned propertyName) const; 00174 00186 bool deleteProperty(ExecState *exec, const Identifier &propertyName); 00187 bool deleteProperty(ExecState *exec, unsigned propertyName); 00188 00201 Value defaultValue(ExecState *exec, Type hint) const; 00202 00211 bool implementsConstruct() const; 00212 00238 Object construct(ExecState *exec, const List &args); 00239 00248 bool implementsCall() const; 00249 00250 00268 Value call(ExecState *exec, Object &thisObj, const List &args); 00269 00278 bool implementsHasInstance() const; 00279 00289 Boolean hasInstance(ExecState *exec, const Value &value); 00290 00316 const ScopeChain &scope() const; 00317 void setScope(const ScopeChain &s); 00318 00335 ReferenceList propList(ExecState *exec, bool recursive = true); 00336 00345 Value internalValue() const; 00346 00354 void setInternalValue(const Value &v); 00355 }; 00356 00357 inline Object Value::toObject(ExecState *exec) const { return rep->dispatchToObject(exec); } 00358 00359 class ObjectImp : public ValueImp { 00360 friend class ObjectProtoFuncImp; 00361 public: 00367 ObjectImp(const Object &proto); 00368 ObjectImp(ObjectImp *proto); 00369 00375 ObjectImp(); 00376 00377 virtual ~ObjectImp(); 00378 00379 virtual void mark(); 00380 00381 Type type() const; 00382 00420 virtual const ClassInfo *classInfo() const; 00421 00448 bool inherits(const ClassInfo *cinfo) const; 00449 00450 // internal properties (ECMA 262-3 8.6.2) 00451 00458 Value prototype() const; 00459 void setPrototype(const Value &proto); 00460 00472 virtual UString className() const; 00473 00480 // [[Get]] - must be implemented by all Objects 00481 virtual Value get(ExecState *exec, const Identifier &propertyName) const; 00482 virtual Value getPropertyByIndex(ExecState *exec, 00483 unsigned propertyName) const; 00484 00491 virtual void put(ExecState *exec, const Identifier &propertyName, 00492 const Value &value, int attr = None); 00493 virtual void putPropertyByIndex(ExecState *exec, unsigned propertyName, 00494 const Value &value, int attr = None); 00495 00502 virtual bool canPut(ExecState *exec, const Identifier &propertyName) const; 00503 00510 virtual bool hasProperty(ExecState *exec, 00511 const Identifier &propertyName) const; 00512 virtual bool hasPropertyByIndex(ExecState *exec, unsigned propertyName) const; 00513 00520 virtual bool deleteProperty(ExecState *exec, 00521 const Identifier &propertyName); 00522 virtual bool deletePropertyByIndex(ExecState *exec, unsigned propertyName); 00523 00529 void deleteAllProperties(ExecState *); 00530 00537 virtual Value defaultValue(ExecState *exec, Type hint) const; 00538 00539 virtual bool implementsConstruct() const; 00545 virtual Object construct(ExecState *exec, const List &args); 00546 00547 virtual bool implementsCall() const; 00553 virtual Value call(ExecState *exec, Object &thisObj, 00554 const List &args); 00555 00556 virtual bool implementsHasInstance() const; 00562 virtual Boolean hasInstance(ExecState *exec, const Value &value); 00563 00569 const ScopeChain &scope() const { return _scope; } 00570 void setScope(const ScopeChain &s) { _scope = s; } 00571 00572 virtual ReferenceList propList(ExecState *exec, bool recursive = true); 00573 00574 Value internalValue() const; 00575 void setInternalValue(const Value &v); 00576 void setInternalValue(ValueImp *v); 00577 00578 Value toPrimitive(ExecState *exec, 00579 Type preferredType = UnspecifiedType) const; 00580 bool toBoolean(ExecState *exec) const; 00581 double toNumber(ExecState *exec) const; 00582 UString toString(ExecState *exec) const; 00583 Object toObject(ExecState *exec) const; 00584 00585 // This get method only looks at the property map. 00586 // A bit like hasProperty(recursive=false), this doesn't go to the prototype. 00587 // This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want 00588 // to look up in the prototype, it might already exist there) 00589 ValueImp *getDirect(const Identifier& propertyName) const 00590 { return _prop.get(propertyName); } 00591 void putDirect(const Identifier &propertyName, ValueImp *value, int attr = 0); 00592 void putDirect(const Identifier &propertyName, int value, int attr = 0); 00593 00598 void setFunctionName(const Identifier &propertyName); 00599 00600 protected: 00601 PropertyMap _prop; 00602 private: 00603 const HashEntry* findPropertyHashEntry( const Identifier& propertyName ) const; 00604 ObjectImpPrivate *_od; 00605 ValueImp *_proto; 00606 ValueImp *_internalValue; 00607 ScopeChain _scope; 00608 }; 00609 00614 enum ErrorType { GeneralError = 0, 00615 EvalError = 1, 00616 RangeError = 2, 00617 ReferenceError = 3, 00618 SyntaxError = 4, 00619 TypeError = 5, 00620 URIError = 6}; 00621 00625 class Error { 00626 public: 00636 static Object create(ExecState *exec, ErrorType errtype = GeneralError, 00637 const char *message = 0, int lineno = -1, 00638 int sourceId = -1); 00639 00643 static const char * const * const errorNames; 00644 }; 00645 00646 inline Object::Object(ObjectImp *v) : Value(v) { } 00647 00648 inline ObjectImp *Object::imp() const { return static_cast<ObjectImp*>(rep); } 00649 00650 inline const ClassInfo *Object::classInfo() const 00651 { return imp()->classInfo(); } 00652 00653 inline bool Object::inherits(const ClassInfo *cinfo) const 00654 { return imp()->inherits(cinfo); } 00655 00656 inline Value Object::prototype() const 00657 { return Value(imp()->prototype()); } 00658 00659 inline UString Object::className() const 00660 { return imp()->className(); } 00661 00662 inline Value Object::get(ExecState *exec, const Identifier &propertyName) const 00663 { return imp()->get(exec,propertyName); } 00664 00665 inline Value Object::get(ExecState *exec, unsigned propertyName) const 00666 { return imp()->getPropertyByIndex(exec, propertyName); } 00667 00668 inline void Object::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr) 00669 { imp()->put(exec,propertyName,value,attr); } 00670 00671 inline void Object::put(ExecState *exec, unsigned propertyName, const Value &value, int attr) 00672 { imp()->putPropertyByIndex(exec, propertyName, value, attr); } 00673 00674 inline bool Object::canPut(ExecState *exec, const Identifier &propertyName) const 00675 { return imp()->canPut(exec,propertyName); } 00676 00677 inline bool Object::hasProperty(ExecState *exec, const Identifier &propertyName) const 00678 { return imp()->hasProperty(exec, propertyName); } 00679 00680 inline bool Object::hasProperty(ExecState *exec, unsigned propertyName) const 00681 { return imp()->hasPropertyByIndex(exec, propertyName); } 00682 00683 inline bool Object::deleteProperty(ExecState *exec, const Identifier &propertyName) 00684 { return imp()->deleteProperty(exec,propertyName); } 00685 00686 inline bool Object::deleteProperty(ExecState *exec, unsigned propertyName) 00687 { return imp()->deletePropertyByIndex(exec, propertyName); } 00688 00689 inline Value Object::defaultValue(ExecState *exec, Type hint) const 00690 { return imp()->defaultValue(exec,hint); } 00691 00692 inline bool Object::implementsConstruct() const 00693 { return imp()->implementsConstruct(); } 00694 00695 inline Object Object::construct(ExecState *exec, const List &args) 00696 { return imp()->construct(exec,args); } 00697 00698 inline bool Object::implementsCall() const 00699 { return imp()->implementsCall(); } 00700 00701 inline bool Object::implementsHasInstance() const 00702 { return imp()->implementsHasInstance(); } 00703 00704 inline Boolean Object::hasInstance(ExecState *exec, const Value &value) 00705 { return imp()->hasInstance(exec,value); } 00706 00707 inline const ScopeChain &Object::scope() const 00708 { return imp()->scope(); } 00709 00710 inline void Object::setScope(const ScopeChain &s) 00711 { imp()->setScope(s); } 00712 00713 inline ReferenceList Object::propList(ExecState *exec, bool recursive) 00714 { return imp()->propList(exec,recursive); } 00715 00716 inline Value Object::internalValue() const 00717 { return imp()->internalValue(); } 00718 00719 inline void Object::setInternalValue(const Value &v) 00720 { imp()->setInternalValue(v); } 00721 00722 } // namespace 00723 00724 #endif // _KJS_OBJECT_H_
KDE Logo
This file is part of the documentation for kjs Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Aug 30 22:54:17 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003