| 1 |
/* { dg-do compile { target arm*-*-* } } */ |
| 2 |
/* { dg-require-effective-target arm_cpu_xscale_arm_ok } */ |
| 3 |
/* { dg-options "-O1 -Wno-return-type" } */ |
| 4 |
/* { dg-add-options arm_cpu_xscale_arm } */ |
| 5 |
|
| 6 |
typedef unsigned int size_t; |
| 7 |
__extension__ |
| 8 |
typedef long long int int64_t; |
| 9 |
namespace WTF { |
| 10 |
template<typename T> class RefPtr { |
| 11 |
public: |
| 12 |
inline T* operator->() const { return m_ptr; } |
| 13 |
T* m_ptr; |
| 14 |
}; |
| 15 |
} |
| 16 |
using WTF::RefPtr; |
| 17 |
namespace JSC { |
| 18 |
class ExecState; |
| 19 |
class JSString; |
| 20 |
typedef int64_t EncodedJSValue; |
| 21 |
class JSValue { |
| 22 |
public: |
| 23 |
static EncodedJSValue encode(JSValue); |
| 24 |
JSString* toString(ExecState*) const; |
| 25 |
}; |
| 26 |
} |
| 27 |
typedef unsigned char LChar; |
| 28 |
typedef short unsigned int UChar; |
| 29 |
namespace WTF { |
| 30 |
template<typename T, size_t inlineCapacity = 0> |
| 31 |
class Vector { |
| 32 |
public: |
| 33 |
template<typename U> bool tryAppend(const U*, size_t); |
| 34 |
}; |
| 35 |
} |
| 36 |
using WTF::Vector; |
| 37 |
namespace WTF { |
| 38 |
template<typename CharType> inline bool isASCIIDigit(CharType c) |
| 39 |
{ |
| 40 |
} |
| 41 |
template<typename CharType> inline bool isASCIIHexDigit(CharType c) |
| 42 |
{ |
| 43 |
return isASCIIDigit(c) || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); |
| 44 |
} |
| 45 |
class StringImpl; |
| 46 |
} |
| 47 |
using WTF::StringImpl; |
| 48 |
namespace WTF { |
| 49 |
class StringImpl { |
| 50 |
public: |
| 51 |
unsigned length() const { return m_length; } |
| 52 |
unsigned m_length; |
| 53 |
}; |
| 54 |
} |
| 55 |
namespace JSC { |
| 56 |
class Register { |
| 57 |
}; |
| 58 |
class UString { |
| 59 |
public: |
| 60 |
unsigned length() const |
| 61 |
{ |
| 62 |
return m_impl->length(); |
| 63 |
} |
| 64 |
const LChar* characters8() const |
| 65 |
{ |
| 66 |
} |
| 67 |
RefPtr<StringImpl> m_impl; |
| 68 |
}; |
| 69 |
class ExecState : private Register { |
| 70 |
public: |
| 71 |
JSValue argument(size_t argument) |
| 72 |
{ |
| 73 |
} |
| 74 |
}; |
| 75 |
class JSCell { |
| 76 |
}; |
| 77 |
class JSString : public JSCell { |
| 78 |
public: |
| 79 |
const UString& value(ExecState*) const; |
| 80 |
}; |
| 81 |
class JSStringBuilder { |
| 82 |
public: |
| 83 |
void append(const UChar u) |
| 84 |
{ |
| 85 |
m_okay &= buffer16.tryAppend(&u, 1); |
| 86 |
} |
| 87 |
Vector<UChar, 64> buffer16; |
| 88 |
bool m_okay; |
| 89 |
}; |
| 90 |
template <typename T> |
| 91 |
class Lexer { |
| 92 |
public: |
| 93 |
static unsigned char convertHex(int c1, int c2); |
| 94 |
}; |
| 95 |
} |
| 96 |
namespace WTF { |
| 97 |
namespace Unicode { |
| 98 |
int UTF8SequenceLength(char); |
| 99 |
int decodeUTF8Sequence(const char*); |
| 100 |
} |
| 101 |
} |
| 102 |
using namespace WTF; |
| 103 |
using namespace Unicode; |
| 104 |
namespace JSC { |
| 105 |
template <typename CharType> |
| 106 |
static JSValue decode(ExecState* exec, const CharType* characters, int length, const char* doNotUnescape, bool strict) |
| 107 |
{ |
| 108 |
JSStringBuilder builder; |
| 109 |
int k = 0; |
| 110 |
UChar u = 0; |
| 111 |
while (k < length) { |
| 112 |
const CharType* p = characters + k; |
| 113 |
CharType c = *p; |
| 114 |
if (c == '%') { |
| 115 |
int charLen = 0; |
| 116 |
if (k <= length - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) { |
| 117 |
const char b0 = Lexer<CharType>::convertHex(p[1], p[2]); |
| 118 |
const int sequenceLen = UTF8SequenceLength(b0); |
| 119 |
if (sequenceLen && k <= length - sequenceLen * 3) { |
| 120 |
charLen = sequenceLen * 3; |
| 121 |
char sequence[5]; |
| 122 |
if (charLen != 0) { |
| 123 |
const int character = decodeUTF8Sequence(sequence); |
| 124 |
if (character < 0 || character >= 0x110000) |
| 125 |
charLen = 0; |
| 126 |
else if (character >= 0x10000) { |
| 127 |
builder.append(static_cast<UChar>(0xD800 | ((character - 0x10000) >> 10))); |
| 128 |
} else |
| 129 |
u = static_cast<UChar>(character); |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
static JSValue decode(ExecState* exec, const char* doNotUnescape, bool strict) |
| 137 |
{ |
| 138 |
UString str = exec->argument(0).toString(exec)->value(exec); |
| 139 |
return decode(exec, str.characters8(), str.length(), doNotUnescape, strict); |
| 140 |
} |
| 141 |
EncodedJSValue globalFuncDecodeURI(ExecState* exec) |
| 142 |
{ |
| 143 |
static const char do_not_unescape_when_decoding_URI[] = |
| 144 |
"#$&+,/:;=?@"; |
| 145 |
return JSValue::encode(decode(exec, do_not_unescape_when_decoding_URI, true)); |
| 146 |
} |
| 147 |
} |