29 #include "interpreter.h"
30 #include "property_map.h"
31 #include "property_slot.h"
32 #include "scope_chain.h"
33 #include <wtf/AlwaysInline.h>
34 #include "propertydescriptor.h"
42 class InternalFunctionImp;
43 class PropertyNameArray;
70 class GetterSetterImp :
public JSCell
73 JSType type()
const override
75 return GetterSetterType;
78 GetterSetterImp() : getter(nullptr), setter(nullptr) { }
80 JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType)
const override;
81 bool getPrimitiveNumber(ExecState *,
double &number, JSValue *&value)
override;
82 bool toBoolean(ExecState *exec)
const override;
83 double toNumber(ExecState *exec)
const override;
84 UString toString(ExecState *exec)
const override;
85 JSObject *toObject(ExecState *exec)
const override;
93 void setGetter(JSObject *g)
101 void setSetter(JSObject *s)
111 class KJS_EXPORT JSObject :
public JSCell
119 explicit JSObject(JSValue *proto);
127 void mark()
override;
128 JSType
type()
const override;
167 virtual const ClassInfo *classInfo()
const;
195 bool inherits(
const ClassInfo *cinfo)
const;
207 JSValue *prototype()
const;
208 void setPrototype(JSValue *proto);
226 virtual UString className()
const;
240 JSValue *
get(ExecState *exec,
const Identifier &propertyName)
const;
241 JSValue *
get(ExecState *exec,
unsigned propertyName)
const;
243 bool getPropertySlot(ExecState *,
const Identifier &, PropertySlot &);
244 bool getPropertySlot(ExecState *,
unsigned, PropertySlot &);
246 bool getPropertyDescriptor(ExecState *,
const Identifier &propertyName, PropertyDescriptor &);
248 virtual bool getOwnPropertySlot(ExecState *,
const Identifier &, PropertySlot &);
249 virtual bool getOwnPropertySlot(ExecState *,
unsigned index, PropertySlot &);
250 virtual bool getOwnPropertyDescriptor(ExecState *,
const Identifier &, PropertyDescriptor &);
262 virtual void put(ExecState *exec,
const Identifier &propertyName, JSValue *value,
int attr = None);
263 virtual void put(ExecState *exec,
unsigned propertyName, JSValue *value,
int attr = None);
279 virtual bool canPut(ExecState *exec,
const Identifier &propertyName)
const;
290 bool propertyIsEnumerable(ExecState *exec,
const Identifier &propertyName)
const;
302 bool hasProperty(ExecState *exec,
const Identifier &propertyName)
const;
303 bool hasProperty(ExecState *exec,
unsigned propertyName)
const;
316 virtual bool deleteProperty(ExecState *exec,
const Identifier &propertyName);
317 virtual bool deleteProperty(ExecState *exec,
unsigned propertyName);
335 virtual JSValue *defaultValue(ExecState *exec, JSType hint)
const;
345 virtual bool implementsConstruct()
const;
375 virtual JSObject *construct(ExecState *exec,
const List &args);
376 virtual JSObject *construct(ExecState *exec,
const List &args,
const Identifier &functionName,
const UString &sourceURL,
int lineNumber);
385 virtual JSObject *valueClone(Interpreter *targetCtx)
const;
395 virtual bool isFunctionType()
const;
414 JSValue *call(ExecState *exec, JSObject *thisObj,
const List &args);
415 virtual JSValue *
callAsFunction(ExecState *exec, JSObject *thisObj,
const List &args);
425 virtual bool implementsHasInstance()
const;
436 virtual bool hasInstance(ExecState *exec, JSValue *value);
438 void getPropertyNames(ExecState *, PropertyNameArray &, PropertyMap::PropertyMode mode = PropertyMap::ExcludeDontEnumProperties);
439 virtual void getOwnPropertyNames(ExecState *, PropertyNameArray &, PropertyMap::PropertyMode mode);
441 JSValue *toPrimitive(ExecState *exec, JSType preferredType = UnspecifiedType)
const override;
442 bool getPrimitiveNumber(ExecState *,
double &number, JSValue *&value)
override;
443 bool toBoolean(ExecState *exec)
const override;
444 double toNumber(ExecState *exec)
const override;
445 UString
toString(ExecState *exec)
const override;
446 JSObject *toObject(ExecState *exec)
const override;
448 virtual bool getPropertyAttributes(
const Identifier &propertyName,
unsigned &attributes)
const;
451 virtual bool masqueradeAsUndefined()
const
462 virtual JSValue *getDirect(
const Identifier &propertyName)
const
464 return _prop.get(propertyName);
466 JSValue **getDirectLocation(
const Identifier &propertyName)
468 return _prop.getLocation(propertyName);
474 JSValue **getDirectWriteLocation(
const Identifier &propertyName)
476 return _prop.getWriteLocation(propertyName);
485 virtual void putDirect(
const Identifier &propertyName, JSValue *value,
int attr = 0)
487 _prop.put(propertyName, value, attr);
489 virtual void putDirect(
const Identifier &propertyName,
int value,
int attr = 0);
490 virtual void removeDirect(
const Identifier &propertyName);
493 void putDirectFunction(InternalFunctionImp *,
int attr = 0);
495 void fillGetterPropertySlot(PropertySlot &slot, JSValue **location);
496 void fillDirectLocationSlot(PropertySlot &slot, JSValue **location);
498 void defineGetter(ExecState *exec,
const Identifier &propertyName, JSObject *getterFunc);
499 void defineSetter(ExecState *exec,
const Identifier &propertyName, JSObject *setterFunc);
501 virtual bool defineOwnProperty(ExecState *exec,
const Identifier &propertyName, PropertyDescriptor &desc,
bool shouldThrow);
503 void preventExtensions();
506 return _prop.isExtensible();
514 void clearProperties()
519 void saveProperties(SavedProperties &p)
const
523 void restoreProperties(
const SavedProperties &p)
528 virtual bool isActivation()
const
532 virtual bool isGlobalObject()
const
539 bool isLocalInjected()
const
541 return _prop.m_objLocalInjected;
543 void setLocalInjected()
545 _prop.m_objLocalInjected =
true;
552 const HashEntry *findPropertyHashEntry(
const Identifier &propertyName)
const;
555 JSObject(
const JSObject &);
556 JSObject &operator=(
const JSObject &);
564 enum ErrorType { GeneralError = 0,
600 KJS_EXPORT JSObject *throwError(
ExecState *, ErrorType,
const char *
message);
601 KJS_EXPORT JSObject *throwError(
ExecState *, ErrorType);
603 inline JSObject::JSObject(
JSValue *proto)
609 inline JSObject::JSObject()
613 inline JSValue *JSObject::prototype()
const
618 inline void JSObject::setPrototype(JSValue *proto)
624 inline bool JSObject::inherits(
const ClassInfo *info)
const
626 for (
const ClassInfo *ci = classInfo(); ci; ci = ci->parentClass)
633 inline void JSObject::fillDirectLocationSlot(PropertySlot &slot,
636 if (_prop.hasGetterSetterProperties() &&
637 JSValue::type(*location) == GetterSetterType) {
638 fillGetterPropertySlot(slot, location);
640 slot.setValueSlot(
this, location);
645 inline bool JSCell::isObject(
const ClassInfo *info)
const
647 return isObject() &&
static_cast<const JSObject *
>(
this)->inherits(info);
651 inline bool JSValue::isObject(
const ClassInfo *c)
const
653 return isObject(
this, c);
656 inline bool JSValue::isObject(
const JSValue *value,
const ClassInfo *c)
658 return !JSImmediate::isImmediate(value) && value->asCell()->isObject(c);
663 inline bool JSObject::getPropertySlot(ExecState *exec,
const Identifier &propertyName, PropertySlot &slot)
665 JSObject *
object =
this;
667 if (object->getOwnPropertySlot(exec, propertyName, slot)) {
671 JSValue *proto =
object->_proto;
672 if (!JSValue::isObject(proto)) {
676 object =
static_cast<JSObject *
>(proto);
680 inline void JSObject::getPropertyNames(ExecState *exec, PropertyNameArray &propertyNames, PropertyMap::PropertyMode mode)
682 for (JSObject *cur =
this; cur; cur = JSValue::getObject(cur->_proto)) {
683 cur->getOwnPropertyNames(exec, propertyNames, mode);
687 inline JSValue *JSObject::toPrimitive(ExecState *exec, JSType preferredType)
const
689 return defaultValue(exec, preferredType);
692 inline JSValue *JSObject::call(ExecState *exec, JSObject *thisObj,
const List &args)
699 #endif // KJS_OBJECT_H