Changeset 34518 in webkit for trunk/JavaScriptCore/kjs/internal.cpp
- Timestamp:
- Jun 12, 2008, 9:53:56 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/internal.cpp
r34355 r34518 60 60 { 61 61 value = this; 62 number = val.toDouble(); 63 return false; 64 } 65 66 bool StringImp::toBoolean(ExecState *) const 67 { 68 return (val.size() > 0); 69 } 70 71 double StringImp::toNumber(ExecState *) const 72 { 73 return val.toDouble(); 74 } 75 76 UString StringImp::toString(ExecState *) const 77 { 78 return val; 79 } 80 81 JSObject* StringImp::toObject(ExecState *exec) const 82 { 83 return new StringInstance(exec->lexicalGlobalObject()->stringPrototype(), const_cast<StringImp*>(this)); 62 number = m_value.toDouble(); 63 return false; 64 } 65 66 bool StringImp::toBoolean(ExecState*) const 67 { 68 return !m_value.isEmpty(); 69 } 70 71 double StringImp::toNumber(ExecState*) const 72 { 73 return m_value.toDouble(); 74 } 75 76 UString StringImp::toString(ExecState*) const 77 { 78 return m_value; 79 } 80 81 inline StringInstance* StringInstance::create(ExecState* exec, StringImp* string) 82 { 83 return new StringInstance(exec->lexicalGlobalObject()->stringPrototype(), string); 84 } 85 86 JSObject* StringImp::toObject(ExecState* exec) const 87 { 88 return StringInstance::create(exec, const_cast<StringImp*>(this)); 84 89 } 85 90 86 91 JSObject* StringImp::toThisObject(ExecState* exec) const 87 92 { 88 return new StringInstance(exec->lexicalGlobalObject()->stringPrototype(), const_cast<StringImp*>(this)); 93 return StringInstance::create(exec, const_cast<StringImp*>(this)); 94 } 95 96 JSValue* StringImp::lengthGetter(ExecState*, const Identifier&, const PropertySlot& slot) 97 { 98 return jsNumber(static_cast<StringImp*>(slot.slotBase())->value().size()); 99 } 100 101 JSValue* StringImp::indexGetter(ExecState*, const Identifier&, const PropertySlot& slot) 102 { 103 return jsString(static_cast<StringImp*>(slot.slotBase())->value().substr(slot.index(), 1)); 104 } 105 106 JSValue* StringImp::indexNumericPropertyGetter(ExecState*, unsigned index, const PropertySlot& slot) 107 { 108 return jsString(static_cast<StringImp*>(slot.slotBase())->value().substr(index, 1)); 109 } 110 111 bool StringImp::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 112 { 113 // The semantics here are really getPropertySlot, not getOwnPropertySlot. 114 // This function should only be called by JSValue::get. 115 if (getStringPropertySlot(exec, propertyName, slot)) 116 return true; 117 JSObject* object = StringInstance::create(exec, this); 118 slot.setBase(object); 119 if (object->JSObject::getOwnPropertySlot(exec, propertyName, slot)) 120 return true; 121 while (true) { 122 JSValue* proto = object->prototype(); 123 if (!proto->isObject()) { 124 slot.setUndefined(); 125 return true; 126 } 127 object = static_cast<JSObject*>(proto); 128 if (object->getOwnPropertySlot(exec, propertyName, slot)) 129 return true; 130 } 131 } 132 133 bool StringImp::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot) 134 { 135 // The semantics here are really getPropertySlot, not getOwnPropertySlot. 136 // This function should only be called by JSValue::get. 137 if (getStringPropertySlot(propertyName, slot)) 138 return true; 139 return StringImp::getOwnPropertySlot(exec, Identifier::from(propertyName), slot); 89 140 } 90 141
Note:
See TracChangeset
for help on using the changeset viewer.