OLD | NEW |
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 else | 174 else |
175 m_resolver->reject(DOMException::create(ec, errorDetails)); | 175 m_resolver->reject(DOMException::create(ec, errorDetails)); |
176 clearResolver(); | 176 clearResolver(); |
177 } | 177 } |
178 | 178 |
179 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize) | 179 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize) |
180 { | 180 { |
181 if (!m_resolver) | 181 if (!m_resolver) |
182 return; | 182 return; |
183 | 183 |
184 m_resolver->resolve(DOMArrayBuffer::create(bytes, bytesSize)); | 184 // FIXME(crbug.com/536816): |
| 185 // Instead of crashing when array buffer allocation fails, we could |
| 186 // and probably should use DOMArrayBuffer::createOrNull and reject |
| 187 // the promise with a RangeError exception when crewation returns null. |
| 188 // The specs for all crypto methods that use this code state: "If the |
| 189 // following steps or referenced procedures say to throw an error, |
| 190 // reject promise with the returned error and then terminate the algorithm." |
| 191 // In this case, the procedure of allocating an ArrayBuffer is not explicitl
y |
| 192 // referenced in the algorithms laid out in the spec, but one could argue |
| 193 // that it is implied, and the ECMAScript spec says that failure to |
| 194 // allocate the buffer should result in a RangeError being thrown. |
| 195 // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock |
| 196 // The crypto spec probably needs to be edited to be more explicit about |
| 197 // this issue. |
| 198 m_resolver->resolve(DOMArrayBuffer::deprecatedCreateOrCrash(bytes, bytesSize
)); |
185 clearResolver(); | 199 clearResolver(); |
186 } | 200 } |
187 | 201 |
188 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) | 202 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) |
189 { | 203 { |
190 if (!m_resolver) | 204 if (!m_resolver) |
191 return; | 205 return; |
192 | 206 |
193 ScriptState* scriptState = m_resolver->scriptState(); | 207 ScriptState* scriptState = m_resolver->scriptState(); |
194 ScriptState::Scope scope(scriptState); | 208 ScriptState::Scope scope(scriptState); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 m_cancel.clear(); | 260 m_cancel.clear(); |
247 clearResolver(); | 261 clearResolver(); |
248 } | 262 } |
249 | 263 |
250 ScriptPromise CryptoResultImpl::promise() | 264 ScriptPromise CryptoResultImpl::promise() |
251 { | 265 { |
252 return m_resolver ? m_resolver->promise() : ScriptPromise(); | 266 return m_resolver ? m_resolver->promise() : ScriptPromise(); |
253 } | 267 } |
254 | 268 |
255 } // namespace blink | 269 } // namespace blink |
OLD | NEW |