Changeset 27218 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Oct 29, 2007, 12:55:34 AM (18 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/internal.h
r27209 r27218 50 50 enum HasOtherOwnerType { HasOtherOwner }; 51 51 StringImp(const UString& value, HasOtherOwnerType) : val(value) { } 52 UStringvalue() const { return val; }52 const UString& value() const { return val; } 53 53 54 private: 54 55 virtual JSType type() const { return StringType; } 55 56 … … 58 59 virtual bool toBoolean(ExecState *exec) const; 59 60 virtual double toNumber(ExecState *exec) const; 60 virtual UString toString(ExecState *exec) const;61 61 virtual JSObject *toObject(ExecState *exec) const; 62 63 private:62 virtual UString toString(ExecState*) const; 63 64 64 UString val; 65 65 }; -
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 -
trunk/JavaScriptCore/kjs/string_object.h
r24873 r27218 32 32 public: 33 33 StringInstance(JSObject *proto); 34 StringInstance(JSObject *proto, StringImp* string);35 StringInstance(JSObject *proto, const UString &string);34 StringInstance(JSObject *proto, StringImp*); 35 StringInstance(JSObject *proto, const UString&); 36 36 37 37 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 38 virtual void put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr = None); 38 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 39 40 virtual void put(ExecState* exec, const Identifier& propertyName, JSValue*, int attr = None); 39 41 virtual bool deleteProperty(ExecState* exec, const Identifier& propertyName); 40 42 virtual void getPropertyNames(ExecState*, PropertyNameArray&); … … 46 48 47 49 private: 48 static JSValue *lengthGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot &slot); 49 static JSValue *indexGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot &slot); 50 bool inlineGetOwnPropertySlot(ExecState*, unsigned, PropertySlot&); 51 52 static JSValue* lengthGetter(ExecState*, JSObject *, const Identifier&, const PropertySlot&); 53 static JSValue* indexGetter(ExecState*, JSObject *, const Identifier&, const PropertySlot&); 50 54 }; 51 55
Note:
See TracChangeset
for help on using the changeset viewer.