28 #include "interpreter.h"
30 #include "reference_list.h"
37 #include "collector.h"
38 #include "operations.h"
39 #include "error_object.h"
51 return Object(static_cast<ObjectImp*>(v.imp()));
58 if (++depth > KJS_MAX_STACK) {
60 fprintf(stderr,
"Exceeded maximum function call depth\n");
62 int saveDepth = depth - 1;
64 "Exceeded maximum function call depth.");
67 exec->setException(err);
73 Value ret =
static_cast<ObjectImp*
>(rep)->
call(exec,thisObj,args);
84 ObjectImp::ObjectImp(
const Object &proto)
85 : _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L)
90 ObjectImp::ObjectImp(ObjectImp *proto)
91 : _proto(proto), _internalValue(0L)
95 ObjectImp::ObjectImp()
98 _proto = NullImp::staticNull;
102 ObjectImp::~ObjectImp()
107 void ObjectImp::mark()
112 if (_proto && !_proto->marked())
117 if (_internalValue && !_internalValue->marked())
118 _internalValue->mark();
123 const ClassInfo *ObjectImp::classInfo()
const
128 bool ObjectImp::inherits(
const ClassInfo *info)
const
137 while (ci && ci != info)
143 Type ObjectImp::type()
const
148 Value ObjectImp::prototype()
const
150 return Value(_proto);
153 void ObjectImp::setPrototype(
const Value &proto)
155 _proto = proto.imp();
158 UString ObjectImp::className()
const
168 ValueImp *imp = getDirect(propertyName);
175 if (propertyName == specialPrototypePropertyName) {
185 return proto.
get(exec,propertyName);
189 unsigned propertyName)
const
191 return get(exec, Identifier::from(propertyName));
196 const Value &value,
int attr)
201 if (propertyName == specialPrototypePropertyName) {
211 if ((attr == None || attr == DontDelete) && !canPut(exec,propertyName)) {
213 fprintf( stderr,
"[kjs-object] WARNING: canPut %s said NO\n", propertyName.
ascii() );
218 _prop.put(propertyName,value.imp(),attr);
222 void ObjectImp::putPropertyByIndex(
ExecState *exec,
unsigned propertyName,
223 const Value &value,
int attr)
225 put(exec, Identifier::from(propertyName), value, attr);
232 ValueImp *v = _prop.get(propertyName, attributes);
234 return!(attributes & ReadOnly);
237 const HashEntry* e = findPropertyHashEntry(propertyName);
239 return !(e->
attr & ReadOnly);
249 if (_prop.get(propertyName))
253 if (findPropertyHashEntry(propertyName))
257 if (propertyName == specialPrototypePropertyName)
265 bool ObjectImp::hasPropertyByIndex(
ExecState *exec,
unsigned propertyName)
const
267 return hasProperty(exec, Identifier::from(propertyName));
274 ValueImp *v = _prop.get(propertyName, attributes);
276 if ((attributes & DontDelete))
278 _prop.remove(propertyName);
283 const HashEntry* entry = findPropertyHashEntry(propertyName);
284 if (entry && entry->
attr & DontDelete)
289 bool ObjectImp::deletePropertyByIndex(
ExecState *exec,
unsigned propertyName)
291 return deleteProperty(exec, Identifier::from(propertyName));
294 void ObjectImp::deleteAllProperties(
ExecState * )
302 if (hint != StringType && hint != NumberType) {
311 if (hint == StringType)
312 v =
get(exec,toStringPropertyName);
314 v =
get(exec,valueOfPropertyName);
316 if (v.
type() == ObjectType) {
321 Type defType = def.
type();
322 if (defType == UnspecifiedType || defType == UndefinedType ||
323 defType == NullType || defType == BooleanType ||
324 defType == StringType || defType == NumberType) {
330 if (hint == StringType)
331 v =
get(exec,valueOfPropertyName);
333 v =
get(exec,toStringPropertyName);
335 if (v.
type() == ObjectType) {
340 Type defType = def.
type();
341 if (defType == UnspecifiedType || defType == UndefinedType ||
342 defType == NullType || defType == BooleanType ||
343 defType == StringType || defType == NumberType) {
350 exec->setException(err);
368 bool ObjectImp::implementsConstruct()
const
379 bool ObjectImp::implementsCall()
const
390 bool ObjectImp::implementsHasInstance()
const
404 if (_proto && _proto->dispatchType() == ObjectType && recursive)
405 list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive);
407 _prop.addEnumerablesToReferenceList(list,
Object(
this));
415 for (
int i = 0; i < size; ++i, ++e) {
426 Value ObjectImp::internalValue()
const
428 return Value(_internalValue);
431 void ObjectImp::setInternalValue(
const Value &v)
433 _internalValue = v.imp();
436 void ObjectImp::setInternalValue(
ValueImp *v)
442 Value ObjectImp::toPrimitive(
ExecState *exec, Type preferredType)
const
444 return defaultValue(exec,preferredType);
447 bool ObjectImp::toBoolean(
ExecState* )
const
452 double ObjectImp::toNumber(
ExecState *exec)
const
454 Value prim = toPrimitive(exec,NumberType);
455 if (exec->hadException())
462 Value prim = toPrimitive(exec,StringType);
463 if (exec->hadException())
470 return Object(const_cast<ObjectImp*>(
this));
475 value->setGcAllowed();
476 _prop.put(propertyName, value, attr);
479 void ObjectImp::putDirect(
const Identifier &propertyName,
int value,
int attr)
481 _prop.put(propertyName, NumberImp::create(value), attr);
484 void ObjectImp::setFunctionName(
const Identifier &propertyName)
486 if (inherits(&InternalFunctionImp::info))
492 const char *
const errorNamesArr[] = {
494 I18N_NOOP(
"Evaluation error"),
495 I18N_NOOP(
"Range error"),
496 I18N_NOOP(
"Reference error"),
497 I18N_NOOP(
"Syntax error"),
498 I18N_NOOP(
"Type error"),
499 I18N_NOOP(
"URI error"),
505 int lineno,
int sourceId)
509 fprintf(stderr,
"WARNING: KJS %s: %s\n",
errorNames[errtype], message);
547 err.
put(exec,
"sourceId",
Number(sourceId));
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents...
Type type() const
Returns the type of value.
const ClassInfo * parentClass
Pointer to the class information of the base class.
Base class for all function objects.
const char *const sbase
pointer to the string table.
Value get(ExecState *exec, const Identifier &propertyName) const
Retrieves the specified property from the object.
Object construct(ExecState *exec, const List &args)
Creates a new object based on this object.
int size
size is the total number of entries in the hashtable, including the null entries, i...
Represents an primitive Number value.
void append(const Value &val)
Append an object to the end of the list.
Represents an primitive Null value.
Interpreter * lexicalInterpreter() const
Returns the interpreter associated with the current scope's global object.
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...
Object builtinDatePrototype() const
Returns the builtin "Date.prototype" object.
An entry in a hash table.
static Object create(ExecState *exec, ErrorType errtype=GeneralError, const char *message=0, int lineno=-1, int sourceId=-1)
Factory method for error objects.
double toNumber(ExecState *exec) const
Performs the ToNumber type conversion operation on this value (ECMA 9.3)
unsigned char attr
attr is a set for flags (e.g.
unsigned short soffset
s is the offset to the string key (e.g.
Represents an primitive Undefined value.
const char * className
A string denoting the class name.
Object builtinError() const
Returns the builtin "Error" object.
const char * ascii() const
Char * of the identifier's string.
bool implementsCall() const
Whether or not the object implements the call() method.
Represents an primitive String value.
Defines a Javascript reference.
static Object dynamicCast(const Value &v)
Converts a Value into an Object.
static const char *const *const errorNames
Array of error names corresponding to ErrorType.
ValueImp is the base type for all primitives (Undefined, Null, Boolean, String, Number) and objects i...
Object builtinEvalError() const
The initial value of "Error" global property.
static const HashEntry * findEntry(const struct HashTable *table, const Identifier &s)
Find an entry in the table, and return the entry This variant gives access to the other attributes of...
const HashTable * propHashTable
Static hash-table of properties.
static const List & empty()
Returns a pointer to a static instance of an empty list.
A list of Reference objects.
const HashEntry *const entries
pointer to the array of entries Mind that some entries in the array are null (0,0,0,0).
void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr=None)
Sets the specified property.
Represents an primitive Boolean value.
UString toString(ExecState *exec) const
Performs the ToString type conversion operation on this value (ECMA 9.8)
Value call(ExecState *exec, Object &thisObj, const List &args)
Calls this object as if it is a function.
bool isValid() const
Returns whether or not this is a valid value.
Represents the current state of script execution.
Represents an Identifier for a Javascript object.