Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | define( function() { |
| 2 | |
| 3 | "use strict"; |
| 4 | |
| 5 | function addGetHookIf( conditionFn, hookFn ) { |
| 6 | |
| 7 | // Define the hook, we'll check on the first run if it's really needed. |
| 8 | return { |
| 9 | get: function() { |
| 10 | if ( conditionFn() ) { |
| 11 | |
| 12 | // Hook not needed (or it's not possible to use it due |
| 13 | // to missing dependency), remove it. |
| 14 | delete this.get; |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | // Hook needed; redefine it so that the support test is not executed again. |
| 19 | return ( this.get = hookFn ).apply( this, arguments ); |
| 20 | } |
| 21 | }; |
| 22 | } |
| 23 | |
| 24 | return addGetHookIf; |
| 25 | |
| 26 | } ); |