Changeset 9889 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Jul 25, 2005, 3:17:20 PM (20 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/array_instance.h
r9768 r9889 34 34 ~ArrayInstanceImp(); 35 35 36 virtual Value get(ExecState *exec, const Identifier &propertyName) const;37 virtual Value get(ExecState *exec, unsigned propertyName) const;36 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 37 virtual bool getOwnProperty(ExecState *exec, unsigned index, Value& result) const; 38 38 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None); 39 39 virtual void put(ExecState *exec, unsigned propertyName, const Value &value, int attr = None); -
trunk/JavaScriptCore/kjs/array_object.cpp
r9842 r9889 71 71 } 72 72 73 Value ArrayInstanceImp::get(ExecState *exec, const Identifier &propertyName) const 74 { 75 if (propertyName == lengthPropertyName) 76 return Number(length); 73 bool ArrayInstanceImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 74 { 75 if (propertyName == lengthPropertyName) { 76 result = Number(length); 77 return true; 78 } 77 79 78 80 bool ok; … … 80 82 if (ok) { 81 83 if (index >= length) 82 return Undefined();84 return false; 83 85 if (index < storageLength) { 84 86 ValueImp *v = storage[index]; 85 return v ? Value(v) : Undefined(); 86 } 87 } 88 89 return ObjectImp::get(exec, propertyName); 90 } 91 92 Value ArrayInstanceImp::get(ExecState *exec, unsigned index) const 87 if (!v || v == UndefinedImp::staticUndefined) 88 return false; 89 90 result = Value(v); 91 return true; 92 } 93 } 94 95 return ObjectImp::getOwnProperty(exec, propertyName, result); 96 } 97 98 bool ArrayInstanceImp::getOwnProperty(ExecState *exec, unsigned index, Value& result) const 93 99 { 94 100 if (index >= length) 95 return Undefined();101 return false; 96 102 if (index < storageLength) { 97 103 ValueImp *v = storage[index]; 98 return v ? Value(v) : Undefined(); 99 } 100 101 return ObjectImp::get(exec, Identifier::from(index)); 104 if (!v || v == UndefinedImp::staticUndefined) 105 return false; 106 107 result = Value(v); 108 return true; 109 } 110 111 return ObjectImp::getOwnProperty(exec, Identifier::from(index), result); 102 112 } 103 113 … … 419 429 } 420 430 421 Value ArrayPrototypeImp::get(ExecState *exec, const Identifier &propertyName) const 422 { 423 //fprintf( stderr, "ArrayPrototypeImp::get(%s)\n", propertyName.ascii() ); 424 return lookupGetFunction<ArrayProtoFuncImp, ArrayInstanceImp>( exec, propertyName, &arrayTable, this ); 431 bool ArrayPrototypeImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 432 { 433 return lookupGetOwnFunction<ArrayProtoFuncImp, ArrayInstanceImp>(exec, propertyName, &arrayTable, this, result); 425 434 } 426 435 … … 445 454 { 446 455 unsigned int length = thisObj.get(exec,lengthPropertyName).toUInt32(exec); 456 ObjectImp *thisImp = thisObj.imp(); 447 457 448 458 Value result; … … 502 512 length = curObj.get(exec,lengthPropertyName).toUInt32(exec); 503 513 while (k < length) { 504 if (curObj.hasProperty(exec,k)) 505 arr.put(exec, n, curObj.get(exec, k)); 514 Value v; 515 if (curObj.imp()->getProperty(exec, k, v)) 516 arr.put(exec, n, v); 506 517 n++; 507 518 k++; … … 545 556 for (unsigned int k = 0; k < middle; k++) { 546 557 unsigned lk1 = length - k - 1; 547 Value obj = thisObj.get(exec,k); 548 Value obj2 = thisObj.get(exec,lk1); 549 if (thisObj.hasProperty(exec,lk1)) { 550 if (thisObj.hasProperty(exec,k)) { 551 thisObj.put(exec, k, obj2); 552 thisObj.put(exec, lk1, obj); 553 } else { 554 thisObj.put(exec, k, obj2); 555 thisObj.deleteProperty(exec, lk1); 556 } 557 } else { 558 if (thisObj.hasProperty(exec, k)) { 559 thisObj.deleteProperty(exec, k); 560 thisObj.put(exec, lk1, obj); 561 } else { 562 // why delete something that's not there ? Strange. 563 thisObj.deleteProperty(exec, k); 564 thisObj.deleteProperty(exec, lk1); 565 } 566 } 558 Value obj; 559 Value obj2; 560 bool has2 = thisImp->getProperty(exec, lk1, obj2); 561 bool has1 = thisImp->getProperty(exec, k, obj); 562 563 if (has2) 564 thisObj.put(exec, k, obj2); 565 else 566 thisObj.deleteProperty(exec, k); 567 568 if (has1) 569 thisObj.put(exec, lk1, obj); 570 else 571 thisObj.deleteProperty(exec, lk1); 567 572 } 568 573 result = thisObj; … … 576 581 result = thisObj.get(exec, 0); 577 582 for(unsigned int k = 1; k < length; k++) { 578 if (thisObj.hasProperty(exec, k)) {579 Value obj = thisObj.get(exec, k);583 Value obj; 584 if (thisImp->getProperty(exec, k, obj)) 580 585 thisObj.put(exec, k-1, obj); 581 }else586 else 582 587 thisObj.deleteProperty(exec, k-1); 583 588 } … … 623 628 int e = static_cast<int>(end); 624 629 for(int k = b; k < e; k++, n++) { 625 if (thisObj.hasProperty(exec, k)) {626 Value obj = thisObj.get(exec, k);630 Value obj; 631 if (thisImp->getProperty(exec, k, obj)) 627 632 resObj.put(exec, n, obj); 628 }629 633 } 630 634 resObj.put(exec, lengthPropertyName, Number(n), DontEnum | DontDelete); … … 646 650 } 647 651 648 if (this Obj.imp()->classInfo() == &ArrayInstanceImp::info) {652 if (thisImp->classInfo() == &ArrayInstanceImp::info) { 649 653 if (useSortFunction) 650 ((ArrayInstanceImp *)this Obj.imp())->sort(exec, sortFunction);654 ((ArrayInstanceImp *)thisImp)->sort(exec, sortFunction); 651 655 else 652 ((ArrayInstanceImp *)this Obj.imp())->sort(exec);656 ((ArrayInstanceImp *)thisImp)->sort(exec); 653 657 result = thisObj; 654 658 break; … … 719 723 //printf( "Splicing from %d, deleteCount=%d \n", begin, deleteCount ); 720 724 for(unsigned int k = 0; k < deleteCount; k++) { 721 if (thisObj.hasProperty(exec,k+begin)) {722 Value obj = thisObj.get(exec, k+begin);725 Value obj; 726 if (thisImp->getProperty(exec, k+begin, obj)) 723 727 resObj.put(exec, k, obj); 724 }725 728 } 726 729 resObj.put(exec, lengthPropertyName, Number(deleteCount), DontEnum | DontDelete); … … 733 736 for ( unsigned int k = begin; k < length - deleteCount; ++k ) 734 737 { 735 if (thisObj.hasProperty(exec,k+deleteCount)) {736 Value obj = thisObj.get(exec, k+deleteCount);738 Value obj; 739 if (thisImp->getProperty(exec, k+deleteCount, obj)) 737 740 thisObj.put(exec, k+additionalArgs, obj); 738 }739 741 else 740 742 thisObj.deleteProperty(exec, k+additionalArgs); … … 747 749 for ( unsigned int k = length - deleteCount; (int)k > begin; --k ) 748 750 { 749 if (thisObj.hasProperty(exec,k+deleteCount-1)) { 750 Value obj = thisObj.get(exec, k+deleteCount-1); 751 thisObj.put(exec, k+additionalArgs-1, obj); 752 } 751 Value obj; 752 if (thisImp->getProperty(exec, k + deleteCount - 1, obj)) 753 thisObj.put(exec, k + additionalArgs - 1, obj); 753 754 else 754 755 thisObj.deleteProperty(exec, k+additionalArgs-1); … … 767 768 for ( unsigned int k = length; k > 0; --k ) 768 769 { 769 if (thisObj.hasProperty(exec,k-1)) {770 Value obj = thisObj.get(exec, k-1);770 Value obj; 771 if (thisImp->getProperty(exec, k - 1, obj)) 771 772 thisObj.put(exec, k+nrArgs-1, obj); 772 } else {773 else 773 774 thisObj.deleteProperty(exec, k+nrArgs-1); 774 }775 775 } 776 776 for ( unsigned int k = 0; k < nrArgs; ++k ) -
trunk/JavaScriptCore/kjs/array_object.h
r9768 r9889 32 32 ArrayPrototypeImp(ExecState *exec, 33 33 ObjectPrototypeImp *objProto); 34 Value get(ExecState *exec, const Identifier &p) const;34 bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 35 35 virtual const ClassInfo *classInfo() const { return &info; } 36 36 static const ClassInfo info; -
trunk/JavaScriptCore/kjs/date_object.cpp
r9875 r9889 467 467 } 468 468 469 Value DatePrototypeImp::get(ExecState *exec, const Identifier &propertyName) const470 { 471 return lookupGet Function<DateProtoFuncImp, ObjectImp>( exec, propertyName, &dateTable, this);469 bool DatePrototypeImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 470 { 471 return lookupGetOwnFunction<DateProtoFuncImp, ObjectImp>(exec, propertyName, &dateTable, this, result); 472 472 } 473 473 -
trunk/JavaScriptCore/kjs/date_object.h
r9768 r9889 47 47 public: 48 48 DatePrototypeImp(ExecState *exec, ObjectPrototypeImp *objectProto); 49 Value get(ExecState *exec, const Identifier &p) const;49 bool getOwnProperty(ExecState *exec, const Identifier& p, Value& result) const; 50 50 virtual const ClassInfo *classInfo() const { return &info; } 51 51 static const ClassInfo info; -
trunk/JavaScriptCore/kjs/function.cpp
r9768 r9889 203 203 } 204 204 205 Value FunctionImp::get(ExecState *exec, const Identifier &propertyName) const205 bool FunctionImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 206 206 { 207 207 // Find the arguments from the closest context. … … 209 209 ContextImp *context = exec->_context; 210 210 while (context) { 211 if (context->function() == this) 212 return static_cast<ActivationImp *> 213 (context->activationObject())->get(exec, propertyName); 214 context = context->callingContext(); 211 if (context->function() == this) { 212 result = static_cast<ActivationImp *>(context->activationObject())->get(exec, propertyName); 213 return true; 214 } 215 context = context->callingContext(); 215 216 } 216 return Null(); 217 result = Null(); 218 return true; 217 219 } 218 220 … … 225 227 p = p->next; 226 228 } 227 return Number(count); 229 result = Number(count); 230 return true; 228 231 } 229 232 230 return InternalFunctionImp::get (exec, propertyName);233 return InternalFunctionImp::getOwnProperty(exec, propertyName, result); 231 234 } 232 235 … … 441 444 } 442 445 443 Value ArgumentsImp::get(ExecState *exec, const Identifier &propertyName) const446 bool ArgumentsImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 444 447 { 445 448 if (indexToNameMap.isMapped(propertyName)) { 446 return _activationObject->get(exec, indexToNameMap[propertyName]); 447 } else { 448 return ObjectImp::get(exec, propertyName); 449 } 449 result = _activationObject->get(exec, indexToNameMap[propertyName]); 450 return true; 451 } 452 453 return ObjectImp::getOwnProperty(exec, propertyName, result); 450 454 } 451 455 … … 489 493 } 490 494 491 Value ActivationImp::get(ExecState *exec, const Identifier &propertyName) const 492 { 495 bool ActivationImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 496 { 497 // do this first so property map arguments property wins over the below 498 if (ObjectImp::getOwnProperty(exec, propertyName, result)) 499 return true; 500 493 501 if (propertyName == argumentsPropertyName) { 494 // check for locally declared arguments property495 ValueImp *v = getDirect(propertyName);496 if (v)497 return Value(v);498 499 502 // default: return builtin arguments array 500 503 if (!_argumentsObject) 501 createArgumentsObject(exec); 502 return Value(_argumentsObject); 503 } 504 return ObjectImp::get(exec, propertyName); 504 createArgumentsObject(exec); 505 506 result = Value(_argumentsObject); 507 return true; 508 } 509 510 return false; 505 511 } 506 512 -
trunk/JavaScriptCore/kjs/function.h
r9768 r9889 42 42 virtual ~FunctionImp(); 43 43 44 virtual Value get(ExecState *exec, const Identifier &propertyName) const;44 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 45 45 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None); 46 46 virtual bool hasOwnProperty(ExecState *exec, const Identifier &propertyName) const; … … 109 109 ArgumentsImp(ExecState *exec, FunctionImp *func, const List &args, ActivationImp *act); 110 110 virtual void mark(); 111 virtual Value get(ExecState *exec, const Identifier &propertyName) const;111 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 112 112 virtual void put(ExecState *exec, const Identifier &propertyName, 113 113 const Value &value, int attr = None); … … 125 125 ActivationImp(FunctionImp *function, const List &arguments); 126 126 127 virtual Value get(ExecState *exec, const Identifier &propertyName) const;127 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 128 128 virtual bool hasOwnProperty(ExecState *exec, const Identifier &propertyName) const; 129 129 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName); -
trunk/JavaScriptCore/kjs/lookup.h
r9834 r9889 165 165 */ 166 166 template <class FuncImp, class ThisImp, class ParentImp> 167 inline Value lookupGet(ExecState *exec, const Identifier &propertyName,168 const HashTable* table, const ThisImp* thisObj)167 inline bool lookupGetOwnProperty(ExecState *exec, const Identifier &propertyName, 168 const HashTable* table, const ThisImp* thisObj, Value& result) 169 169 { 170 170 const HashEntry* entry = Lookup::findEntry(table, propertyName); 171 171 172 172 if (!entry) // not found, forward to parent 173 return thisObj->ParentImp::get(exec, propertyName); 174 175 //fprintf(stderr, "lookupGet: found value=%d attr=%d\n", entry->value, entry->attr); 173 return thisObj->ParentImp::getOwnProperty(exec, propertyName, result); 174 176 175 if (entry->attr & Function) 177 return lookupOrCreateFunction<FuncImp>(exec, propertyName, thisObj, entry->value, entry->params, entry->attr); 178 return thisObj->getValueProperty(exec, entry->value); 176 result = lookupOrCreateFunction<FuncImp>(exec, propertyName, thisObj, entry->value, entry->params, entry->attr); 177 else 178 result = thisObj->getValueProperty(exec, entry->value); 179 180 return true; 179 181 } 180 182 … … 184 186 */ 185 187 template <class FuncImp, class ParentImp> 186 inline Value lookupGetFunction(ExecState *exec, const Identifier &propertyName,187 const HashTable* table, const ObjectImp* thisObj)188 inline bool lookupGetOwnFunction(ExecState *exec, const Identifier &propertyName, 189 const HashTable* table, const ObjectImp* thisObj, Value& result) 188 190 { 189 191 const HashEntry* entry = Lookup::findEntry(table, propertyName); 190 192 191 193 if (!entry) // not found, forward to parent 192 return static_cast<const ParentImp *>(thisObj)->ParentImp::get(exec, propertyName); 193 194 if (entry->attr & Function) 195 return lookupOrCreateFunction<FuncImp>(exec, propertyName, thisObj, entry->value, entry->params, entry->attr); 196 197 fprintf(stderr, "Function bit not set! Shouldn't happen in lookupGetFunction!\n" ); 198 return Undefined(); 194 return static_cast<const ParentImp *>(thisObj)->ParentImp::getOwnProperty(exec, propertyName, result); 195 196 assert(entry->attr & Function); 197 198 result = lookupOrCreateFunction<FuncImp>(exec, propertyName, thisObj, entry->value, entry->params, entry->attr); 199 return true; 199 200 } 200 201 … … 204 205 */ 205 206 template <class ThisImp, class ParentImp> 206 inline Value lookupGetValue(ExecState *exec, const Identifier &propertyName,207 const HashTable* table, const ThisImp* thisObj)207 inline bool lookupGetOwnValue(ExecState *exec, const Identifier &propertyName, 208 const HashTable* table, const ThisImp* thisObj, Value& result) 208 209 { 209 210 const HashEntry* entry = Lookup::findEntry(table, propertyName); 210 211 211 212 if (!entry) // not found, forward to parent 212 return thisObj->ParentImp::get(exec, propertyName); 213 214 if (entry->attr & Function) 215 fprintf(stderr, "Function bit set! Shouldn't happen in lookupGetValue! propertyName was %s\n", propertyName.ascii() ); 216 return thisObj->getValueProperty(exec, entry->value); 213 return thisObj->ParentImp::getOwnProperty(exec, propertyName, result); 214 215 assert(!entry->attr & Function); 216 217 result = thisObj->getValueProperty(exec, entry->value); 218 return true; 217 219 } 218 220 … … 294 296 virtual const ClassInfo *classInfo() const { return &info; } \ 295 297 static const ClassInfo info; \ 296 Value get(ExecState *exec, const Identifier &propertyName) const; \298 bool getOwnProperty(ExecState *exec, const Identifier &propertyName, Value& result) const; \ 297 299 bool hasOwnProperty(ExecState *exec, const Identifier &propertyName) const; \ 298 300 }; \ … … 300 302 301 303 #define IMPLEMENT_PROTOTYPE(ClassProto,ClassFunc) \ 302 Value ClassProto::get(ExecState *exec, const Identifier &propertyName) const \ 303 { \ 304 /*fprintf( stderr, "%sProto::get(%s) [in macro, no parent]\n", info.className, propertyName.ascii());*/ \ 305 return lookupGetFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this ); \ 304 bool ClassProto::getOwnProperty(ExecState *exec, const Identifier &propertyName, Value& result) const \ 305 { \ 306 return lookupGetOwnFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this, result); \ 306 307 } \ 307 308 bool ClassProto::hasOwnProperty(ExecState *exec, const Identifier &propertyName) const \ … … 311 312 312 313 #define IMPLEMENT_PROTOTYPE_WITH_PARENT(ClassProto,ClassFunc,ParentProto) \ 313 Value ClassProto::get(ExecState *exec, const Identifier &propertyName) const \ 314 { \ 315 /*fprintf( stderr, "%sProto::get(%s) [in macro]\n", info.className, propertyName.ascii());*/ \ 316 Value val = lookupGetFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this ); \ 317 if ( val.type() != UndefinedType ) return val; \ 318 /* Not found -> forward request to "parent" prototype */ \ 319 return ParentProto::self(exec)->get( exec, propertyName ); \ 314 bool ClassProto::getOwnProperty(ExecState *exec, const Identifier &propertyName, Value& result) const \ 315 { \ 316 if (lookupGetOwnFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this, result)) \ 317 return true; \ 318 return ParentProto::self(exec)->getOwnProperty(exec, propertyName, result); \ 320 319 } \ 321 320 bool ClassProto::hasOwnProperty(ExecState *exec, const Identifier &propertyName) const \ -
trunk/JavaScriptCore/kjs/math_object.cpp
r9768 r9889 22 22 #include <math.h> 23 23 #include <stdlib.h> 24 #include <stdio.h>25 24 #include <assert.h> 26 25 … … 82 81 83 82 // ECMA 15.8 84 Value MathObjectImp::get(ExecState *exec, const Identifier &propertyName) const 85 { 86 return lookupGet<MathFuncImp, MathObjectImp, ObjectImp>( exec, propertyName, &mathTable, this ); 83 84 bool MathObjectImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 85 { 86 return lookupGetOwnProperty<MathFuncImp, MathObjectImp, ObjectImp>(exec, propertyName, &mathTable, this, result); 87 87 } 88 88 … … 116 116 break; 117 117 default: 118 fprintf( stderr, "Internal error in MathObjectImp: unhandled token %d\n", token ); 119 break; 118 assert(0); 120 119 } 121 120 -
trunk/JavaScriptCore/kjs/math_object.h
r9768 r9889 32 32 MathObjectImp(ExecState *exec, 33 33 ObjectPrototypeImp *objProto); 34 Value get(ExecState *exec, const Identifier &p) const;34 bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 35 35 Value getValueProperty(ExecState *exec, int token) const; 36 36 virtual const ClassInfo *classInfo() const { return &info; } -
trunk/JavaScriptCore/kjs/nodes.cpp
r9768 r9889 285 285 Value ResolveNode::evaluate(ExecState *exec) 286 286 { 287 return evaluateReference(exec).getValue(exec); 287 ScopeChain chain = exec->context().imp()->scopeChain(); 288 289 Value result; 290 while (!chain.isEmpty()) { 291 ObjectImp *o = chain.top(); 292 293 if (o->getProperty(exec, ident, result)) 294 return result; 295 296 chain.pop(); 297 } 298 299 UString m = I18N_NOOP("Can't find variable: ") + ident.ustring(); 300 Object err = Error::create(exec, ReferenceError, m.ascii()); 301 exec->setException(err); 302 return err; 288 303 } 289 304 -
trunk/JavaScriptCore/kjs/number_object.cpp
r9768 r9889 403 403 } 404 404 405 Value NumberObjectImp::get(ExecState *exec, const Identifier &propertyName) const406 { 407 return lookupGet Value<NumberObjectImp, InternalFunctionImp>( exec, propertyName, &numberTable, this);405 bool NumberObjectImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 406 { 407 return lookupGetOwnValue<NumberObjectImp, InternalFunctionImp>(exec, propertyName, &numberTable, this, result); 408 408 } 409 409 -
trunk/JavaScriptCore/kjs/number_object.h
r9768 r9889 85 85 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 86 86 87 Value get(ExecState *exec, const Identifier &p) const;87 bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 88 88 Value getValueProperty(ExecState *exec, int token) const; 89 89 virtual const ClassInfo *classInfo() const { return &info; } -
trunk/JavaScriptCore/kjs/object.cpp
r9768 r9889 209 209 Value ObjectImp::get(ExecState *exec, const Identifier &propertyName) const 210 210 { 211 ValueImp *imp = getDirect(propertyName); 212 if (imp) 213 return Value(imp); 214 215 // non-standard netscape extension 216 if (propertyName == specialPrototypePropertyName) 217 return Value(_proto); 218 219 if (_proto->dispatchType() != ObjectType) { 220 return Undefined(); 221 } 222 223 return static_cast<ObjectImp *>(_proto)->get(exec, propertyName); 211 Value result; 212 213 const ObjectImp *imp = this; 214 215 while (true) { 216 if (imp->getOwnProperty(exec, propertyName, result)) 217 return result; 218 219 const ValueImp *proto = imp->_proto; 220 if (proto->dispatchType() != ObjectType) 221 break; 222 223 imp = static_cast<const ObjectImp *>(proto); 224 } 225 226 return Undefined(); 227 } 228 229 bool ObjectImp::getOwnProperty(ExecState *exec, unsigned propertyName, Value& result) const 230 { 231 return getOwnProperty(exec, Identifier::from(propertyName), result); 224 232 } 225 233 226 234 Value ObjectImp::get(ExecState *exec, unsigned propertyName) const 227 235 { 228 return get(exec, Identifier::from(propertyName)); 236 Value result; 237 238 const ObjectImp *imp = this; 239 240 while (imp) { 241 if (imp->getOwnProperty(exec, propertyName, result)) 242 return result; 243 244 const ValueImp *proto = imp->_proto; 245 if (proto->dispatchType() != ObjectType) 246 break; 247 248 imp = static_cast<const ObjectImp *>(proto); 249 } 250 251 return Undefined(); 252 } 253 254 bool ObjectImp::getProperty(ExecState *exec, unsigned propertyName, Value& result) const 255 { 256 const ObjectImp *imp = this; 257 258 while (true) { 259 if (imp->getOwnProperty(exec, propertyName, result)) 260 return true; 261 262 const ValueImp *proto = imp->_proto; 263 if (proto->dispatchType() != ObjectType) 264 break; 265 266 imp = static_cast<const ObjectImp *>(proto); 267 } 268 269 return false; 229 270 } 230 271 -
trunk/JavaScriptCore/kjs/object.h
r9795 r9889 504 504 */ 505 505 // [[Get]] - must be implemented by all Objects 506 virtual Value get(ExecState *exec, const Identifier &propertyName) const; 507 virtual Value get(ExecState *exec, unsigned propertyName) const; 506 Value get(ExecState *exec, const Identifier &propertyName) const; 507 Value get(ExecState *exec, unsigned propertyName) const; 508 509 bool getProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 510 bool getProperty(ExecState *exec, unsigned propertyName, Value& result) const; 511 512 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 513 virtual bool getOwnProperty(ExecState *exec, unsigned propertyName, Value& result) const; 508 514 509 515 /** … … 633 639 }; 634 640 641 642 // it may seem crazy to inline a function this large but it makes a big difference 643 // since this is function very hot in variable lookup 644 inline bool ObjectImp::getProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 645 { 646 const ObjectImp *imp = this; 647 648 while (true) { 649 if (imp->getOwnProperty(exec, propertyName, result)) 650 return true; 651 652 const ValueImp *proto = imp->_proto; 653 if (proto->dispatchType() != ObjectType) 654 break; 655 656 imp = static_cast<const ObjectImp *>(proto); 657 } 658 659 return false; 660 } 661 662 // it may seem crazy to inline a function this large, especially a virtual function, 663 // but it makes a big difference to property lookup if subclasses can inline their 664 // superclass call to this 665 inline bool ObjectImp::getOwnProperty(ExecState *exec, const Identifier &propertyName, Value &result) const 666 { 667 ValueImp *imp = getDirect(propertyName); 668 if (imp) { 669 result = Value(imp); 670 return true; 671 } 672 673 // non-standard netscape extension 674 if (propertyName == specialPrototypePropertyName) { 675 result = Value(_proto); 676 return true; 677 } 678 679 return false; 680 } 681 635 682 /** 636 683 * Types of Native Errors available. For custom errors, GeneralError -
trunk/JavaScriptCore/kjs/object_object.cpp
r9768 r9889 71 71 return thisObj; 72 72 case HasOwnProperty: { 73 // Same as hasProperty()but without checking the prototype73 // Same as the in operator but without checking the prototype 74 74 Identifier propertyName(args[0].toString(exec)); 75 75 bool exists = thisObj.hasOwnProperty(exec, propertyName); -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r9768 r9889 217 217 } 218 218 219 Value RegExpObjectImp::get(ExecState *exec, const Identifier &p) const219 bool RegExpObjectImp::getOwnProperty(ExecState *exec, const Identifier& p, Value& result) const 220 220 { 221 221 UString s = p.ustring(); … … 229 229 { 230 230 UString substring = lastString.substr( lastOvector[2*i], lastOvector[2*i+1] - lastOvector[2*i] ); 231 return String(substring); 232 } 233 return String(""); 234 } 235 } 236 return InternalFunctionImp::get(exec, p); 231 result = String(substring); 232 } else 233 result = String(""); 234 235 return true; 236 } 237 } 238 239 return InternalFunctionImp::getOwnProperty(exec, p, result); 237 240 } 238 241 -
trunk/JavaScriptCore/kjs/regexp_object.h
r9768 r9889 75 75 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 76 76 77 Value get(ExecState *exec, const Identifier &p) const;77 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 78 78 int ** registerRegexp( const RegExp* re, const UString& s ); 79 79 void setSubPatterns(int num) { lastNrSubPatterns = num; } -
trunk/JavaScriptCore/kjs/string_object.cpp
r9768 r9889 51 51 } 52 52 53 Value StringInstanceImp::get(ExecState *exec, const Identifier &propertyName) const 54 { 55 if (propertyName == lengthPropertyName) 56 return Number(internalValue().toString(exec).size()); 53 bool StringInstanceImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 54 { 55 if (propertyName == lengthPropertyName) { 56 result = Value(internalValue().toString(exec).size()); 57 return true; 58 } 57 59 58 60 bool ok; … … 64 66 return Undefined(); 65 67 const UChar c = s[index]; 66 return String(UString(&c, 1)); 67 } 68 69 return ObjectImp::get(exec, propertyName); 68 result = Value(UString(&c, 1)); 69 return true; 70 } 71 72 return ObjectImp::getOwnProperty(exec, propertyName, result); 70 73 } 71 74 … … 152 155 } 153 156 154 Value StringPrototypeImp::get(ExecState *exec, const Identifier &propertyName) const155 { 156 return lookupGet Function<StringProtoFuncImp, StringInstanceImp>( exec, propertyName, &stringTable, this);157 bool StringPrototypeImp::getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const 158 { 159 return lookupGetOwnFunction<StringProtoFuncImp, StringInstanceImp>(exec, propertyName, &stringTable, this, result); 157 160 } 158 161 -
trunk/JavaScriptCore/kjs/string_object.h
r9768 r9889 33 33 StringInstanceImp(ObjectImp *proto, const UString &string); 34 34 35 virtual Value get(ExecState *exec, const Identifier &propertyName) const;35 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 36 36 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None); 37 37 virtual bool hasOwnProperty(ExecState *exec, const Identifier &propertyName) const; … … 52 52 StringPrototypeImp(ExecState *exec, 53 53 ObjectPrototypeImp *objProto); 54 Value get(ExecState *exec, const Identifier &p) const;54 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 55 55 virtual const ClassInfo *classInfo() const { return &info; } 56 56 static const ClassInfo info;
Note:
See TracChangeset
for help on using the changeset viewer.