forked from mirrors/gecko-dev
Bug 1656359 - eliminate needless string flattening when calling JS_ParseJSON; r=peterv
JS_ParseJSON doesn't require a null-terminated buffer, so we shouldn't have to provide one. Differential Revision: https://phabricator.services.mozilla.com/D85475
This commit is contained in:
parent
01d89c4bd0
commit
0050523469
3 changed files with 3 additions and 7 deletions
|
|
@ -2115,8 +2115,7 @@ bool DictionaryBase::ParseJSON(JSContext* aCx, const nsAString& aJSON,
|
|||
if (aJSON.IsEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return JS_ParseJSON(aCx, PromiseFlatString(aJSON).get(), aJSON.Length(),
|
||||
aVal);
|
||||
return JS_ParseJSON(aCx, aJSON.BeginReading(), aJSON.Length(), aVal);
|
||||
}
|
||||
|
||||
bool DictionaryBase::StringifyToJSON(JSContext* aCx, JS::Handle<JSObject*> aObj,
|
||||
|
|
|
|||
|
|
@ -50,9 +50,7 @@ nsresult DeserializeToJSObject(const nsAString& aSerializedObject,
|
|||
nsresult DeserializeToJSValue(const nsAString& aSerializedObject,
|
||||
JSContext* aCx, JS::MutableHandleValue aValue) {
|
||||
MOZ_ASSERT(aCx);
|
||||
if (!JS_ParseJSON(aCx,
|
||||
static_cast<const char16_t*>(
|
||||
PromiseFlatString(aSerializedObject).get()),
|
||||
if (!JS_ParseJSON(aCx, aSerializedObject.BeginReading(),
|
||||
aSerializedObject.Length(), aValue)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,8 +225,7 @@ void ReportingHeader::ReportingFromChannel(nsIHttpChannel* aChannel) {
|
|||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> jsonValue(cx);
|
||||
bool ok = JS_ParseJSON(cx, PromiseFlatString(json).get(), json.Length(),
|
||||
&jsonValue);
|
||||
bool ok = JS_ParseJSON(cx, json.BeginReading(), json.Length(), &jsonValue);
|
||||
if (!ok) {
|
||||
LogToConsoleInvalidJSON(aChannel, aURI);
|
||||
return nullptr;
|
||||
|
|
|
|||
Loading…
Reference in a new issue