25 #include "interpreter.h"
26 #include "operations.h"
27 #include "object_object.h"
28 #include "function_object.h"
37 ObjectPrototypeImp::ObjectPrototypeImp(
ExecState *exec,
42 putDirect(toStringPropertyName,
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToString,
43 0, toStringPropertyName), DontEnum);
44 putDirect(toLocaleStringPropertyName,
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToLocaleString,
45 0, toLocaleStringPropertyName), DontEnum);
46 putDirect(valueOfPropertyName,
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ValueOf,
47 0, valueOfPropertyName), DontEnum);
48 putDirect(
"hasOwnProperty",
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::HasOwnProperty,
49 1,
"hasOwnProperty"),DontEnum);
50 putDirect(
"isPrototypeOf",
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::IsPrototypeOf,
51 1,
"isPrototypeOf"),DontEnum);
52 putDirect(
"propertyIsEnumerable",
new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::PropertyIsEnumerable,
53 1,
"propertyIsEnumerable"),DontEnum);
58 Object(
new GlobalFuncImp(exec, funcProto,GlobalFuncImp::Eval, 1,
"eval")),
65 ObjectProtoFuncImp::ObjectProtoFuncImp(
ExecState * ,
71 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
76 bool ObjectProtoFuncImp::implementsCall()
const
92 case HasOwnProperty: {
94 Identifier propertyName(args[0].toString(exec));
95 Value tempProto(thisObj.imp()->prototype());
96 thisObj.imp()->setPrototype(
Value());
97 bool exists = thisObj.
hasProperty(exec,propertyName);
98 thisObj.imp()->setPrototype(tempProto);
99 return Value(exists ? BooleanImp::staticTrue : BooleanImp::staticFalse);
101 case IsPrototypeOf: {
103 for (; v.
isValid() && v.
isA(ObjectType); v = Object::dynamicCast(v).prototype()) {
104 if (v.imp() == thisObj.imp())
105 return Value(BooleanImp::staticTrue);
107 return Value(BooleanImp::staticFalse);
109 case PropertyIsEnumerable: {
110 Identifier propertyName(args[0].toString(exec));
111 ObjectImp *obj =
static_cast<ObjectImp*
>(thisObj.imp());
114 ValueImp *v = obj->_prop.get(propertyName,attributes);
116 return Value((attributes & DontEnum) ?
117 BooleanImp::staticFalse : BooleanImp::staticTrue);
119 if (propertyName == specialPrototypePropertyName)
120 return Value(BooleanImp::staticFalse);
122 const HashEntry *entry = obj->findPropertyHashEntry(propertyName);
123 return Value((entry && !(entry->
attr & DontEnum)) ?
124 BooleanImp::staticTrue : BooleanImp::staticFalse);
133 ObjectObjectImp::ObjectObjectImp(
ExecState * ,
134 ObjectPrototypeImp *objProto,
140 putDirect(prototypePropertyName, objProto, DontEnum|DontDelete|ReadOnly);
143 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);
147 bool ObjectObjectImp::implementsConstruct()
const
158 Object result(
new ObjectImp(proto));
163 Object obj = Object::dynamicCast(arg);
167 switch (arg.
type()) {
173 assert(!
"unhandled switch case in ObjectConstructor");
177 return Object(
new ObjectImp(proto));
181 bool ObjectObjectImp::implementsCall()
const
193 result = construct(exec,argList);
196 if (arg.
type() == NullType || arg.
type() == UndefinedType) {
198 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.