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 |