mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 446132 - Allocate nsJSONWriter on the stack, r=sayrer sr=jst
This commit is contained in:
parent
2ffbc6aee8
commit
73948e4e37
@ -87,22 +87,19 @@ nsJSON::Encode(nsAString &aJSON)
|
||||
// This function should only be called from JS.
|
||||
nsresult rv;
|
||||
|
||||
nsAutoPtr<nsJSONWriter> writer(new nsJSONWriter());
|
||||
if (!writer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = EncodeInternal(writer);
|
||||
nsJSONWriter writer;
|
||||
rv = EncodeInternal(&writer);
|
||||
|
||||
// FIXME: bug 408838. Get exception types sorted out
|
||||
if (NS_SUCCEEDED(rv) || rv == NS_ERROR_INVALID_ARG) {
|
||||
rv = NS_OK;
|
||||
// if we didn't consume anything, it's not JSON, so return null
|
||||
if (!writer->DidWrite()) {
|
||||
if (!writer.DidWrite()) {
|
||||
aJSON.Truncate();
|
||||
aJSON.SetIsVoid(PR_TRUE);
|
||||
} else {
|
||||
writer->FlushBuffer();
|
||||
aJSON.Append(writer->mOutputString);
|
||||
writer.FlushBuffer();
|
||||
aJSON.Append(writer.mOutputString);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,13 +169,11 @@ nsJSON::EncodeToStream(nsIOutputStream *aStream,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
nsAutoPtr<nsJSONWriter> writer(new nsJSONWriter(bufferedStream));
|
||||
if (!writer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = writer->SetCharset(aCharset);
|
||||
nsJSONWriter writer(bufferedStream);
|
||||
rv = writer.SetCharset(aCharset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = EncodeInternal(writer);
|
||||
rv = EncodeInternal(&writer);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = bufferedStream->Flush();
|
||||
|
@ -55,7 +55,7 @@ class nsIURI;
|
||||
#define JSON_MAX_DEPTH 2048
|
||||
#define JSON_PARSER_BUFSIZE 1024
|
||||
|
||||
class nsJSONWriter
|
||||
class NS_STACK_CLASS nsJSONWriter
|
||||
{
|
||||
public:
|
||||
nsJSONWriter();
|
||||
|
Loading…
Reference in New Issue
Block a user