Changeset 31807 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Apr 11, 2008, 12:37:33 AM (17 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSGlobalObject.h
r31746 r31807 138 138 ActivationStackNode* activations; 139 139 size_t activationCount; 140 141 OwnPtr<HashSet<JSObject*> > arrayVisitedElements; // Global data shared by array prototype functions. 140 142 }; 141 143 … … 242 244 ExecStateStack& activeExecStates() const { return d()->activeExecStates; } 243 245 246 HashSet<JSObject*>& arrayVisitedElements() { if (!d()->arrayVisitedElements) d()->arrayVisitedElements.set(new HashSet<JSObject*>); return *d()->arrayVisitedElements; } 247 244 248 private: 245 249 void init(); -
trunk/JavaScriptCore/kjs/array_object.cpp
r31746 r31807 93 93 return throwError(exec, TypeError); 94 94 95 static HashSet<JSObject*> visitedElems; 96 static const UString* empty = new UString(""); 97 static const UString* comma = new UString(","); 98 bool alreadyVisited = !visitedElems.add(thisObj).second; 95 bool alreadyVisited = !exec->dynamicGlobalObject()->arrayVisitedElements().add(thisObj).second; 96 Vector<UChar, 256> strBuffer; 99 97 if (alreadyVisited) 100 return jsString(*empty); 101 UString separator = *comma; 102 UString str = *empty; 98 return jsString(UString(0, 0)); // return an empty string, avoding infinite recursion. 103 99 104 100 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 105 101 for (unsigned k = 0; k < length; k++) { 106 102 if (k >= 1) 107 str += separator;108 if ( str.isNull()) {103 strBuffer.append(','); 104 if (!strBuffer.data()) { 109 105 JSObject* error = Error::create(exec, GeneralError, "Out of memory"); 110 106 exec->setException(error); … … 116 112 continue; 117 113 118 str += element->toString(exec); 119 120 if (str.isNull()) { 114 UString str = element->toString(exec); 115 strBuffer.append(str.data(), str.size()); 116 117 if (!strBuffer.data()) { 121 118 JSObject* error = Error::create(exec, GeneralError, "Out of memory"); 122 119 exec->setException(error); … … 126 123 break; 127 124 } 128 visitedElems.remove(thisObj);129 return jsString( str);125 exec->dynamicGlobalObject()->arrayVisitedElements().remove(thisObj); 126 return jsString(UString(strBuffer.data(), strBuffer.data() ? strBuffer.size() : 0)); 130 127 } 131 128 … … 135 132 return throwError(exec, TypeError); 136 133 137 static HashSet<JSObject*> visitedElems; 138 static const UString* empty = new UString(""); 139 static const UString* comma = new UString(","); 140 bool alreadyVisited = !visitedElems.add(thisObj).second; 134 bool alreadyVisited = !exec->dynamicGlobalObject()->arrayVisitedElements().add(thisObj).second; 135 Vector<UChar, 256> strBuffer; 141 136 if (alreadyVisited) 142 return jsString(*empty); 143 UString separator = *comma; 144 UString str = *empty; 137 return jsString(UString(0, 0)); // return an empty string, avoding infinite recursion. 145 138 146 139 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 147 140 for (unsigned k = 0; k < length; k++) { 148 141 if (k >= 1) 149 str += separator;150 if ( str.isNull()) {142 strBuffer.append(','); 143 if (!strBuffer.data()) { 151 144 JSObject* error = Error::create(exec, GeneralError, "Out of memory"); 152 145 exec->setException(error); … … 160 153 JSObject* o = element->toObject(exec); 161 154 JSValue* conversionFunction = o->get(exec, exec->propertyNames().toLocaleString); 155 UString str; 162 156 if (conversionFunction->isObject() && static_cast<JSObject*>(conversionFunction)->implementsCall()) 163 str += static_cast<JSObject*>(conversionFunction)->call(exec, o, exec->emptyList())->toString(exec);157 str = static_cast<JSObject*>(conversionFunction)->call(exec, o, exec->emptyList())->toString(exec); 164 158 else 165 str += element->toString(exec); 166 167 if (str.isNull()) { 159 str = element->toString(exec); 160 strBuffer.append(str.data(), str.size()); 161 162 if (!strBuffer.data()) { 168 163 JSObject* error = Error::create(exec, GeneralError, "Out of memory"); 169 164 exec->setException(error); … … 173 168 break; 174 169 } 175 visitedElems.remove(thisObj);176 return jsString( str);170 exec->dynamicGlobalObject()->arrayVisitedElements().remove(thisObj); 171 return jsString(UString(strBuffer.data(), strBuffer.data() ? strBuffer.size() : 0)); 177 172 } 178 173 179 174 JSValue* arrayProtoFuncJoin(ExecState* exec, JSObject* thisObj, const List& args) 180 175 { 181 static HashSet<JSObject*> visitedElems; 182 static const UString* empty = new UString(""); 183 static const UString* comma = new UString(","); 184 bool alreadyVisited = !visitedElems.add(thisObj).second; 176 bool alreadyVisited = !exec->dynamicGlobalObject()->arrayVisitedElements().add(thisObj).second; 177 Vector<UChar, 256> strBuffer; 185 178 if (alreadyVisited) 186 return jsString(*empty); 187 UString separator = *comma; 188 UString str = *empty; 189 190 if (!args[0]->isUndefined()) 191 separator = args[0]->toString(exec); 179 return jsString(UString(0, 0)); // return an empty string, avoding infinite recursion. 180 181 UChar comma = ','; 182 UString separator = args[0]->isUndefined() ? UString(&comma, 1) : args[0]->toString(exec); 192 183 193 184 unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec); 194 185 for (unsigned k = 0; k < length; k++) { 195 186 if (k >= 1) 196 str += separator;197 if ( str.isNull()) {187 strBuffer.append(separator.data(), separator.size()); 188 if (!strBuffer.data()) { 198 189 JSObject* error = Error::create(exec, GeneralError, "Out of memory"); 199 190 exec->setException(error); … … 205 196 continue; 206 197 207 str += element->toString(exec); 208 209 if (str.isNull()) { 198 UString str = element->toString(exec); 199 strBuffer.append(str.data(), str.size()); 200 201 if (!strBuffer.data()) { 210 202 JSObject* error = Error::create(exec, GeneralError, "Out of memory"); 211 203 exec->setException(error); … … 215 207 break; 216 208 } 217 visitedElems.remove(thisObj);218 return jsString( str);209 exec->dynamicGlobalObject()->arrayVisitedElements().remove(thisObj); 210 return jsString(UString(strBuffer.data(), strBuffer.data() ? strBuffer.size() : 0)); 219 211 } 220 212
Note:
See TracChangeset
for help on using the changeset viewer.