Commit 0e2d66e2 authored by weinig@apple.com's avatar weinig@apple.com

2008-07-05 Sam Weinig <sam@webkit.org>

        Reviewed by Cameron Zwarich.

        First step in broad cleanup effort.

        [ File list elided ]



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35022 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 49b32500
2008-07-05 Sam Weinig <sam@webkit.org>
Reviewed by Cameron Zwarich.
First step in broad cleanup effort.
[ File list elided ]
2008-07-05 Sam Weinig <sam@webkit.org>
Rubber-stamped by Cameron Zwarich.
......@@ -1090,10 +1090,10 @@
F68EBB8C0255D4C601FF60F7 /* config.h */,
BC8F3CCF0DAF17BA00577A80 /* ConstructData.h */,
F692A8540255597D01FF60F7 /* create_hash_table */,
BC1166000E1997B1008066DD /* DateInstance.cpp */,
BC1166010E1997B1008066DD /* DateInstance.h */,
BCD203450E17135E002C7E82 /* DateConstructor.cpp */,
BCD203460E17135E002C7E82 /* DateConstructor.h */,
BC1166000E1997B1008066DD /* DateInstance.cpp */,
BC1166010E1997B1008066DD /* DateInstance.h */,
BCD203470E17135E002C7E82 /* DatePrototype.cpp */,
BCD203480E17135E002C7E82 /* DatePrototype.h */,
D21202280AD4310C00ED79B6 /* DateMath.cpp */,
......
......@@ -2699,8 +2699,8 @@ JSValue* Machine::retrieveArguments(ExecState* exec, JSFunction* function) const
JSActivation* activation = static_cast<JSActivation*>(callFrame[RegisterFile::OptionalCalleeActivation].u.jsValue);
if (!activation) {
CodeBlock* codeBlock = &function->body->generatedCode();
activation = new (exec) JSActivation(function->body, callFrame + RegisterFile::CallFrameHeaderSize + codeBlock->numLocals);
CodeBlock* codeBlock = &function->m_body->generatedCode();
activation = new (exec) JSActivation(function->m_body, callFrame + RegisterFile::CallFrameHeaderSize + codeBlock->numLocals);
callFrame[RegisterFile::OptionalCalleeActivation].u.jsValue = activation;
}
......
......@@ -35,62 +35,62 @@ namespace KJS {
const ClassInfo Arguments::info = { "Arguments", 0, 0, 0 };
// ECMA 10.1.8
Arguments::Arguments(ExecState* exec, JSFunction* func, const ArgList& args, JSActivation* act)
Arguments::Arguments(ExecState* exec, JSFunction* function, const ArgList& args, JSActivation* activation)
: JSObject(exec->lexicalGlobalObject()->objectPrototype())
, _activationObject(act)
, indexToNameMap(func, args)
, m_activationObject(activation)
, m_indexToNameMap(function, args)
{
putDirect(exec->propertyNames().callee, func, DontEnum);
putDirect(exec->propertyNames().callee, function, DontEnum);
putDirect(exec, exec->propertyNames().length, args.size(), DontEnum);
int i = 0;
ArgList::const_iterator end = args.end();
for (ArgList::const_iterator it = args.begin(); it != end; ++it, ++i) {
Identifier name = Identifier::from(exec, i);
if (!indexToNameMap.isMapped(name))
if (!m_indexToNameMap.isMapped(name))
putDirect(name, *it, DontEnum);
}
}
void Arguments::mark()
{
JSObject::mark();
if (_activationObject && !_activationObject->marked())
_activationObject->mark();
JSObject::mark();
if (m_activationObject && !m_activationObject->marked())
m_activationObject->mark();
}
JSValue* Arguments::mappedIndexGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
{
Arguments* thisObj = static_cast<Arguments*>(slot.slotBase());
return thisObj->_activationObject->get(exec, thisObj->indexToNameMap[propertyName]);
Arguments* thisObj = static_cast<Arguments*>(slot.slotBase());
return thisObj->m_activationObject->get(exec, thisObj->m_indexToNameMap[propertyName]);
}
bool Arguments::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
if (indexToNameMap.isMapped(propertyName)) {
slot.setCustom(this, mappedIndexGetter);
return true;
}
if (m_indexToNameMap.isMapped(propertyName)) {
slot.setCustom(this, mappedIndexGetter);
return true;
}
return JSObject::getOwnPropertySlot(exec, propertyName, slot);
return JSObject::getOwnPropertySlot(exec, propertyName, slot);
}
void Arguments::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
{
if (indexToNameMap.isMapped(propertyName))
_activationObject->put(exec, indexToNameMap[propertyName], value);
if (m_indexToNameMap.isMapped(propertyName))
m_activationObject->put(exec, m_indexToNameMap[propertyName], value);
else
JSObject::put(exec, propertyName, value);
}
bool Arguments::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
if (indexToNameMap.isMapped(propertyName)) {
indexToNameMap.unMap(exec, propertyName);
return true;
} else {
if (m_indexToNameMap.isMapped(propertyName)) {
m_indexToNameMap.unMap(exec, propertyName);
return true;
}
return JSObject::deleteProperty(exec, propertyName);
}
}
} // namespace KJS
......@@ -29,23 +29,27 @@
namespace KJS {
class JSActivation;
class Arguments : public JSObject {
public:
Arguments(ExecState*, JSFunction* func, const ArgList& args, JSActivation* act);
virtual void mark();
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
virtual void put(ExecState*, const Identifier& propertyName, JSValue*);
virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
private:
static JSValue* mappedIndexGetter(ExecState*, const Identifier&, const PropertySlot& slot);
JSActivation* _activationObject;
mutable IndexToNameMap indexToNameMap;
};
class JSActivation;
class Arguments : public JSObject {
public:
Arguments(ExecState*, JSFunction*, const ArgList&, JSActivation*);
virtual void mark();
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
virtual void put(ExecState*, const Identifier& propertyName, JSValue*);
virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
private:
static JSValue* mappedIndexGetter(ExecState*, const Identifier&, const PropertySlot& slot);
JSActivation* m_activationObject;
mutable IndexToNameMap m_indexToNameMap;
};
} // namespace KJS
......
......@@ -31,11 +31,11 @@
namespace KJS {
ArrayConstructor::ArrayConstructor(ExecState* exec, FunctionPrototype* funcProto, ArrayPrototype* arrayProto)
: InternalFunction(funcProto, Identifier(exec, arrayProto->classInfo()->className))
ArrayConstructor::ArrayConstructor(ExecState* exec, FunctionPrototype* functionPrototype, ArrayPrototype* arrayPrototype)
: InternalFunction(functionPrototype, Identifier(exec, arrayPrototype->classInfo()->className))
{
// ECMA 15.4.3.1 Array.prototype
putDirect(exec->propertyNames().prototype, arrayProto, DontEnum|DontDelete|ReadOnly);
putDirect(exec->propertyNames().prototype, arrayPrototype, DontEnum | DontDelete | ReadOnly);
// no. of arguments for constructor
putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
......@@ -80,4 +80,4 @@ CallType ArrayConstructor::getCallData(CallData& callData)
return CallTypeNative;
}
}
} // namespace KJS
......@@ -25,15 +25,16 @@
namespace KJS {
class ArrayPrototype;
class FunctionPrototype;
class ArrayConstructor : public InternalFunction {
public:
ArrayConstructor(ExecState*, FunctionPrototype*, ArrayPrototype*);
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
};
class ArrayPrototype;
class FunctionPrototype;
class ArrayConstructor : public InternalFunction {
public:
ArrayConstructor(ExecState*, FunctionPrototype*, ArrayPrototype*);
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
};
} // namespace KJS
......
......@@ -28,9 +28,9 @@
#include "ObjectPrototype.h"
#include "lookup.h"
#include "operations.h"
#include <algorithm>
#include <wtf/Assertions.h>
#include <wtf/HashSet.h>
#include <algorithm> // for std::min
namespace KJS {
......@@ -89,8 +89,8 @@ const ClassInfo ArrayPrototype::info = {"Array", &JSArray::info, 0, ExecState::a
*/
// ECMA 15.4.4
ArrayPrototype::ArrayPrototype(ExecState*, ObjectPrototype* objProto)
: JSArray(objProto, 0)
ArrayPrototype::ArrayPrototype(ExecState*, ObjectPrototype* objectPrototype)
: JSArray(objectPrototype, 0)
{
}
......@@ -774,4 +774,4 @@ JSValue* arrayProtoFuncLastIndexOf(ExecState* exec, JSObject*, JSValue* thisValu
return jsNumber(exec, -1);
}
}
} // namespace KJS
......@@ -26,14 +26,15 @@
namespace KJS {
class ArrayPrototype : public JSArray {
public:
ArrayPrototype(ExecState*, ObjectPrototype*);
bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
};
class ArrayPrototype : public JSArray {
public:
ArrayPrototype(ExecState*, ObjectPrototype*);
bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
};
} // namespace KJS
......
......@@ -28,14 +28,10 @@ namespace KJS {
class BooleanPrototype;
class FunctionPrototype;
/**
* @internal
*
* The initial value of the the global variable's "Boolean" property
*/
class BooleanConstructor : public InternalFunction {
public:
BooleanConstructor(ExecState*, FunctionPrototype*, BooleanPrototype*);
private:
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
......
......@@ -25,8 +25,8 @@ namespace KJS {
const ClassInfo BooleanObject::info = { "Boolean", 0, 0, 0 };
BooleanObject::BooleanObject(JSObject* proto)
: JSWrapperObject(proto)
BooleanObject::BooleanObject(JSObject* prototype)
: JSWrapperObject(prototype)
{
}
......
......@@ -27,7 +27,7 @@ namespace KJS {
class BooleanObject : public JSWrapperObject {
public:
BooleanObject(JSObject* proto);
BooleanObject(JSObject* prototype);
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
......
......@@ -28,12 +28,6 @@ namespace KJS {
class FunctionPrototype;
class ObjectPrototype;
/**
* @internal
*
* The initial value of Boolean.prototype (and thus all objects created
* with the Boolean constructor
*/
class BooleanPrototype : public BooleanObject {
public:
BooleanPrototype(ExecState*, ObjectPrototype*, FunctionPrototype*);
......
......@@ -27,37 +27,35 @@
namespace KJS {
struct HashEntry;
struct HashTable;
/**
* Class Information
*/
struct ClassInfo {
/**
* A string denoting the class name. Example: "Window".
*/
const char* className;
/**
* Pointer to the class information of the base class.
* 0L if there is none.
*/
const ClassInfo* parentClass;
/**
* Static hash-table of properties.
* For classes that can be used from multiple threads, it is accessed via a getter function that would typically return a pointer to thread-specific value.
*/
const HashTable* propHashTable(ExecState* exec) const
{
if (classPropHashTableGetterFunction)
return classPropHashTableGetterFunction(exec);
return staticPropHashTable;
}
const HashTable* staticPropHashTable;
typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*);
const ClassPropHashTableGetterFunction classPropHashTableGetterFunction;
};
struct HashEntry;
struct HashTable;
struct ClassInfo {
/**
* A string denoting the class name. Example: "Window".
*/
const char* className;
/**
* Pointer to the class information of the base class.
* 0L if there is none.
*/
const ClassInfo* parentClass;
/**
* Static hash-table of properties.
* For classes that can be used from multiple threads, it is accessed via a getter function that would typically return a pointer to thread-specific value.
*/
const HashTable* propHashTable(ExecState* exec) const
{
if (classPropHashTableGetterFunction)
return classPropHashTableGetterFunction(exec);
return staticPropHashTable;
}
const HashTable* staticPropHashTable;
typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*);
const ClassPropHashTableGetterFunction classPropHashTableGetterFunction;
};
} // namespace KJS
......
......@@ -29,47 +29,48 @@
#ifndef CollectorHeapIntrospector_h
#define CollectorHeapIntrospector_h
#include <malloc/malloc.h>
#include "Assertions.h"
#include <malloc/malloc.h>
namespace KJS {
struct CollectorHeap;
class CollectorHeapIntrospector {
public:
static void init(CollectorHeap*, CollectorHeap*);
static kern_return_t enumerate(task_t, void* context, unsigned typeMask, vm_address_t zoneAddress, memory_reader_t, vm_range_recorder_t);
static size_t goodSize(malloc_zone_t*, size_t size) { return size; }
static boolean_t check(malloc_zone_t*) { return true; }
static void print(malloc_zone_t*, boolean_t) { }
static void log(malloc_zone_t*, void*) { }
static void forceLock(malloc_zone_t*) { }
static void forceUnlock(malloc_zone_t*) { }
static void statistics(malloc_zone_t*, malloc_statistics_t*);
struct CollectorHeap;
class CollectorHeapIntrospector {
public:
static void init(CollectorHeap*, CollectorHeap*);
static kern_return_t enumerate(task_t, void* context, unsigned typeMask, vm_address_t zoneAddress, memory_reader_t, vm_range_recorder_t);
static size_t goodSize(malloc_zone_t*, size_t size) { return size; }
static boolean_t check(malloc_zone_t*) { return true; }
static void print(malloc_zone_t*, boolean_t) { }
static void log(malloc_zone_t*, void*) { }
static void forceLock(malloc_zone_t*) { }
static void forceUnlock(malloc_zone_t*) { }
static void statistics(malloc_zone_t*, malloc_statistics_t*);
private:
CollectorHeapIntrospector(CollectorHeap*, CollectorHeap*);
private:
CollectorHeapIntrospector(CollectorHeap*, CollectorHeap*);
static size_t size(malloc_zone_t*, const void*) { return 0; }
static void* zoneMalloc(malloc_zone_t*, size_t) { LOG_ERROR("malloc is not supported"); return 0; }
static void* zoneCalloc(malloc_zone_t*, size_t, size_t) { LOG_ERROR("calloc is not supported"); return 0; }
static void* zoneRealloc(malloc_zone_t*, void*, size_t) { LOG_ERROR("realloc is not supported"); return 0; }
static void* zoneValloc(malloc_zone_t*, size_t) { LOG_ERROR("valloc is not supported"); return 0; }
static void zoneDestroy(malloc_zone_t*) { }
static size_t size(malloc_zone_t*, const void*) { return 0; }
static void* zoneMalloc(malloc_zone_t*, size_t) { LOG_ERROR("malloc is not supported"); return 0; }
static void* zoneCalloc(malloc_zone_t*, size_t, size_t) { LOG_ERROR("calloc is not supported"); return 0; }
static void* zoneRealloc(malloc_zone_t*, void*, size_t) { LOG_ERROR("realloc is not supported"); return 0; }
static void* zoneValloc(malloc_zone_t*, size_t) { LOG_ERROR("valloc is not supported"); return 0; }
static void zoneDestroy(malloc_zone_t*) { }
static void zoneFree(malloc_zone_t*, void* ptr)
{
// Due to <rdar://problem/5671357> zoneFree may be called by the system free even if the pointer
// is not in this zone. When this happens, the pointer being freed was not allocated by any
// zone so we need to print a useful error for the application developer.
malloc_printf("*** error for object %p: pointer being freed was not allocated\n", ptr);
}
static void zoneFree(malloc_zone_t*, void* ptr)
{
// Due to <rdar://problem/5671357> zoneFree may be called by the system free even if the pointer
// is not in this zone. When this happens, the pointer being freed was not allocated by any
// zone so we need to print a useful error for the application developer.
malloc_printf("*** error for object %p: pointer being freed was not allocated\n", ptr);
}
malloc_zone_t m_zone;
CollectorHeap* m_primaryHeap;
CollectorHeap* m_numberHeap;
};
malloc_zone_t m_zone;
CollectorHeap* m_primaryHeap;
CollectorHeap* m_numberHeap;
};
}
} // namespace KJS
#endif // CollectorHeapIntrospector_h
......@@ -18,8 +18,8 @@
*
*/
#ifndef KJS_COMMON_IDENTIFIERS_H
#define KJS_COMMON_IDENTIFIERS_H
#ifndef CommonIdentifiers_h
#define CommonIdentifiers_h
#include "identifier.h"
#include <wtf/Noncopyable.h>
......@@ -81,7 +81,7 @@ namespace KJS {
KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
#undef KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL
};
} // namespace KJS
#endif // KJS_COMMON_IDENTIFIERS_H
} // namespace KJS
#endif // CommonIdentifiers_h
......@@ -49,62 +49,64 @@ static JSValue* dateParse(ExecState*, JSObject*, JSValue*, const ArgList&);
static JSValue* dateNow(ExecState*, JSObject*, JSValue*, const ArgList&);
static JSValue* dateUTC(ExecState*, JSObject*, JSValue*, const ArgList&);
DateConstructor::DateConstructor(ExecState* exec, FunctionPrototype* funcProto, DatePrototype* dateProto)
: InternalFunction(funcProto, Identifier(exec, dateProto->classInfo()->className))
DateConstructor::DateConstructor(ExecState* exec, FunctionPrototype* functionPrototype, DatePrototype* datePrototype)
: InternalFunction(functionPrototype, Identifier(exec, datePrototype->classInfo()->className))
{
putDirect(exec->propertyNames().prototype, dateProto, DontEnum|DontDelete|ReadOnly);
putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 1, exec->propertyNames().parse, dateParse), DontEnum);
putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 7, exec->propertyNames().UTC, dateUTC), DontEnum);
putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 0, exec->propertyNames().now, dateNow), DontEnum);
putDirect(exec, exec->propertyNames().length, 7, ReadOnly | DontEnum | DontDelete);
putDirect(exec->propertyNames().prototype, datePrototype, DontEnum|DontDelete|ReadOnly);
putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().parse, dateParse), DontEnum);
putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 7, exec->propertyNames().UTC, dateUTC), DontEnum);
putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().now, dateNow), DontEnum);
putDirect(exec, exec->propertyNames().length, 7, ReadOnly | DontEnum | DontDelete);
}
// ECMA 15.9.3
static JSObject* constructDate(ExecState* exec, JSObject*, const ArgList& args)
{
int numArgs = args.size();
double value;
if (numArgs == 0) { // new Date() ECMA 15.9.3.3
value = getCurrentUTCTime();
} else if (numArgs == 1) {
if (args[0]->isObject(&DateInstance::info))
value = static_cast<DateInstance*>(args[0])->internalNumber();
else {
JSValue* primitive = args[0]->toPrimitive(exec);
if (primitive->isString())
value = parseDate(primitive->getString());
else
value = primitive->toNumber(exec);
}
} else {
if (isnan(args[0]->toNumber(exec))
|| isnan(args[1]->toNumber(exec))
|| (numArgs >= 3 && isnan(args[2]->toNumber(exec)))
|| (numArgs >= 4 && isnan(args[3]->toNumber(exec)))
|| (numArgs >= 5 && isnan(args[4]->toNumber(exec)))
|| (numArgs >= 6 && isnan(args[5]->toNumber(exec)))
|| (numArgs >= 7 && isnan(args[6]->toNumber(exec)))) {
value = NaN;
int numArgs = args.size();
double value;
if (numArgs == 0) // new Date() ECMA 15.9.3.3
value = getCurrentUTCTime();
else if (numArgs == 1) {
if (args[0]->isObject(&DateInstance::info))
value = static_cast<DateInstance*>(args[0])->internalNumber();
else {
JSValue* primitive = args[0]->toPrimitive(exec);
if (primitive->isString())
value = parseDate(primitive->getString());
else
value = primitive->toNumber(exec);
}
} else {
GregorianDateTime t;
int year = args[0]->toInt32(exec);
t.year = (year >= 0 && year <= 99) ? year : year - 1900;
t.month = args[1]->toInt32(exec);
t.monthDay = (numArgs >= 3) ? args[2]->toInt32(exec) : 1;
t.hour = args[3]->toInt32(exec);
t.minute = args[4]->toInt32(exec);
t.second = args[5]->toInt32(exec);
t.isDST = -1;
double ms = (numArgs >= 7) ? args[6]->toNumber(exec) : 0;
value = gregorianDateTimeToMS(t, ms, false);
if (isnan(args[0]->toNumber(exec))
|| isnan(args[1]->toNumber(exec))
|| (numArgs >= 3 && isnan(args[2]->toNumber(exec)))
|| (numArgs >= 4 && isnan(args[3]->toNumber(exec)))
|| (numArgs >= 5 && isnan(args[4]->toNumber(exec)))
|| (numArgs >= 6 && isnan(args[5]->toNumber(exec)))
|| (numArgs >= 7 && isnan(args[6]->toNumber(exec))))
value = NaN;
else {
GregorianDateTime t;
int year = args[0]->toInt32(exec);
t.year = (year >= 0 && year <= 99) ? year : year - 1900;
t.month = args[1]->toInt32(exec);
t.monthDay = (numArgs >= 3) ? args[2]->toInt32(exec) : 1;
t.hour = args[3]->toInt32(exec);
t.minute = args[4]->toInt32(exec);
t.second = args[5]->toInt32(exec);
t.isDST = -1;
double ms = (numArgs >= 7) ? args[6]->toNumber(exec) : 0;
value = gregorianDateTimeToMS(t, ms, false);
}
}
}
DateInstance* ret = new (exec) DateInstance(exec->lexicalGlobalObject()->datePrototype());
ret->setInternalValue(jsNumber(exec, timeClip(value)));
return ret;