Changeset 47857 in webkit for trunk/JavaScriptCore/runtime/JSONObject.cpp
- Timestamp:
- Aug 27, 2009, 11:17:36 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSONObject.cpp
r47847 r47857 121 121 // ------------------------------ helper functions -------------------------------- 122 122 123 static inline JSValue unwrapBoxedPrimitive( JSValue value)123 static inline JSValue unwrapBoxedPrimitive(ExecState* exec, JSValue value) 124 124 { 125 125 if (!value.isObject()) 126 126 return value; 127 if (!asObject(value)->inherits(&NumberObject::info) && !asObject(value)->inherits(&StringObject::info) && !asObject(value)->inherits(&BooleanObject::info)) 128 return value; 129 return static_cast<JSWrapperObject*>(asObject(value))->internalValue(); 130 } 131 132 static inline UString gap(JSValue space) 133 { 134 space = unwrapBoxedPrimitive(space); 127 JSObject* object = asObject(value); 128 if (object->inherits(&NumberObject::info)) 129 return jsNumber(exec, object->toNumber(exec)); 130 if (object->inherits(&StringObject::info)) 131 return jsString(exec, object->toString(exec)); 132 if (object->inherits(&BooleanObject::info)) 133 return object->toPrimitive(exec); 134 return value; 135 } 136 137 static inline UString gap(ExecState* exec, JSValue space) 138 { 139 const int maxGapLength = 10; 140 space = unwrapBoxedPrimitive(exec, space); 135 141 136 142 // If the space value is a number, create a gap string with that number of spaces. 137 143 double spaceCount; 138 144 if (space.getNumber(spaceCount)) { 139 const int maxSpaceCount = 100;140 145 int count; 141 if (spaceCount > max SpaceCount)142 count = max SpaceCount;146 if (spaceCount > maxGapLength) 147 count = maxGapLength; 143 148 else if (!(spaceCount > 0)) 144 149 count = 0; 145 150 else 146 151 count = static_cast<int>(spaceCount); 147 UChar spaces[max SpaceCount];152 UChar spaces[maxGapLength]; 148 153 for (int i = 0; i < count; ++i) 149 154 spaces[i] = ' '; … … 152 157 153 158 // If the space value is a string, use it as the gap string, otherwise use no gap string. 154 return space.getString(); 159 UString spaces = space.getString(); 160 if (spaces.size() > maxGapLength) { 161 spaces = spaces.substr(0, maxGapLength); 162 } 163 return spaces; 155 164 } 156 165 … … 188 197 , m_arrayReplacerPropertyNames(exec) 189 198 , m_replacerCallType(CallTypeNone) 190 , m_gap(gap( space))199 , m_gap(gap(exec, space)) 191 200 { 192 201 exec->globalData().firstStringifierToMark = this; … … 204 213 break; 205 214 206 if (name.isObject()) {207 if (!asObject(name)->inherits(&NumberObject::info) && !asObject(name)->inherits(&StringObject::info))208 continue;209 name = static_cast<JSWrapperObject*>(asObject(name))->internalValue();210 }211 212 215 UString propertyName; 213 216 if (name.getString(propertyName)) { … … 222 225 } 223 226 224 if (exec->hadException()) 225 return; 227 if (name.isObject()) { 228 if (!asObject(name)->inherits(&NumberObject::info) && !asObject(name)->inherits(&StringObject::info)) 229 continue; 230 propertyName = name.toString(exec); 231 if (exec->hadException()) 232 break; 233 m_arrayReplacerPropertyNames.add(Identifier(exec, propertyName)); 234 } 226 235 } 227 236 return; … … 370 379 } 371 380 372 value = unwrapBoxedPrimitive(value); 381 value = unwrapBoxedPrimitive(m_exec, value); 382 383 if (m_exec->hadException()) 384 return StringifyFailed; 373 385 374 386 if (value.isBoolean()) {
Note:
See TracChangeset
for help on using the changeset viewer.