Changeset 16711 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Oct 2, 2006, 3:26:58 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/lookup.h
r15321 r16711 42 42 * s is the key (e.g. a property name) 43 43 */ 44 const char *s;44 const char* s; 45 45 46 46 /** … … 60 60 * next is the pointer to the next entry for the same hash value 61 61 */ 62 const HashEntry *next;62 const HashEntry* next; 63 63 }; 64 64 … … 89 89 * Mind that some entries in the array are null (0,0,0,0). 90 90 */ 91 const HashEntry *entries;91 const HashEntry* entries; 92 92 /** 93 93 * the maximum value for the hash. Always smaller than size. … … 104 104 * Find an entry in the table, and return its value (i.e. the value field of HashEntry) 105 105 */ 106 static int find(const struct HashTable *table, const Identifier &s); 107 static int find(const struct HashTable *table, 108 const UChar *c, unsigned int len); 106 static int find(const struct HashTable*, const Identifier&); 107 static int find(const struct HashTable*, const UChar*, unsigned int len); 109 108 110 109 … … 114 113 * especially the attr field. 115 114 */ 116 static const HashEntry* findEntry(const struct HashTable *table, 117 const Identifier &s); 115 static const HashEntry* findEntry(const struct HashTable*, const Identifier&); 118 116 119 117 }; … … 126 124 */ 127 125 template <class FuncImp> 128 inline JSValue *staticFunctionGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)126 inline JSValue* staticFunctionGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) 129 127 { 130 128 // Look for cached value in dynamic map of properties (in JSObject) 131 JSObject *thisObj = slot.slotBase();132 JSValue *cachedVal = thisObj->getDirect(propertyName);129 JSObject* thisObj = slot.slotBase(); 130 JSValue* cachedVal = thisObj->getDirect(propertyName); 133 131 if (cachedVal) 134 132 return cachedVal; 135 133 136 const HashEntry *entry = slot.staticEntry();137 JSValue *val = new FuncImp(exec, entry->value, entry->params, propertyName);134 const HashEntry* entry = slot.staticEntry(); 135 JSValue* val = new FuncImp(exec, entry->value, entry->params, propertyName); 138 136 thisObj->putDirect(propertyName, val, entry->attr); 139 137 return val; … … 145 143 */ 146 144 template <class ThisImp> 147 inline JSValue *staticValueGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot& slot)145 inline JSValue* staticValueGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot& slot) 148 146 { 149 147 ThisImp* thisObj = static_cast<ThisImp*>(slot.slotBase()); … … 173 171 */ 174 172 template <class FuncImp, class ThisImp, class ParentImp> 175 inline bool getStaticPropertySlot(ExecState *exec, const HashTable* table,173 inline bool getStaticPropertySlot(ExecState* exec, const HashTable* table, 176 174 ThisImp* thisObj, const Identifier& propertyName, PropertySlot& slot) 177 175 { … … 195 193 */ 196 194 template <class FuncImp, class ParentImp> 197 inline bool getStaticFunctionSlot(ExecState *exec, const HashTable *table,195 inline bool getStaticFunctionSlot(ExecState* exec, const HashTable* table, 198 196 JSObject* thisObj, const Identifier& propertyName, PropertySlot& slot) 199 197 { … … 201 199 202 200 if (!entry) // not found, forward to parent 203 return static_cast<ParentImp 201 return static_cast<ParentImp*>(thisObj)->ParentImp::getOwnPropertySlot(exec, propertyName, slot); 204 202 205 203 assert(entry->attr & Function); … … 214 212 */ 215 213 template <class ThisImp, class ParentImp> 216 inline bool getStaticValueSlot(ExecState *exec, const HashTable* table,217 ThisImp* thisObj, const Identifier &propertyName, PropertySlot& slot)214 inline bool getStaticValueSlot(ExecState* exec, const HashTable* table, 215 ThisImp* thisObj, const Identifier& propertyName, PropertySlot& slot) 218 216 { 219 217 const HashEntry* entry = Lookup::findEntry(table, propertyName); … … 234 232 */ 235 233 template <class ThisImp> 236 inline bool lookupPut(ExecState* exec, const Identifier &propertyName,234 inline bool lookupPut(ExecState* exec, const Identifier& propertyName, 237 235 JSValue* value, int attr, 238 236 const HashTable* table, ThisImp* thisObj) … … 264 262 */ 265 263 template <class ThisImp, class ParentImp> 266 inline void lookupPut(ExecState* exec, const Identifier &propertyName,264 inline void lookupPut(ExecState* exec, const Identifier& propertyName, 267 265 JSValue* value, int attr, 268 266 const HashTable* table, ThisImp* thisObj) … … 272 270 } 273 271 272 /** 273 * This template method retrieves or create an object that is unique 274 * (for a given interpreter) The first time this is called (for a given 275 * property name), the Object will be constructed, and set as a property 276 * of the interpreter's global object. Later calls will simply retrieve 277 * that cached object. Note that the object constructor must take 1 argument, exec. 278 */ 279 template <class ClassCtor> 280 inline JSObject* cacheGlobalObject(ExecState* exec, const Identifier& propertyName) 281 { 282 JSObject* globalObject = static_cast<JSObject*>(exec->lexicalInterpreter()->globalObject()); 283 JSValue* obj = globalObject->getDirect(propertyName); 284 if (obj) { 285 assert(obj->isObject()); 286 return static_cast<JSObject* >(obj); 287 } 288 JSObject* newObject = new ClassCtor(exec); 289 globalObject->put(exec, propertyName, newObject, Internal | DontEnum); 290 return newObject; 291 } 292 274 293 } // namespace 275 276 /*277 * The template method below can't be in the KJS namespace because it's used in278 * KJS_DEFINE_PROPERTY which can be used outside of the KJS namespace. It can be moved back279 * when a gcc with http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8355 is mainstream enough.280 */281 282 /**283 * This template method retrieves or create an object that is unique284 * (for a given interpreter) The first time this is called (for a given285 * property name), the Object will be constructed, and set as a property286 * of the interpreter's global object. Later calls will simply retrieve287 * that cached object. Note that the object constructor must take 1 argument, exec.288 */289 template <class ClassCtor>290 inline KJS::JSObject *cacheGlobalObject(KJS::ExecState *exec, const KJS::Identifier &propertyName)291 {292 KJS::JSObject *globalObject = static_cast<KJS::JSObject *>(exec->lexicalInterpreter()->globalObject());293 KJS::JSValue *obj = globalObject->getDirect(propertyName);294 if (obj) {295 assert(obj->isObject());296 return static_cast<KJS::JSObject *>(obj);297 }298 KJS::JSObject *newObject = new ClassCtor(exec);299 globalObject->put(exec, propertyName, newObject, KJS::Internal | KJS::DontEnum);300 return newObject;301 }302 294 303 295 /** … … 318 310 */ 319 311 320 // Work around a bug in GCC 4.1321 #if !COMPILER(GCC)322 #define KJS_GCC_ROOT_NS_HACK ::323 #else324 #define KJS_GCC_ROOT_NS_HACK325 #endif326 327 312 // These macros assume that a prototype's only properties are functions 328 313 #define KJS_DEFINE_PROTOTYPE(ClassProto) \ 329 314 class ClassProto : public KJS::JSObject { \ 330 friend KJS::JSObject *KJS_GCC_ROOT_NS_HACK cacheGlobalObject<ClassProto>(KJS::ExecState *exec, const KJS::Identifier &propertyName); \331 315 public: \ 332 static KJS::JSObject *self(KJS::ExecState *exec); \333 virtual const KJS::ClassInfo *classInfo() const { return &info; } \316 static KJS::JSObject* self(KJS::ExecState* exec); \ 317 virtual const KJS::ClassInfo* classInfo() const { return &info; } \ 334 318 static const KJS::ClassInfo info; \ 335 bool getOwnPropertySlot(KJS::ExecState *, const KJS::Identifier&, KJS::PropertySlot&); \ 336 protected: \ 337 ClassProto(KJS::ExecState *exec) \ 319 bool getOwnPropertySlot(KJS::ExecState* , const KJS::Identifier&, KJS::PropertySlot&); \ 320 ClassProto(KJS::ExecState* exec) \ 338 321 : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) { } \ 339 322 \ … … 342 325 #define KJS_DEFINE_PROTOTYPE_WITH_PROTOTYPE(ClassProto, ClassProtoProto) \ 343 326 class ClassProto : public KJS::JSObject { \ 344 friend KJS::JSObject* KJS_GCC_ROOT_NS_HACK cacheGlobalObject<ClassProto>(KJS::ExecState* exec, const KJS::Identifier& propertyName); \345 327 public: \ 346 328 static KJS::JSObject* self(KJS::ExecState* exec); \ … … 348 330 static const KJS::ClassInfo info; \ 349 331 bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&); \ 350 protected: \351 332 ClassProto(KJS::ExecState* exec) \ 352 333 : KJS::JSObject(ClassProtoProto::self(exec)) { } \ … … 356 337 #define KJS_IMPLEMENT_PROTOTYPE(ClassName, ClassProto, ClassFunc) \ 357 338 const ClassInfo ClassProto::info = { ClassName, 0, &ClassProto##Table, 0 }; \ 358 JSObject *ClassProto::self(ExecState *exec) \339 JSObject* ClassProto::self(ExecState* exec) \ 359 340 { \ 360 return ::cacheGlobalObject<ClassProto>(exec, "[[" ClassName ".prototype]]"); \341 return KJS::cacheGlobalObject<ClassProto>(exec, "[[" ClassName ".prototype]]"); \ 361 342 } \ 362 bool ClassProto::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot) \343 bool ClassProto::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) \ 363 344 { \ 364 345 return getStaticFunctionSlot<ClassFunc, JSObject>(exec, &ClassProto##Table, this, propertyName, slot); \ … … 375 356 } \ 376 357 /* Macro user needs to implement the callAsFunction function. */ \ 377 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args); \358 virtual JSValue* callAsFunction(ExecState* exec, JSObject* thisObj, const List& args); \ 378 359 private: \ 379 360 int id; \ 380 361 }; 381 362 382 /*383 * List of things to do when porting an objectimp to the 'static hashtable' mechanism:384 * - write the hashtable source, between @begin and @end385 * - add a rule to build the .lut.h386 * - include the .lut.h387 * - mention the table in the classinfo (add a classinfo if necessary)388 * - write/update the class enum (for the tokens)389 * - turn get() into getValueProperty(), put() into putValueProperty(), using a switch and removing funcs390 * - write get() and/or put() using a template method391 * - cleanup old stuff (e.g. hasProperty)392 * - compile, test, commit ;)393 */394 395 396 363 #endif
Note:
See TracChangeset
for help on using the changeset viewer.