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

kjs

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

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
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.8.8
This website is maintained by Timothy Pearson.