Changeset 27218 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- Oct 29, 2007, 12:55:34 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r27202 r27218 64 64 } 65 65 66 JSValue *StringInstance::lengthGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot &slot)67 { 68 return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()-> toString(exec).size());69 } 70 71 JSValue *StringInstance::indexGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot &slot)72 { 73 const UChar c = static_cast<StringInstance *>(slot.slotBase())->internalValue()->toString(exec)[slot.index()];66 JSValue *StringInstance::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot &slot) 67 { 68 return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().size()); 69 } 70 71 JSValue *StringInstance::indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot &slot) 72 { 73 const UChar c = static_cast<StringInstance*>(slot.slotBase())->internalValue()->value()[slot.index()]; 74 74 return jsString(UString(&c, 1)); 75 75 } 76 76 77 bool StringInstance::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot) 78 { 79 if (propertyName == exec->propertyNames().length) { 80 slot.setCustom(this, lengthGetter); 81 return true; 82 } 83 84 bool ok; 85 const unsigned index = propertyName.toArrayIndex(&ok); 86 if (ok) { 87 const UString s = internalValue()->toString(exec); 88 const unsigned length = s.size(); 89 if (index < length) { 90 slot.setCustomIndex(this, index, indexGetter); 91 return true; 92 } 93 } 94 95 return JSObject::getOwnPropertySlot(exec, propertyName, slot); 77 bool StringInstance::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 78 { 79 if (propertyName == exec->propertyNames().length) { 80 slot.setCustom(this, lengthGetter); 81 return true; 82 } 83 84 bool isStrictUInt32; 85 unsigned i = propertyName.toStrictUInt32(&isStrictUInt32); 86 unsigned length = internalValue()->value().size(); 87 if (isStrictUInt32 && i < length) { 88 slot.setCustomIndex(this, i, indexGetter); 89 return true; 90 } 91 92 return JSObject::getOwnPropertySlot(exec, propertyName, slot); 93 } 94 95 bool StringInstance::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot) 96 { 97 unsigned length = internalValue()->value().size(); 98 if (propertyName < length) { 99 slot.setCustomIndex(this, propertyName, indexGetter); 100 return true; 101 } 102 103 return JSObject::getOwnPropertySlot(exec, Identifier::from(propertyName), slot); 96 104 } 97 105
Note:
See TracChangeset
for help on using the changeset viewer.