tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

no-throw-cr-literal.rst (1243B)


      1 no-throw-cr-literal
      2 ===================
      3 
      4 This is similar to the ESLint built-in rule no-throw-literal. It disallows
      5 throwing Components.results code directly.
      6 
      7 Throwing bare literals is inferior to throwing Exception objects, which provide
      8 stack information.  Cr.ERRORs should be be passed as the second argument to
      9 ``Components.Exception()`` to create an Exception object with stack info, and
     10 the correct result property corresponding to the NS_ERROR that other code
     11 expects.
     12 Using a regular ``new Error()`` to wrap just turns it into a string and doesn't
     13 set the result property, so the errors can't be recognised.
     14 
     15 This option can be autofixed (``--fix``).
     16 
     17 .. code-block:: js
     18 
     19    performance.timing.navigationStart + performance.now()
     20 
     21 Often timing relative to the page load is adequate and that conversion may not
     22 be necessary.
     23 
     24 Examples of incorrect code for this rule:
     25 -----------------------------------------
     26 
     27 .. code-block:: js
     28 
     29   throw Cr.NS_ERROR_UNEXPECTED;
     30   throw Components.results.NS_ERROR_ABORT;
     31   throw new Error(Cr.NS_ERROR_NO_INTERFACE);
     32 
     33 Examples of correct code for this rule:
     34 ---------------------------------------
     35 
     36 .. code-block:: js
     37 
     38 	throw Components.Exception("Not implemented", Cr.NS_ERROR_NOT_IMPLEMENTED);