Changeset 35022 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jul 5, 2008, 10:26:58 PM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r35021 r35022 1 2008-07-05 Sam Weinig <[email protected]> 2 3 Reviewed by Cameron Zwarich. 4 5 First step in broad cleanup effort. 6 7 [ File list elided ] 8 1 9 2008-07-05 Sam Weinig <[email protected]> 2 10 -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r35021 r35022 1091 1091 BC8F3CCF0DAF17BA00577A80 /* ConstructData.h */, 1092 1092 F692A8540255597D01FF60F7 /* create_hash_table */, 1093 BCD203450E17135E002C7E82 /* DateConstructor.cpp */, 1094 BCD203460E17135E002C7E82 /* DateConstructor.h */, 1093 1095 BC1166000E1997B1008066DD /* DateInstance.cpp */, 1094 1096 BC1166010E1997B1008066DD /* DateInstance.h */, 1095 BCD203450E17135E002C7E82 /* DateConstructor.cpp */,1096 BCD203460E17135E002C7E82 /* DateConstructor.h */,1097 1097 BCD203470E17135E002C7E82 /* DatePrototype.cpp */, 1098 1098 BCD203480E17135E002C7E82 /* DatePrototype.h */, -
trunk/JavaScriptCore/VM/Machine.cpp
r35016 r35022 2700 2700 JSActivation* activation = static_cast<JSActivation*>(callFrame[RegisterFile::OptionalCalleeActivation].u.jsValue); 2701 2701 if (!activation) { 2702 CodeBlock* codeBlock = &function-> body->generatedCode();2703 activation = new (exec) JSActivation(function-> body, callFrame + RegisterFile::CallFrameHeaderSize + codeBlock->numLocals);2702 CodeBlock* codeBlock = &function->m_body->generatedCode(); 2703 activation = new (exec) JSActivation(function->m_body, callFrame + RegisterFile::CallFrameHeaderSize + codeBlock->numLocals); 2704 2704 callFrame[RegisterFile::OptionalCalleeActivation].u.jsValue = activation; 2705 2705 } -
trunk/JavaScriptCore/kjs/Arguments.cpp
r35018 r35022 36 36 37 37 // ECMA 10.1.8 38 Arguments::Arguments(ExecState* exec, JSFunction* func , const ArgList& args, JSActivation* act)38 Arguments::Arguments(ExecState* exec, JSFunction* function, const ArgList& args, JSActivation* activation) 39 39 : JSObject(exec->lexicalGlobalObject()->objectPrototype()) 40 , _activationObject(act)41 , indexToNameMap(func, args)40 , m_activationObject(activation) 41 , m_indexToNameMap(function, args) 42 42 { 43 putDirect(exec->propertyNames().callee, func , DontEnum);43 putDirect(exec->propertyNames().callee, function, DontEnum); 44 44 putDirect(exec, exec->propertyNames().length, args.size(), DontEnum); 45 45 … … 48 48 for (ArgList::const_iterator it = args.begin(); it != end; ++it, ++i) { 49 49 Identifier name = Identifier::from(exec, i); 50 if (! indexToNameMap.isMapped(name))50 if (!m_indexToNameMap.isMapped(name)) 51 51 putDirect(name, *it, DontEnum); 52 52 } … … 55 55 void Arguments::mark() 56 56 { 57 JSObject::mark();58 if (_activationObject && !_activationObject->marked())59 _activationObject->mark();57 JSObject::mark(); 58 if (m_activationObject && !m_activationObject->marked()) 59 m_activationObject->mark(); 60 60 } 61 61 62 62 JSValue* Arguments::mappedIndexGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) 63 63 { 64 Arguments* thisObj = static_cast<Arguments*>(slot.slotBase());65 return thisObj->_activationObject->get(exec, thisObj->indexToNameMap[propertyName]);64 Arguments* thisObj = static_cast<Arguments*>(slot.slotBase()); 65 return thisObj->m_activationObject->get(exec, thisObj->m_indexToNameMap[propertyName]); 66 66 } 67 67 68 68 bool Arguments::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 69 69 { 70 if (indexToNameMap.isMapped(propertyName)) {71 slot.setCustom(this, mappedIndexGetter);72 return true;73 }70 if (m_indexToNameMap.isMapped(propertyName)) { 71 slot.setCustom(this, mappedIndexGetter); 72 return true; 73 } 74 74 75 return JSObject::getOwnPropertySlot(exec, propertyName, slot);75 return JSObject::getOwnPropertySlot(exec, propertyName, slot); 76 76 } 77 77 78 78 void Arguments::put(ExecState* exec, const Identifier& propertyName, JSValue* value) 79 79 { 80 if ( indexToNameMap.isMapped(propertyName))81 _activationObject->put(exec,indexToNameMap[propertyName], value);80 if (m_indexToNameMap.isMapped(propertyName)) 81 m_activationObject->put(exec, m_indexToNameMap[propertyName], value); 82 82 else 83 83 JSObject::put(exec, propertyName, value); … … 86 86 bool Arguments::deleteProperty(ExecState* exec, const Identifier& propertyName) 87 87 { 88 if (indexToNameMap.isMapped(propertyName)) { 89 indexToNameMap.unMap(exec, propertyName); 90 return true; 91 } else { 88 if (m_indexToNameMap.isMapped(propertyName)) { 89 m_indexToNameMap.unMap(exec, propertyName); 90 return true; 91 } 92 92 93 return JSObject::deleteProperty(exec, propertyName); 93 }94 94 } 95 95 -
trunk/JavaScriptCore/kjs/Arguments.h
r35016 r35022 30 30 namespace KJS { 31 31 32 class JSActivation;32 class JSActivation; 33 33 34 class Arguments : public JSObject { 35 public: 36 Arguments(ExecState*, JSFunction* func, const ArgList& args, JSActivation* act); 37 virtual void mark(); 38 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 39 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 40 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 41 virtual const ClassInfo* classInfo() const { return &info; } 42 static const ClassInfo info; 43 private: 44 static JSValue* mappedIndexGetter(ExecState*, const Identifier&, const PropertySlot& slot); 34 class Arguments : public JSObject { 35 public: 36 Arguments(ExecState*, JSFunction*, const ArgList&, JSActivation*); 45 37 46 JSActivation* _activationObject; 47 mutable IndexToNameMap indexToNameMap; 48 }; 38 virtual void mark(); 39 40 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 41 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 42 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 43 44 virtual const ClassInfo* classInfo() const { return &info; } 45 static const ClassInfo info; 46 47 private: 48 static JSValue* mappedIndexGetter(ExecState*, const Identifier&, const PropertySlot& slot); 49 50 JSActivation* m_activationObject; 51 mutable IndexToNameMap m_indexToNameMap; 52 }; 49 53 50 54 } // namespace KJS -
trunk/JavaScriptCore/kjs/ArrayConstructor.cpp
r34876 r35022 32 32 namespace KJS { 33 33 34 ArrayConstructor::ArrayConstructor(ExecState* exec, FunctionPrototype* func Proto, ArrayPrototype* arrayProto)35 : InternalFunction(func Proto, Identifier(exec, arrayProto->classInfo()->className))34 ArrayConstructor::ArrayConstructor(ExecState* exec, FunctionPrototype* functionPrototype, ArrayPrototype* arrayPrototype) 35 : InternalFunction(functionPrototype, Identifier(exec, arrayPrototype->classInfo()->className)) 36 36 { 37 37 // ECMA 15.4.3.1 Array.prototype 38 putDirect(exec->propertyNames().prototype, arrayProto , DontEnum|DontDelete|ReadOnly);38 putDirect(exec->propertyNames().prototype, arrayPrototype, DontEnum | DontDelete | ReadOnly); 39 39 40 40 // no. of arguments for constructor … … 81 81 } 82 82 83 } 83 } // namespace KJS -
trunk/JavaScriptCore/kjs/ArrayConstructor.h
r34901 r35022 26 26 namespace KJS { 27 27 28 class ArrayPrototype;29 class FunctionPrototype;28 class ArrayPrototype; 29 class FunctionPrototype; 30 30 31 class ArrayConstructor : public InternalFunction { 32 public: 33 ArrayConstructor(ExecState*, FunctionPrototype*, ArrayPrototype*); 34 virtual ConstructType getConstructData(ConstructData&); 35 virtual CallType getCallData(CallData&); 36 }; 31 class ArrayConstructor : public InternalFunction { 32 public: 33 ArrayConstructor(ExecState*, FunctionPrototype*, ArrayPrototype*); 34 35 virtual ConstructType getConstructData(ConstructData&); 36 virtual CallType getCallData(CallData&); 37 }; 37 38 38 39 } // namespace KJS -
trunk/JavaScriptCore/kjs/ArrayPrototype.cpp
r34876 r35022 29 29 #include "lookup.h" 30 30 #include "operations.h" 31 #include <algorithm> 31 32 #include <wtf/Assertions.h> 32 33 #include <wtf/HashSet.h> 33 #include <algorithm> // for std::min34 34 35 35 namespace KJS { … … 90 90 91 91 // ECMA 15.4.4 92 ArrayPrototype::ArrayPrototype(ExecState*, ObjectPrototype* obj Proto)93 : JSArray(obj Proto, 0)92 ArrayPrototype::ArrayPrototype(ExecState*, ObjectPrototype* objectPrototype) 93 : JSArray(objectPrototype, 0) 94 94 { 95 95 } … … 775 775 } 776 776 777 } 777 } // namespace KJS -
trunk/JavaScriptCore/kjs/ArrayPrototype.h
r34843 r35022 27 27 namespace KJS { 28 28 29 class ArrayPrototype : public JSArray {30 public:31 ArrayPrototype(ExecState*, ObjectPrototype*);29 class ArrayPrototype : public JSArray { 30 public: 31 ArrayPrototype(ExecState*, ObjectPrototype*); 32 32 33 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 34 virtual const ClassInfo* classInfo() const { return &info; } 35 static const ClassInfo info; 36 }; 33 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 34 35 virtual const ClassInfo* classInfo() const { return &info; } 36 static const ClassInfo info; 37 }; 37 38 38 39 } // namespace KJS -
trunk/JavaScriptCore/kjs/BooleanConstructor.h
r34901 r35022 29 29 class FunctionPrototype; 30 30 31 /**32 * @internal33 *34 * The initial value of the the global variable's "Boolean" property35 */36 31 class BooleanConstructor : public InternalFunction { 37 32 public: 38 33 BooleanConstructor(ExecState*, FunctionPrototype*, BooleanPrototype*); 34 39 35 private: 40 36 virtual ConstructType getConstructData(ConstructData&); -
trunk/JavaScriptCore/kjs/BooleanObject.cpp
r34843 r35022 26 26 const ClassInfo BooleanObject::info = { "Boolean", 0, 0, 0 }; 27 27 28 BooleanObject::BooleanObject(JSObject* proto )29 : JSWrapperObject(proto )28 BooleanObject::BooleanObject(JSObject* prototype) 29 : JSWrapperObject(prototype) 30 30 { 31 31 } -
trunk/JavaScriptCore/kjs/BooleanObject.h
r34843 r35022 28 28 class BooleanObject : public JSWrapperObject { 29 29 public: 30 BooleanObject(JSObject* proto );30 BooleanObject(JSObject* prototype); 31 31 32 32 virtual const ClassInfo* classInfo() const { return &info; } -
trunk/JavaScriptCore/kjs/BooleanPrototype.h
r34855 r35022 29 29 class ObjectPrototype; 30 30 31 /**32 * @internal33 *34 * The initial value of Boolean.prototype (and thus all objects created35 * with the Boolean constructor36 */37 31 class BooleanPrototype : public BooleanObject { 38 32 public: -
trunk/JavaScriptCore/kjs/ClassInfo.h
r35007 r35022 28 28 namespace KJS { 29 29 30 struct HashEntry;31 struct HashTable;30 struct HashEntry; 31 struct HashTable; 32 32 33 /** 34 * Class Information 35 */ 36 struct ClassInfo { 37 /** 38 * A string denoting the class name. Example: "Window". 39 */ 40 const char* className; 41 /** 42 * Pointer to the class information of the base class. 43 * 0L if there is none. 44 */ 45 const ClassInfo* parentClass; 46 /** 47 * Static hash-table of properties. 48 * 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. 49 */ 50 const HashTable* propHashTable(ExecState* exec) const 51 { 52 if (classPropHashTableGetterFunction) 53 return classPropHashTableGetterFunction(exec); 54 return staticPropHashTable; 55 } 33 struct ClassInfo { 34 /** 35 * A string denoting the class name. Example: "Window". 36 */ 37 const char* className; 56 38 57 const HashTable* staticPropHashTable; 58 typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*); 59 const ClassPropHashTableGetterFunction classPropHashTableGetterFunction; 60 }; 39 /** 40 * Pointer to the class information of the base class. 41 * 0L if there is none. 42 */ 43 const ClassInfo* parentClass; 44 /** 45 * Static hash-table of properties. 46 * 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. 47 */ 48 const HashTable* propHashTable(ExecState* exec) const 49 { 50 if (classPropHashTableGetterFunction) 51 return classPropHashTableGetterFunction(exec); 52 return staticPropHashTable; 53 } 54 55 const HashTable* staticPropHashTable; 56 typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*); 57 const ClassPropHashTableGetterFunction classPropHashTableGetterFunction; 58 }; 61 59 62 60 } // namespace KJS -
trunk/JavaScriptCore/kjs/CollectorHeapIntrospector.h
r34824 r35022 30 30 #define CollectorHeapIntrospector_h 31 31 32 #include "Assertions.h" 32 33 #include <malloc/malloc.h> 33 #include "Assertions.h"34 34 35 35 namespace KJS { 36 36 37 struct CollectorHeap;38 39 class CollectorHeapIntrospector {40 public:41 static void init(CollectorHeap*, CollectorHeap*);42 static kern_return_t enumerate(task_t, void* context, unsigned typeMask, vm_address_t zoneAddress, memory_reader_t, vm_range_recorder_t);43 static size_t goodSize(malloc_zone_t*, size_t size) { return size; }44 static boolean_t check(malloc_zone_t*) { return true; }45 static void print(malloc_zone_t*, boolean_t) { }46 static void log(malloc_zone_t*, void*) { }47 static void forceLock(malloc_zone_t*) { }48 static void forceUnlock(malloc_zone_t*) { }49 static void statistics(malloc_zone_t*, malloc_statistics_t*);37 struct CollectorHeap; 38 39 class CollectorHeapIntrospector { 40 public: 41 static void init(CollectorHeap*, CollectorHeap*); 42 static kern_return_t enumerate(task_t, void* context, unsigned typeMask, vm_address_t zoneAddress, memory_reader_t, vm_range_recorder_t); 43 static size_t goodSize(malloc_zone_t*, size_t size) { return size; } 44 static boolean_t check(malloc_zone_t*) { return true; } 45 static void print(malloc_zone_t*, boolean_t) { } 46 static void log(malloc_zone_t*, void*) { } 47 static void forceLock(malloc_zone_t*) { } 48 static void forceUnlock(malloc_zone_t*) { } 49 static void statistics(malloc_zone_t*, malloc_statistics_t*); 50 50 51 private: 52 CollectorHeapIntrospector(CollectorHeap*, CollectorHeap*); 53 static size_t size(malloc_zone_t*, const void*) { return 0; } 54 static void* zoneMalloc(malloc_zone_t*, size_t) { LOG_ERROR("malloc is not supported"); return 0; } 55 static void* zoneCalloc(malloc_zone_t*, size_t, size_t) { LOG_ERROR("calloc is not supported"); return 0; } 56 static void* zoneRealloc(malloc_zone_t*, void*, size_t) { LOG_ERROR("realloc is not supported"); return 0; } 57 static void* zoneValloc(malloc_zone_t*, size_t) { LOG_ERROR("valloc is not supported"); return 0; } 58 static void zoneDestroy(malloc_zone_t*) { } 51 private: 52 CollectorHeapIntrospector(CollectorHeap*, CollectorHeap*); 59 53 60 static void zoneFree(malloc_zone_t*, void* ptr) 61 { 62 // Due to <rdar://problem/5671357> zoneFree may be called by the system free even if the pointer 63 // is not in this zone. When this happens, the pointer being freed was not allocated by any 64 // zone so we need to print a useful error for the application developer. 65 malloc_printf("*** error for object %p: pointer being freed was not allocated\n", ptr); 66 } 54 static size_t size(malloc_zone_t*, const void*) { return 0; } 55 static void* zoneMalloc(malloc_zone_t*, size_t) { LOG_ERROR("malloc is not supported"); return 0; } 56 static void* zoneCalloc(malloc_zone_t*, size_t, size_t) { LOG_ERROR("calloc is not supported"); return 0; } 57 static void* zoneRealloc(malloc_zone_t*, void*, size_t) { LOG_ERROR("realloc is not supported"); return 0; } 58 static void* zoneValloc(malloc_zone_t*, size_t) { LOG_ERROR("valloc is not supported"); return 0; } 59 static void zoneDestroy(malloc_zone_t*) { } 67 60 68 malloc_zone_t m_zone; 69 CollectorHeap* m_primaryHeap; 70 CollectorHeap* m_numberHeap; 71 }; 61 static void zoneFree(malloc_zone_t*, void* ptr) 62 { 63 // Due to <rdar://problem/5671357> zoneFree may be called by the system free even if the pointer 64 // is not in this zone. When this happens, the pointer being freed was not allocated by any 65 // zone so we need to print a useful error for the application developer. 66 malloc_printf("*** error for object %p: pointer being freed was not allocated\n", ptr); 67 } 72 68 73 } 69 malloc_zone_t m_zone; 70 CollectorHeap* m_primaryHeap; 71 CollectorHeap* m_numberHeap; 72 }; 73 74 } // namespace KJS 74 75 75 76 #endif // CollectorHeapIntrospector_h -
trunk/JavaScriptCore/kjs/CommonIdentifiers.h
r34843 r35022 19 19 */ 20 20 21 #ifndef KJS_COMMON_IDENTIFIERS_H22 #define KJS_COMMON_IDENTIFIERS_H21 #ifndef CommonIdentifiers_h 22 #define CommonIdentifiers_h 23 23 24 24 #include "identifier.h" … … 82 82 #undef KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL 83 83 }; 84 84 85 } // namespace KJS 85 86 86 #endif // KJS_COMMON_IDENTIFIERS_H 87 87 #endif // CommonIdentifiers_h -
trunk/JavaScriptCore/kjs/DateConstructor.cpp
r35018 r35022 50 50 static JSValue* dateUTC(ExecState*, JSObject*, JSValue*, const ArgList&); 51 51 52 DateConstructor::DateConstructor(ExecState* exec, FunctionPrototype* func Proto, DatePrototype* dateProto)53 : InternalFunction(funcProto, Identifier(exec, dateProto->classInfo()->className))52 DateConstructor::DateConstructor(ExecState* exec, FunctionPrototype* functionPrototype, DatePrototype* datePrototype) 53 : InternalFunction(functionPrototype, Identifier(exec, datePrototype->classInfo()->className)) 54 54 { 55 putDirect(exec->propertyNames().prototype, dateProto, DontEnum|DontDelete|ReadOnly); 56 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 1, exec->propertyNames().parse, dateParse), DontEnum); 57 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 7, exec->propertyNames().UTC, dateUTC), DontEnum); 58 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 0, exec->propertyNames().now, dateNow), DontEnum); 59 putDirect(exec, exec->propertyNames().length, 7, ReadOnly | DontEnum | DontDelete); 55 putDirect(exec->propertyNames().prototype, datePrototype, DontEnum|DontDelete|ReadOnly); 56 57 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 1, exec->propertyNames().parse, dateParse), DontEnum); 58 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 7, exec->propertyNames().UTC, dateUTC), DontEnum); 59 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().now, dateNow), DontEnum); 60 61 putDirect(exec, exec->propertyNames().length, 7, ReadOnly | DontEnum | DontDelete); 60 62 } 61 63 … … 63 65 static JSObject* constructDate(ExecState* exec, JSObject*, const ArgList& args) 64 66 { 65 int numArgs = args.size();67 int numArgs = args.size(); 66 68 67 double value;69 double value; 68 70 69 if (numArgs == 0) { // new Date() ECMA 15.9.3.3 70 value = getCurrentUTCTime(); 71 } else if (numArgs == 1) { 72 if (args[0]->isObject(&DateInstance::info)) 73 value = static_cast<DateInstance*>(args[0])->internalNumber(); 74 else { 75 JSValue* primitive = args[0]->toPrimitive(exec); 76 if (primitive->isString()) 77 value = parseDate(primitive->getString()); 78 else 79 value = primitive->toNumber(exec); 71 if (numArgs == 0) // new Date() ECMA 15.9.3.3 72 value = getCurrentUTCTime(); 73 else if (numArgs == 1) { 74 if (args[0]->isObject(&DateInstance::info)) 75 value = static_cast<DateInstance*>(args[0])->internalNumber(); 76 else { 77 JSValue* primitive = args[0]->toPrimitive(exec); 78 if (primitive->isString()) 79 value = parseDate(primitive->getString()); 80 else 81 value = primitive->toNumber(exec); 82 } 83 } else { 84 if (isnan(args[0]->toNumber(exec)) 85 || isnan(args[1]->toNumber(exec)) 86 || (numArgs >= 3 && isnan(args[2]->toNumber(exec))) 87 || (numArgs >= 4 && isnan(args[3]->toNumber(exec))) 88 || (numArgs >= 5 && isnan(args[4]->toNumber(exec))) 89 || (numArgs >= 6 && isnan(args[5]->toNumber(exec))) 90 || (numArgs >= 7 && isnan(args[6]->toNumber(exec)))) 91 value = NaN; 92 else { 93 GregorianDateTime t; 94 int year = args[0]->toInt32(exec); 95 t.year = (year >= 0 && year <= 99) ? year : year - 1900; 96 t.month = args[1]->toInt32(exec); 97 t.monthDay = (numArgs >= 3) ? args[2]->toInt32(exec) : 1; 98 t.hour = args[3]->toInt32(exec); 99 t.minute = args[4]->toInt32(exec); 100 t.second = args[5]->toInt32(exec); 101 t.isDST = -1; 102 double ms = (numArgs >= 7) ? args[6]->toNumber(exec) : 0; 103 value = gregorianDateTimeToMS(t, ms, false); 104 } 80 105 } 81 } else { 82 if (isnan(args[0]->toNumber(exec)) 83 || isnan(args[1]->toNumber(exec)) 84 || (numArgs >= 3 && isnan(args[2]->toNumber(exec))) 85 || (numArgs >= 4 && isnan(args[3]->toNumber(exec))) 86 || (numArgs >= 5 && isnan(args[4]->toNumber(exec))) 87 || (numArgs >= 6 && isnan(args[5]->toNumber(exec))) 88 || (numArgs >= 7 && isnan(args[6]->toNumber(exec)))) { 89 value = NaN; 90 } else { 91 GregorianDateTime t; 92 int year = args[0]->toInt32(exec); 93 t.year = (year >= 0 && year <= 99) ? year : year - 1900; 94 t.month = args[1]->toInt32(exec); 95 t.monthDay = (numArgs >= 3) ? args[2]->toInt32(exec) : 1; 96 t.hour = args[3]->toInt32(exec); 97 t.minute = args[4]->toInt32(exec); 98 t.second = args[5]->toInt32(exec); 99 t.isDST = -1; 100 double ms = (numArgs >= 7) ? args[6]->toNumber(exec) : 0; 101 value = gregorianDateTimeToMS(t, ms, false); 102 } 103 } 104 105 DateInstance* ret = new (exec) DateInstance(exec->lexicalGlobalObject()->datePrototype()); 106 ret->setInternalValue(jsNumber(exec, timeClip(value))); 107 return ret; 106 107 DateInstance* ret = new (exec) DateInstance(exec->lexicalGlobalObject()->datePrototype()); 108 ret->setInternalValue(jsNumber(exec, timeClip(value))); 109 return ret; 108 110 } 109 111 … … 149 151 || (n >= 5 && isnan(args[4]->toNumber(exec))) 150 152 || (n >= 6 && isnan(args[5]->toNumber(exec))) 151 || (n >= 7 && isnan(args[6]->toNumber(exec)))) {153 || (n >= 7 && isnan(args[6]->toNumber(exec)))) 152 154 return jsNaN(exec); 153 }154 155 155 156 GregorianDateTime t; -
trunk/JavaScriptCore/kjs/DateConstructor.h
r34901 r35022 29 29 class FunctionPrototype; 30 30 31 /**32 * @internal33 *34 * The initial value of the the global variable's "Date" property35 */36 31 class DateConstructor : public InternalFunction { 37 32 public: 38 33 DateConstructor(ExecState*, FunctionPrototype*, DatePrototype*); 34 39 35 private: 40 36 virtual ConstructType getConstructData(ConstructData&); -
trunk/JavaScriptCore/kjs/DateInstance.cpp
r34897 r35022 38 38 const ClassInfo DateInstance::info = {"Date", 0, 0, 0}; 39 39 40 DateInstance::DateInstance(JSObject *proto)41 : JSWrapperObject(proto)42 , m_cache(0)40 DateInstance::DateInstance(JSObject* prototype) 41 : JSWrapperObject(prototype) 42 , m_cache(0) 43 43 { 44 44 } … … 72 72 } 73 73 74 bool DateInstance::getTime(GregorianDateTime &t, int &offset) const74 bool DateInstance::getTime(GregorianDateTime& t, int& offset) const 75 75 { 76 76 double milli = internalNumber(); … … 83 83 } 84 84 85 bool DateInstance::getUTCTime(GregorianDateTime &t) const85 bool DateInstance::getUTCTime(GregorianDateTime& t) const 86 86 { 87 87 double milli = internalNumber(); … … 93 93 } 94 94 95 bool DateInstance::getTime(double &milli, int &offset) const95 bool DateInstance::getTime(double& milli, int& offset) const 96 96 { 97 97 milli = internalNumber(); … … 105 105 } 106 106 107 bool DateInstance::getUTCTime(double &milli) const107 bool DateInstance::getUTCTime(double& milli) const 108 108 { 109 109 milli = internalNumber(); -
trunk/JavaScriptCore/kjs/DateInstance.h
r34897 r35022 41 41 bool getTime(double& milliseconds, int& offset) const; 42 42 bool getUTCTime(double& milliseconds) const; 43 43 44 44 static const ClassInfo info; 45 45 -
trunk/JavaScriptCore/kjs/DatePrototype.cpp
r34897 r35022 123 123 } 124 124 125 static UString formatLocaleDate(ExecState *exec, double time, bool includeDate, bool includeTime, const ArgList& args)125 static UString formatLocaleDate(ExecState* exec, double time, bool includeDate, bool includeTime, const ArgList& args) 126 126 { 127 127 CFDateFormatterStyle dateStyle = (includeDate ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle); … … 138 138 dateStyle = styleFromArgString(arg0String, dateStyle); 139 139 timeStyle = styleFromArgString(args[1]->toString(exec), timeStyle); 140 } else if (includeDate && !args[0]->isUndefined()) {140 } else if (includeDate && !args[0]->isUndefined()) 141 141 dateStyle = styleFromArgString(arg0String, dateStyle); 142 } else if (includeTime && !args[0]->isUndefined()) {142 else if (includeTime && !args[0]->isUndefined()) 143 143 timeStyle = styleFromArgString(arg0String, timeStyle); 144 }145 144 146 145 CFLocaleRef locale = CFLocaleCopyCurrent(); … … 185 184 int year = gdt.year + 1900; 186 185 bool yearNeedsOffset = year < 1900 || year > 2038; 187 if (yearNeedsOffset) {186 if (yearNeedsOffset) 188 187 localTM.tm_year = equivalentYearForDST(year) - 1900; 189 }190 188 191 189 // Do the formatting 192 const int bufsize =128;190 const int bufsize = 128; 193 191 char timebuffer[bufsize]; 194 192 size_t ret = strftime(timebuffer, bufsize, formatStrings[format], &localTM); 195 193 196 if ( ret == 0)194 if (ret == 0) 197 195 return jsString(exec, ""); 198 196 … … 292 290 return ok; 293 291 } 294 295 296 297 298 292 299 293 const ClassInfo DatePrototype::info = {"Date", &DateInstance::info, 0, ExecState::dateTable}; … … 350 344 // ECMA 15.9.4 351 345 352 DatePrototype::DatePrototype(ExecState* exec, ObjectPrototype* objectProto )353 : DateInstance(objectProto )346 DatePrototype::DatePrototype(ExecState* exec, ObjectPrototype* objectPrototype) 347 : DateInstance(objectPrototype) 354 348 { 355 349 setInternalValue(jsNaN(exec)); -
trunk/JavaScriptCore/kjs/DatePrototype.h
r34897 r35022 28 28 class ObjectPrototype; 29 29 30 /**31 * @internal32 *33 * The initial value of Date.prototype (and thus all objects created34 * with the Date constructor35 */36 30 class DatePrototype : public DateInstance { 37 31 public: 38 DatePrototype(ExecState *, ObjectPrototype *); 39 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&); 40 virtual const ClassInfo *classInfo() const { return &info; } 32 DatePrototype(ExecState*, ObjectPrototype*); 33 34 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 35 36 virtual const ClassInfo* classInfo() const { return &info; } 41 37 static const ClassInfo info; 42 38 }; -
trunk/JavaScriptCore/kjs/Error.cpp
r35008 r35022 34 34 namespace KJS { 35 35 36 JSObject* Error::create(ExecState* exec, ErrorType errtype, const UString& message, 37 int lineno, int sourceId, const UString& sourceURL) 36 JSObject* Error::create(ExecState* exec, ErrorType type, const UString& message, int lineNumber, int sourceId, const UString& sourceURL) 38 37 { 39 JSObject* cons;40 const char* name;41 switch (errtype) {42 case EvalError:43 cons= exec->lexicalGlobalObject()->evalErrorConstructor();44 name = "Evaluation error";45 break;46 case RangeError:47 cons= exec->lexicalGlobalObject()->rangeErrorConstructor();48 name = "Range error";49 break;50 case ReferenceError:51 cons= exec->lexicalGlobalObject()->referenceErrorConstructor();52 name = "Reference error";53 break;54 case SyntaxError:55 cons= exec->lexicalGlobalObject()->syntaxErrorConstructor();56 name = "Syntax error";57 break;58 case TypeError:59 cons= exec->lexicalGlobalObject()->typeErrorConstructor();60 name = "Type error";61 break;62 case URIError:63 cons= exec->lexicalGlobalObject()->URIErrorConstructor();64 name = "URI error";65 break;66 default:67 cons= exec->lexicalGlobalObject()->errorConstructor();68 name = "Error";69 break;70 }38 JSObject* constructor; 39 const char* name; 40 switch (type) { 41 case EvalError: 42 constructor = exec->lexicalGlobalObject()->evalErrorConstructor(); 43 name = "Evaluation error"; 44 break; 45 case RangeError: 46 constructor = exec->lexicalGlobalObject()->rangeErrorConstructor(); 47 name = "Range error"; 48 break; 49 case ReferenceError: 50 constructor = exec->lexicalGlobalObject()->referenceErrorConstructor(); 51 name = "Reference error"; 52 break; 53 case SyntaxError: 54 constructor = exec->lexicalGlobalObject()->syntaxErrorConstructor(); 55 name = "Syntax error"; 56 break; 57 case TypeError: 58 constructor = exec->lexicalGlobalObject()->typeErrorConstructor(); 59 name = "Type error"; 60 break; 61 case URIError: 62 constructor = exec->lexicalGlobalObject()->URIErrorConstructor(); 63 name = "URI error"; 64 break; 65 default: 66 constructor = exec->lexicalGlobalObject()->errorConstructor(); 67 name = "Error"; 68 break; 69 } 71 70 72 ArgList args;73 if (message.isEmpty())74 args.append(jsString(exec, name));75 else76 args.append(jsString(exec, message));77 ConstructData constructData;78 ConstructType constructType = cons->getConstructData(constructData);79 JSObject* err = construct(exec, cons, constructType, constructData, args);71 ArgList args; 72 if (message.isEmpty()) 73 args.append(jsString(exec, name)); 74 else 75 args.append(jsString(exec, message)); 76 ConstructData constructData; 77 ConstructType constructType = constructor->getConstructData(constructData); 78 JSObject* error = construct(exec, constructor, constructType, constructData, args); 80 79 81 if (lineno != -1) 82 err->put(exec, Identifier(exec, "line"), jsNumber(exec, lineno)); 83 if (sourceId != -1) 84 err->put(exec, Identifier(exec, "sourceId"), jsNumber(exec, sourceId)); 80 if (lineNumber != -1) 81 error->put(exec, Identifier(exec, "line"), jsNumber(exec, lineNumber)); 82 if (sourceId != -1) 83 error->put(exec, Identifier(exec, "sourceId"), jsNumber(exec, sourceId)); 84 if (!sourceURL.isNull()) 85 error->put(exec, Identifier(exec, "sourceURL"), jsString(exec, sourceURL)); 85 86 86 if(!sourceURL.isNull()) 87 err->put(exec, Identifier(exec, "sourceURL"), jsString(exec, sourceURL)); 88 89 return err; 87 return error; 90 88 } 91 89 92 JSObject *Error::create(ExecState *exec, ErrorType type, const char *message)90 JSObject* Error::create(ExecState* exec, ErrorType type, const char* message) 93 91 { 94 92 return create(exec, type, message, -1, -1, NULL); 95 93 } 96 94 97 JSObject *throwError(ExecState *exec, ErrorType type)95 JSObject* throwError(ExecState* exec, ErrorType type) 98 96 { 99 JSObject *error = Error::create(exec, type, UString(), -1, -1, NULL);97 JSObject* error = Error::create(exec, type, UString(), -1, -1, NULL); 100 98 exec->setException(error); 101 99 return error; 102 100 } 103 101 104 JSObject *throwError(ExecState *exec, ErrorType type, const UString &message)102 JSObject* throwError(ExecState* exec, ErrorType type, const UString& message) 105 103 { 106 JSObject *error = Error::create(exec, type, message, -1, -1, NULL);104 JSObject* error = Error::create(exec, type, message, -1, -1, NULL); 107 105 exec->setException(error); 108 106 return error; 109 107 } 110 108 111 JSObject *throwError(ExecState *exec, ErrorType type, const char *message)109 JSObject* throwError(ExecState* exec, ErrorType type, const char* message) 112 110 { 113 JSObject *error = Error::create(exec, type, message, -1, -1, NULL);111 JSObject* error = Error::create(exec, type, message, -1, -1, NULL); 114 112 exec->setException(error); 115 113 return error; 116 114 } 117 115 118 JSObject *throwError(ExecState *exec, ErrorType type, const UString &message, int line, int sourceId, const UString &sourceURL)116 JSObject* throwError(ExecState* exec, ErrorType type, const UString& message, int line, int sourceId, const UString& sourceURL) 119 117 { 120 JSObject *error = Error::create(exec, type, message, line, sourceId, sourceURL);118 JSObject* error = Error::create(exec, type, message, line, sourceId, sourceURL); 121 119 exec->setException(error); 122 120 return error; -
trunk/JavaScriptCore/kjs/Error.h
r35007 r35022 26 26 namespace KJS { 27 27 28 class ExecState;29 class JSObject;30 class UString;28 class ExecState; 29 class JSObject; 30 class UString; 31 31 32 /** 33 * Types of Native Errors available. For custom errors, GeneralError 34 * should be used. 35 */ 36 enum ErrorType { GeneralError = 0, 37 EvalError = 1, 38 RangeError = 2, 39 ReferenceError = 3, 40 SyntaxError = 4, 41 TypeError = 5, 42 URIError = 6}; 32 /** 33 * Types of Native Errors available. For custom errors, GeneralError 34 * should be used. 35 */ 36 enum ErrorType { 37 GeneralError = 0, 38 EvalError = 1, 39 RangeError = 2, 40 ReferenceError = 3, 41 SyntaxError = 4, 42 TypeError = 5, 43 URIError = 6 44 }; 43 45 44 /** 45 * @short Factory methods for error objects. 46 */ 47 class Error { 48 public: 49 /** 50 * Factory method for error objects. 51 * 52 * @param exec The current execution state 53 * @param errtype Type of error. 54 * @param message Optional error message. 55 * @param lineNumber Optional line number. 56 * @param sourceId Optional source id. 57 * @param sourceURL Optional source URL. 58 */ 59 static JSObject *create(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString &sourceURL); 60 static JSObject *create(ExecState *, ErrorType, const char *message); 61 }; 46 class Error { 47 public: 48 static JSObject* create(ExecState*, ErrorType, const UString& message, int lineNumber, int sourceId, const UString& sourceURL); 49 static JSObject* create(ExecState*, ErrorType, const char* message); 50 }; 62 51 63 JSObject *throwError(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString &sourceURL);64 JSObject *throwError(ExecState *, ErrorType, const UString &message);65 JSObject *throwError(ExecState *, ErrorType, const char *message);66 JSObject *throwError(ExecState*, ErrorType);52 JSObject* throwError(ExecState*, ErrorType, const UString& message, int lineNumber, int sourceId, const UString& sourceURL); 53 JSObject* throwError(ExecState*, ErrorType, const UString& message); 54 JSObject* throwError(ExecState*, ErrorType, const char* message); 55 JSObject* throwError(ExecState*, ErrorType); 67 56 68 57 } // namespace KJS -
trunk/JavaScriptCore/kjs/ErrorConstructor.cpp
r34876 r35022 30 30 namespace KJS { 31 31 32 ErrorConstructor::ErrorConstructor(ExecState* exec, FunctionPrototype* func Proto, ErrorPrototype* errorProto)33 : InternalFunction(func Proto, Identifier(exec, errorProto->classInfo()->className))32 ErrorConstructor::ErrorConstructor(ExecState* exec, FunctionPrototype* functionPrototype, ErrorPrototype* errorPrototype) 33 : InternalFunction(functionPrototype, Identifier(exec, errorPrototype->classInfo()->className)) 34 34 { 35 35 // ECMA 15.11.3.1 Error.prototype 36 putDirect(exec->propertyNames().prototype, errorProto , DontEnum|DontDelete|ReadOnly);37 putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete |ReadOnly|DontEnum);36 putDirect(exec->propertyNames().prototype, errorPrototype, DontEnum | DontDelete | ReadOnly); 37 putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum); 38 38 } 39 39 -
trunk/JavaScriptCore/kjs/FunctionConstructor.h
r34901 r35022 30 30 class FunctionPrototype; 31 31 32 /**33 * @internal34 *35 * The initial value of the the global variable's "Function" property36 */37 32 class FunctionConstructor : public InternalFunction { 38 33 public: 39 34 FunctionConstructor(ExecState*, FunctionPrototype*); 35 40 36 private: 41 37 virtual ConstructType getConstructData(ConstructData&); -
trunk/JavaScriptCore/kjs/FunctionPrototype.cpp
r35020 r35022 66 66 if (function->inherits(&JSFunction::info)) { 67 67 JSFunction* fi = static_cast<JSFunction*>(thisValue); 68 return jsString(exec, "function " + fi->functionName().ustring() + "(" + fi-> body->paramString() + ") " + fi->body->toSourceString());68 return jsString(exec, "function " + fi->functionName().ustring() + "(" + fi->m_body->paramString() + ") " + fi->m_body->toSourceString()); 69 69 } 70 70 -
trunk/JavaScriptCore/kjs/FunctionPrototype.h
r34901 r35022 28 28 namespace KJS { 29 29 30 /**31 * @internal32 *33 * The initial value of Function.prototype (and thus all objects created34 * with the Function constructor)35 */36 30 class FunctionPrototype : public InternalFunction { 37 31 public: 38 32 FunctionPrototype(ExecState*); 33 39 34 private: 40 35 virtual CallType getCallData(CallData&); -
trunk/JavaScriptCore/kjs/GetterSetter.h
r35007 r35022 28 28 namespace KJS { 29 29 30 class JSObject;30 class JSObject; 31 31 32 // This is an internal value object which stores getter and setter functions 33 // for a property. 34 class GetterSetter : public JSCell { 35 public: 36 JSType type() const { return GetterSetterType; } 37 38 GetterSetter() : m_getter(0), m_setter(0) { } 39 40 virtual void mark(); 41 42 JSObject* getter() const { return m_getter; } 43 void setGetter(JSObject* getter) { m_getter = getter; } 44 JSObject* setter() const { return m_setter; } 45 void setSetter(JSObject* setter) { m_setter = setter; } 46 47 private: 48 virtual JSValue* toPrimitive(ExecState*, JSType preferred) const; 49 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 50 virtual bool toBoolean(ExecState*) const; 51 virtual double toNumber(ExecState*) const; 52 virtual UString toString(ExecState*) const; 53 virtual JSObject* toObject(ExecState*) const; 32 // This is an internal value object which stores getter and setter functions 33 // for a property. 34 class GetterSetter : public JSCell { 35 public: 36 GetterSetter() 37 : m_getter(0) 38 , m_setter(0) 39 { 40 } 54 41 55 JSObject* m_getter; 56 JSObject* m_setter; 57 }; 58 42 JSType type() const { return GetterSetterType; } 43 44 virtual void mark(); 45 46 JSObject* getter() const { return m_getter; } 47 void setGetter(JSObject* getter) { m_getter = getter; } 48 JSObject* setter() const { return m_setter; } 49 void setSetter(JSObject* setter) { m_setter = setter; } 50 51 private: 52 virtual JSValue* toPrimitive(ExecState*, JSType preferred) const; 53 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value); 54 virtual bool toBoolean(ExecState*) const; 55 virtual double toNumber(ExecState*) const; 56 virtual UString toString(ExecState*) const; 57 virtual JSObject* toObject(ExecState*) const; 58 59 JSObject* m_getter; 60 JSObject* m_setter; 61 }; 62 59 63 } // namespace KJS 60 64 -
trunk/JavaScriptCore/kjs/GlobalEvalFunction.h
r35016 r35022 29 29 namespace KJS { 30 30 31 class ExecState;32 class FunctionPrototype;33 class JSGlobalObject;31 class ExecState; 32 class FunctionPrototype; 33 class JSGlobalObject; 34 34 35 35 class GlobalEvalFunction : public PrototypeFunction { -
trunk/JavaScriptCore/kjs/IndexToNameMap.cpp
r35021 r35022 42 42 43 43 IndexToNameMap::IndexToNameMap(JSFunction* func, const ArgList& args) 44 : m_size(args.size()) 45 , m_map(new Identifier[args.size()]) 44 46 { 45 _map = new Identifier[args.size()]; 46 this->size = args.size(); 47 48 unsigned i = 0; 49 ArgList::const_iterator end = args.end(); 50 for (ArgList::const_iterator it = args.begin(); it != end; ++i, ++it) 51 _map[i] = func->getParameterName(i); // null if there is no corresponding parameter 47 unsigned i = 0; 48 ArgList::const_iterator end = args.end(); 49 for (ArgList::const_iterator it = args.begin(); it != end; ++i, ++it) 50 m_map[i] = func->getParameterName(i); // null if there is no corresponding parameter 52 51 } 53 52 54 53 IndexToNameMap::~IndexToNameMap() 55 54 { 56 delete []_map;55 delete [] m_map; 57 56 } 58 57 59 58 bool IndexToNameMap::isMapped(const Identifier& index) const 60 59 { 61 bool indexIsNumber; 62 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber); 63 64 if (!indexIsNumber) 65 return false; 66 67 if (indexAsNumber >= size) 68 return false; 60 bool indexIsNumber; 61 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber); 69 62 70 if (_map[indexAsNumber].isNull()) 71 return false; 72 73 return true; 63 if (!indexIsNumber) 64 return false; 65 66 if (indexAsNumber >= m_size) 67 return false; 68 69 if (m_map[indexAsNumber].isNull()) 70 return false; 71 72 return true; 74 73 } 75 74 76 75 void IndexToNameMap::unMap(ExecState* exec, const Identifier& index) 77 76 { 78 bool indexIsNumber;79 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber);77 bool indexIsNumber; 78 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber); 80 79 81 ASSERT(indexIsNumber && indexAsNumber <size);82 83 _map[indexAsNumber] = exec->propertyNames().nullIdentifier;80 ASSERT(indexIsNumber && indexAsNumber < m_size); 81 82 m_map[indexAsNumber] = exec->propertyNames().nullIdentifier; 84 83 } 85 84 86 85 Identifier& IndexToNameMap::operator[](const Identifier& index) 87 86 { 88 bool indexIsNumber;89 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber);87 bool indexIsNumber; 88 unsigned indexAsNumber = index.toStrictUInt32(&indexIsNumber); 90 89 91 ASSERT(indexIsNumber && indexAsNumber <size);92 93 return_map[indexAsNumber];90 ASSERT(indexIsNumber && indexAsNumber < m_size); 91 92 return m_map[indexAsNumber]; 94 93 } 95 94 -
trunk/JavaScriptCore/kjs/IndexToNameMap.h
r35016 r35022 27 27 namespace KJS { 28 28 29 class ArgList;30 class ExecState;31 class Identifier;32 class JSFunction;29 class ArgList; 30 class ExecState; 31 class Identifier; 32 class JSFunction; 33 33 34 class IndexToNameMap {35 public:36 IndexToNameMap(JSFunction*, const ArgList&);37 ~IndexToNameMap();38 39 Identifier& operator[](const Identifier& index);40 bool isMapped(const Identifier& index) const;41 void unMap(ExecState* exec, const Identifier& index);42 43 private:44 unsignedsize;45 Identifier* _map;46 };34 class IndexToNameMap { 35 public: 36 IndexToNameMap(JSFunction*, const ArgList&); 37 ~IndexToNameMap(); 38 39 Identifier& operator[](const Identifier& index); 40 bool isMapped(const Identifier& index) const; 41 void unMap(ExecState* exec, const Identifier& index); 42 43 private: 44 unsigned m_size; 45 Identifier* m_map; // FIMXE: this should be an OwnArrayPtr 46 }; 47 47 48 48 } // namespace KJS -
trunk/JavaScriptCore/kjs/InitializeThreading.cpp
r34977 r35022 72 72 } 73 73 74 } 74 } // namespace KJS -
trunk/JavaScriptCore/kjs/InitializeThreading.h
r32808 r35022 38 38 } 39 39 40 #endif 40 #endif // KJS_InitializeThreading_h -
trunk/JavaScriptCore/kjs/InternalFunction.h
r34901 r35022 25 25 #define InternalFunction_h 26 26 27 #include "JSObject.h" 27 28 #include "identifier.h" 28 #include "JSObject.h"29 29 30 30 namespace KJS { 31 31 32 class FunctionPrototype;32 class FunctionPrototype; 33 33 34 class InternalFunction : public JSObject { 35 public: 36 static const ClassInfo info; 37 virtual const ClassInfo* classInfo() const { return &info; } 38 const Identifier& functionName() const { return m_name; } 34 class InternalFunction : public JSObject { 35 public: 36 virtual const ClassInfo* classInfo() const { return &info; } 37 static const ClassInfo info; 39 38 40 protected: 41 InternalFunction(); 42 InternalFunction(FunctionPrototype*, const Identifier&); 39 const Identifier& functionName() const { return m_name; } 43 40 44 private:45 virtual CallType getCallData(CallData&) = 0;46 virtual bool implementsHasInstance() const;41 protected: 42 InternalFunction(); 43 InternalFunction(FunctionPrototype*, const Identifier&); 47 44 48 Identifier m_name; 49 }; 45 private: 46 virtual CallType getCallData(CallData&) = 0; 47 virtual bool implementsHasInstance() const; 48 49 Identifier m_name; 50 }; 50 51 51 52 } // namespace KJS -
trunk/JavaScriptCore/kjs/JSActivation.h
r34906 r35022 39 39 40 40 class JSActivation : public JSVariableObject { 41 typedef JSVariableObject Base;41 typedef JSVariableObject Base; 42 42 public: 43 43 JSActivation(PassRefPtr<FunctionBodyNode>, Register*); -
trunk/JavaScriptCore/kjs/JSArray.cpp
r34985 r35022 834 834 } 835 835 836 } 836 } // namespace KJS -
trunk/JavaScriptCore/kjs/JSArray.h
r34964 r35022 27 27 namespace KJS { 28 28 29 typedef HashMap<unsigned, JSValue*> SparseArrayValueMap;29 typedef HashMap<unsigned, JSValue*> SparseArrayValueMap; 30 30 31 struct ArrayStorage {32 unsigned m_vectorLength;33 unsigned m_numValuesInVector;34 SparseArrayValueMap* m_sparseValueMap;35 void* lazyCreationData; // A JSArray subclass can use this to fill the vector lazily.36 JSValue* m_vector[1];37 };31 struct ArrayStorage { 32 unsigned m_vectorLength; 33 unsigned m_numValuesInVector; 34 SparseArrayValueMap* m_sparseValueMap; 35 void* lazyCreationData; // A JSArray subclass can use this to fill the vector lazily. 36 JSValue* m_vector[1]; 37 }; 38 38 39 class JSArray : public JSObject {40 public:41 JSArray(JSValue* prototype, unsigned initialLength);42 JSArray(JSObject* prototype, const ArgList& initialValues);43 virtual ~JSArray();39 class JSArray : public JSObject { 40 public: 41 JSArray(JSValue* prototype, unsigned initialLength); 42 JSArray(JSObject* prototype, const ArgList& initialValues); 43 virtual ~JSArray(); 44 44 45 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);46 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);47 virtual void put(ExecState*, unsigned propertyName, JSValue*); // FIXME: Make protected and add setItem.45 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); 46 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 47 virtual void put(ExecState*, unsigned propertyName, JSValue*); // FIXME: Make protected and add setItem. 48 48 49 static const ClassInfo info;49 static const ClassInfo info; 50 50 51 unsigned getLength() const { return m_length; }52 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray.51 unsigned getLength() const { return m_length; } 52 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray. 53 53 54 void sort(ExecState*);55 void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&);54 void sort(ExecState*); 55 void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&); 56 56 57 bool canGetIndex(unsigned i) { return i < m_fastAccessCutoff; }58 JSValue* getIndex(unsigned i)59 {60 ASSERT(canGetIndex(i));61 return m_storage->m_vector[i];62 }57 bool canGetIndex(unsigned i) { return i < m_fastAccessCutoff; } 58 JSValue* getIndex(unsigned i) 59 { 60 ASSERT(canGetIndex(i)); 61 return m_storage->m_vector[i]; 62 } 63 63 64 bool canSetIndex(unsigned i) { return i < m_fastAccessCutoff; }65 JSValue* setIndex(unsigned i, JSValue* v)66 {67 ASSERT(canSetIndex(i));68 return m_storage->m_vector[i] = v;69 }64 bool canSetIndex(unsigned i) { return i < m_fastAccessCutoff; } 65 JSValue* setIndex(unsigned i, JSValue* v) 66 { 67 ASSERT(canSetIndex(i)); 68 return m_storage->m_vector[i] = v; 69 } 70 70 71 protected:72 virtual void put(ExecState*, const Identifier& propertyName, JSValue*);73 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);74 virtual bool deleteProperty(ExecState*, unsigned propertyName);75 virtual void getPropertyNames(ExecState*, PropertyNameArray&);76 virtual void mark();71 protected: 72 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 73 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 74 virtual bool deleteProperty(ExecState*, unsigned propertyName); 75 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 76 virtual void mark(); 77 77 78 void* lazyCreationData();79 void setLazyCreationData(void*);78 void* lazyCreationData(); 79 void setLazyCreationData(void*); 80 80 81 private:82 virtual const ClassInfo* classInfo() const { return &info; }81 private: 82 virtual const ClassInfo* classInfo() const { return &info; } 83 83 84 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);84 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&); 85 85 86 bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&);87 void putSlowCase(ExecState*, unsigned propertyName, JSValue*);86 bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&); 87 void putSlowCase(ExecState*, unsigned propertyName, JSValue*); 88 88 89 bool increaseVectorLength(unsigned newLength);90 91 unsigned compactForSorting();89 bool increaseVectorLength(unsigned newLength); 90 91 unsigned compactForSorting(); 92 92 93 enum ConsistencyCheckType { NormalConsistencyCheck, DestructorConsistencyCheck, SortConsistencyCheck };94 void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck);93 enum ConsistencyCheckType { NormalConsistencyCheck, DestructorConsistencyCheck, SortConsistencyCheck }; 94 void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck); 95 95 96 unsigned m_length;97 unsigned m_fastAccessCutoff;98 ArrayStorage* m_storage;99 };96 unsigned m_length; 97 unsigned m_fastAccessCutoff; 98 ArrayStorage* m_storage; 99 }; 100 100 101 JSArray* constructEmptyArray(ExecState*);102 JSArray* constructEmptyArray(ExecState*, unsigned initialLength);103 JSArray* constructArray(ExecState*, JSValue* singleItemValue);104 JSArray* constructArray(ExecState*, const ArgList& values);101 JSArray* constructEmptyArray(ExecState*); 102 JSArray* constructEmptyArray(ExecState*, unsigned initialLength); 103 JSArray* constructArray(ExecState*, JSValue* singleItemValue); 104 JSArray* constructArray(ExecState*, const ArgList& values); 105 105 106 106 } // namespace KJS 107 107 108 #endif 108 #endif // JSArray_h -
trunk/JavaScriptCore/kjs/JSCell.h
r34964 r35022 29 29 namespace KJS { 30 30 31 class JSCell : public JSValue {32 friend class Heap;33 friend class GetterSetter;34 friend class JSObject;35 friend class JSPropertyNameIterator;36 friend class JSValue;37 friend class JSNumberCell;38 friend class JSString;39 friend class Machine;40 private:41 JSCell();42 virtual ~JSCell();43 44 public:45 // Querying the type.46 virtual JSType type() const = 0;47 bool isNumber() const;48 bool isString() const;49 bool isObject() const;50 bool isObject(const ClassInfo*) const; // FIXME: Merge with inherits.51 52 // Extracting the value.53 bool getNumber(double&) const;54 double getNumber() const; // NaN if not a number55 bool getString(UString&) const;56 UString getString() const; // null string if not a string57 JSObject* getObject(); // NULL if not an object58 const JSObject* getObject() const; // NULL if not an object59 60 virtual CallType getCallData(CallData&);61 virtual ConstructType getConstructData(ConstructData&);62 63 // Extracting integer values.64 virtual bool getUInt32(uint32_t&) const;65 virtual bool getTruncatedInt32(int32_t&) const;66 virtual bool getTruncatedUInt32(uint32_t&) const;67 68 // Basic conversions.69 virtual JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const = 0;70 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&) = 0;71 virtual bool toBoolean(ExecState*) const = 0;72 virtual double toNumber(ExecState*) const = 0;73 virtual UString toString(ExecState*) const = 0;74 virtual JSObject* toObject(ExecState*) const = 0;75 76 // Garbage collection.77 void* operator new(size_t, ExecState*);78 void* operator new(size_t, void* placementNewDestination) { return placementNewDestination; }79 virtual void mark();80 bool marked() const;81 82 // Object operations, with the toObject operation included.83 virtual const ClassInfo* classInfo() const;84 virtual void put(ExecState*, const Identifier& propertyName, JSValue*);85 virtual void put(ExecState*, unsigned propertyName, JSValue*);86 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);87 virtual bool deleteProperty(ExecState*, unsigned propertyName);88 89 virtual JSObject* toThisObject(ExecState*) const;90 virtual UString toThisString(ExecState*) const;91 virtual JSString* toThisJSString(ExecState*);92 virtual JSValue* getJSNumber();93 void* vptr() { return *reinterpret_cast<void**>(this); }94 95 private:96 // Base implementation, but for non-object classes implements getPropertySlot.97 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);98 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);99 };100 101 inline JSCell::JSCell()102 {103 }104 105 inline JSCell::~JSCell()106 {107 }108 109 inline bool JSCell::isNumber() const110 {111 return type() == NumberType;112 }113 114 inline bool JSCell::isString() const115 {116 return type() == StringType;117 }118 119 inline bool JSCell::isObject() const120 {121 return type() == ObjectType;122 }123 124 inline bool JSCell::marked() const125 {126 return Heap::isCellMarked(this);127 }128 129 inline void JSCell::mark()130 {131 return Heap::markCell(this);132 }133 134 ALWAYS_INLINE JSCell* JSValue::asCell()135 {136 ASSERT(!JSImmediate::isImmediate(this));137 return static_cast<JSCell*>(this);138 }139 140 ALWAYS_INLINE const JSCell* JSValue::asCell() const141 {142 ASSERT(!JSImmediate::isImmediate(this));143 return static_cast<const JSCell*>(this);144 }145 146 147 // --- JSValue inlines ----------------------------148 149 inline bool JSValue::isNumber() const150 {151 return JSImmediate::isNumber(this) || (!JSImmediate::isImmediate(this) && asCell()->isNumber());152 }153 154 inline bool JSValue::isString() const155 {156 return !JSImmediate::isImmediate(this) && asCell()->isString();157 }158 159 inline bool JSValue::isObject() const160 {161 return !JSImmediate::isImmediate(this) && asCell()->isObject();162 }163 164 inline bool JSValue::getNumber(double& v) const165 {166 if (JSImmediate::isImmediate(this)) {167 v = JSImmediate::toDouble(this);168 return true;169 }170 return asCell()->getNumber(v);171 }172 173 inline double JSValue::getNumber() const174 {175 return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : asCell()->getNumber();176 }177 178 inline bool JSValue::getString(UString& s) const179 {180 return !JSImmediate::isImmediate(this) && asCell()->getString(s);181 }182 183 inline UString JSValue::getString() const184 {185 return JSImmediate::isImmediate(this) ? UString() : asCell()->getString();186 }187 188 inline JSObject *JSValue::getObject()189 {190 return JSImmediate::isImmediate(this) ? 0 : asCell()->getObject();191 }192 193 inline const JSObject *JSValue::getObject() const194 {195 return JSImmediate::isImmediate(this) ? 0 : asCell()->getObject();196 }197 198 inline CallType JSValue::getCallData(CallData& callData)199 {200 return JSImmediate::isImmediate(this) ? CallTypeNone : asCell()->getCallData(callData);201 }202 203 inline ConstructType JSValue::getConstructData(ConstructData& constructData)204 {205 return JSImmediate::isImmediate(this) ? ConstructTypeNone : asCell()->getConstructData(constructData);206 }207 208 ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const209 {210 return JSImmediate::isImmediate(this) ? JSImmediate::getUInt32(this, v) : asCell()->getUInt32(v);211 }212 213 ALWAYS_INLINE bool JSValue::getTruncatedInt32(int32_t& v) const214 {215 return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedInt32(this, v) : asCell()->getTruncatedInt32(v);216 }217 218 inline bool JSValue::getTruncatedUInt32(uint32_t& v) const219 {220 return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedUInt32(this, v) : asCell()->getTruncatedUInt32(v);221 }222 223 inline void JSValue::mark()224 {225 ASSERT(!JSImmediate::isImmediate(this)); // callers should check !marked() before calling mark()226 asCell()->mark();227 }228 229 inline bool JSValue::marked() const230 {231 return JSImmediate::isImmediate(this) || asCell()->marked();232 }233 234 inline JSType JSValue::type() const235 {236 return JSImmediate::isImmediate(this) ? JSImmediate::type(this) : asCell()->type();237 }238 239 inline JSValue* JSValue::toPrimitive(ExecState* exec, JSType preferredType) const240 {241 return JSImmediate::isImmediate(this) ? const_cast<JSValue*>(this) : asCell()->toPrimitive(exec, preferredType);242 }243 244 inline bool JSValue::getPrimitiveNumber(ExecState* exec, double& number, JSValue*& value)245 {246 if (JSImmediate::isImmediate(this)) {247 number = JSImmediate::toDouble(this);248 value = this;249 return true;250 }251 return asCell()->getPrimitiveNumber(exec, number, value);252 }253 254 inline bool JSValue::toBoolean(ExecState *exec) const255 {256 return JSImmediate::isImmediate(this) ? JSImmediate::toBoolean(this) : asCell()->toBoolean(exec);257 }258 259 ALWAYS_INLINE double JSValue::toNumber(ExecState *exec) const260 {261 return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : asCell()->toNumber(exec);262 }263 264 inline UString JSValue::toString(ExecState *exec) const265 {266 return JSImmediate::isImmediate(this) ? JSImmediate::toString(this) : asCell()->toString(exec);267 }268 269 inline JSObject* JSValue::toObject(ExecState* exec) const270 {271 return JSImmediate::isImmediate(this) ? JSImmediate::toObject(this, exec) : asCell()->toObject(exec);272 }273 274 inline JSObject* JSValue::toThisObject(ExecState* exec) const275 {276 if (UNLIKELY(JSImmediate::isImmediate(this)))277 return JSImmediate::toObject(this, exec);278 return asCell()->toThisObject(exec);279 }280 281 inline UString JSValue::toThisString(ExecState* exec) const282 {283 return JSImmediate::isImmediate(this) ? JSImmediate::toString(this) : asCell()->toThisString(exec);284 }285 286 inline JSValue* JSValue::getJSNumber()287 {288 289 return JSImmediate::isNumber(this) ? this : (JSImmediate::isImmediate(this) ? 0 : asCell()->getJSNumber());290 }31 class JSCell : public JSValue { 32 friend class Heap; 33 friend class GetterSetter; 34 friend class JSObject; 35 friend class JSPropertyNameIterator; 36 friend class JSValue; 37 friend class JSNumberCell; 38 friend class JSString; 39 friend class Machine; 40 private: 41 JSCell(); 42 virtual ~JSCell(); 43 44 public: 45 // Querying the type. 46 virtual JSType type() const = 0; 47 bool isNumber() const; 48 bool isString() const; 49 bool isObject() const; 50 bool isObject(const ClassInfo*) const; // FIXME: Merge with inherits. 51 52 // Extracting the value. 53 bool getNumber(double&) const; 54 double getNumber() const; // NaN if not a number 55 bool getString(UString&) const; 56 UString getString() const; // null string if not a string 57 JSObject* getObject(); // NULL if not an object 58 const JSObject* getObject() const; // NULL if not an object 59 60 virtual CallType getCallData(CallData&); 61 virtual ConstructType getConstructData(ConstructData&); 62 63 // Extracting integer values. 64 virtual bool getUInt32(uint32_t&) const; 65 virtual bool getTruncatedInt32(int32_t&) const; 66 virtual bool getTruncatedUInt32(uint32_t&) const; 67 68 // Basic conversions. 69 virtual JSValue* toPrimitive(ExecState*, JSType preferredType = UnspecifiedType) const = 0; 70 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*&) = 0; 71 virtual bool toBoolean(ExecState*) const = 0; 72 virtual double toNumber(ExecState*) const = 0; 73 virtual UString toString(ExecState*) const = 0; 74 virtual JSObject* toObject(ExecState*) const = 0; 75 76 // Garbage collection. 77 void* operator new(size_t, ExecState*); 78 void* operator new(size_t, void* placementNewDestination) { return placementNewDestination; } 79 virtual void mark(); 80 bool marked() const; 81 82 // Object operations, with the toObject operation included. 83 virtual const ClassInfo* classInfo() const; 84 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 85 virtual void put(ExecState*, unsigned propertyName, JSValue*); 86 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 87 virtual bool deleteProperty(ExecState*, unsigned propertyName); 88 89 virtual JSObject* toThisObject(ExecState*) const; 90 virtual UString toThisString(ExecState*) const; 91 virtual JSString* toThisJSString(ExecState*); 92 virtual JSValue* getJSNumber(); 93 void* vptr() { return *reinterpret_cast<void**>(this); } 94 95 private: 96 // Base implementation, but for non-object classes implements getPropertySlot. 97 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); 98 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 99 }; 100 101 inline JSCell::JSCell() 102 { 103 } 104 105 inline JSCell::~JSCell() 106 { 107 } 108 109 inline bool JSCell::isNumber() const 110 { 111 return type() == NumberType; 112 } 113 114 inline bool JSCell::isString() const 115 { 116 return type() == StringType; 117 } 118 119 inline bool JSCell::isObject() const 120 { 121 return type() == ObjectType; 122 } 123 124 inline bool JSCell::marked() const 125 { 126 return Heap::isCellMarked(this); 127 } 128 129 inline void JSCell::mark() 130 { 131 return Heap::markCell(this); 132 } 133 134 ALWAYS_INLINE JSCell* JSValue::asCell() 135 { 136 ASSERT(!JSImmediate::isImmediate(this)); 137 return static_cast<JSCell*>(this); 138 } 139 140 ALWAYS_INLINE const JSCell* JSValue::asCell() const 141 { 142 ASSERT(!JSImmediate::isImmediate(this)); 143 return static_cast<const JSCell*>(this); 144 } 145 146 147 // --- JSValue inlines ---------------------------- 148 149 inline bool JSValue::isNumber() const 150 { 151 return JSImmediate::isNumber(this) || (!JSImmediate::isImmediate(this) && asCell()->isNumber()); 152 } 153 154 inline bool JSValue::isString() const 155 { 156 return !JSImmediate::isImmediate(this) && asCell()->isString(); 157 } 158 159 inline bool JSValue::isObject() const 160 { 161 return !JSImmediate::isImmediate(this) && asCell()->isObject(); 162 } 163 164 inline bool JSValue::getNumber(double& v) const 165 { 166 if (JSImmediate::isImmediate(this)) { 167 v = JSImmediate::toDouble(this); 168 return true; 169 } 170 return asCell()->getNumber(v); 171 } 172 173 inline double JSValue::getNumber() const 174 { 175 return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : asCell()->getNumber(); 176 } 177 178 inline bool JSValue::getString(UString& s) const 179 { 180 return !JSImmediate::isImmediate(this) && asCell()->getString(s); 181 } 182 183 inline UString JSValue::getString() const 184 { 185 return JSImmediate::isImmediate(this) ? UString() : asCell()->getString(); 186 } 187 188 inline JSObject* JSValue::getObject() 189 { 190 return JSImmediate::isImmediate(this) ? 0 : asCell()->getObject(); 191 } 192 193 inline const JSObject* JSValue::getObject() const 194 { 195 return JSImmediate::isImmediate(this) ? 0 : asCell()->getObject(); 196 } 197 198 inline CallType JSValue::getCallData(CallData& callData) 199 { 200 return JSImmediate::isImmediate(this) ? CallTypeNone : asCell()->getCallData(callData); 201 } 202 203 inline ConstructType JSValue::getConstructData(ConstructData& constructData) 204 { 205 return JSImmediate::isImmediate(this) ? ConstructTypeNone : asCell()->getConstructData(constructData); 206 } 207 208 ALWAYS_INLINE bool JSValue::getUInt32(uint32_t& v) const 209 { 210 return JSImmediate::isImmediate(this) ? JSImmediate::getUInt32(this, v) : asCell()->getUInt32(v); 211 } 212 213 ALWAYS_INLINE bool JSValue::getTruncatedInt32(int32_t& v) const 214 { 215 return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedInt32(this, v) : asCell()->getTruncatedInt32(v); 216 } 217 218 inline bool JSValue::getTruncatedUInt32(uint32_t& v) const 219 { 220 return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedUInt32(this, v) : asCell()->getTruncatedUInt32(v); 221 } 222 223 inline void JSValue::mark() 224 { 225 ASSERT(!JSImmediate::isImmediate(this)); // callers should check !marked() before calling mark() 226 asCell()->mark(); 227 } 228 229 inline bool JSValue::marked() const 230 { 231 return JSImmediate::isImmediate(this) || asCell()->marked(); 232 } 233 234 inline JSType JSValue::type() const 235 { 236 return JSImmediate::isImmediate(this) ? JSImmediate::type(this) : asCell()->type(); 237 } 238 239 inline JSValue* JSValue::toPrimitive(ExecState* exec, JSType preferredType) const 240 { 241 return JSImmediate::isImmediate(this) ? const_cast<JSValue*>(this) : asCell()->toPrimitive(exec, preferredType); 242 } 243 244 inline bool JSValue::getPrimitiveNumber(ExecState* exec, double& number, JSValue*& value) 245 { 246 if (JSImmediate::isImmediate(this)) { 247 number = JSImmediate::toDouble(this); 248 value = this; 249 return true; 250 } 251 return asCell()->getPrimitiveNumber(exec, number, value); 252 } 253 254 inline bool JSValue::toBoolean(ExecState* exec) const 255 { 256 return JSImmediate::isImmediate(this) ? JSImmediate::toBoolean(this) : asCell()->toBoolean(exec); 257 } 258 259 ALWAYS_INLINE double JSValue::toNumber(ExecState* exec) const 260 { 261 return JSImmediate::isImmediate(this) ? JSImmediate::toDouble(this) : asCell()->toNumber(exec); 262 } 263 264 inline UString JSValue::toString(ExecState* exec) const 265 { 266 return JSImmediate::isImmediate(this) ? JSImmediate::toString(this) : asCell()->toString(exec); 267 } 268 269 inline JSObject* JSValue::toObject(ExecState* exec) const 270 { 271 return JSImmediate::isImmediate(this) ? JSImmediate::toObject(this, exec) : asCell()->toObject(exec); 272 } 273 274 inline JSObject* JSValue::toThisObject(ExecState* exec) const 275 { 276 if (UNLIKELY(JSImmediate::isImmediate(this))) 277 return JSImmediate::toObject(this, exec); 278 return asCell()->toThisObject(exec); 279 } 280 281 inline UString JSValue::toThisString(ExecState* exec) const 282 { 283 return JSImmediate::isImmediate(this) ? JSImmediate::toString(this) : asCell()->toThisString(exec); 284 } 285 286 inline JSValue* JSValue::getJSNumber() 287 { 288 289 return JSImmediate::isNumber(this) ? this : (JSImmediate::isImmediate(this) ? 0 : asCell()->getJSNumber()); 290 } 291 291 292 292 } // namespace KJS -
trunk/JavaScriptCore/kjs/JSFunction.cpp
r35016 r35022 42 42 const ClassInfo JSFunction::info = { "Function", &InternalFunction::info, 0, 0 }; 43 43 44 JSFunction::JSFunction(ExecState* exec, const Identifier& name, FunctionBodyNode* b , ScopeChainNode* scopeChain)45 : InternalFunction(exec->lexicalGlobalObject()->functionPrototype(), name)46 , body(b)47 , _scope(scopeChain)44 JSFunction::JSFunction(ExecState* exec, const Identifier& name, FunctionBodyNode* body, ScopeChainNode* scopeChainNode) 45 : InternalFunction(exec->lexicalGlobalObject()->functionPrototype(), name) 46 , m_body(body) 47 , m_scopeChain(scopeChainNode) 48 48 { 49 49 } … … 52 52 { 53 53 InternalFunction::mark(); 54 body->mark();55 _scope.mark();54 m_body->mark(); 55 m_scopeChain.mark(); 56 56 } 57 57 58 58 CallType JSFunction::getCallData(CallData& callData) 59 59 { 60 callData.js.functionBody = body.get();61 callData.js.scopeChain = _scope.node();60 callData.js.functionBody = m_body.get(); 61 callData.js.scopeChain = m_scopeChain.node(); 62 62 return CallTypeJS; 63 63 } … … 65 65 JSValue* JSFunction::call(ExecState* exec, JSValue* thisValue, const ArgList& args) 66 66 { 67 return exec->machine()->execute( body.get(), exec, this, thisValue->toThisObject(exec), args, _scope.node(), exec->exceptionSlot());67 return exec->machine()->execute(m_body.get(), exec, this, thisValue->toThisObject(exec), args, m_scopeChain.node(), exec->exceptionSlot()); 68 68 } 69 69 … … 83 83 { 84 84 JSFunction* thisObj = static_cast<JSFunction*>(slot.slotBase()); 85 return jsNumber(exec, thisObj-> body->parameters().size());85 return jsNumber(exec, thisObj->m_body->parameters().size()); 86 86 } 87 87 … … 129 129 const Identifier& JSFunction::getParameterName(int index) 130 130 { 131 Vector<Identifier>& parameters = body->parameters();131 Vector<Identifier>& parameters = m_body->parameters(); 132 132 133 if (static_cast<size_t>(index) >= body->parameters().size())134 return _scope.globalObject()->globalData()->propertyNames->nullIdentifier;133 if (static_cast<size_t>(index) >= m_body->parameters().size()) 134 return m_scopeChain.globalObject()->globalData()->propertyNames->nullIdentifier; 135 135 136 136 const Identifier& name = parameters[index]; … … 138 138 // Are there any subsequent parameters with the same name? 139 139 size_t size = parameters.size(); 140 for (size_t i = index + 1; i < size; ++i) 140 for (size_t i = index + 1; i < size; ++i) { 141 141 if (parameters[i] == name) 142 return _scope.globalObject()->globalData()->propertyNames->nullIdentifier; 142 return m_scopeChain.globalObject()->globalData()->propertyNames->nullIdentifier; 143 } 143 144 144 145 return name; … … 148 149 ConstructType JSFunction::getConstructData(ConstructData& constructData) 149 150 { 150 constructData.js.functionBody = body.get();151 constructData.js.scopeChain = _scope.node();151 constructData.js.functionBody = m_body.get(); 152 constructData.js.scopeChain = m_scopeChain.node(); 152 153 return ConstructTypeJS; 153 154 } … … 164 165 JSObject* thisObj = new (exec) JSObject(proto); 165 166 166 JSValue* result = exec->machine()->execute( body.get(), exec, this, thisObj, args, _scope.node(), exec->exceptionSlot());167 JSValue* result = exec->machine()->execute(m_body.get(), exec, this, thisObj, args, m_scopeChain.node(), exec->exceptionSlot()); 167 168 if (exec->hadException() || !result->isObject()) 168 169 return thisObj; -
trunk/JavaScriptCore/kjs/JSFunction.h
r35016 r35022 33 33 namespace KJS { 34 34 35 class FunctionBodyNode;36 class FunctionPrototype;37 class JSActivation;38 class JSGlobalObject;35 class FunctionBodyNode; 36 class FunctionPrototype; 37 class JSActivation; 38 class JSGlobalObject; 39 39 40 class JSFunction : public InternalFunction {41 public:42 JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);40 class JSFunction : public InternalFunction { 41 public: 42 JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*); 43 43 44 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);45 virtual void put(ExecState*, const Identifier& propertyName, JSValue*);46 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);44 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 45 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 46 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 47 47 48 JSObject* construct(ExecState*, const ArgList&);49 JSValue* call(ExecState*, JSValue* thisValue, const ArgList&);48 JSObject* construct(ExecState*, const ArgList&); 49 JSValue* call(ExecState*, JSValue* thisValue, const ArgList&); 50 50 51 // Note: Returns a null identifier for any parameters that will never get set52 // due to a later parameter with the same name.53 const Identifier& getParameterName(int index);51 // Note: Returns a null identifier for any parameters that will never get set 52 // due to a later parameter with the same name. 53 const Identifier& getParameterName(int index); 54 54 55 static const ClassInfo info; 55 void setScope(const ScopeChain& scopeChain) { m_scopeChain = scopeChain; } 56 ScopeChain& scope() { return m_scopeChain; } 56 57 57 RefPtr<FunctionBodyNode> body;58 virtual void mark(); 58 59 59 void setScope(const ScopeChain& s) { _scope = s; } 60 ScopeChain& scope() { return _scope; } 60 static const ClassInfo info; 61 61 62 virtual void mark(); 62 // FIXME: This should be private 63 RefPtr<FunctionBodyNode> m_body; 63 64 64 private: 65 virtual const ClassInfo* classInfo() const { return &info; } 66 virtual ConstructType getConstructData(ConstructData&); 67 virtual CallType getCallData(CallData&); 65 private: 66 virtual const ClassInfo* classInfo() const { return &info; } 68 67 69 ScopeChain _scope; 68 virtual ConstructType getConstructData(ConstructData&); 69 virtual CallType getCallData(CallData&); 70 70 71 static JSValue* argumentsGetter(ExecState*, const Identifier&, const PropertySlot&); 72 static JSValue* callerGetter(ExecState*, const Identifier&, const PropertySlot&); 73 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&); 74 }; 71 static JSValue* argumentsGetter(ExecState*, const Identifier&, const PropertySlot&); 72 static JSValue* callerGetter(ExecState*, const Identifier&, const PropertySlot&); 73 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&); 74 75 ScopeChain m_scopeChain; 76 }; 75 77 76 78 } // namespace kJS -
trunk/JavaScriptCore/kjs/completion.h
r34578 r35022 27 27 namespace KJS { 28 28 29 class JSValue;29 class JSValue; 30 30 31 enum ComplType { Normal, Break, Continue, ReturnValue, Throw, Interrupted };31 enum ComplType { Normal, Break, Continue, ReturnValue, Throw, Interrupted }; 32 32 33 /** 34 * Completion objects are used to convey the return status and value 35 * from functions. 36 * 37 * See JSFunction::execute() 38 * 39 * @see JSFunction 40 * 41 * @short Handle for a Completion type. 42 */ 43 class Completion { 44 public: 45 Completion(ComplType type = Normal, JSValue* value = 0) 46 : m_type(type), m_value(value) { } 33 /* 34 * Completion objects are used to convey the return status and value 35 * from functions. 36 */ 37 class Completion { 38 public: 39 Completion(ComplType type = Normal, JSValue* value = 0) 40 : m_type(type) 41 , m_value(value) 42 { 43 } 47 44 48 ComplType complType() const { return m_type; }49 JSValue* value() const { return m_value; }50 void setValue(JSValue* v) { m_value = v; }51 bool isValueCompletion() const { return !!m_value; }45 ComplType complType() const { return m_type; } 46 JSValue* value() const { return m_value; } 47 void setValue(JSValue* v) { m_value = v; } 48 bool isValueCompletion() const { return !!m_value; } 52 49 53 private:54 ComplType m_type;55 JSValue* m_value;56 };50 private: 51 ComplType m_type; 52 JSValue* m_value; 53 }; 57 54 58 } 55 } // namespace KJS 59 56 60 #endif 57 #endif // KJS_COMPLETION_H -
trunk/JavaScriptCore/profiler/Profiler.cpp
r34901 r35022 161 161 name = AnonymousFunction; 162 162 163 return CallIdentifier(name, functionImp-> body->sourceURL(), functionImp->body->lineNo());163 return CallIdentifier(name, functionImp->m_body->sourceURL(), functionImp->m_body->lineNo()); 164 164 } 165 165
Note:
See TracChangeset
for help on using the changeset viewer.