object.h
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _KJS_OBJECT_H_
#define _KJS_OBJECT_H_
// Objects
#include "value.h"
#include "types.h"
#include "reference_list.h"
#include "identifier.h"
#include "property_map.h"
#include "scope_chain.h"
namespace KJS {
class ObjectImpPrivate;
class PropertyMap;
class HashTable;
struct HashEntry;
class ListImp;
enum Attribute { None = 0,
ReadOnly = 1 << 1,
DontEnum = 1 << 2,
DontDelete = 1 << 3,
Internal = 1 << 4,
Function = 1 << 5 };
struct ClassInfo {
const char* className;
const ClassInfo *parentClass;
const HashTable *propHashTable;
void *dummy;
};
class KJS_EXPORT Object : public Value {
public:
Object() { }
explicit Object(ObjectImp *v);
ObjectImp *imp() const;
const ClassInfo *classInfo() const;
bool inherits(const ClassInfo *cinfo) const;
static Object dynamicCast(const Value &v);
Value prototype() const;
UString className() const;
Value get(ExecState *exec, const Identifier &propertyName) const;
Value get(ExecState *exec, unsigned propertyName) const;
void put(ExecState *exec, const Identifier &propertyName,
const Value &value, int attr = None);
void put(ExecState *exec, unsigned propertyName,
const Value &value, int attr = None);
bool canPut(ExecState *exec, const Identifier &propertyName) const;
bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
bool hasProperty(ExecState *exec, unsigned propertyName) const;
bool deleteProperty(ExecState *exec, const Identifier &propertyName);
bool deleteProperty(ExecState *exec, unsigned propertyName);
Value defaultValue(ExecState *exec, Type hint) const;
bool implementsConstruct() const;
Object construct(ExecState *exec, const List &args);
bool implementsCall() const;
Value call(ExecState *exec, Object &thisObj, const List &args);
bool implementsHasInstance() const;
Boolean hasInstance(ExecState *exec, const Value &value);
const ScopeChain &scope() const;
void setScope(const ScopeChain &s);
ReferenceList propList(ExecState *exec, bool recursive = true);
Value internalValue() const;
void setInternalValue(const Value &v);
};
inline Object Value::toObject(ExecState *exec) const { return rep->dispatchToObject(exec); }
class KJS_EXPORT ObjectImp : public ValueImp {
friend class ObjectProtoFuncImp;
public:
ObjectImp(const Object &proto);
ObjectImp(ObjectImp *proto);
ObjectImp();
virtual ~ObjectImp();
virtual void mark();
Type type() const;
virtual const ClassInfo *classInfo() const;
bool inherits(const ClassInfo *cinfo) const;
// internal properties (ECMA 262-3 8.6.2)
Value prototype() const;
void setPrototype(const Value &proto);
virtual UString className() const;
// [[Get]] - must be implemented by all Objects
virtual Value get(ExecState *exec, const Identifier &propertyName) const;
virtual Value getPropertyByIndex(ExecState *exec,
unsigned propertyName) const;
virtual void put(ExecState *exec, const Identifier &propertyName,
const Value &value, int attr = None);
virtual void putPropertyByIndex(ExecState *exec, unsigned propertyName,
const Value &value, int attr = None);
virtual bool canPut(ExecState *exec, const Identifier &propertyName) const;
virtual bool hasProperty(ExecState *exec,
const Identifier &propertyName) const;
virtual bool hasPropertyByIndex(ExecState *exec, unsigned propertyName) const;
virtual bool deleteProperty(ExecState *exec,
const Identifier &propertyName);
virtual bool deletePropertyByIndex(ExecState *exec, unsigned propertyName);
void deleteAllProperties(ExecState *);
virtual Value defaultValue(ExecState *exec, Type hint) const;
virtual bool implementsConstruct() const;
virtual Object construct(ExecState *exec, const List &args);
virtual bool implementsCall() const;
virtual Value call(ExecState *exec, Object &thisObj,
const List &args);
virtual bool implementsHasInstance() const;
virtual Boolean hasInstance(ExecState *exec, const Value &value);
const ScopeChain &scope() const { return _scope; }
void setScope(const ScopeChain &s) { _scope = s; }
virtual ReferenceList propList(ExecState *exec, bool recursive = true);
Value internalValue() const;
void setInternalValue(const Value &v);
void setInternalValue(ValueImp *v);
Value toPrimitive(ExecState *exec,
Type preferredType = UnspecifiedType) const;
bool toBoolean(ExecState *exec) const;
double toNumber(ExecState *exec) const;
UString toString(ExecState *exec) const;
Object toObject(ExecState *exec) const;
// This get method only looks at the property map.
// A bit like hasProperty(recursive=false), this doesn't go to the prototype.
// This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
// to look up in the prototype, it might already exist there)
ValueImp *getDirect(const Identifier& propertyName) const
{ return _prop.get(propertyName); }
void putDirect(const Identifier &propertyName, ValueImp *value, int attr = 0);
void putDirect(const Identifier &propertyName, int value, int attr = 0);
void setFunctionName(const Identifier &propertyName);
protected:
PropertyMap _prop;
private:
const HashEntry* findPropertyHashEntry( const Identifier& propertyName ) const;
ObjectImpPrivate *_od;
ValueImp *_proto;
ValueImp *_internalValue;
ScopeChain _scope;
};
enum ErrorType { GeneralError = 0,
EvalError = 1,
RangeError = 2,
ReferenceError = 3,
SyntaxError = 4,
TypeError = 5,
URIError = 6};
class KJS_EXPORT Error {
public:
static Object create(ExecState *exec, ErrorType errtype = GeneralError,
const char *message = 0, int lineno = -1,
int sourceId = -1);
static const char * const * const errorNames;
};
inline Object::Object(ObjectImp *v) : Value(v) { }
inline ObjectImp *Object::imp() const { return static_cast<ObjectImp*>(rep); }
inline const ClassInfo *Object::classInfo() const
{ return imp()->classInfo(); }
inline bool Object::inherits(const ClassInfo *cinfo) const
{ return imp()->inherits(cinfo); }
inline Value Object::prototype() const
{ return Value(imp()->prototype()); }
inline UString Object::className() const
{ return imp()->className(); }
inline Value Object::get(ExecState *exec, const Identifier &propertyName) const
{ return imp()->get(exec,propertyName); }
inline Value Object::get(ExecState *exec, unsigned propertyName) const
{ return imp()->getPropertyByIndex(exec, propertyName); }
inline void Object::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
{ imp()->put(exec,propertyName,value,attr); }
inline void Object::put(ExecState *exec, unsigned propertyName, const Value &value, int attr)
{ imp()->putPropertyByIndex(exec, propertyName, value, attr); }
inline bool Object::canPut(ExecState *exec, const Identifier &propertyName) const
{ return imp()->canPut(exec,propertyName); }
inline bool Object::hasProperty(ExecState *exec, const Identifier &propertyName) const
{ return imp()->hasProperty(exec, propertyName); }
inline bool Object::hasProperty(ExecState *exec, unsigned propertyName) const
{ return imp()->hasPropertyByIndex(exec, propertyName); }
inline bool Object::deleteProperty(ExecState *exec, const Identifier &propertyName)
{ return imp()->deleteProperty(exec,propertyName); }
inline bool Object::deleteProperty(ExecState *exec, unsigned propertyName)
{ return imp()->deletePropertyByIndex(exec, propertyName); }
inline Value Object::defaultValue(ExecState *exec, Type hint) const
{ return imp()->defaultValue(exec,hint); }
inline bool Object::implementsConstruct() const
{ return imp()->implementsConstruct(); }
inline Object Object::construct(ExecState *exec, const List &args)
{ return imp()->construct(exec,args); }
inline bool Object::implementsCall() const
{ return imp()->implementsCall(); }
inline bool Object::implementsHasInstance() const
{ return imp()->implementsHasInstance(); }
inline Boolean Object::hasInstance(ExecState *exec, const Value &value)
{ return imp()->hasInstance(exec,value); }
inline const ScopeChain &Object::scope() const
{ return imp()->scope(); }
inline void Object::setScope(const ScopeChain &s)
{ imp()->setScope(s); }
inline ReferenceList Object::propList(ExecState *exec, bool recursive)
{ return imp()->propList(exec,recursive); }
inline Value Object::internalValue() const
{ return imp()->internalValue(); }
inline void Object::setInternalValue(const Value &v)
{ imp()->setInternalValue(v); }
} // namespace
#endif // _KJS_OBJECT_H_
KJS::Value
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents...
Definition: value.h:168
KJS::Error
Factory methods for error objects.
Definition: object.h:627
KJS::ClassInfo::parentClass
const ClassInfo * parentClass
Pointer to the class information of the base class.
Definition: object.h:68
KJS::Object::defaultValue
Value defaultValue(ExecState *exec, Type hint) const
Converts the object into a primitive value.
Definition: object.h:691
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:664
KJS::Object::construct
Object construct(ExecState *exec, const List &args)
Creates a new object based on this object.
Definition: object.h:697
KJS::Object::hasInstance
Boolean hasInstance(ExecState *exec, const Value &value)
Checks whether value delegates behavior to this object.
Definition: object.h:706
KJS::Object::implementsConstruct
bool implementsConstruct() const
Whether or not the object implements the construct() method.
Definition: object.h:694
KJS::Object::deleteProperty
bool deleteProperty(ExecState *exec, const Identifier &propertyName)
Removes the specified property from the object.
Definition: object.h:685
KJS::ClassInfo::dummy
void * dummy
Reserved for future extension.
Definition: object.h:76
KJS::Object::className
UString className() const
Returns the class name of the object.
Definition: object.h:661
KJS::Object::setInternalValue
void setInternalValue(const Value &v)
Sets the internal value of the object.
Definition: object.h:721
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::HashTable
A hash table Usually the hashtable is generated by the create_hash_table script, from a ...
Definition: lookup.h:72
KJS::Object
Represents an Object.
Definition: object.h:82
KJS::Object::implementsHasInstance
bool implementsHasInstance() const
Whether or not the object implements the hasInstance() method.
Definition: object.h:703
KJS::ClassInfo::className
const char * className
A string denoting the class name.
Definition: object.h:63
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::Object::implementsCall
bool implementsCall() const
Whether or not the object implements the call() method.
Definition: object.h:700
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:676
KJS::Error::errorNames
static const char *const *const errorNames
Array of error names corresponding to ErrorType.
Definition: object.h:645
KJS::ValueImp
ValueImp is the base type for all primitives (Undefined, Null, Boolean, String, Number) and objects i...
Definition: value.h:79
KJS::Object::internalValue
Value internalValue() const
Returns the internal value of the object.
Definition: object.h:718
KJS::ClassInfo::propHashTable
const HashTable * propHashTable
Static hash-table of properties.
Definition: object.h:72
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::ReferenceList
A list of Reference objects.
Definition: reference_list.h:54
KJS::Object::scope
const ScopeChain & scope() const
Returns the scope of this object.
Definition: object.h:709
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::List
Native list type.
Definition: list.h:48
KJS::Boolean
Represents an primitive Boolean value.
Definition: value.h:317
KJS::ClassInfo
Class Information.
Definition: object.h:59
KJS::Object::prototype
Value prototype() const
Returns the prototype of this object.
Definition: object.h:658
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

KDE Home | KDE Accessibility Home | Description of Access Keys