зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1023778 part 8 - Address review comments. r=Waldo
This commit is contained in:
Родитель
466585b4b2
Коммит
5cfffe50d0
|
@ -7,6 +7,7 @@
|
|||
#include "builtin/Eval.h"
|
||||
|
||||
#include "mozilla/HashFunctions.h"
|
||||
#include "mozilla/Range.h"
|
||||
|
||||
#include "jscntxt.h"
|
||||
#include "jsonparser.h"
|
||||
|
@ -20,6 +21,7 @@ using namespace js;
|
|||
|
||||
using mozilla::AddToHash;
|
||||
using mozilla::HashString;
|
||||
using mozilla::Range;
|
||||
|
||||
// We should be able to assert this for *any* fp->scopeChain().
|
||||
static void
|
||||
|
@ -173,9 +175,10 @@ TryEvalJSON(JSContext *cx, JSScript *callerScript,
|
|||
|
||||
if (cp == end) {
|
||||
bool isArray = (chars[0] == '[');
|
||||
JSONParser<jschar> parser(cx, isArray ? chars : chars + 1U,
|
||||
isArray ? length : length - 2,
|
||||
JSONParserBase::NoError);
|
||||
auto jsonChars = isArray
|
||||
? Range<const jschar>(chars.get(), length)
|
||||
: Range<const jschar>(chars.get() + 1U, length - 2);
|
||||
JSONParser<jschar> parser(cx, jsonChars, JSONParserBase::NoError);
|
||||
RootedValue tmp(cx);
|
||||
if (!parser.parse(&tmp))
|
||||
return EvalJSON_Failure;
|
||||
|
|
|
@ -778,7 +778,7 @@ js::ParseJSONWithReviver(JSContext *cx, mozilla::Range<const CharT> chars,
|
|||
HandleValue reviver, MutableHandleValue vp)
|
||||
{
|
||||
/* 15.12.2 steps 2-3. */
|
||||
JSONParser<CharT> parser(cx, chars.start(), chars.length());
|
||||
JSONParser<CharT> parser(cx, chars);
|
||||
if (!parser.parse(vp))
|
||||
return false;
|
||||
|
||||
|
@ -832,13 +832,9 @@ json_parse(JSContext *cx, unsigned argc, Value *vp)
|
|||
RootedValue reviver(cx, args.get(1));
|
||||
|
||||
/* Steps 2-5. */
|
||||
if (flatChars.isLatin1()) {
|
||||
mozilla::Range<const Latin1Char> chars(flatChars.latin1Chars(), flat->length());
|
||||
return ParseJSONWithReviver(cx, chars, reviver, args.rval());
|
||||
}
|
||||
|
||||
mozilla::Range<const jschar> chars(flatChars.twoByteChars(), flat->length());
|
||||
return ParseJSONWithReviver(cx, chars, reviver, args.rval());
|
||||
return flatChars.isLatin1()
|
||||
? ParseJSONWithReviver(cx, flatChars.latin1Range(), reviver, args.rval())
|
||||
: ParseJSONWithReviver(cx, flatChars.twoByteRange(), reviver, args.rval());
|
||||
}
|
||||
|
||||
/* ES5 15.12.3. */
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define jsonparser_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Range.h"
|
||||
|
||||
#include "jspubtd.h"
|
||||
|
||||
|
@ -191,12 +192,12 @@ class MOZ_STACK_CLASS JSONParser : public JSONParserBase
|
|||
/* Public API */
|
||||
|
||||
/* Create a parser for the provided JSON data. */
|
||||
JSONParser(JSContext *cx, CharPtr data, size_t length,
|
||||
JSONParser(JSContext *cx, mozilla::Range<const CharT> data,
|
||||
ErrorHandling errorHandling = RaiseError)
|
||||
: JSONParserBase(cx, errorHandling),
|
||||
current(data),
|
||||
begin(data),
|
||||
end((data + length).get(), data.get(), length)
|
||||
current(data.start()),
|
||||
begin(current),
|
||||
end(data.end())
|
||||
{
|
||||
JS_ASSERT(current <= end);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
#include "mozilla/Range.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
|
@ -1086,14 +1087,14 @@ class MOZ_STACK_CLASS AutoStableStringChars
|
|||
bool isLatin1() const { return state_ == Latin1; }
|
||||
bool isTwoByte() const { return state_ == TwoByte; }
|
||||
|
||||
const JS::Latin1Char *latin1Chars() const {
|
||||
mozilla::Range<const Latin1Char> latin1Range() const {
|
||||
MOZ_ASSERT(state_ == Latin1);
|
||||
return latin1Chars_;
|
||||
return mozilla::Range<const Latin1Char>(latin1Chars_, s_->length());
|
||||
}
|
||||
|
||||
const jschar *twoByteChars() const {
|
||||
mozilla::Range<const jschar> twoByteRange() const {
|
||||
MOZ_ASSERT(state_ == TwoByte);
|
||||
return twoByteChars_;
|
||||
return mozilla::Range<const jschar>(twoByteChars_, s_->length());
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
Загрузка…
Ссылка в новой задаче