27 #include "interpreter.h"
29 #include "reference_list.h"
36 #include "collector.h"
37 #include "operations.h"
38 #include "error_object.h"
50 return Object(
static_cast<ObjectImp*
>(v.imp()));
57 if (++depth > KJS_MAX_STACK) {
59 fprintf(stderr,
"Exceeded maximum function call depth\n");
61 int saveDepth = depth - 1;
63 "Exceeded maximum function call depth.");
66 exec->setException(err);
72 Value ret =
static_cast<ObjectImp*
>(rep)->
call(exec,thisObj,args);
83 ObjectImp::ObjectImp(
const Object &proto)
84 : _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L)
89 ObjectImp::ObjectImp(ObjectImp *proto)
90 : _proto(proto), _internalValue(0L)
94 ObjectImp::ObjectImp()
97 _proto = NullImp::staticNull;
101 ObjectImp::~ObjectImp()
106 void ObjectImp::mark()
111 if (_proto && !_proto->marked())
116 if (_internalValue && !_internalValue->marked())
117 _internalValue->mark();
122 const ClassInfo *ObjectImp::classInfo()
const
127 bool ObjectImp::inherits(
const ClassInfo *info)
const
136 while (ci && ci != info)
142 Type ObjectImp::type()
const
147 Value ObjectImp::prototype()
const
149 return Value(_proto);
152 void ObjectImp::setPrototype(
const Value &proto)
154 _proto = proto.imp();
157 UString ObjectImp::className()
const
167 ValueImp *imp = getDirect(propertyName);
174 if (propertyName == specialPrototypePropertyName) {
184 return proto.
get(exec,propertyName);
188 unsigned propertyName)
const
190 return get(exec, Identifier::from(propertyName));
195 const Value &value,
int attr)
200 if (propertyName == specialPrototypePropertyName) {
210 if ((attr == None || attr == DontDelete) && !canPut(exec,propertyName)) {
212 fprintf( stderr,
"[kjs-object] WARNING: canPut %s said NO\n", propertyName.
ascii() );
217 _prop.put(propertyName,value.imp(),attr);
221 void ObjectImp::putPropertyByIndex(
ExecState *exec,
unsigned propertyName,
222 const Value &value,
int attr)
224 put(exec, Identifier::from(propertyName), value, attr);
231 ValueImp *v = _prop.get(propertyName, attributes);
233 return!(attributes & ReadOnly);
236 const HashEntry* e = findPropertyHashEntry(propertyName);
238 return !(e->
attr & ReadOnly);
248 if (_prop.get(propertyName))
252 if (findPropertyHashEntry(propertyName))
256 if (propertyName == specialPrototypePropertyName)
264 bool ObjectImp::hasPropertyByIndex(
ExecState *exec,
unsigned propertyName)
const
266 return hasProperty(exec, Identifier::from(propertyName));
273 ValueImp *v = _prop.get(propertyName, attributes);
275 if ((attributes & DontDelete))
277 _prop.remove(propertyName);
282 const HashEntry* entry = findPropertyHashEntry(propertyName);
283 if (entry && entry->
attr & DontDelete)
288 bool ObjectImp::deletePropertyByIndex(
ExecState *exec,
unsigned propertyName)
290 return deleteProperty(exec, Identifier::from(propertyName));
293 void ObjectImp::deleteAllProperties(
ExecState * )
301 if (hint != StringType && hint != NumberType) {
310 if (hint == StringType)
311 v = get(exec,toStringPropertyName);
313 v = get(exec,valueOfPropertyName);
315 if (v.
type() == ObjectType) {
320 Type defType = def.
type();
321 if (defType == UnspecifiedType || defType == UndefinedType ||
322 defType == NullType || defType == BooleanType ||
323 defType == StringType || defType == NumberType) {
329 if (hint == StringType)
330 v = get(exec,valueOfPropertyName);
332 v = get(exec,toStringPropertyName);
334 if (v.
type() == ObjectType) {
339 Type defType = def.
type();
340 if (defType == UnspecifiedType || defType == UndefinedType ||
341 defType == NullType || defType == BooleanType ||
342 defType == StringType || defType == NumberType) {
349 exec->setException(err);
367 bool ObjectImp::implementsConstruct()
const
378 bool ObjectImp::implementsCall()
const
389 bool ObjectImp::implementsHasInstance()
const
403 if (_proto && _proto->dispatchType() == ObjectType && recursive)
404 list =
static_cast<ObjectImp*
>(_proto)->propList(exec,recursive);
406 _prop.addEnumerablesToReferenceList(list,
Object(
this));
414 for (
int i = 0; i < size; ++i, ++e) {
425 Value ObjectImp::internalValue()
const
427 return Value(_internalValue);
430 void ObjectImp::setInternalValue(
const Value &v)
432 _internalValue = v.imp();
435 void ObjectImp::setInternalValue(
ValueImp *v)
441 Value ObjectImp::toPrimitive(
ExecState *exec, Type preferredType)
const
443 return defaultValue(exec,preferredType);
446 bool ObjectImp::toBoolean(
ExecState* )
const
451 double ObjectImp::toNumber(
ExecState *exec)
const
453 Value prim = toPrimitive(exec,NumberType);
454 if (exec->hadException())
461 Value prim = toPrimitive(exec,StringType);
462 if (exec->hadException())
469 return Object(
const_cast<ObjectImp*
>(
this));
474 value->setGcAllowed();
475 _prop.put(propertyName, value, attr);
478 void ObjectImp::putDirect(
const Identifier &propertyName,
int value,
int attr)
480 _prop.put(propertyName, NumberImp::create(value), attr);
483 void ObjectImp::setFunctionName(
const Identifier &propertyName)
485 if (inherits(&InternalFunctionImp::info))
491 const char *
const errorNamesArr[] = {
493 I18N_NOOP(
"Evaluation error"),
494 I18N_NOOP(
"Range error"),
495 I18N_NOOP(
"Reference error"),
496 I18N_NOOP(
"Syntax error"),
497 I18N_NOOP(
"Type error"),
498 I18N_NOOP(
"URI error"),
504 int lineno,
int sourceId)
508 fprintf(stderr,
"WARNING: KJS %s: %s\n",
errorNames[errtype], message);
546 err.
put(exec,
"sourceId",
Number(sourceId));
Represents an primitive Boolean value.
static Object create(ExecState *exec, ErrorType errtype=GeneralError, const char *message=0, int lineno=-1, int sourceId=-1)
Factory method for error objects.
static const char *const *const errorNames
Array of error names corresponding to ErrorType.
Represents the current state of script execution.
Interpreter * lexicalInterpreter() const
Returns the interpreter associated with the current scope's global object.
Represents an Identifier for a Javascript object.
const char * ascii() const
Char * of the identifier's string.
Base class for all function objects.
Object builtinError() const
Returns the builtin "Error" object.
Object builtinDatePrototype() const
Returns the builtin "Date.prototype" object.
Object builtinEvalError() const
The initial value of "Error" global property.
void append(const Value &val)
Append an object to the end of the list.
static const List & empty()
Returns a pointer to a static instance of an empty list.
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...
Represents an primitive Null value.
Represents an primitive Number value.
bool implementsCall() const
Whether or not the object implements the call() method.
Object construct(ExecState *exec, const List &args)
Creates a new object based on this object.
void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr=None)
Sets the specified property.
Value call(ExecState *exec, Object &thisObj, const List &args)
Calls this object as if it is a function.
static Object dynamicCast(const Value &v)
Converts a Value into an 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...
Value get(ExecState *exec, const Identifier &propertyName) const
Retrieves the specified property from the object.
A list of Reference objects.
Defines a Javascript reference.
Represents an primitive String value.
Represents an primitive Undefined value.
ValueImp is the base type for all primitives (Undefined, Null, Boolean, String, Number) and objects i...
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents.
UString toString(ExecState *exec) const
Performs the ToString type conversion operation on this value (ECMA 9.8)
bool isValid() const
Returns whether or not this is a valid value.
Type type() const
Returns the type of value.
double toNumber(ExecState *exec) const
Performs the ToNumber type conversion operation on this value (ECMA 9.3)
const char * className
A string denoting the class name.
const HashTable * propHashTable
Static hash-table of properties.
const ClassInfo * parentClass
Pointer to the class information of the base class.
An entry in a hash table.
unsigned char attr
attr is a set for flags (e.g.
unsigned short soffset
s is the offset to the string key (e.g.
const char *const sbase
pointer to the string table.
const HashEntry *const entries
pointer to the array of entries Mind that some entries in the array are null (0,0,...
int size
size is the total number of entries in the hashtable, including the null entries, i....