Changeset 1326 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Jun 10, 2002, 1:08:04 PM (23 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r1126 r1326 226 226 227 227 // SWEEP: delete everything with a zero refcount (garbage) 228 // 1st step: destruct all objects 228 229 block = root; 229 230 while (block) { 230 231 ValueImp **r = (ValueImp**)block->mem; 231 int del = 0;232 232 for (int i = 0; i < block->size; i++, r++) { 233 233 ValueImp *imp = (*r); … … 239 239 //fprintf( stderr, "Collector::deleting ValueImp %p (%s)\n", (void*)imp, typeid(*imp).name()); 240 240 imp->~ValueImp(); 241 free(imp); 241 } 242 } 243 block = block->next; 244 } 245 246 // 2nd step: free memory 247 block = root; 248 while (block) { 249 ValueImp **r = (ValueImp**)block->mem; 250 int del = 0; 251 for (int i = 0; i < block->size; i++, r++) { 252 ValueImp *imp = (*r); 253 if (imp && (imp->_flags & ValueImp::VI_DESTRUCTED) != 0) { 254 free(imp); 242 255 *r = 0L; 243 256 del++; -
trunk/JavaScriptCore/kjs/date_object.cpp
r1024 r1326 77 77 @begin dateTable 61 78 78 toString DateProtoFuncImp::ToString DontEnum|Function 0 79 toUTCString -DateProtoFuncImp::ToString DontEnum|Function 079 toUTCString DateProtoFuncImp::ToUTCString DontEnum|Function 0 80 80 toDateString DateProtoFuncImp::ToDateString DontEnum|Function 0 81 81 toTimeString DateProtoFuncImp::ToTimeString DontEnum|Function 0 … … 196 196 case ToTimeString: 197 197 case ToGMTString: 198 case ToUTCString: 198 199 setlocale(LC_TIME,"C"); 199 200 if (id == DateProtoFuncImp::ToDateString) { … … 201 202 } else if (id == DateProtoFuncImp::ToTimeString) { 202 203 strftime(timebuffer, bufsize, "%X",t); 203 } else { 204 } else { // toGMTString & toUTCString 204 205 t = gmtime(&tv); 205 strftime(timebuffer, bufsize, "%a, %d -%b-%y%H:%M:%S %Z", t);206 strftime(timebuffer, bufsize, "%a, %d %b %Y %H:%M:%S %Z", t); 206 207 } 207 208 setlocale(LC_TIME,oldlocale.c_str()); -
trunk/JavaScriptCore/kjs/date_object.lut.h
r901 r1326 63 63 { "getUTCSeconds", -DateProtoFuncImp::GetSeconds, DontEnum|Function, 0, 0 }, 64 64 { "getHours", DateProtoFuncImp::GetHours, DontEnum|Function, 0, 0 }, 65 { "toUTCString", -DateProtoFuncImp::ToString, DontEnum|Function, 0, &dateTableEntries[62] },65 { "toUTCString", DateProtoFuncImp::ToUTCString, DontEnum|Function, 0, &dateTableEntries[62] }, 66 66 { 0, 0, 0, 0, 0 }, 67 67 { 0, 0, 0, 0, 0 }, -
trunk/JavaScriptCore/kjs/function.cpp
r1024 r1326 370 370 "0123456789@*_+-./"; 371 371 372 if (id == Eval) { // eval() 372 switch (id) { 373 case Eval: { // eval() 373 374 Value x = args[0]; 374 375 if (x.type() != StringType) … … 423 424 else 424 425 return Undefined(); 425 } else 426 } else { 426 427 return c; 427 } 428 } else if (id == ParseInt) { 428 } 429 } 430 break; 431 } 432 case ParseInt: { 429 433 String str = args[0].toString(exec); 430 434 int radix = args[1].toInt32(exec); … … 442 446 else 443 447 res = Number(static_cast<long>(value)); // remove floating-point part 444 } else if (id == ParseFloat) { 448 break; 449 } 450 case ParseFloat: { 445 451 String str = args[0].toString(exec); 446 452 res = Number(str.value().toDouble( true /*tolerant*/ )); 447 } else if (id == IsNaN) { 453 break; 454 } 455 case IsNaN: 448 456 res = Boolean(isNaN(args[0].toNumber(exec))); 449 } else if (id == IsFinite) { 457 break; 458 case IsFinite: { 450 459 Number n = args[0].toNumber(exec); 451 460 res = Boolean(!n.isNaN() && !n.isInf()); 452 } else if (id == Escape) { 461 break; 462 } 463 case Escape: { 453 464 UString r = "", s, str = args[0].toString(exec); 454 465 const UChar *c = str.data(); … … 469 480 } 470 481 res = String(r); 471 } else if (id == UnEscape) { 482 break; 483 } 484 case UnEscape: { 472 485 UString s, str = args[0].toString(exec); 473 486 int k = 0, len = str.size(); … … 489 502 } 490 503 res = String(s); 504 break; 505 } 491 506 } 492 507 -
trunk/JavaScriptCore/kjs/internal.cpp
r1192 r1326 918 918 919 919 // built-in values 920 global.put(globExec, "NaN", Number(NaN), DontEnum);921 global.put(globExec, "Infinity", Number(Inf), DontEnum);922 global.put(globExec, "undefined", Undefined(), DontEnum);920 global.put(globExec, "NaN", Number(NaN), DontEnum|DontDelete); 921 global.put(globExec, "Infinity", Number(Inf), DontEnum|DontDelete); 922 global.put(globExec, "undefined", Undefined(), DontEnum|DontDelete); 923 923 924 924 // built-in functions -
trunk/JavaScriptCore/kjs/lookup.h
r1024 r1326 195 195 fprintf(stderr, "Function bit not set! Shouldn't happen in lookupGetFunction!\n" ); 196 196 return Undefined(); 197 } ;197 } 198 198 199 199 /** -
trunk/JavaScriptCore/kjs/object.cpp
r1024 r1326 201 201 { 202 202 //fprintf(stderr,"ObjectImp::~ObjectImp %p\n",(void*)this); 203 #if 0 // Those could be already deleted. The collector ensures no order204 // ### Check if this leads to memory leaks....205 203 if (_proto) 206 204 _proto->setGcAllowed(); … … 209 207 if (_scope) 210 208 _scope->setGcAllowed(); 211 #endif212 209 delete _prop; 213 210 } -
trunk/JavaScriptCore/kjs/operations.cpp
r798 r1326 221 221 Value KJS::add(ExecState *exec, const Value &v1, const Value &v2, char oper) 222 222 { 223 Value p1 = v1.toPrimitive(exec); 224 Value p2 = v2.toPrimitive(exec); 223 // exception for the Date exception in defaultValue() 224 Type preferred = oper == '+' ? UnspecifiedType : NumberType; 225 Value p1 = v1.toPrimitive(exec, preferred); 226 Value p2 = v2.toPrimitive(exec, preferred); 225 227 226 228 if ((p1.type() == StringType || p2.type() == StringType) && oper == '+') { -
trunk/JavaScriptCore/kjs/regexp.cpp
r1024 r1326 20 20 */ 21 21 22 #include "regexp.h" 23 22 24 #include <stdio.h> 23 25 #include <stdlib.h> 24 26 #include <string.h> 25 26 #include "regexp.h"27 27 28 28 using namespace KJS; … … 31 31 : pattern(p), flags(f) 32 32 { 33 34 33 #ifdef HAVE_PCREPOSIX 35 34 int pcreflags = 0; … … 45 44 pcregex = pcre_compile(p.ascii(), pcreflags, 46 45 &perrormsg, &errorOffset, NULL); 46 #ifndef NDEBUG 47 if (!pcregex) 48 fprintf(stderr, "KJS: pcre_compile() failed with '%s'\n", perrormsg); 49 #endif 47 50 48 51 #ifdef PCRE_INFO_CAPTURECOUNT … … 55 58 #else /* HAVE_PCREPOSIX */ 56 59 57 nrSubPatterns = 0; // not implementedwith POSIX regex.60 nrSubPatterns = 0; // determined in match() with POSIX regex. 58 61 int regflags = 0; 59 62 #ifdef REG_EXTENDED … … 79 82 { 80 83 #ifdef HAVE_PCREPOSIX 81 pcre_free(pcregex);82 84 if (pcregex) 85 pcre_free(pcregex); 83 86 #else 84 87 /* TODO: is this really okay after an error ? */ … … 89 92 UString RegExp::match(const UString &s, int i, int *pos, int **ovector) 90 93 { 94 if (i < 0) 95 i = 0; 96 if (ovector) 97 *ovector = 0L; 98 int dummyPos; 99 if (!pos) 100 pos = &dummyPos; 101 *pos = -1; 102 if (i > s.size() || s.isNull()) 103 return UString::null; 91 104 92 105 #ifdef HAVE_PCREPOSIX … … 95 108 if (ovector) *ovector = new int[ovecsize]; 96 109 97 if (i < 0) 98 i = 0; 99 100 if (i > s.size() || s.isNull() || 101 pcre_exec(pcregex, NULL, buffer.c_str(), buffer.size(), i, 102 0, ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH) { 103 104 if (pos) 105 *pos = -1; 110 if (!pcregex || pcre_exec(pcregex, NULL, buffer.c_str(), buffer.size(), i, 111 0, ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH) 106 112 return UString::null; 107 }108 113 109 114 if (!ovector) 110 115 return UString::null; // don't rely on the return value if you pass ovector==0 111 if (pos) 112 *pos = (*ovector)[0]; 113 return s.substr((*ovector)[0], (*ovector)[1] - (*ovector)[0]); 116 #else 117 #ifdef APPLE_CHANGES 118 const uint maxMatch = 10; 119 #else 120 const int maxMatch = 10; 121 #endif 122 regmatch_t rmatch[maxMatch]; 114 123 115 #else 116 regmatch_t rmatch[10]; 117 118 if (i < 0) 119 i = 0; 120 121 char *str = strdup(s.ascii()); 122 if (i > s.size() || s.isNull() || 123 regexec(&preg, str + i, 10, rmatch, 0)) { 124 if (pos) 125 *pos = -1; 124 char *str = strdup(s.ascii()); // TODO: why ??? 125 if (regexec(&preg, str + i, maxMatch, rmatch, 0)) { 126 free(str); 126 127 return UString::null; 127 128 } 128 129 free(str); 129 130 130 if (pos) 131 *pos = rmatch[0].rm_so + i; 132 // TODO copy from rmatch to ovector 133 return s.substr(rmatch[0].rm_so + i, rmatch[0].rm_eo - rmatch[0].rm_so); 131 if (!ovector) { 132 *pos = rmatch[0].rm_so + i; 133 return s.substr(rmatch[0].rm_so + i, rmatch[0].rm_eo - rmatch[0].rm_so); 134 } 135 136 // map rmatch array to ovector used in PCRE case 137 nrSubPatterns = 0; 138 #ifdef APPLE_CHANGES 139 for(uint j = 1; j < maxMatch && rmatch[j].rm_so >= 0 ; j++) 140 #else 141 for(int j = 1; j < maxMatch && rmatch[j].rm_so >= 0 ; j++) 134 142 #endif 143 nrSubPatterns++; 144 int ovecsize = (nrSubPatterns+1)*3; // see above 145 *ovector = new int[ovecsize]; 146 #ifdef APPLE_CHANGES 147 for (uint j = 0; j < nrSubPatterns + 1; j++) { 148 #else 149 for (int j = 0; j < nrSubPatterns + 1; j++) { 150 #endif 151 if (j>maxMatch) 152 break; 153 (*ovector)[2*j] = rmatch[j].rm_so + i; 154 (*ovector)[2*j+1] = rmatch[j].rm_eo + i; 155 #ifdef APPLE_CHANGES 156 } // balance extra { so we don't confuse prepare-ChangeLog 157 #else 158 } 159 #endif 160 #endif 161 162 *pos = (*ovector)[0]; 163 return s.substr((*ovector)[0], (*ovector)[1] - (*ovector)[0]); 135 164 } 136 165 -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r1024 r1326 93 93 if (i < 0 || i > length) { 94 94 thisObj.put(exec,"lastIndex", Number(0), DontDelete | DontEnum); 95 return Null(); 95 if (id == Test) 96 return Boolean(false); 97 else 98 Null(); 96 99 } 97 100 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp()); … … 99 102 100 103 str = re->match(s.value(), i, 0L, ovector); 104 regExpObj->setSubPatterns(re->subPatterns()); 101 105 102 106 if (id == Test) … … 160 164 RegExpObjectImp::~RegExpObjectImp() 161 165 { 162 if (lastOvector) 163 delete [] lastOvector; 166 delete [] lastOvector; 164 167 } 165 168 … … 167 170 { 168 171 lastString = s; 169 if (lastOvector) 170 delete [] lastOvector; 172 delete [] lastOvector; 171 173 lastOvector = 0; 172 174 lastNrSubPatterns = re->subPatterns(); -
trunk/JavaScriptCore/kjs/regexp_object.h
r1024 r1326 75 75 Value get(ExecState *exec, const UString &p) const; 76 76 int ** registerRegexp( const RegExp* re, const UString& s ); 77 void setSubPatterns(int num) { lastNrSubPatterns = num; } 77 78 Value arrayOfMatches(ExecState *exec, const UString &result) const; 78 79 private: -
trunk/JavaScriptCore/kjs/string_object.cpp
r1024 r1326 214 214 int **ovector = regExpObj->registerRegexp( reg, u ); 215 215 UString mstr = reg->match(u, -1, &pos, ovector); 216 regExpObj->setSubPatterns(reg->subPatterns()); 216 217 if (a0.isA(StringType)) 217 218 delete reg; … … 243 244 int **ovector = regExpObj->registerRegexp( reg, u ); 244 245 UString mstr = reg->match(u, lastIndex, &pos, ovector); 246 regExpObj->setSubPatterns(reg->subPatterns()); 247 if (pos == -1) 248 break; 245 249 len = mstr.size(); 250 // special case of empty match 251 if (len == 0 && lastIndex > 0) { 252 pos = lastIndex + 1; 253 if (pos > u.size()) 254 break; 255 } 246 256 UString rstr(u3); 247 257 bool ok; … … 263 273 } 264 274 lastIndex = pos + rstr.size(); 265 if ( pos != -1 ) 266 u = u.substr(0, pos) + rstr + u.substr(pos + len); 275 u = u.substr(0, pos) + rstr + u.substr(pos + len); 267 276 //fprintf(stderr,"pos=%d,len=%d,lastIndex=%d,u=%s\n",pos,len,lastIndex,u.ascii()); 268 } while ( global && pos != -1);277 } while (global); 269 278 270 279 result = String(u); -
trunk/JavaScriptCore/kjs/testkjs.cpp
r1041 r1326 22 22 23 23 #include <stdio.h> 24 #if !APPLE_CHANGES25 #include <iostream.h>26 #endif27 24 28 25 #include "value.h" -
trunk/JavaScriptCore/kjs/ustring.cpp
r1272 r1326 424 424 // empty string ? 425 425 if (*c == '\0') 426 return 0.0;426 return tolerant ? NaN : 0.0; 427 427 428 428 // hex number ? -
trunk/JavaScriptCore/kjs/value.cpp
r1126 r1326 65 65 { 66 66 //fprintf(stderr,"ValueImp::~ValueImp %p\n",(void*)this); 67 _flags |= VI_DESTRUCTED; 67 68 } 68 69 -
trunk/JavaScriptCore/kjs/value.h
r1140 r1326 161 161 VI_MARKED = 1, 162 162 VI_GCALLOWED = 2, 163 VI_CREATED = 4 163 VI_CREATED = 4, 164 VI_DESTRUCTED = 8 164 165 }; // VI means VALUEIMPL 165 166
Note:
See TracChangeset
for help on using the changeset viewer.