123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: Exception.js</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
- </head>
- <body>
- <div id="main">
- <h1 class="page-title">Source: Exception.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>// Licensed Materials - Property of IBM
- //
- // IBM Watson Analytics
- //
- // (C) Copyright IBM Corp. 2015
- //
- // US Government Users Restricted Rights - Use, duplication or
- // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- module.exports = ( function( Error, decl )
- {
- "use strict";
- /**
- * Interprets a line of a stack trace and tries to extract information from it.
- * @param {string} _line The line to interpret
- * @memberof module:barejs.Exception~
- * @private
- */
- /*istanbul ignore next: NodeJS has the Error.captureStackTrace method natively so this function will not be hit*/
- function splitStackLine( _line )
- {
- /*
- Expected input looks like:
- myFunction@http://my.domain.com:8080/my/site/script.js:120:8 (Firefox, Safari)
- @http://my.domain.com:8080/my/site/script.js:120:8 (Firefox)
- http://my.domain.com:8080/my/site/script.js:120:8 (Safari)
- */
- if ( !_line )
- return null;
- var line = String( _line );
- var result = new Array( 4 );
- // Try to find a name (can be empty string)
- var match = line.match( /^([^@]*)@/ );
- result[0] = null;
- if ( match )
- {
- result[0] = match[1] || null;
- // Chop off the <functionName>@ part
- line = line.substr( match[0].length );
- }
- // Try to find line and column number
- match = line.match( /(:[0-9]+)?:([0-9]+)$/ );
- if ( match )
- {
- if ( match[1] )
- {
- result[2] = parseInt( match[1].substr( 1 ), 10 );
- result[3] = parseInt( match[2], 10 ) - 1;
- }
- else
- {
- result[2] = parseInt( match[2], 10 );
- result[3] = null;
- }
- // Chop off the :LineNumber:ColumnNumber part
- line = line.substr( 0, line.length - match[0].length );
- }
- // The result should be the filename
- result[1] = line;
- return result;
- }
- /*istanbul ignore next: NodeJS has the Error.captureStackTrace method natively so this function will not be hit*/
- function processStack( _obj, _ctor, _err )
- {
- var fileName, lineNumber, columnNumber; // Additional metadata
- var line, match; // used to parse the stack entries
- var stack = _err.stack.split( "\n" ); // Split version of _err.stack
- // Initialize fileName etc. to null
- fileName = lineNumber = columnNumber = null;
- if ( _ctor.name )
- {
- for ( line = 0; line < stack.length; ++line )
- {
- if ( stack[line].startsWith( _ctor.name + "@" ) )
- break;
- }
- // Never remove the last entry
- if ( line >= ( stack.length - 1 ) )
- line = -1;
- }
- else
- {
- // We know for a fact the lowest entry can be ignored, unless it's the only entry
- line = ( stack.length === 1 ) ? -1 : 0;
- }
- // If we get here and line >= 0, we can remove those entries
- if ( line >= 0 )
- {
- stack = stack.slice( line + 1 );
- match = splitStackLine( stack[0] );
- if ( match )
- {
- fileName = match[1];
- lineNumber = match[2];
- columnNumber = match[3];
- }
- }
- decl.defineProperty( _obj, "stack", { configurable: true, value: stack.join( "\n" ) } );
- if ( fileName )
- {
- decl.defineProperties( _obj,
- {
- fileName: { configurable: true, value: fileName },
- lineNumber: { configurable: true, value: lineNumber },
- columnNumber: { configurable: true, value: columnNumber }
- } );
- }
- }
- /*istanbul ignore next: NodeJS has the Error.captureStackTrace method natively so this function will not be hit*/
- function captureStackTrace( _obj, _ctor, _err )
- {
- if ( "stack" in _err )
- processStack( _obj, _ctor, _err );
- // if ( "opera#sourceLoc" in _err ) // Opera support?
- }
- /**
- * The Exception constructor will set up the exception with a name and stack property. You can pass the "creator function"
- * as second argument, this is the topmost function that will be ignored from the stack. It defaults to the constructed
- * object's constructor, which ensures the "Exception" and parent constructors never show up in the stack.
- * @class module:barejs.Exception
- * @param {string} _message The message that describes the exception.
- * @param {function} [_creatorFn] Optional: function to exclude from the call stack.
- * Defaults to the this.constructor function.
- *
- * @classdesc Exception creates a normalized base class for creating custom Error (Exception) classes to throw.
- * It handles determining the stack trace for the created exception in a cross browser way.
- * This class relies on the constructor property being set correctly, otherwise sub-class constructors
- * may show up in the stack trace. Using {@link module:barejs.decl#declareClass decl.declareClass}
- * to define base classes ensures the constructor property is set correctly.
- *
- * Sub classes should also set the name property on the prototype to the name of the exception, for example:
- *
- * function MyCustomError( _message, _myAdditionalData )
- * {
- * Exception.call( this, _message );
- *
- * this.myAdditionalData = _myAdditionalData;
- * }
- *
- * decl.declareClass( MyCustomError, Exception,
- * {
- * // Setting the name ensures our custom error looks and behaves as expected
- * // Avoid using MyCustomError.name (named function name) as the name may get
- * // mangled by a minifier/uglifier.
- * name: "MyCustomError",
- *
- * myAdditionalData: null
- * } );
- *
- */
- function Exception( _message/*, _creatorFn*/ )
- {
- if ( !this || !( this instanceof Exception ) )
- throw new TypeError( "Invalid context for Exception. Did you forget the new keyword?" );
- var fn = arguments[1] || this.constructor;
- if ( typeof fn !== "function" )
- throw new TypeError( "_creatorFn must be omitted, null or a function." );
- /*istanbul ignore else: NodeJS has the Error.captureStackTrace method natively*/
- if ( Error.captureStackTrace )
- Error.captureStackTrace( this, fn );
- else
- captureStackTrace( this, fn, new Error() );
- decl.defineProperty( this, "message", { configurable: true, writable: true, value: _message } );
- }
- return decl.declareClass( Exception, Error,
- /** @lends module:barejs.Exception# */
- {
- /**
- * The name of the Exception type. Base classes are supposed to set the correct name on the prototype too.
- * It is recommended not to use the constructor function's name for this, as that might get obfuscated by
- * a minifier, or the name property may not be supported at all.
- * @member {string}
- */
- name: { configurable: true, writable: true, value: "Exception" }
- } );
- // End of module
- }( Error, require( "./decl" ) ) );
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-barejs.html">barejs</a></li><li><a href="module-barejs_polyfill.html">barejs/polyfill</a></li><li><a href="module-barejs_polyfill_Intl.html">barejs/polyfill/Intl</a></li></ul><h3>Classes</h3><ul><li><a href="module-barejs.decl.html">decl</a></li><li><a href="module-barejs.decl-Enum.html">Enum</a></li><li><a href="module-barejs.decl-Interface.html">Interface</a></li><li><a href="module-barejs.decl-SpecialType.html">SpecialType</a></li><li><a href="module-barejs.Destroyable.html">Destroyable</a></li><li><a href="module-barejs.EventArgs.html">EventArgs</a></li><li><a href="module-barejs.Evented.html">Evented</a></li><li><a href="module-barejs.Evented-EventedHandle.html">EventedHandle</a></li><li><a href="module-barejs.Exception.html">Exception</a></li><li><a href="module-barejs_polyfill.Array.html">Array</a></li><li><a href="module-barejs_polyfill.Date.html">Date</a></li><li><a href="module-barejs_polyfill.EntryStore.html">EntryStore</a></li><li><a href="module-barejs_polyfill.EntryStore.Iterator.html">Iterator</a></li><li><a href="module-barejs_polyfill.Function.html">Function</a></li><li><a href="module-barejs_polyfill.Map.html">Map</a></li><li><a href="module-barejs_polyfill.Map-MapIterator.html">MapIterator</a></li><li><a href="module-barejs_polyfill.Math.html">Math</a></li><li><a href="module-barejs_polyfill.Number.html">Number</a></li><li><a href="module-barejs_polyfill.Object.html">Object</a></li><li><a href="module-barejs_polyfill.Promise.html">Promise</a></li><li><a href="module-barejs_polyfill.Set.html">Set</a></li><li><a href="module-barejs_polyfill.Set-SetIterator.html">SetIterator</a></li><li><a href="module-barejs_polyfill.String.html">String</a></li><li><a href="module-barejs_polyfill.Symbol.html">Symbol</a></li><li><a href="module-barejs_polyfill.WeakMap.html">WeakMap</a></li><li><a href="module-barejs_polyfill.WeakSet.html">WeakSet</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat.html">DateTimeFormat</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat-DateTimeFormatOptions.html">DateTimeFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat.html">NumberFormat</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat-NumberFormatOptions.html">NumberFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl-Format.html">Format</a></li></ul>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 03 2018 15:59:33 GMT+0200 (W. Europe Daylight Time)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|