24 #include "interpreter.h"
25 #include "operations.h"
26 #include "object_object.h"
27 #include "function_object.h"
36 ObjectPrototypeImp::ObjectPrototypeImp(
ExecState *exec,
41 putDirect(toStringPropertyName,
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToString,
42 0, toStringPropertyName), DontEnum);
43 putDirect(toLocaleStringPropertyName,
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToLocaleString,
44 0, toLocaleStringPropertyName), DontEnum);
45 putDirect(valueOfPropertyName,
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ValueOf,
46 0, valueOfPropertyName), DontEnum);
47 putDirect(
"hasOwnProperty",
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::HasOwnProperty,
48 1,
"hasOwnProperty"),DontEnum);
49 putDirect(
"isPrototypeOf",
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::IsPrototypeOf,
50 1,
"isPrototypeOf"),DontEnum);
51 putDirect(
"propertyIsEnumerable",
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::PropertyIsEnumerable,
52 1,
"propertyIsEnumerable"),DontEnum);
57 Object(
new GlobalFuncImp(exec, funcProto,GlobalFuncImp::Eval, 1,
"eval")),
64 ObjectProtoFuncImp::ObjectProtoFuncImp(
ExecState * ,
70 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
75 bool ObjectProtoFuncImp::implementsCall()
const
91 case HasOwnProperty: {
93 Identifier propertyName(args[0].toString(exec));
94 Value tempProto(thisObj.imp()->prototype());
95 thisObj.imp()->setPrototype(
Value());
96 bool exists = thisObj.
hasProperty(exec,propertyName);
97 thisObj.imp()->setPrototype(tempProto);
98 return Value(exists ? BooleanImp::staticTrue : BooleanImp::staticFalse);
100 case IsPrototypeOf: {
102 for (; v.
isValid() && v.
isA(ObjectType); v = Object::dynamicCast(v).prototype()) {
103 if (v.imp() == thisObj.imp())
104 return Value(BooleanImp::staticTrue);
106 return Value(BooleanImp::staticFalse);
108 case PropertyIsEnumerable: {
109 Identifier propertyName(args[0].toString(exec));
110 ObjectImp *obj =
static_cast<ObjectImp*
>(thisObj.imp());
113 ValueImp *v = obj->_prop.get(propertyName,attributes);
115 return Value((attributes & DontEnum) ?
116 BooleanImp::staticFalse : BooleanImp::staticTrue);
118 if (propertyName == specialPrototypePropertyName)
119 return Value(BooleanImp::staticFalse);
121 const HashEntry *entry = obj->findPropertyHashEntry(propertyName);
122 return Value((entry && !(entry->
attr & DontEnum)) ?
123 BooleanImp::staticTrue : BooleanImp::staticFalse);
132 ObjectObjectImp::ObjectObjectImp(
ExecState * ,
133 ObjectPrototypeImp *objProto,
139 putDirect(prototypePropertyName, objProto, DontEnum|DontDelete|ReadOnly);
142 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);
146 bool ObjectObjectImp::implementsConstruct()
const
157 Object result(
new ObjectImp(proto));
162 Object obj = Object::dynamicCast(arg);
166 switch (arg.
type()) {
172 assert(!
"unhandled switch case in ObjectConstructor");
176 return Object(
new ObjectImp(proto));
180 bool ObjectObjectImp::implementsCall()
const
192 result = construct(exec,argList);
195 if (arg.
type() == NullType || arg.
type() == UndefinedType) {
197 result = construct(exec,argList);
Represents the current state of script execution.
Interpreter * lexicalInterpreter() const
Returns the interpreter associated with the current scope's global object.
The initial value of Function.prototype (and thus all objects created with the Function constructor)
Represents an Identifier for a Javascript object.
Base class for all function objects.
Object builtinObjectPrototype() const
Returns the builtin "Object.prototype" object.
void append(const Value &val)
Append an object to the end of the list.
ListIterator begin() const
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...
UString className() const
Returns the class name of the object.
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.
bool isA(Type t) const
Checks whether or not the value is of a particular tpye.
Object toObject(ExecState *exec) const
Performs the ToObject type conversion operation on this value (ECMA 9.9)
bool isValid() const
Returns whether or not this is a valid value.
Type type() const
Returns the type of value.
An entry in a hash table.
unsigned char attr
attr is a set for flags (e.g.