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));