Changeset 171328 in webkit
- Timestamp:
- Jul 21, 2014, 5:58:11 PM (11 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r171323 r171328 1 2014-07-21 Mark Lam <mark.lam@apple.com> 2 3 Refactor ArrayPrototype to use getLength() and putLength() utility functions. 4 https://bugs.webkit.org/show_bug.cgi?id=135139. 5 6 Reviewed by Oliver Hunt. 7 8 - Specialize putProperty() to putLength() because it is only used for setting 9 the length property. 10 - Added a getLength() utility function to get the value of the length property. 11 - Use these getLength() and putLength() functions instead of the existing code 12 to get and put the length property. Less code to read, easier to understand. 13 14 * runtime/ArrayPrototype.cpp: 15 (JSC::getLength): 16 (JSC::putLength): 17 (JSC::arrayProtoFuncToString): 18 (JSC::arrayProtoFuncToLocaleString): 19 (JSC::arrayProtoFuncJoin): 20 (JSC::arrayProtoFuncPop): 21 (JSC::arrayProtoFuncPush): 22 (JSC::arrayProtoFuncReverse): 23 (JSC::arrayProtoFuncShift): 24 (JSC::arrayProtoFuncSlice): 25 (JSC::arrayProtoFuncSort): 26 (JSC::arrayProtoFuncSplice): 27 (JSC::arrayProtoFuncUnShift): 28 (JSC::arrayProtoFuncReduce): 29 (JSC::arrayProtoFuncReduceRight): 30 (JSC::arrayProtoFuncIndexOf): 31 (JSC::arrayProtoFuncLastIndexOf): 32 (JSC::putProperty): Deleted. 33 1 34 2014-07-21 Diego Pino Garcia <dpino@igalia.com> 2 35 -
trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp
r167797 r171328 158 158 } 159 159 160 static void putProperty(ExecState* exec, JSObject* obj, PropertyName propertyName, JSValue value) 160 static ALWAYS_INLINE unsigned getLength(ExecState* exec, JSObject* obj) 161 { 162 return obj->get(exec, exec->propertyNames().length).toUInt32(exec); 163 } 164 165 static void putLength(ExecState* exec, JSObject* obj, JSValue value) 161 166 { 162 167 PutPropertySlot slot(obj); 163 obj->methodTable()->put(obj, exec, propertyName, value, slot);168 obj->methodTable()->put(obj, exec, exec->propertyNames().length, value, slot); 164 169 } 165 170 … … 297 302 JSArray* thisObj = asArray(thisValue); 298 303 299 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);304 unsigned length = getLength(exec, thisObj); 300 305 if (exec->hadException()) 301 306 return JSValue::encode(jsUndefined()); … … 336 341 return JSValue::encode(jsUndefined()); 337 342 338 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);343 unsigned length = getLength(exec, thisObj); 339 344 if (exec->hadException()) 340 345 return JSValue::encode(jsUndefined()); … … 374 379 { 375 380 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 376 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);381 unsigned length = getLength(exec, thisObj); 377 382 if (exec->hadException()) 378 383 return JSValue::encode(jsUndefined()); … … 476 481 477 482 JSObject* thisObj = thisValue.toObject(exec); 478 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);483 unsigned length = getLength(exec, thisObj); 479 484 if (exec->hadException()) 480 485 return JSValue::encode(jsUndefined()); … … 482 487 JSValue result; 483 488 if (length == 0) { 484 put Property(exec, thisObj, exec->propertyNames().length, jsNumber(length));489 putLength(exec, thisObj, jsNumber(length)); 485 490 result = jsUndefined(); 486 491 } else { … … 492 497 return JSValue::encode(jsUndefined()); 493 498 } 494 put Property(exec, thisObj, exec->propertyNames().length, jsNumber(length - 1));499 putLength(exec, thisObj, jsNumber(length - 1)); 495 500 } 496 501 return JSValue::encode(result); … … 508 513 509 514 JSObject* thisObj = thisValue.toObject(exec); 510 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);515 unsigned length = getLength(exec, thisObj); 511 516 if (exec->hadException()) 512 517 return JSValue::encode(jsUndefined()); … … 526 531 527 532 JSValue newLength(static_cast<int64_t>(length) + static_cast<int64_t>(exec->argumentCount())); 528 put Property(exec, thisObj, exec->propertyNames().length, newLength);533 putLength(exec, thisObj, newLength); 529 534 return JSValue::encode(newLength); 530 535 } … … 533 538 { 534 539 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 535 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);540 unsigned length = getLength(exec, thisObj); 536 541 if (exec->hadException()) 537 542 return JSValue::encode(jsUndefined()); … … 571 576 { 572 577 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 573 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);578 unsigned length = getLength(exec, thisObj); 574 579 if (exec->hadException()) 575 580 return JSValue::encode(jsUndefined()); … … 577 582 JSValue result; 578 583 if (length == 0) { 579 put Property(exec, thisObj, exec->propertyNames().length, jsNumber(length));584 putLength(exec, thisObj, jsNumber(length)); 580 585 result = jsUndefined(); 581 586 } else { … … 584 589 if (exec->hadException()) 585 590 return JSValue::encode(jsUndefined()); 586 put Property(exec, thisObj, exec->propertyNames().length, jsNumber(length - 1));591 putLength(exec, thisObj, jsNumber(length - 1)); 587 592 } 588 593 return JSValue::encode(result); … … 593 598 // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10 594 599 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 595 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);600 unsigned length = getLength(exec, thisObj); 596 601 if (exec->hadException()) 597 602 return JSValue::encode(jsUndefined()); … … 701 706 { 702 707 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 703 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);708 unsigned length = getLength(exec, thisObj); 704 709 if (!length || exec->hadException()) 705 710 return JSValue::encode(thisObj); … … 776 781 777 782 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 778 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);783 unsigned length = getLength(exec, thisObj); 779 784 if (exec->hadException()) 780 785 return JSValue::encode(jsUndefined()); … … 825 830 } 826 831 827 put Property(exec, thisObj, exec->propertyNames().length, jsNumber(length - deleteCount + additionalArgs));832 putLength(exec, thisObj, jsNumber(length - deleteCount + additionalArgs)); 828 833 return JSValue::encode(result); 829 834 } … … 834 839 835 840 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 836 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);841 unsigned length = getLength(exec, thisObj); 837 842 if (exec->hadException()) 838 843 return JSValue::encode(jsUndefined()); … … 850 855 } 851 856 JSValue result = jsNumber(length + nrArgs); 852 put Property(exec, thisObj, exec->propertyNames().length, result);857 putLength(exec, thisObj, result); 853 858 return JSValue::encode(result); 854 859 } … … 857 862 { 858 863 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 859 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);864 unsigned length = getLength(exec, thisObj); 860 865 if (exec->hadException()) 861 866 return JSValue::encode(jsUndefined()); … … 934 939 { 935 940 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 936 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);941 unsigned length = getLength(exec, thisObj); 937 942 if (exec->hadException()) 938 943 return JSValue::encode(jsUndefined()); … … 1011 1016 // 15.4.4.14 1012 1017 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 1013 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);1018 unsigned length = getLength(exec, thisObj); 1014 1019 if (exec->hadException()) 1015 1020 return JSValue::encode(jsUndefined()); … … 1034 1039 // 15.4.4.15 1035 1040 JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec); 1036 unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);1041 unsigned length = getLength(exec, thisObj); 1037 1042 if (!length) 1038 1043 return JSValue::encode(jsNumber(-1));
Note:
See TracChangeset
for help on using the changeset viewer.