Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var GetAvailability = requireNative('v8_context').GetAvailability; | 5 var GetAvailability = requireNative('v8_context').GetAvailability; |
| 6 var GetGlobal = requireNative('sendRequest').GetGlobal; | 6 var GetGlobal = requireNative('sendRequest').GetGlobal; |
| 7 | 7 |
| 8 // Utility for setting chrome.*.lastError. | 8 // Utility for setting chrome.*.lastError. |
| 9 // | 9 // |
| 10 // A utility here is useful for two reasons: | 10 // A utility here is useful for two reasons: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 * Check whether there is an error set on |targetChrome| without setting | 61 * Check whether there is an error set on |targetChrome| without setting |
| 62 * |accessedLastError|. | 62 * |accessedLastError|. |
| 63 * @param {Object} targetChrome the Chrome object to check. | 63 * @param {Object} targetChrome the Chrome object to check. |
| 64 * @return boolean Whether lastError has been set. | 64 * @return boolean Whether lastError has been set. |
| 65 */ | 65 */ |
| 66 function hasError(targetChrome) { | 66 function hasError(targetChrome) { |
| 67 if (!targetChrome) | 67 if (!targetChrome) |
| 68 throw new Error('No target chrome to check'); | 68 throw new Error('No target chrome to check'); |
| 69 | 69 |
| 70 assertRuntimeIsAvailable(); | 70 assertRuntimeIsAvailable(); |
| 71 if ('lastError' in targetChrome.runtime) | 71 return $Object.hasOwnProperty(targetChrome.runtime, 'lastError'); |
|
robwu
2016/04/23 09:54:38
Note that |targetChrome| is fully under control of
Devlin
2016/04/25 21:50:35
Yeah, this change was just because IIRC, 'in' actu
robwu
2016/04/25 22:25:53
hasOwnProperty is better than "in" because it only
Devlin
2016/04/25 22:35:00
Right, again this isn't to defend against anything
| |
| 72 return true; | |
| 73 | |
| 74 return false; | |
| 75 }; | 72 }; |
| 76 | 73 |
| 77 /** | 74 /** |
| 78 * Clears the last error on |targetChrome|. | 75 * Clears the last error on |targetChrome|. |
| 79 */ | 76 */ |
| 80 function clear(targetChrome) { | 77 function clear(targetChrome) { |
| 81 if (!targetChrome) | 78 if (!targetChrome) |
| 82 throw new Error('No target chrome to clear error'); | 79 throw new Error('No target chrome to clear error'); |
| 83 | 80 |
| 84 if (GetAvailability('extension.lastError').is_available) | 81 if (GetAvailability('extension.lastError').is_available) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 console.error("Unchecked runtime.lastError while running " + | 131 console.error("Unchecked runtime.lastError while running " + |
| 135 (name || "unknown") + ": " + message + (stack ? "\n" + stack : "")); | 132 (name || "unknown") + ": " + message + (stack ? "\n" + stack : "")); |
| 136 } | 133 } |
| 137 | 134 |
| 138 exports.$set('clear', clear); | 135 exports.$set('clear', clear); |
| 139 exports.$set('hasAccessed', hasAccessed); | 136 exports.$set('hasAccessed', hasAccessed); |
| 140 exports.$set('hasError', hasError); | 137 exports.$set('hasError', hasError); |
| 141 exports.$set('set', set); | 138 exports.$set('set', set); |
| 142 exports.$set('run', run); | 139 exports.$set('run', run); |
| 143 exports.$set('reportIfUnchecked', reportIfUnchecked); | 140 exports.$set('reportIfUnchecked', reportIfUnchecked); |
| OLD | NEW |