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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 { 66 {
67 } 67 }
68 68
69 String TextEncoder::encoding() const 69 String TextEncoder::encoding() const
70 { 70 {
71 String name = String(m_encoding.name()).lower(); 71 String name = String(m_encoding.name()).lower();
72 ASSERT(name == "utf-8" || name == "utf-16le" || name == "utf-16be"); 72 ASSERT(name == "utf-8" || name == "utf-16le" || name == "utf-16be");
73 return name; 73 return name;
74 } 74 }
75 75
76 PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input) 76 PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input, ExceptionStat e& exceptionState)
77 { 77 {
78 CString result; 78 CString result;
79 if (input.is8Bit()) 79 if (input.is8Bit())
80 result = m_codec->encode(input.characters8(), input.length(), WTF::Quest ionMarksForUnencodables); 80 result = m_codec->encode(input.characters8(), input.length(), WTF::Quest ionMarksForUnencodables);
81 else 81 else
82 result = m_codec->encode(input.characters16(), input.length(), WTF::Ques tionMarksForUnencodables); 82 result = m_codec->encode(input.characters16(), input.length(), WTF::Ques tionMarksForUnencodables);
83 83
84 const char* buffer = result.data(); 84 const char* buffer = result.data();
85 const unsigned char* unsignedBuffer = reinterpret_cast<const unsigned char*> (buffer); 85 const unsigned char* unsignedBuffer = reinterpret_cast<const unsigned char*> (buffer);
86 86
87 return DOMUint8Array::create(unsignedBuffer, result.length()); 87 // TODO(junov): crbug.com/536816
88 // We should probably use createOrNull here and throw a RangeError exception
89 // when the buffer allocation fails. The rationale for this is that the ECM AScript
90 // specification states that a RangeError exception should be thrown:
91 // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock
92 // However, the spec for TextEncoder.encode does not state that exceptions
93 // thrown by procedures referenced by the algorithm should be rethrown. It
94 // probably should.
95 return DOMUint8Array::deprecatedCreateOrCrash(unsignedBuffer, result.length( ));
88 } 96 }
89 97
90 } // namespace blink 98 } // namespace blink
OLDNEW
« 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