• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KJS

KJS::JSObject

KJS::JSObject Class Reference

#include <object.h>

Inheritance diagram for KJS::JSObject:

Inheritance graph
[legend]

List of all members.


Detailed Description

Definition at line 104 of file object.h.


Public Member Functions

 JSObject (JSValue *proto)
 JSObject ()
virtual void mark ()
virtual JSType type () const
virtual const ClassInfo * classInfo () const
bool inherits (const ClassInfo *cinfo) const
JSValue * prototype () const
void setPrototype (JSValue *proto)
virtual UString className () const
JSValue * get (ExecState *exec, const Identifier &propertyName) const
JSValue * get (ExecState *exec, unsigned propertyName) const
bool getPropertySlot (ExecState *, const Identifier &, PropertySlot &)
bool getPropertySlot (ExecState *, unsigned, PropertySlot &)
virtual bool getOwnPropertySlot (ExecState *, const Identifier &, PropertySlot &)
virtual bool getOwnPropertySlot (ExecState *, unsigned index, PropertySlot &)
virtual void put (ExecState *exec, const Identifier &propertyName, JSValue *value, int attr=None)
virtual void put (ExecState *exec, unsigned propertyName, JSValue *value, int attr=None)
virtual bool canPut (ExecState *exec, const Identifier &propertyName) const
bool propertyIsEnumerable (ExecState *exec, const Identifier &propertyName) const
bool hasProperty (ExecState *exec, const Identifier &propertyName) const
bool hasProperty (ExecState *exec, unsigned propertyName) const
virtual bool deleteProperty (ExecState *exec, const Identifier &propertyName)
virtual bool deleteProperty (ExecState *exec, unsigned propertyName)
virtual JSValue * defaultValue (ExecState *exec, JSType hint) const
virtual bool implementsConstruct () const
virtual JSObject * construct (ExecState *exec, const List &args)
virtual JSObject * construct (ExecState *exec, const List &args, const Identifier &functionName, const UString &sourceURL, int lineNumber)
virtual bool implementsCall () const
JSValue * call (ExecState *exec, JSObject *thisObj, const List &args)
virtual JSValue * callAsFunction (ExecState *exec, JSObject *thisObj, const List &args)
virtual bool implementsHasInstance () const
virtual bool hasInstance (ExecState *exec, JSValue *value)
virtual void getPropertyNames (ExecState *, PropertyNameArray &)
virtual JSValue * toPrimitive (ExecState *exec, JSType preferredType=UnspecifiedType) const
virtual bool getPrimitiveNumber (ExecState *, double &number, JSValue *&value)
virtual bool toBoolean (ExecState *exec) const
virtual double toNumber (ExecState *exec) const
virtual UString toString (ExecState *exec) const
virtual JSObject * toObject (ExecState *exec) const
bool getPropertyAttributes (const Identifier &propertyName, unsigned &attributes) const
virtual bool masqueradeAsUndefined () const
JSValue * getDirect (const Identifier &propertyName) const
JSValue ** getDirectLocation (const Identifier &propertyName)
void putDirect (const Identifier &propertyName, JSValue *value, int attr=0)
void putDirect (const Identifier &propertyName, int value, int attr=0)
void removeDirect (const Identifier &propertyName)
void putDirectFunction (InternalFunctionImp *, int attr=0)
void fillGetterPropertySlot (PropertySlot &slot, JSValue **location)
void fillDirectLocationSlot (PropertySlot &slot, JSValue **location)
void defineGetter (ExecState *exec, const Identifier &propertyName, JSObject *getterFunc)
void defineSetter (ExecState *exec, const Identifier &propertyName, JSObject *setterFunc)
void clearProperties ()
void saveProperties (SavedProperties &p) const
void restoreProperties (const SavedProperties &p)
virtual bool isActivation () const
bool isLocalInjected () const
void setLocalInjected ()

Protected Attributes

PropertyMap _prop

Constructor & Destructor Documentation

KJS::JSObject::JSObject ( JSValue *  proto  )  [inline, explicit]

Creates a new JSObject with the specified prototype.

Parameters:
proto The prototype

Definition at line 524 of file object.h.

KJS::JSObject::JSObject (  )  [inline, explicit]

Creates a new JSObject with a prototype of jsNull() (that is, the ECMAScript "null" value, not a null object pointer).

Definition at line 530 of file object.h.


Member Function Documentation

void KJS::JSObject::mark (  )  [virtual]

Reimplemented from KJS::JSCell.

Reimplemented in KJS::ArrayInstance, KJS::NativeErrorImp, KJS::Arguments, KJS::ActivationImp, KJS::JSWrapperObject, and KJS::FunctionImp.

Definition at line 120 of file object.cpp.

JSType KJS::JSObject::type (  )  const [virtual]

Implements KJS::JSCell.

Definition at line 144 of file object.cpp.

const ClassInfo * KJS::JSObject::classInfo (  )  const [virtual]

A pointer to a ClassInfo struct for this class.

This provides a basic facility for run-time type information, and can be used to check an object's class an inheritance (see inherits()). This should always return a statically declared pointer, or 0 to indicate that there is no class information.

This is primarily useful if you have application-defined classes that you wish to check against for casting purposes.

For example, to specify the class info for classes FooImp and BarImp, where FooImp inherits from BarImp, you would add the following in your class declarations:

   class BarImp : public JSObject {
     virtual const ClassInfo *classInfo() const { return &info; }
     static const ClassInfo info;
     // ...
   };

   class FooImp : public JSObject {
     virtual const ClassInfo *classInfo() const { return &info; }
     static const ClassInfo info;
     // ...
   };

And in your source file:

   const ClassInfo BarImp::info = {"Bar", 0, 0, 0}; // no parent class
   const ClassInfo FooImp::info = {"Foo", &BarImp::info, 0, 0};

See also:
inherits()

Reimplemented in KJS::ArrayInstance, KJS::ArrayPrototype, KJS::BooleanInstance, KJS::DateInstance, KJS::DatePrototype, KJS::ErrorInstance, KJS::NativeErrorImp, KJS::InternalFunctionImp, KJS::Arguments, KJS::ActivationImp, KJS::MathObjectImp, KJS::NumberInstance, KJS::NumberObjectImp, KJS::PackageObject, KJS::RegExpPrototype, KJS::RegExpImp, KJS::RegExpObjectImp, KJS::FunctionImp, KJS::DeclaredFunctionImp, KJS::StringInstance, and KJS::StringPrototype.

Definition at line 149 of file object.cpp.

bool KJS::JSObject::inherits ( const ClassInfo *  cinfo  )  const [inline]

Checks whether this object inherits from the class with the specified classInfo() pointer.

This requires that both this class and the other class return a non-NULL pointer for their classInfo() methods (otherwise it will return false).

For example, for two JSObject pointers obj1 and obj2, you can check if obj1's class inherits from obj2's class using the following:

if (obj1->inherits(obj2->classInfo())) { // ... }

If you have a handle to a statically declared ClassInfo, such as in the classInfo() example, you can check for inheritance without needing an instance of the other class:

if (obj1->inherits(FooImp::info)) { // ... }

Parameters:
cinfo The ClassInfo pointer for the class you want to check inheritance against.
Returns:
true if this object's class inherits from class with the ClassInfo pointer specified in cinfo

Definition at line 545 of file object.h.

JSValue * KJS::JSObject::prototype (  )  const [inline]

Returns the prototype of this object.

Note that this is not the same as the "prototype" property.

See ECMA 8.6.2

Returns:
The object's prototype

Definition at line 534 of file object.h.

void KJS::JSObject::setPrototype ( JSValue *  proto  )  [inline]

Definition at line 539 of file object.h.

UString KJS::JSObject::className (  )  const [virtual]

Returns the class name of the object.

See ECMA 8.6.2

Returns:
The object's class name Implementation of the [[Class]] internal property (implemented by all Objects)
The default implementation uses classInfo(). You should either implement classInfo(), or if you simply need a classname, you can reimplement className() instead.

Definition at line 154 of file object.cpp.

JSValue * KJS::JSObject::get ( ExecState *  exec,
const Identifier &  propertyName 
) const

Retrieves the specified property from the object.

If neither the object or any other object in it's prototype chain have the property, this function will return Undefined.

See ECMA 8.6.2.1

Parameters:
exec The current execution state
propertyName The name of the property to retrieve
Returns:
The specified property, or Undefined

Definition at line 160 of file object.cpp.

JSValue * KJS::JSObject::get ( ExecState *  exec,
unsigned  propertyName 
) const

Definition at line 170 of file object.cpp.

bool KJS::JSObject::getPropertySlot ( ExecState *  exec,
const Identifier &  propertyName,
PropertySlot &  slot 
) [inline]

Definition at line 577 of file object.h.

bool KJS::JSObject::getPropertySlot ( ExecState *  exec,
unsigned  propertyName,
PropertySlot &  slot 
)

Definition at line 179 of file object.cpp.

ALWAYS_INLINE bool KJS::JSObject::getOwnPropertySlot ( ExecState *  exec,
const Identifier &  propertyName,
PropertySlot &  slot 
) [virtual]

Reimplemented in KJS::ArrayInstance, KJS::ArrayPrototype, KJS::DatePrototype, KJS::Arguments, KJS::ActivationImp, KJS::MathObjectImp, KJS::NumberObjectImp, KJS::RegExpObjectImp, KJS::FunctionImp, KJS::StringInstance, and KJS::StringPrototype.

Definition at line 598 of file object.h.

bool KJS::JSObject::getOwnPropertySlot ( ExecState *  exec,
unsigned  index,
PropertySlot &  slot 
) [virtual]

Reimplemented in KJS::ArrayInstance.

Definition at line 197 of file object.cpp.

void KJS::JSObject::put ( ExecState *  exec,
const Identifier &  propertyName,
JSValue *  value,
int  attr = None 
) [virtual]

Sets the specified property.

See ECMA 8.6.2.2

Parameters:
exec The current execution state
propertyName The name of the property to set
propertyValue The value to set

Reimplemented in KJS::ArrayInstance, KJS::Arguments, KJS::ActivationImp, KJS::RegExpObjectImp, KJS::FunctionImp, and KJS::StringInstance.

Definition at line 208 of file object.cpp.

void KJS::JSObject::put ( ExecState *  exec,
unsigned  propertyName,
JSValue *  value,
int  attr = None 
) [virtual]

Reimplemented in KJS::ArrayInstance.

Definition at line 289 of file object.cpp.

bool KJS::JSObject::canPut ( ExecState *  exec,
const Identifier &  propertyName 
) const [virtual]

Used to check whether or not a particular property is allowed to be set on an object.

See ECMA 8.6.2.3

Parameters:
exec The current execution state
propertyName The name of the property
Returns:
true if the property can be set, otherwise false Implementation of the [[CanPut]] internal property (implemented by all Objects)

Definition at line 296 of file object.cpp.

bool KJS::JSObject::propertyIsEnumerable ( ExecState *  exec,
const Identifier &  propertyName 
) const

Checks if a property is enumerable, that is if it doesn't have the DontEnum flag set.

See ECMA 15.2.4

Parameters:
exec The current execution state
propertyName The name of the property
Returns:
true if the property is enumerable, otherwise false

Definition at line 491 of file object.cpp.

bool KJS::JSObject::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 specified name.

See ECMA 8.6.2.4

Parameters:
exec The current execution state
propertyName The name of the property to check for
Returns:
true if the object has the property, otherwise false

Definition at line 310 of file object.cpp.

bool KJS::JSObject::hasProperty ( ExecState *  exec,
unsigned  propertyName 
) const

Definition at line 316 of file object.cpp.

bool KJS::JSObject::deleteProperty ( ExecState *  exec,
const Identifier &  propertyName 
) [virtual]

Removes the specified property from the object.

See ECMA 8.6.2.5

Parameters:
exec The current execution state
propertyName The name of the property to delete
Returns:
true if the property was successfully deleted or did not exist on the object. false if deleting the specified property is not allowed.

Reimplemented in KJS::ArrayInstance, KJS::Arguments, KJS::ActivationImp, KJS::FunctionImp, and KJS::StringInstance.

Definition at line 323 of file object.cpp.

bool KJS::JSObject::deleteProperty ( ExecState *  exec,
unsigned  propertyName 
) [virtual]

Reimplemented in KJS::ArrayInstance.

Definition at line 343 of file object.cpp.

JSValue * KJS::JSObject::defaultValue ( ExecState *  exec,
JSType  hint 
) const [virtual]

Converts the object into a primitive value.

The value return may differ depending on the supplied hint

See ECMA 8.6.2.6

Parameters:
exec The current execution state
hint The desired primitive type to convert to
Returns:
A primitive value converted from the objetc. Note that the type of primitive value returned may not be the same as the requested hint. Implementation of the [[DefaultValue]] internal property (implemented by all Objects)

Definition at line 372 of file object.cpp.

bool KJS::JSObject::implementsConstruct (  )  const [virtual]

Whether or not the object implements the construct() method.

If this returns false you should not call the construct() method on this object (typically, an assertion will fail to indicate this).

Returns:
true if this object implements the construct() method, otherwise false

Reimplemented in KJS::ArrayObjectImp, KJS::BooleanObjectImp, KJS::DateObjectImp, KJS::ErrorObjectImp, KJS::NativeErrorImp, KJS::FunctionObjectImp, KJS::NumberObjectImp, KJS::ObjectObjectImp, KJS::RegExpObjectImp, KJS::DeclaredFunctionImp, and KJS::StringObjectImp.

Definition at line 440 of file object.cpp.

JSObject * KJS::JSObject::construct ( ExecState *  exec,
const List &  args 
) [virtual]

Creates a new object based on this object.

Typically this means the following: 1. A new object is created 2. The prototype of the new object is set to the value of this object's "prototype" property 3. The call() method of this object is called, with the new object passed as the this value 4. The new object is returned

In some cases, Host objects may differ from these semantics, although this is discouraged.

If an error occurs during construction, the execution state's exception will be set. This can be tested for with ExecState::hadException(). Under some circumstances, the exception object may also be returned.

Note: This function should not be called if implementsConstruct() returns false, in which case it will result in an assertion failure.

Parameters:
exec The current execution state
args The arguments to be passed to call() once the new object has been created
Returns:
The newly created & initialized object Implementation of the [[Construct]] internal property

Reimplemented in KJS::ArrayObjectImp, KJS::BooleanObjectImp, KJS::DateObjectImp, KJS::ErrorObjectImp, KJS::NativeErrorImp, KJS::FunctionObjectImp, KJS::NumberObjectImp, KJS::ObjectObjectImp, KJS::RegExpObjectImp, KJS::DeclaredFunctionImp, and KJS::StringObjectImp.

Definition at line 445 of file object.cpp.

JSObject * KJS::JSObject::construct ( ExecState *  exec,
const List &  args,
const Identifier &  functionName,
const UString &  sourceURL,
int  lineNumber 
) [virtual]

Reimplemented in KJS::FunctionObjectImp.

Definition at line 451 of file object.cpp.

bool KJS::JSObject::implementsCall (  )  const [virtual]

Whether or not the object implements the call() method.

If this returns false you should not call the call() method on this object (typically, an assertion will fail to indicate this).

Returns:
true if this object implements the call() method, otherwise false

Reimplemented in KJS::InternalFunctionImp.

Definition at line 456 of file object.cpp.

JSValue * KJS::JSObject::call ( ExecState *  exec,
JSObject *  thisObj,
const List &  args 
)

Calls this object as if it is a function.

Note: This function should not be called if implementsCall() returns false, in which case it will result in an assertion failure.

See ECMA 8.6.2.3

Parameters:
exec The current execution state
thisObj The obj to be used as "this" within function execution. Note that in most cases this will be different from the C++ "this" object. For example, if the ECMAScript code "window.location->toString()" is executed, call() will be invoked on the C++ object which implements the toString method, with the thisObj being window.location
args List of arguments to be passed to the function
Returns:
The return value from the function

Definition at line 69 of file object.cpp.

JSValue * KJS::JSObject::callAsFunction ( ExecState *  exec,
JSObject *  thisObj,
const List &  args 
) [virtual]

Reimplemented in KJS::ArrayProtoFunc, KJS::ArrayObjectImp, KJS::BooleanProtoFunc, KJS::BooleanObjectImp, KJS::DateProtoFunc, KJS::DateObjectImp, KJS::ErrorProtoFunc, KJS::ErrorObjectImp, KJS::NativeErrorImp, KJS::InternalFunctionImp, KJS::FunctionPrototype, KJS::GlobalFuncImp, KJS::FunctionProtoFunc, KJS::FunctionObjectImp, KJS::MathFuncImp, KJS::NumberProtoFunc, KJS::NumberObjectImp, KJS::ObjectProtoFunc, KJS::ObjectObjectImp, KJS::RegExpProtoFunc, KJS::RegExpObjectImp, KJS::FunctionImp, KJS::StringProtoFunc, KJS::StringObjectImp, and KJS::StringObjectFuncImp.

Definition at line 461 of file object.cpp.

bool KJS::JSObject::implementsHasInstance (  )  const [virtual]

Whether or not the object implements the hasInstance() method.

If this returns false you should not call the hasInstance() method on this object (typically, an assertion will fail to indicate this).

Returns:
true if this object implements the hasInstance() method, otherwise false

Reimplemented in KJS::InternalFunctionImp.

Definition at line 467 of file object.cpp.

bool KJS::JSObject::hasInstance ( ExecState *  exec,
JSValue *  value 
) [virtual]

Checks whether value delegates behavior to this object.

Used by the instanceof operator.

Parameters:
exec The current execution state
value The value to check
Returns:
true if value delegates behavior to this object, otherwise false

Definition at line 472 of file object.cpp.

void KJS::JSObject::getPropertyNames ( ExecState *  exec,
PropertyNameArray &  propertyNames 
) [virtual]

Reimplemented in KJS::ArrayInstance, KJS::ActivationImp, and KJS::StringInstance.

Definition at line 516 of file object.cpp.

JSValue * KJS::JSObject::toPrimitive ( ExecState *  exec,
JSType  preferredType = UnspecifiedType 
) const [inline, virtual]

Implements KJS::JSCell.

Definition at line 642 of file object.h.

bool KJS::JSObject::getPrimitiveNumber ( ExecState *  exec,
double &  number,
JSValue *&  value 
) [virtual]

Implements KJS::JSCell.

Definition at line 364 of file object.cpp.

bool KJS::JSObject::toBoolean ( ExecState *  exec  )  const [virtual]

Implements KJS::JSCell.

Definition at line 537 of file object.cpp.

double KJS::JSObject::toNumber ( ExecState *  exec  )  const [virtual]

Implements KJS::JSCell.

Definition at line 542 of file object.cpp.

UString KJS::JSObject::toString ( ExecState *  exec  )  const [virtual]

Implements KJS::JSCell.

Definition at line 550 of file object.cpp.

JSObject * KJS::JSObject::toObject ( ExecState *  exec  )  const [virtual]

Implements KJS::JSCell.

Definition at line 558 of file object.cpp.

bool KJS::JSObject::getPropertyAttributes ( const Identifier &  propertyName,
unsigned &  attributes 
) const

Definition at line 501 of file object.cpp.

virtual bool KJS::JSObject::masqueradeAsUndefined (  )  const [inline, virtual]

Definition at line 429 of file object.h.

JSValue* KJS::JSObject::getDirect ( const Identifier &  propertyName  )  const [inline]

Definition at line 434 of file object.h.

JSValue** KJS::JSObject::getDirectLocation ( const Identifier &  propertyName  )  [inline]

Definition at line 436 of file object.h.

void KJS::JSObject::putDirect ( const Identifier &  propertyName,
JSValue *  value,
int  attr = 0 
) [inline]

Definition at line 439 of file object.h.

void KJS::JSObject::putDirect ( const Identifier &  propertyName,
int  value,
int  attr = 0 
)

Definition at line 563 of file object.cpp.

void KJS::JSObject::removeDirect ( const Identifier &  propertyName  ) 

Definition at line 568 of file object.cpp.

void KJS::JSObject::putDirectFunction ( InternalFunctionImp *  func,
int  attr = 0 
)

Definition at line 573 of file object.cpp.

void KJS::JSObject::fillGetterPropertySlot ( PropertySlot &  slot,
JSValue **  location 
)

Definition at line 578 of file object.cpp.

void KJS::JSObject::fillDirectLocationSlot ( PropertySlot &  slot,
JSValue **  location 
) [inline]

Definition at line 553 of file object.h.

void KJS::JSObject::defineGetter ( ExecState *  exec,
const Identifier &  propertyName,
JSObject *  getterFunc 
)

Definition at line 408 of file object.cpp.

void KJS::JSObject::defineSetter ( ExecState *  exec,
const Identifier &  propertyName,
JSObject *  setterFunc 
)

Definition at line 424 of file object.cpp.

void KJS::JSObject::clearProperties (  )  [inline]

Remove all properties from this object.

This doesn't take DontDelete into account, and isn't in the ECMA spec. It's simply a quick way to remove everything stored in the property map.

Definition at line 458 of file object.h.

void KJS::JSObject::saveProperties ( SavedProperties &  p  )  const [inline]

Definition at line 460 of file object.h.

void KJS::JSObject::restoreProperties ( const SavedProperties &  p  )  [inline]

Definition at line 461 of file object.h.

virtual bool KJS::JSObject::isActivation (  )  const [inline, virtual]

Reimplemented in KJS::ActivationImp.

Definition at line 463 of file object.h.

bool KJS::JSObject::isLocalInjected (  )  const [inline]

Definition at line 467 of file object.h.

void KJS::JSObject::setLocalInjected (  )  [inline]

Definition at line 468 of file object.h.


Member Data Documentation

PropertyMap KJS::JSObject::_prop [protected]

Definition at line 471 of file object.h.


The documentation for this class was generated from the following files:
  • object.h
  • object.cpp

KJS

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