Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1039)

Unified Diff: third_party/WebKit/Source/modules/encoding/TextEncoder.cpp

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+more tweaks Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/encoding/TextEncoder.cpp
diff --git a/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp b/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp
index fdb5fc5c4fbd6c3b49a1f4651409ff31baececfc..13450da4d39a005055083707a11f000b37735b7e 100644
--- a/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp
+++ b/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp
@@ -73,7 +73,7 @@ String TextEncoder::encoding() const
return name;
}
-PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input)
+PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input, ExceptionState& exceptionState)
{
CString result;
if (input.is8Bit())
@@ -84,7 +84,15 @@ PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input)
const char* buffer = result.data();
const unsigned char* unsignedBuffer = reinterpret_cast<const unsigned char*>(buffer);
- return DOMUint8Array::create(unsignedBuffer, result.length());
+ // TODO(junov): crbug.com/536816
+ // We should probably use createOrNull here and throw a RangeError exception
+ // when the buffer allocation fails. The rationale for this is that the ECMAScript
+ // specification states that a RangeError exception should be thrown:
+ // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock
+ // However, the spec for TextEncoder.encode does not state that exceptions
+ // thrown by procedures referenced by the algorithm should be rethrown. It
+ // probably should.
+ return DOMUint8Array::deprecatedCreateOrCrash(unsignedBuffer, result.length());
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/encoding/TextEncoder.h ('k') | third_party/WebKit/Source/modules/encoding/TextEncoder.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698