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