Ignore:
Timestamp:
Jul 6, 2008, 7:49:29 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-07-06 Sam Weinig <[email protected]>

Reviewed by Cameron Zwarich.

Second step in broad cleanup effort.

[ File list elided ]

WebCore:

2008-07-06 Sam Weinig <[email protected]>

Reviewed by Cameron Zwarich.

Add #include for kjs/protect.h.

  • xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::loadRequestAsynchronously):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/JSGlobalObjectFunctions.cpp

    r35016 r35027  
    4949namespace KJS {
    5050
    51 static JSValue* encode(ExecState* exec, const ArgList& args, const char* do_not_escape)
    52 {
    53   UString r = "", s, str = args[0]->toString(exec);
    54   CString cstr = str.UTF8String(true);
    55   if (!cstr.c_str())
    56     return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
    57   const char* p = cstr.c_str();
    58   for (size_t k = 0; k < cstr.size(); k++, p++) {
    59     char c = *p;
    60     if (c && strchr(do_not_escape, c)) {
    61       r.append(c);
    62     } else {
    63       char tmp[4];
    64       sprintf(tmp, "%%%02X", (unsigned char)c);
    65       r += tmp;
    66     }
    67   }
    68   return jsString(exec, r);
    69 }
    70 
    71 static JSValue* decode(ExecState* exec, const ArgList& args, const char* do_not_unescape, bool strict)
    72 {
    73   UString s = "", str = args[0]->toString(exec);
    74   int k = 0, len = str.size();
    75   const UChar* d = str.data();
    76   UChar u = 0;
    77   while (k < len) {
    78     const UChar* p = d + k;
    79     UChar c = *p;
    80     if (c == '%') {
    81       int charLen = 0;
    82       if (k <= len - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {
    83         const char b0 = Lexer::convertHex(p[1], p[2]);
    84         const int sequenceLen = UTF8SequenceLength(b0);
    85         if (sequenceLen != 0 && k <= len - sequenceLen * 3) {
    86           charLen = sequenceLen * 3;
    87           char sequence[5];
    88           sequence[0] = b0;
    89           for (int i = 1; i < sequenceLen; ++i) {
    90             const UChar* q = p + i * 3;
    91             if (q[0] == '%' && isASCIIHexDigit(q[1]) && isASCIIHexDigit(q[2]))
    92               sequence[i] = Lexer::convertHex(q[1], q[2]);
    93             else {
    94               charLen = 0;
    95               break;
     51static JSValue* encode(ExecState* exec, const ArgList& args, const char* doNotEscape)
     52{
     53    UString str = args[0]->toString(exec);
     54    CString cstr = str.UTF8String(true);
     55    if (!cstr.c_str())
     56        return throwError(exec, URIError, "String contained an illegal UTF-16 sequence.");
     57
     58    UString result = "";
     59    const char* p = cstr.c_str();
     60    for (size_t k = 0; k < cstr.size(); k++, p++) {
     61        char c = *p;
     62        if (c && strchr(doNotEscape, c))
     63            result.append(c);
     64        else {
     65            char tmp[4];
     66            sprintf(tmp, "%%%02X", static_cast<unsigned char>(c));
     67            result += tmp;
     68        }
     69    }
     70    return jsString(exec, result);
     71}
     72
     73static JSValue* decode(ExecState* exec, const ArgList& args, const char* doNotUnescape, bool strict)
     74{
     75    UString result = "";
     76    UString str = args[0]->toString(exec);
     77    int k = 0;
     78    int len = str.size();
     79    const UChar* d = str.data();
     80    UChar u = 0;
     81    while (k < len) {
     82        const UChar* p = d + k;
     83        UChar c = *p;
     84        if (c == '%') {
     85            int charLen = 0;
     86            if (k <= len - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {
     87                const char b0 = Lexer::convertHex(p[1], p[2]);
     88                const int sequenceLen = UTF8SequenceLength(b0);
     89                if (sequenceLen != 0 && k <= len - sequenceLen * 3) {
     90                    charLen = sequenceLen * 3;
     91                    char sequence[5];
     92                    sequence[0] = b0;
     93                    for (int i = 1; i < sequenceLen; ++i) {
     94                        const UChar* q = p + i * 3;
     95                        if (q[0] == '%' && isASCIIHexDigit(q[1]) && isASCIIHexDigit(q[2]))
     96                            sequence[i] = Lexer::convertHex(q[1], q[2]);
     97                        else {
     98                            charLen = 0;
     99                            break;
     100                        }
     101                    }
     102                    if (charLen != 0) {
     103                        sequence[sequenceLen] = 0;
     104                        const int character = decodeUTF8Sequence(sequence);
     105                        if (character < 0 || character >= 0x110000)
     106                            charLen = 0;
     107                        else if (character >= 0x10000) {
     108                            // Convert to surrogate pair.
     109                            result.append(static_cast<UChar>(0xD800 | ((character - 0x10000) >> 10)));
     110                            u = static_cast<UChar>(0xDC00 | ((character - 0x10000) & 0x3FF));
     111                        } else
     112                            u = static_cast<UChar>(character);
     113                    }
     114                }
    96115            }
    97           }
    98           if (charLen != 0) {
    99             sequence[sequenceLen] = 0;
    100             const int character = decodeUTF8Sequence(sequence);
    101             if (character < 0 || character >= 0x110000) {
    102               charLen = 0;
    103             } else if (character >= 0x10000) {
    104               // Convert to surrogate pair.
    105               s.append(static_cast<UChar>(0xD800 | ((character - 0x10000) >> 10)));
    106               u = static_cast<UChar>(0xDC00 | ((character - 0x10000) & 0x3FF));
    107             } else {
    108               u = static_cast<UChar>(character);
     116            if (charLen == 0) {
     117                if (strict)
     118                    return throwError(exec, URIError);
     119                // The only case where we don't use "strict" mode is the "unescape" function.
     120                // For that, it's good to support the wonky "%u" syntax for compatibility with WinIE.
     121                if (k <= len - 6 && p[1] == 'u'
     122                        && isASCIIHexDigit(p[2]) && isASCIIHexDigit(p[3])
     123                        && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) {
     124                    charLen = 6;
     125                    u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]);
     126                }
    109127            }
    110           }
    111         }
    112       }
    113       if (charLen == 0) {
    114         if (strict)
    115           return throwError(exec, URIError);
    116         // The only case where we don't use "strict" mode is the "unescape" function.
    117         // For that, it's good to support the wonky "%u" syntax for compatibility with WinIE.
    118         if (k <= len - 6 && p[1] == 'u'
    119             && isASCIIHexDigit(p[2]) && isASCIIHexDigit(p[3])
    120             && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) {
    121           charLen = 6;
    122           u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]);
    123         }
    124       }
    125       if (charLen && (u == 0 || u >= 128 || !strchr(do_not_unescape, u))) {
    126         c = u;
    127         k += charLen - 1;
    128       }
    129     }
    130     k++;
    131     s.append(c);
    132   }
    133   return jsString(exec, s);
     128            if (charLen && (u == 0 || u >= 128 || !strchr(doNotUnescape, u))) {
     129                c = u;
     130                k += charLen - 1;
     131            }
     132        }
     133        k++;
     134        result.append(c);
     135    }
     136    return jsString(exec, result);
    134137}
    135138
     
    156159    int digit = -1;
    157160
    158     if (c >= '0' && c <= '9') {
     161    if (c >= '0' && c <= '9')
    159162        digit = c - '0';
    160     } else if (c >= 'A' && c <= 'Z') {
     163    else if (c >= 'A' && c <= 'Z')
    161164        digit = c - 'A' + 10;
    162     } else if (c >= 'a' && c <= 'z') {
     165    else if (c >= 'a' && c <= 'z')
    163166        digit = c - 'a' + 10;
    164     }
    165167
    166168    if (digit >= radix)
     
    196198    int p = 0;
    197199
    198     while (p < length && isStrWhiteSpace(s[p])) {
     200    while (p < length && isStrWhiteSpace(s[p]))
    199201        ++p;
    200     }
    201202
    202203    double sign = 1;
    203204    if (p < length) {
    204         if (s[p] == '+') {
     205        if (s[p] == '+')
    205206            ++p;
    206         } else if (s[p] == '-') {
     207        else if (s[p] == '-') {
    207208            sign = -1;
    208209            ++p;
     
    255256    int length = s.size();
    256257    int p = 0;
    257     while (p < length && isStrWhiteSpace(s[p])) {
     258    while (p < length && isStrWhiteSpace(s[p]))
    258259        ++p;
    259     }
    260     if (p < length && (s[p] == '+' || s[p] == '-')) {
     260
     261    if (p < length && (s[p] == '+' || s[p] == '-'))
    261262        ++p;
    262     }
    263     if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X')) {
     263
     264    if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X'))
    264265        return 0;
    265     }
    266 
    267     return s.toDouble( true /*tolerant*/, false /* NaN for empty string */ );
     266
     267    return s.toDouble(true /*tolerant*/, false /* NaN for empty string */);
    268268}
    269269
     
    278278    if (!x->isString())
    279279        return x;
    280    
     280
    281281    UString s = x->toString(exec);
    282    
     282
    283283    int sourceId;
    284284    int errLine;
     
    286286
    287287    RefPtr<EvalNode> evalNode = exec->parser()->parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(s), &sourceId, &errLine, &errMsg);
    288    
     288
    289289    if (!evalNode)
    290290        return throwError(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
     
    357357        "*+-./@_";
    358358
    359     UString r = "", s, str = args[0]->toString(exec);
     359    UString result = "";
     360    UString s;
     361    UString str = args[0]->toString(exec);
    360362    const UChar* c = str.data();
    361363    for (int k = 0; k < str.size(); k++, c++) {
     
    365367            sprintf(tmp, "%%u%04X", u);
    366368            s = UString(tmp);
    367         } else if (u != 0 && strchr(do_not_escape, (char)u))
     369        } else if (u != 0 && strchr(do_not_escape, static_cast<char>(u)))
    368370            s = UString(c, 1);
    369371        else {
     
    372374            s = UString(tmp);
    373375        }
    374         r += s;
    375     }
    376 
    377     return jsString(exec, r);
     376        result += s;
     377    }
     378
     379    return jsString(exec, result);
    378380}
    379381
    380382JSValue* globalFuncUnescape(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
    381383{
    382     UString s = "", str = args[0]->toString(exec);
    383     int k = 0, len = str.size();
     384    UString result = "";
     385    UString str = args[0]->toString(exec);
     386    int k = 0;
     387    int len = str.size();
    384388    while (k < len) {
    385389        const UChar* c = str.data() + k;
     
    397401        }
    398402        k++;
    399         s.append(*c);
    400     }
    401 
    402     return jsString(exec, s);
     403        result.append(*c);
     404    }
     405
     406    return jsString(exec, result);
    403407}
    404408
Note: See TracChangeset for help on using the changeset viewer.