зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1023778 part 2 - Parameterize JSONParser. r=Waldo
This commit is contained in:
Родитель
956d61eaf6
Коммит
e30254798a
|
@ -173,8 +173,9 @@ TryEvalJSON(JSContext *cx, JSScript *callerScript,
|
||||||
|
|
||||||
if (cp == end) {
|
if (cp == end) {
|
||||||
bool isArray = (chars[0] == '[');
|
bool isArray = (chars[0] == '[');
|
||||||
JSONParser parser(cx, isArray ? chars : chars + 1U, isArray ? length : length - 2,
|
JSONParser<jschar> parser(cx, isArray ? chars : chars + 1U,
|
||||||
JSONParserBase::NoError);
|
isArray ? length : length - 2,
|
||||||
|
JSONParserBase::NoError);
|
||||||
RootedValue tmp(cx);
|
RootedValue tmp(cx);
|
||||||
if (!parser.parse(&tmp))
|
if (!parser.parse(&tmp))
|
||||||
return EvalJSON_Failure;
|
return EvalJSON_Failure;
|
||||||
|
|
|
@ -777,7 +777,7 @@ js::ParseJSONWithReviver(JSContext *cx, ConstTwoByteChars chars, size_t length,
|
||||||
HandleValue reviver, MutableHandleValue vp)
|
HandleValue reviver, MutableHandleValue vp)
|
||||||
{
|
{
|
||||||
/* 15.12.2 steps 2-3. */
|
/* 15.12.2 steps 2-3. */
|
||||||
JSONParser parser(cx, chars, length);
|
JSONParser<jschar> parser(cx, chars, length);
|
||||||
if (!parser.parse(vp))
|
if (!parser.parse(vp))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -57,10 +57,11 @@ JSONParserBase::trace(JSTracer *trc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
void
|
void
|
||||||
JSONParser::getTextPosition(uint32_t *column, uint32_t *line)
|
JSONParser<CharT>::getTextPosition(uint32_t *column, uint32_t *line)
|
||||||
{
|
{
|
||||||
ConstTwoByteChars ptr = begin;
|
CharPtr ptr = begin;
|
||||||
uint32_t col = 1;
|
uint32_t col = 1;
|
||||||
uint32_t row = 1;
|
uint32_t row = 1;
|
||||||
for (; ptr < current; ptr++) {
|
for (; ptr < current; ptr++) {
|
||||||
|
@ -78,8 +79,9 @@ JSONParser::getTextPosition(uint32_t *column, uint32_t *line)
|
||||||
*line = row;
|
*line = row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
void
|
void
|
||||||
JSONParser::error(const char *msg)
|
JSONParser<CharT>::error(const char *msg)
|
||||||
{
|
{
|
||||||
if (errorHandling == RaiseError) {
|
if (errorHandling == RaiseError) {
|
||||||
uint32_t column = 1, line = 1;
|
uint32_t column = 1, line = 1;
|
||||||
|
@ -102,9 +104,10 @@ JSONParserBase::errorReturn()
|
||||||
return errorHandling == NoError;
|
return errorHandling == NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<JSONParserBase::StringType ST>
|
template <typename CharT>
|
||||||
|
template <JSONParserBase::StringType ST>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::readString()
|
JSONParser<CharT>::readString()
|
||||||
{
|
{
|
||||||
JS_ASSERT(current < end);
|
JS_ASSERT(current < end);
|
||||||
JS_ASSERT(*current == '"');
|
JS_ASSERT(*current == '"');
|
||||||
|
@ -236,8 +239,9 @@ JSONParser::readString()
|
||||||
return token(Error);
|
return token(Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::readNumber()
|
JSONParser<CharT>::readNumber()
|
||||||
{
|
{
|
||||||
JS_ASSERT(current < end);
|
JS_ASSERT(current < end);
|
||||||
JS_ASSERT(JS7_ISDEC(*current) || *current == '-');
|
JS_ASSERT(JS7_ISDEC(*current) || *current == '-');
|
||||||
|
@ -341,8 +345,9 @@ IsJSONWhitespace(jschar c)
|
||||||
return c == '\t' || c == '\r' || c == '\n' || c == ' ';
|
return c == '\t' || c == '\r' || c == '\n' || c == ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::advance()
|
JSONParser<CharT>::advance()
|
||||||
{
|
{
|
||||||
while (current < end && IsJSONWhitespace(*current))
|
while (current < end && IsJSONWhitespace(*current))
|
||||||
current++;
|
current++;
|
||||||
|
@ -422,8 +427,9 @@ JSONParser::advance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::advanceAfterObjectOpen()
|
JSONParser<CharT>::advanceAfterObjectOpen()
|
||||||
{
|
{
|
||||||
JS_ASSERT(current[-1] == '{');
|
JS_ASSERT(current[-1] == '{');
|
||||||
|
|
||||||
|
@ -473,8 +479,9 @@ AssertPastValue(const RangedPtr<const jschar> current)
|
||||||
JS7_ISDEC(current[-1]));
|
JS7_ISDEC(current[-1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::advanceAfterArrayElement()
|
JSONParser<CharT>::advanceAfterArrayElement()
|
||||||
{
|
{
|
||||||
AssertPastValue(current);
|
AssertPastValue(current);
|
||||||
|
|
||||||
|
@ -499,8 +506,9 @@ JSONParser::advanceAfterArrayElement()
|
||||||
return token(Error);
|
return token(Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::advancePropertyName()
|
JSONParser<CharT>::advancePropertyName()
|
||||||
{
|
{
|
||||||
JS_ASSERT(current[-1] == ',');
|
JS_ASSERT(current[-1] == ',');
|
||||||
|
|
||||||
|
@ -518,8 +526,9 @@ JSONParser::advancePropertyName()
|
||||||
return token(Error);
|
return token(Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::advancePropertyColon()
|
JSONParser<CharT>::advancePropertyColon()
|
||||||
{
|
{
|
||||||
JS_ASSERT(current[-1] == '"');
|
JS_ASSERT(current[-1] == '"');
|
||||||
|
|
||||||
|
@ -539,8 +548,9 @@ JSONParser::advancePropertyColon()
|
||||||
return token(Error);
|
return token(Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
JSONParserBase::Token
|
JSONParserBase::Token
|
||||||
JSONParser::advanceAfterProperty()
|
JSONParser<CharT>::advanceAfterProperty()
|
||||||
{
|
{
|
||||||
AssertPastValue(current);
|
AssertPastValue(current);
|
||||||
|
|
||||||
|
@ -645,8 +655,9 @@ JSONParserBase::finishArray(MutableHandleValue vp, ElementVector &elements)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
bool
|
bool
|
||||||
JSONParser::parse(MutableHandleValue vp)
|
JSONParser<CharT>::parse(MutableHandleValue vp)
|
||||||
{
|
{
|
||||||
RootedValue value(cx);
|
RootedValue value(cx);
|
||||||
JS_ASSERT(stack.empty());
|
JS_ASSERT(stack.empty());
|
||||||
|
@ -815,3 +826,5 @@ JSONParser::parse(MutableHandleValue vp)
|
||||||
vp.set(value);
|
vp.set(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template class js::JSONParser<jschar>;
|
||||||
|
|
|
@ -178,17 +178,20 @@ class MOZ_STACK_CLASS JSONParserBase : private JS::AutoGCRooter
|
||||||
void operator=(const JSONParserBase &other) MOZ_DELETE;
|
void operator=(const JSONParserBase &other) MOZ_DELETE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
class MOZ_STACK_CLASS JSONParser : public JSONParserBase
|
class MOZ_STACK_CLASS JSONParser : public JSONParserBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
JS::ConstTwoByteChars current;
|
typedef mozilla::RangedPtr<const CharT> CharPtr;
|
||||||
const JS::ConstTwoByteChars begin, end;
|
|
||||||
|
CharPtr current;
|
||||||
|
const CharPtr begin, end;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Public API */
|
/* Public API */
|
||||||
|
|
||||||
/* Create a parser for the provided JSON data. */
|
/* Create a parser for the provided JSON data. */
|
||||||
JSONParser(JSContext *cx, JS::ConstTwoByteChars data, size_t length,
|
JSONParser(JSContext *cx, CharPtr data, size_t length,
|
||||||
ErrorHandling errorHandling = RaiseError)
|
ErrorHandling errorHandling = RaiseError)
|
||||||
: JSONParserBase(cx, errorHandling),
|
: JSONParserBase(cx, errorHandling),
|
||||||
current(data),
|
current(data),
|
||||||
|
|
Загрузка…
Ссылка в новой задаче