• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
object.h
1 // -*- c-basic-offset: 2 -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
5  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
6  * Copyright (C) 2003 Apple Computer, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 
26 #ifndef _KJS_OBJECT_H_
27 #define _KJS_OBJECT_H_
28 
29 // Objects
30 
31 #include "value.h"
32 #include "types.h"
33 #include "reference_list.h"
34 #include "identifier.h"
35 #include "property_map.h"
36 #include "scope_chain.h"
37 
38 namespace KJS {
39 
40  class ObjectImpPrivate;
41  class PropertyMap;
42  class HashTable;
43  struct HashEntry;
44  class ListImp;
45 
49  enum Attribute { None = 0,
50  ReadOnly = 1 << 1,
51  DontEnum = 1 << 2,
52  DontDelete = 1 << 3,
53  Internal = 1 << 4,
54  Function = 1 << 5 };
55 
59  struct ClassInfo {
63  const char* className;
68  const ClassInfo *parentClass;
72  const HashTable *propHashTable;
76  void *dummy;
77  };
78 
82  class KJS_EXPORT Object : public Value {
83  public:
84  Object() { }
85  explicit Object(ObjectImp *v);
86 
87  ObjectImp *imp() const;
88 
89  const ClassInfo *classInfo() const;
90  bool inherits(const ClassInfo *cinfo) const;
91 
101  static Object dynamicCast(const Value &v);
102 
111  Value prototype() const;
112 
120  UString className() const;
121 
134  Value get(ExecState *exec, const Identifier &propertyName) const;
135  Value get(ExecState *exec, unsigned propertyName) const;
136 
147  void put(ExecState *exec, const Identifier &propertyName,
148  const Value &value, int attr = None);
149  void put(ExecState *exec, unsigned propertyName,
150  const Value &value, int attr = None);
151 
162  bool canPut(ExecState *exec, const Identifier &propertyName) const;
163 
174  bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
175  bool hasProperty(ExecState *exec, unsigned propertyName) const;
176 
188  bool deleteProperty(ExecState *exec, const Identifier &propertyName);
189  bool deleteProperty(ExecState *exec, unsigned propertyName);
190 
203  Value defaultValue(ExecState *exec, Type hint) const;
204 
213  bool implementsConstruct() const;
214 
240  Object construct(ExecState *exec, const List &args);
241 
250  bool implementsCall() const;
251 
252 
270  Value call(ExecState *exec, Object &thisObj, const List &args);
271 
280  bool implementsHasInstance() const;
281 
291  Boolean hasInstance(ExecState *exec, const Value &value);
292 
318  const ScopeChain &scope() const;
319  void setScope(const ScopeChain &s);
320 
337  ReferenceList propList(ExecState *exec, bool recursive = true);
338 
347  Value internalValue() const;
348 
356  void setInternalValue(const Value &v);
357  };
358 
359  inline Object Value::toObject(ExecState *exec) const { return rep->dispatchToObject(exec); }
360 
361  class KJS_EXPORT ObjectImp : public ValueImp {
362  friend class ObjectProtoFuncImp;
363  public:
369  ObjectImp(const Object &proto);
370  ObjectImp(ObjectImp *proto);
371 
377  ObjectImp();
378 
379  virtual ~ObjectImp();
380 
381  virtual void mark();
382 
383  Type type() const;
384 
422  virtual const ClassInfo *classInfo() const;
423 
450  bool inherits(const ClassInfo *cinfo) const;
451 
452  // internal properties (ECMA 262-3 8.6.2)
453 
460  Value prototype() const;
461  void setPrototype(const Value &proto);
462 
474  virtual UString className() const;
475 
482  // [[Get]] - must be implemented by all Objects
483  virtual Value get(ExecState *exec, const Identifier &propertyName) const;
484  virtual Value getPropertyByIndex(ExecState *exec,
485  unsigned propertyName) const;
486 
493  virtual void put(ExecState *exec, const Identifier &propertyName,
494  const Value &value, int attr = None);
495  virtual void putPropertyByIndex(ExecState *exec, unsigned propertyName,
496  const Value &value, int attr = None);
497 
504  virtual bool canPut(ExecState *exec, const Identifier &propertyName) const;
505 
512  virtual bool hasProperty(ExecState *exec,
513  const Identifier &propertyName) const;
514  virtual bool hasPropertyByIndex(ExecState *exec, unsigned propertyName) const;
515 
522  virtual bool deleteProperty(ExecState *exec,
523  const Identifier &propertyName);
524  virtual bool deletePropertyByIndex(ExecState *exec, unsigned propertyName);
525 
531  void deleteAllProperties(ExecState *);
532 
539  virtual Value defaultValue(ExecState *exec, Type hint) const;
540 
541  virtual bool implementsConstruct() const;
547  virtual Object construct(ExecState *exec, const List &args);
548 
549  virtual bool implementsCall() const;
555  virtual Value call(ExecState *exec, Object &thisObj,
556  const List &args);
557 
558  virtual bool implementsHasInstance() const;
564  virtual Boolean hasInstance(ExecState *exec, const Value &value);
565 
571  const ScopeChain &scope() const { return _scope; }
572  void setScope(const ScopeChain &s) { _scope = s; }
573 
574  virtual ReferenceList propList(ExecState *exec, bool recursive = true);
575 
576  Value internalValue() const;
577  void setInternalValue(const Value &v);
578  void setInternalValue(ValueImp *v);
579 
580  Value toPrimitive(ExecState *exec,
581  Type preferredType = UnspecifiedType) const;
582  bool toBoolean(ExecState *exec) const;
583  double toNumber(ExecState *exec) const;
584  UString toString(ExecState *exec) const;
585  Object toObject(ExecState *exec) const;
586 
587  // This get method only looks at the property map.
588  // A bit like hasProperty(recursive=false), this doesn't go to the prototype.
589  // This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
590  // to look up in the prototype, it might already exist there)
591  ValueImp *getDirect(const Identifier& propertyName) const
592  { return _prop.get(propertyName); }
593  void putDirect(const Identifier &propertyName, ValueImp *value, int attr = 0);
594  void putDirect(const Identifier &propertyName, int value, int attr = 0);
595 
600  void setFunctionName(const Identifier &propertyName);
601 
602  protected:
603  PropertyMap _prop;
604  private:
605  const HashEntry* findPropertyHashEntry( const Identifier& propertyName ) const;
606  ObjectImpPrivate *_od;
607  ValueImp *_proto;
608  ValueImp *_internalValue;
609  ScopeChain _scope;
610  };
611 
616  enum ErrorType { GeneralError = 0,
617  EvalError = 1,
618  RangeError = 2,
619  ReferenceError = 3,
620  SyntaxError = 4,
621  TypeError = 5,
622  URIError = 6};
623 
627  class KJS_EXPORT Error {
628  public:
638  static Object create(ExecState *exec, ErrorType errtype = GeneralError,
639  const char *message = 0, int lineno = -1,
640  int sourceId = -1);
641 
645  static const char * const * const errorNames;
646  };
647 
648  inline Object::Object(ObjectImp *v) : Value(v) { }
649 
650  inline ObjectImp *Object::imp() const { return static_cast<ObjectImp*>(rep); }
651 
652  inline const ClassInfo *Object::classInfo() const
653  { return imp()->classInfo(); }
654 
655  inline bool Object::inherits(const ClassInfo *cinfo) const
656  { return imp()->inherits(cinfo); }
657 
658  inline Value Object::prototype() const
659  { return Value(imp()->prototype()); }
660 
661  inline UString Object::className() const
662  { return imp()->className(); }
663 
664  inline Value Object::get(ExecState *exec, const Identifier &propertyName) const
665  { return imp()->get(exec,propertyName); }
666 
667  inline Value Object::get(ExecState *exec, unsigned propertyName) const
668  { return imp()->getPropertyByIndex(exec, propertyName); }
669 
670  inline void Object::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
671  { imp()->put(exec,propertyName,value,attr); }
672 
673  inline void Object::put(ExecState *exec, unsigned propertyName, const Value &value, int attr)
674  { imp()->putPropertyByIndex(exec, propertyName, value, attr); }
675 
676  inline bool Object::canPut(ExecState *exec, const Identifier &propertyName) const
677  { return imp()->canPut(exec,propertyName); }
678 
679  inline bool Object::hasProperty(ExecState *exec, const Identifier &propertyName) const
680  { return imp()->hasProperty(exec, propertyName); }
681 
682  inline bool Object::hasProperty(ExecState *exec, unsigned propertyName) const
683  { return imp()->hasPropertyByIndex(exec, propertyName); }
684 
685  inline bool Object::deleteProperty(ExecState *exec, const Identifier &propertyName)
686  { return imp()->deleteProperty(exec,propertyName); }
687 
688  inline bool Object::deleteProperty(ExecState *exec, unsigned propertyName)
689  { return imp()->deletePropertyByIndex(exec, propertyName); }
690 
691  inline Value Object::defaultValue(ExecState *exec, Type hint) const
692  { return imp()->defaultValue(exec,hint); }
693 
694  inline bool Object::implementsConstruct() const
695  { return imp()->implementsConstruct(); }
696 
697  inline Object Object::construct(ExecState *exec, const List &args)
698  { return imp()->construct(exec,args); }
699 
700  inline bool Object::implementsCall() const
701  { return imp()->implementsCall(); }
702 
703  inline bool Object::implementsHasInstance() const
704  { return imp()->implementsHasInstance(); }
705 
706  inline Boolean Object::hasInstance(ExecState *exec, const Value &value)
707  { return imp()->hasInstance(exec,value); }
708 
709  inline const ScopeChain &Object::scope() const
710  { return imp()->scope(); }
711 
712  inline void Object::setScope(const ScopeChain &s)
713  { imp()->setScope(s); }
714 
715  inline ReferenceList Object::propList(ExecState *exec, bool recursive)
716  { return imp()->propList(exec,recursive); }
717 
718  inline Value Object::internalValue() const
719  { return imp()->internalValue(); }
720 
721  inline void Object::setInternalValue(const Value &v)
722  { imp()->setInternalValue(v); }
723 
724 } // namespace
725 
726 #endif // _KJS_OBJECT_H_
KJS::Boolean
Represents an primitive Boolean value.
Definition: value.h:317
KJS::Error
Factory methods for error objects.
Definition: object.h:627
KJS::Error::errorNames
static const char *const *const errorNames
Array of error names corresponding to ErrorType.
Definition: object.h:645
KJS::ExecState
Represents the current state of script execution.
Definition: interpreter.h:439
KJS::Identifier
Represents an Identifier for a Javascript object.
Definition: identifier.h:32
KJS::List
Native list type.
Definition: list.h:48
KJS::Object
Represents an Object.
Definition: object.h:82
KJS::Object::prototype
Value prototype() const
Returns the prototype of this object.
Definition: object.h:658
KJS::Object::deleteProperty
bool deleteProperty(ExecState *exec, const Identifier &propertyName)
Removes the specified property from the object.
Definition: object.h:685
KJS::Object::defaultValue
Value defaultValue(ExecState *exec, Type hint) const
Converts the object into a primitive value.
Definition: object.h:691
KJS::Object::setInternalValue
void setInternalValue(const Value &v)
Sets the internal value of the object.
Definition: object.h:721
KJS::Object::implementsHasInstance
bool implementsHasInstance() const
Whether or not the object implements the hasInstance() method.
Definition: object.h:703
KJS::Object::implementsCall
bool implementsCall() const
Whether or not the object implements the call() method.
Definition: object.h:700
KJS::Object::implementsConstruct
bool implementsConstruct() const
Whether or not the object implements the construct() method.
Definition: object.h:694
KJS::Object::construct
Object construct(ExecState *exec, const List &args)
Creates a new object based on this object.
Definition: object.h:697
KJS::Object::propList
ReferenceList propList(ExecState *exec, bool recursive=true)
Returns a List of References to all the properties of the object.
Definition: object.h:715
KJS::Object::internalValue
Value internalValue() const
Returns the internal value of the object.
Definition: object.h:718
KJS::Object::canPut
bool canPut(ExecState *exec, const Identifier &propertyName) const
Used to check whether or not a particular property is allowed to be set on an object.
Definition: object.h:676
KJS::Object::put
void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr=None)
Sets the specified property.
Definition: object.h:670
KJS::Object::scope
const ScopeChain & scope() const
Returns the scope of this object.
Definition: object.h:709
KJS::Object::hasInstance
Boolean hasInstance(ExecState *exec, const Value &value)
Checks whether value delegates behavior to this object.
Definition: object.h:706
KJS::Object::hasProperty
bool hasProperty(ExecState *exec, const Identifier &propertyName) const
Checks to see whether the object (or any object in it's prototype chain) has a property with the spec...
Definition: object.h:679
KJS::Object::get
Value get(ExecState *exec, const Identifier &propertyName) const
Retrieves the specified property from the object.
Definition: object.h:664
KJS::Object::className
UString className() const
Returns the class name of the object.
Definition: object.h:661
KJS::ReferenceList
A list of Reference objects.
Definition: reference_list.h:54
KJS::ScopeChain
A scope chain object.
Definition: scope_chain.h:47
KJS::UString
Unicode string class.
Definition: ustring.h:190
KJS::ValueImp
ValueImp is the base type for all primitives (Undefined, Null, Boolean, String, Number) and objects i...
Definition: value.h:79
KJS::Value
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents.
Definition: value.h:168
KJS::Value::toObject
Object toObject(ExecState *exec) const
Performs the ToObject type conversion operation on this value (ECMA 9.9)
Definition: object.h:359
KJS::ClassInfo
Class Information.
Definition: object.h:59
KJS::ClassInfo::dummy
void * dummy
Reserved for future extension.
Definition: object.h:76
KJS::ClassInfo::className
const char * className
A string denoting the class name.
Definition: object.h:63
KJS::ClassInfo::propHashTable
const HashTable * propHashTable
Static hash-table of properties.
Definition: object.h:72
KJS::ClassInfo::parentClass
const ClassInfo * parentClass
Pointer to the class information of the base class.
Definition: object.h:68
KJS::HashTable
A hash table Usually the hashtable is generated by the create_hash_table script, from a ....
Definition: lookup.h:72

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kjs by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |