sw-background-sync-queue
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -30,2 +30,315 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -51,3 +364,3 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
if (!parameters.some(parameter => object[parameter] !== undefined)) { | ||
throw Error('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
throwError('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
} | ||
@@ -60,3 +373,4 @@ } | ||
if (type !== 'function') { | ||
throw Error(`The '${parameter}' parameter must be an object that exposes ` + `a '${expectedMethod}' method.`); | ||
throwError(`The '${parameter}' parameter must be an object that exposes a | ||
'${expectedMethod}' method.`); | ||
} | ||
@@ -68,3 +382,4 @@ } | ||
if (!(object[parameter] instanceof expectedClass)) { | ||
throw Error(`The '${parameter}' parameter must be an instance of ` + `'${expectedClass.name}'`); | ||
throwError(`The '${parameter}' parameter must be an instance of | ||
'${expectedClass.name}'`); | ||
} | ||
@@ -76,3 +391,4 @@ } | ||
if (!values.includes(object[parameter])) { | ||
throw Error(`The '${parameter}' parameter must be set to one of the ` + `following: ${values}`); | ||
throwError(`The '${parameter}' parameter must be set to one of the | ||
following: ${values}`); | ||
} | ||
@@ -85,3 +401,4 @@ } | ||
if (actualType !== expectedType) { | ||
throw Error(`The '${parameter}' parameter has the wrong type. ` + `(Expected: ${expectedType}, actual: ${actualType})`); | ||
throwError(`The '${parameter}' parameter has the wrong type. (Expected: | ||
${expectedType}, actual: ${actualType})`); | ||
} | ||
@@ -98,6 +415,24 @@ } | ||
if (actualValue !== expectedValue) { | ||
throw Error(`The '${parameter}' parameter has the wrong value. ` + `(Expected: ${expectedValue}, actual: ${actualValue})`); | ||
throwError(`The '${parameter}' parameter has the wrong value. (Expected: | ||
${expectedValue}, actual: ${actualValue})`); | ||
} | ||
} | ||
function throwError(message) { | ||
const error = new Error(message); | ||
const stackFrames = errorStackParser.parse(error); | ||
// If, for some reason, we don't have all the stack information we need, | ||
// we'll just end up throwing a basic Error. | ||
if (stackFrames.length >= 3) { | ||
// Assuming we have the stack frames, set the message to include info | ||
// about what the underlying method was, and set the name to reflect | ||
// the assertion type that failed. | ||
error.message = `Invalid call to ${stackFrames[2].functionName}() — ` + message.replace(/\s+/g, ' '); | ||
error.name = stackFrames[1].functionName.replace(/^Object\./, ''); | ||
} | ||
throw error; | ||
} | ||
var assert = { | ||
@@ -135,6 +470,2 @@ atLeastOne, | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var idb = createCommonjsModule(function (module) { | ||
@@ -141,0 +472,0 @@ 'use strict'; |
@@ -15,3 +15,8 @@ /* | ||
*/ | ||
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b((a.goog=a.goog||{},a.goog.backgroundSyncQueue=a.goog.backgroundSyncQueue||{}))})(this,function(a){'use strict';function j(M){w.isType({dbName:M},'string'),x=M}function k(){return x}function m({broadcastChannel:M,type:N,url:O}){M&&(w.isInstance({broadcastChannel:M},BroadcastChannel),w.isType({type:N},'string'),w.isType({url:O},'string'),M.postMessage({type:N,meta:u,payload:{url:O}}))}const t='SW_BACKGROUND_QUEUE_TAG_',u='SW_BACKGROUND_SYNC_QUEUE',v='QUEUES';var w={atLeastOne:function(M){const N=Object.keys(M);if(!N.some((O)=>M[O]!==void 0))throw Error('Please set at least one of the following parameters: '+N.map((O)=>`'${O}'`).join(', '))},hasMethod:function(M,N){const O=Object.keys(M).pop(),P=typeof M[O][N];if('function'!=P)throw Error(`The '${O}' parameter must be an object that exposes `+`a '${N}' method.`)},isInstance:function(M,N){const O=Object.keys(M).pop();if(!(M[O]instanceof N))throw Error(`The '${O}' parameter must be an instance of `+`'${N.name}'`)},isOneOf:function(M,N){const O=Object.keys(M).pop();if(!N.includes(M[O]))throw Error(`The '${O}' parameter must be set to one of the `+`following: ${N}`)},isType:function(M,N){const O=Object.keys(M).pop(),P=typeof M[O];if(P!==N)throw Error(`The '${O}' parameter has the wrong type. `+`(Expected: ${N}, actual: ${P})`)},isSWEnv:function(){return'ServiceWorkerGlobalScope'in self&&self instanceof ServiceWorkerGlobalScope},isValue:function(M,N){const O=Object.keys(M).pop(),P=M[O];if(P!==N)throw Error(`The '${O}' parameter has the wrong value. `+`(Expected: ${N}, actual: ${P})`)}};let x='bgQueueSyncDB';var y=function(M,N){return N={exports:{}},M(N,N.exports),N.exports}(function(M){'use strict';(function(){function N(aa){return Array.prototype.slice.call(aa)}function O(aa){return new Promise(function(ba,ca){aa.onsuccess=function(){ba(aa.result)},aa.onerror=function(){ca(aa.error)}})}function P(aa,ba,ca){var da,ea=new Promise(function(fa,ga){da=aa[ba].apply(aa,ca),O(da).then(fa,ga)});return ea.request=da,ea}function Q(aa,ba,ca){var da=P(aa,ba,ca);return da.then(function(ea){return ea?new W(ea,da.request):void 0})}function R(aa,ba,ca){ca.forEach(function(da){Object.defineProperty(aa.prototype,da,{get:function(){return this[ba][da]},set:function(ea){this[ba][da]=ea}})})}function S(aa,ba,ca,da){da.forEach(function(ea){ea in ca.prototype&&(aa.prototype[ea]=function(){return P(this[ba],ea,arguments)})})}function T(aa,ba,ca,da){da.forEach(function(ea){ea in ca.prototype&&(aa.prototype[ea]=function(){return this[ba][ea].apply(this[ba],arguments)})})}function U(aa,ba,ca,da){da.forEach(function(ea){ea in ca.prototype&&(aa.prototype[ea]=function(){return Q(this[ba],ea,arguments)})})}function V(aa){this._index=aa}function W(aa,ba){this._cursor=aa,this._request=ba}function X(aa){this._store=aa}function Y(aa){this._tx=aa,this.complete=new Promise(function(ba,ca){aa.oncomplete=function(){ba()},aa.onerror=function(){ca(aa.error)},aa.onabort=function(){ca(aa.error)}})}function Z(aa,ba,ca){this._db=aa,this.oldVersion=ba,this.transaction=new Y(ca)}function $(aa){this._db=aa}R(V,'_index',['name','keyPath','multiEntry','unique']),S(V,'_index',IDBIndex,['get','getKey','getAll','getAllKeys','count']),U(V,'_index',IDBIndex,['openCursor','openKeyCursor']),R(W,'_cursor',['direction','key','primaryKey','value']),S(W,'_cursor',IDBCursor,['update','delete']),['advance','continue','continuePrimaryKey'].forEach(function(aa){aa in IDBCursor.prototype&&(W.prototype[aa]=function(){var ba=this,ca=arguments;return Promise.resolve().then(function(){return ba._cursor[aa].apply(ba._cursor,ca),O(ba._request).then(function(da){return da?new W(da,ba._request):void 0})})})}),X.prototype.createIndex=function(){return new V(this._store.createIndex.apply(this._store,arguments))},X.prototype.index=function(){return new V(this._store.index.apply(this._store,arguments))},R(X,'_store',['name','keyPath','indexNames','autoIncrement']),S(X,'_store',IDBObjectStore,['put','add','delete','clear','get','getAll','getKey','getAllKeys','count']),U(X,'_store',IDBObjectStore,['openCursor','openKeyCursor']),T(X,'_store',IDBObjectStore,['deleteIndex']),Y.prototype.objectStore=function(){return new X(this._tx.objectStore.apply(this._tx,arguments))},R(Y,'_tx',['objectStoreNames','mode']),T(Y,'_tx',IDBTransaction,['abort']),Z.prototype.createObjectStore=function(){return new X(this._db.createObjectStore.apply(this._db,arguments))},R(Z,'_db',['name','version','objectStoreNames']),T(Z,'_db',IDBDatabase,['deleteObjectStore','close']),$.prototype.transaction=function(){return new Y(this._db.transaction.apply(this._db,arguments))},R($,'_db',['name','version','objectStoreNames']),T($,'_db',IDBDatabase,['close']),['openCursor','openKeyCursor'].forEach(function(aa){[X,V].forEach(function(ba){ba.prototype[aa.replace('open','iterate')]=function(){var ca=N(arguments),da=ca[ca.length-1],ea=this._store||this._index,fa=ea[aa].apply(ea,ca.slice(0,-1));fa.onsuccess=function(){da(fa.result)}}})}),[V,X].forEach(function(aa){aa.prototype.getAll||(aa.prototype.getAll=function(ba,ca){var da=this,ea=[];return new Promise(function(fa){da.iterateCursor(ba,function(ga){return ga?(ea.push(ga.value),void 0!==ca&&ea.length==ca?void fa(ea):void ga.continue()):void fa(ea)})})})});M.exports={open:function(aa,ba,ca){var da=P(indexedDB,'open',[aa,ba]),ea=da.request;return ea.onupgradeneeded=function(fa){ca&&ca(new Z(ea.result,fa.oldVersion,ea.transaction))},da.then(function(fa){return new $(fa)})},delete:function(aa){return P(indexedDB,'deleteDatabase',[aa])}}})()});class z{constructor(M,N,O){if(M==void 0||N==void 0||O==void 0)throw Error('name, version, storeName must be passed to the constructor.');this._name=M,this._version=N,this._storeName=O}_getDb(){return this._dbPromise?this._dbPromise:(this._dbPromise=y.open(this._name,this._version,(M)=>{M.createObjectStore(this._storeName)}).then((M)=>{return M}),this._dbPromise)}close(){return this._dbPromise?this._dbPromise.then((M)=>{M.close(),this._dbPromise=null}):void 0}put(M,N){return this._getDb().then((O)=>{const P=O.transaction(this._storeName,'readwrite'),Q=P.objectStore(this._storeName);return Q.put(N,M),P.complete})}delete(M){return this._getDb().then((N)=>{const O=N.transaction(this._storeName,'readwrite'),P=O.objectStore(this._storeName);return P.delete(M),O.complete})}get(M){return this._getDb().then((N)=>{return N.transaction(this._storeName).objectStore(this._storeName).get(M)})}getAllValues(){return this._getDb().then((M)=>{return M.transaction(this._storeName).objectStore(this._storeName).getAll()})}getAllKeys(){return this._getDb().then((M)=>{return M.transaction(this._storeName).objectStore(this._storeName).getAllKeys()})}}var A=function(M){return function(){var N=M.apply(this,arguments);return new Promise(function(O,P){function Q(R,S){try{var T=N[R](S),U=T.value}catch(V){return void P(V)}return T.done?void O(U):Promise.resolve(U).then(function(V){Q('next',V)},function(V){Q('throw',V)})}return Q('next')})}};let B=(()=>{var M=A(function*({hash:N,idbObject:O,response:P,idbQDb:Q}){O.response={headers:JSON.stringify([...P.headers]),status:P.status,body:yield P.blob()},Q.put(N,O)});return function(){return M.apply(this,arguments)}})(),C=(()=>{var M=A(function*({id:N}){const O=new z(k(),1,'QueueStore'),P=yield O.get(N);return P&&P.response?P.response:null});return function(){return M.apply(this,arguments)}})(),D=(()=>{var M=A(function*({request:N,config:O}){let P={config:O,metadata:{creationTimestamp:Date.now()},request:{url:N.url,headers:JSON.stringify([...N.headers]),mode:N.mode,method:N.method,redirect:N.redirect}};const Q=yield N.text();return 0<Q.length&&(P.request.body=Q),P});return function(){return M.apply(this,arguments)}})(),E=(()=>{var M=A(function*({idbRequestObject:N}){let O={mode:N.mode,method:N.method,redirect:N.redirect,headers:new Headers(JSON.parse(N.headers))};return N.body&&(O.body=N.body),new Request(N.url,O)});return function(){return M.apply(this,arguments)}})(),F=(()=>{var M=A(function*(){let N=new z(k(),1,'QueueStore'),O=yield N.get(v);return O?void(yield Promise.all(O.map((()=>{var P=A(function*(Q){const R=yield N.get(Q);let S=[],T=[];yield Promise.all(R.map((()=>{var U=A(function*(V){const W=yield N.get(V);W&&W.metadata&&W.metadata.creationTimestamp+W.config.maxAge<=Date.now()?T.push(N.delete(V)):S.push(V)});return function(){return U.apply(this,arguments)}})())),yield Promise.all(T),N.put(Q,S)});return function(){return P.apply(this,arguments)}})()))):null});return function(){return M.apply(this,arguments)}})();class G{constructor({callbacks:M,queue:N}){this._globalCallbacks=M||{},this._queue=N,this.attachSyncHandler()}attachSyncHandler(){self.addEventListener('sync',(M)=>{M.tag===t+this._queue.queueName&&M.waitUntil(this.replayRequests())})}replayRequests(){var M=this;return this._queue.queue.reduce((N,O)=>{return N.then((()=>{var P=A(function*(){const R=yield M._queue.getRequestFromQueue({hash:O});if(!R.response){const S=yield E({idbRequestObject:R.request});return fetch(S).then(function(T){return T.ok?void(B({hash:O,idbObject:R,response:T.clone(),idbQDb:M._queue.idbQDb}),M._globalCallbacks.onResponse&&M._globalCallbacks.onResponse(O,T)):Promise.resolve()}).catch(function(T){M._globalCallbacks.onRetryFailure&&M._globalCallbacks.onRetryFailure(O,T)})}});return function(){return P.apply(this,arguments)}})())},Promise.resolve())}}let H=0,I=0;class J{constructor({config:M,queueName:P='DEFAULT_QUEUE'+'_'+I++,idbQDb:N,broadcastChannel:O}){this._isQueueNameAddedToAllQueue=!1,this._queueName=P,this._config=M,this._idbQDb=N,this._broadcastChannel=O,this._queue=[],this.initQueue()}initQueue(){var M=this;return A(function*(){const N=yield M._idbQDb.get(M._queueName);M._queue.concat(N)})()}addQueueNameToAllQueues(){var M=this;return A(function*(){if(!M._isQueueNameAddedToAllQueue){let N=yield M._idbQDb.get(v);N=N||[],N.includes(M._queueName)||N.push(M._queueName),M._idbQDb.put(v,N),M._isQueueNameAddedToAllQueue=!0}})()}saveQueue(){var M=this;return A(function*(){yield M._idbQDb.put(M._queueName,M._queue)})()}push({request:M}){var N=this;return A(function*(){w.isInstance({request:M},Request);const O=`${M.url}!${Date.now()}!${H++}`,P=yield D({request:M,config:N._config});try{N._queue.push(O),N.saveQueue(),N._idbQDb.put(O,P),yield N.addQueueNameToAllQueues(),self.registration&&self.registration.sync.register(t+N._queueName),m({broadcastChannel:N._broadcastChannel,type:'BACKGROUND_REQUESTED_ADDED',id:O,url:M.url})}catch(Q){m({broadcastChannel:N._broadcastChannel,type:'BACKGROUND_REQUESTED_FAILED',id:O,url:M.url})}})()}getRequestFromQueue({hash:M}){var N=this;return A(function*(){if(w.isType({hash:M},'string'),N._queue.includes(M))return yield N._idbQDb.get(M)})()}get queue(){return Object.assign([],this._queue)}get queueName(){return this._queueName}get idbQDb(){return this._idbQDb}}let L=(()=>{var M=A(function*({dbName:N}={}){N&&(w.isType({dbName:N},'string'),j(N)),yield F()});return function(){return M.apply(this,arguments)}})();a.initialize=L,a.getResponse=C,a.BackgroundSyncQueue=class{constructor({maxRetentionTime:P=432000000,callbacks:M,queueName:N,broadcastChannel:O}={}){N&&w.isType({queueName:N},'string'),P&&w.isType({maxRetentionTime:P},'number'),O&&w.isInstance({broadcastChannel:O},BroadcastChannel),this._queue=new J({config:{maxAge:P},queueName:N,idbQDb:new z(k(),1,'QueueStore'),broadcastChannel:O}),this._requestManager=new G({callbacks:M,queue:this._queue})}pushIntoQueue({request:M}){return w.isInstance({request:M},Request),this._queue.push({request:M})}fetchDidFail({request:M}){return this.pushIntoQueue({request:M})}},Object.defineProperty(a,'__esModule',{value:!0})}); | ||
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b((a.goog=a.goog||{},a.goog.backgroundSyncQueue=a.goog.backgroundSyncQueue||{}))})(this,function(a){'use strict';function createCommonjsModule(F,G){return G={exports:{}},F(G,G.exports),G.exports}function throwError(F){const G=new Error(F),H=r.parse(G);throw 3<=H.length&&(G.message=`Invalid call to ${H[2].functionName}() — `+F.replace(/\s+/g,' '),G.name=H[1].functionName.replace(/^Object\./,'')),G}function setDbName(F){s.isType({dbName:F},'string'),t=F}function getDbName(){return t}function broadcastMessage({broadcastChannel:F,type:G,url:H}){F&&(s.isInstance({broadcastChannel:F},BroadcastChannel),s.isType({type:G},'string'),s.isType({url:H},'string'),F.postMessage({type:G,meta:l,payload:{url:H}}))}const h='SW_BACKGROUND_QUEUE_TAG_',l='SW_BACKGROUND_SYNC_QUEUE',m='QUEUES';var o='undefined'==typeof window?'undefined'==typeof global?'undefined'==typeof self?{}:self:global:window,q=createCommonjsModule(function(F){(function(H,I){'use strict';F.exports=I()})(o,function(){'use strict';function _isNumber(O){return!isNaN(parseFloat(O))&&isFinite(O)}function _capitalize(O){return O[0].toUpperCase()+O.substring(1)}function _getter(O){return function(){return this[O]}}function StackFrame(O){if(O instanceof Object)for(var P=H.concat(I.concat(J.concat(K))),Q=0;Q<P.length;Q++)O.hasOwnProperty(P[Q])&&void 0!==O[P[Q]]&&this['set'+_capitalize(P[Q])](O[P[Q]])}var H=['isConstructor','isEval','isNative','isToplevel'],I=['columnNumber','lineNumber'],J=['fileName','functionName','source'],K=['args'];StackFrame.prototype={getArgs:function(){return this.args},setArgs:function(O){if('[object Array]'!==Object.prototype.toString.call(O))throw new TypeError('Args must be an Array');this.args=O},getEvalOrigin:function(){return this.evalOrigin},setEvalOrigin:function(O){if(O instanceof StackFrame)this.evalOrigin=O;else if(O instanceof Object)this.evalOrigin=new StackFrame(O);else throw new TypeError('Eval Origin must be an Object or StackFrame')},toString:function(){var O=this.getFunctionName()||'{anonymous}',P='('+(this.getArgs()||[]).join(',')+')',Q=this.getFileName()?'@'+this.getFileName():'',R=_isNumber(this.getLineNumber())?':'+this.getLineNumber():'',S=_isNumber(this.getColumnNumber())?':'+this.getColumnNumber():'';return O+P+Q+R+S}};for(var L=0;L<H.length;L++)StackFrame.prototype['get'+_capitalize(H[L])]=_getter(H[L]),StackFrame.prototype['set'+_capitalize(H[L])]=function(O){return function(P){this[O]=!!P}}(H[L]);for(var M=0;M<I.length;M++)StackFrame.prototype['get'+_capitalize(I[M])]=_getter(I[M]),StackFrame.prototype['set'+_capitalize(I[M])]=function(O){return function(P){if(!_isNumber(P))throw new TypeError(O+' must be a Number');this[O]=+P}}(I[M]);for(var N=0;N<J.length;N++)StackFrame.prototype['get'+_capitalize(J[N])]=_getter(J[N]),StackFrame.prototype['set'+_capitalize(J[N])]=function(O){return function(P){this[O]=P+''}}(J[N]);return StackFrame})}),r=createCommonjsModule(function(F){(function(H,I){'use strict';F.exports=I(q)})(o,function ErrorStackParser(H){'use strict';var I=/(^|@)\S+\:\d+/,J=/^\s*at .*(\S+\:\d+|\(native\))/m,K=/^(eval@)?(\[native code\])?$/;return{parse:function ErrorStackParser$$parse(L){if('undefined'!=typeof L.stacktrace||'undefined'!=typeof L['opera#sourceloc'])return this.parseOpera(L);if(L.stack&&L.stack.match(J))return this.parseV8OrIE(L);if(L.stack)return this.parseFFOrSafari(L);throw new Error('Cannot parse given Error object')},extractLocation:function ErrorStackParser$$extractLocation(L){if(-1===L.indexOf(':'))return[L];var M=/(.+?)(?:\:(\d+))?(?:\:(\d+))?$/,N=M.exec(L.replace(/[\(\)]/g,''));return[N[1],N[2]||void 0,N[3]||void 0]},parseV8OrIE:function ErrorStackParser$$parseV8OrIE(L){var M=L.stack.split('\n').filter(function(N){return!!N.match(J)},this);return M.map(function(N){-1<N.indexOf('(eval ')&&(N=N.replace(/eval code/g,'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g,''));var O=N.replace(/^\s+/,'').replace(/\(eval code/g,'(').split(/\s+/).slice(1),P=this.extractLocation(O.pop()),Q=O.join(' ')||void 0,R=-1<['eval','<anonymous>'].indexOf(P[0])?void 0:P[0];return new H({functionName:Q,fileName:R,lineNumber:P[1],columnNumber:P[2],source:N})},this)},parseFFOrSafari:function ErrorStackParser$$parseFFOrSafari(L){var M=L.stack.split('\n').filter(function(N){return!N.match(K)},this);return M.map(function(N){if(-1<N.indexOf(' > eval')&&(N=N.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g,':$1')),-1===N.indexOf('@')&&-1===N.indexOf(':'))return new H({functionName:N});var O=N.split('@'),P=this.extractLocation(O.pop()),Q=O.join('@')||void 0;return new H({functionName:Q,fileName:P[0],lineNumber:P[1],columnNumber:P[2],source:N})},this)},parseOpera:function ErrorStackParser$$parseOpera(L){return!L.stacktrace||-1<L.message.indexOf('\n')&&L.message.split('\n').length>L.stacktrace.split('\n').length?this.parseOpera9(L):L.stack?this.parseOpera11(L):this.parseOpera10(L)},parseOpera9:function ErrorStackParser$$parseOpera9(L){for(var R,M=/Line (\d+).*script (?:in )?(\S+)/i,N=L.message.split('\n'),O=[],P=2,Q=N.length;P<Q;P+=2)R=M.exec(N[P]),R&&O.push(new H({fileName:R[2],lineNumber:R[1],source:N[P]}));return O},parseOpera10:function ErrorStackParser$$parseOpera10(L){for(var R,M=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,N=L.stacktrace.split('\n'),O=[],P=0,Q=N.length;P<Q;P+=2)R=M.exec(N[P]),R&&O.push(new H({functionName:R[3]||void 0,fileName:R[2],lineNumber:R[1],source:N[P]}));return O},parseOpera11:function ErrorStackParser$$parseOpera11(L){var M=L.stack.split('\n').filter(function(N){return!!N.match(I)&&!N.match(/^Error created at/)},this);return M.map(function(N){var O=N.split('@'),P=this.extractLocation(O.pop()),Q=O.shift()||'',R=Q.replace(/<anonymous function(: (\w+))?>/,'$2').replace(/\([^\)]*\)/g,'')||void 0,S;Q.match(/\(([^\)]*)\)/)&&(S=Q.replace(/^[^\(]+\(([^\)]*)\)$/,'$1'));var T=S===void 0||'[arguments not available]'===S?void 0:S.split(',');return new H({functionName:R,args:T,fileName:P[0],lineNumber:P[1],columnNumber:P[2],source:N})},this)}}})}),s={atLeastOne:function atLeastOne(F){const G=Object.keys(F);G.some((H)=>F[H]!==void 0)||throwError('Please set at least one of the following parameters: '+G.map((H)=>`'${H}'`).join(', '))},hasMethod:function hasMethod(F,G){const H=Object.keys(F).pop(),I=typeof F[H][G];'function'!=I&&throwError(`The '${H}' parameter must be an object that exposes a | ||
'${G}' method.`)},isInstance:function isInstance(F,G){const H=Object.keys(F).pop();F[H]instanceof G||throwError(`The '${H}' parameter must be an instance of | ||
'${G.name}'`)},isOneOf:function isOneOf(F,G){const H=Object.keys(F).pop();G.includes(F[H])||throwError(`The '${H}' parameter must be set to one of the | ||
following: ${G}`)},isType:function isType(F,G){const H=Object.keys(F).pop(),I=typeof F[H];I!==G&&throwError(`The '${H}' parameter has the wrong type. (Expected: | ||
${G}, actual: ${I})`)},isSWEnv:function isSWEnv(){return'ServiceWorkerGlobalScope'in self&&self instanceof ServiceWorkerGlobalScope},isValue:function isValue(F,G){const H=Object.keys(F).pop(),I=F[H];I!==G&&throwError(`The '${H}' parameter has the wrong value. (Expected: | ||
${G}, actual: ${I})`)}};let t='bgQueueSyncDB';var u=createCommonjsModule(function(F){'use strict';(function(){function toArray(H){return Array.prototype.slice.call(H)}function promisifyRequest(H){return new Promise(function(I,J){H.onsuccess=function(){I(H.result)},H.onerror=function(){J(H.error)}})}function promisifyRequestCall(H,I,J){var K,L=new Promise(function(M,N){K=H[I].apply(H,J),promisifyRequest(K).then(M,N)});return L.request=K,L}function promisifyCursorRequestCall(H,I,J){var K=promisifyRequestCall(H,I,J);return K.then(function(L){return L?new Cursor(L,K.request):void 0})}function proxyProperties(H,I,J){J.forEach(function(K){Object.defineProperty(H.prototype,K,{get:function(){return this[I][K]},set:function(L){this[I][K]=L}})})}function proxyRequestMethods(H,I,J,K){K.forEach(function(L){L in J.prototype&&(H.prototype[L]=function(){return promisifyRequestCall(this[I],L,arguments)})})}function proxyMethods(H,I,J,K){K.forEach(function(L){L in J.prototype&&(H.prototype[L]=function(){return this[I][L].apply(this[I],arguments)})})}function proxyCursorRequestMethods(H,I,J,K){K.forEach(function(L){L in J.prototype&&(H.prototype[L]=function(){return promisifyCursorRequestCall(this[I],L,arguments)})})}function Index(H){this._index=H}function Cursor(H,I){this._cursor=H,this._request=I}function ObjectStore(H){this._store=H}function Transaction(H){this._tx=H,this.complete=new Promise(function(I,J){H.oncomplete=function(){I()},H.onerror=function(){J(H.error)},H.onabort=function(){J(H.error)}})}function UpgradeDB(H,I,J){this._db=H,this.oldVersion=I,this.transaction=new Transaction(J)}function DB(H){this._db=H}proxyProperties(Index,'_index',['name','keyPath','multiEntry','unique']),proxyRequestMethods(Index,'_index',IDBIndex,['get','getKey','getAll','getAllKeys','count']),proxyCursorRequestMethods(Index,'_index',IDBIndex,['openCursor','openKeyCursor']),proxyProperties(Cursor,'_cursor',['direction','key','primaryKey','value']),proxyRequestMethods(Cursor,'_cursor',IDBCursor,['update','delete']),['advance','continue','continuePrimaryKey'].forEach(function(H){H in IDBCursor.prototype&&(Cursor.prototype[H]=function(){var I=this,J=arguments;return Promise.resolve().then(function(){return I._cursor[H].apply(I._cursor,J),promisifyRequest(I._request).then(function(K){return K?new Cursor(K,I._request):void 0})})})}),ObjectStore.prototype.createIndex=function(){return new Index(this._store.createIndex.apply(this._store,arguments))},ObjectStore.prototype.index=function(){return new Index(this._store.index.apply(this._store,arguments))},proxyProperties(ObjectStore,'_store',['name','keyPath','indexNames','autoIncrement']),proxyRequestMethods(ObjectStore,'_store',IDBObjectStore,['put','add','delete','clear','get','getAll','getKey','getAllKeys','count']),proxyCursorRequestMethods(ObjectStore,'_store',IDBObjectStore,['openCursor','openKeyCursor']),proxyMethods(ObjectStore,'_store',IDBObjectStore,['deleteIndex']),Transaction.prototype.objectStore=function(){return new ObjectStore(this._tx.objectStore.apply(this._tx,arguments))},proxyProperties(Transaction,'_tx',['objectStoreNames','mode']),proxyMethods(Transaction,'_tx',IDBTransaction,['abort']),UpgradeDB.prototype.createObjectStore=function(){return new ObjectStore(this._db.createObjectStore.apply(this._db,arguments))},proxyProperties(UpgradeDB,'_db',['name','version','objectStoreNames']),proxyMethods(UpgradeDB,'_db',IDBDatabase,['deleteObjectStore','close']),DB.prototype.transaction=function(){return new Transaction(this._db.transaction.apply(this._db,arguments))},proxyProperties(DB,'_db',['name','version','objectStoreNames']),proxyMethods(DB,'_db',IDBDatabase,['close']),['openCursor','openKeyCursor'].forEach(function(H){[ObjectStore,Index].forEach(function(I){I.prototype[H.replace('open','iterate')]=function(){var J=toArray(arguments),K=J[J.length-1],L=this._store||this._index,M=L[H].apply(L,J.slice(0,-1));M.onsuccess=function(){K(M.result)}}})}),[Index,ObjectStore].forEach(function(H){H.prototype.getAll||(H.prototype.getAll=function(I,J){var K=this,L=[];return new Promise(function(M){K.iterateCursor(I,function(N){return N?(L.push(N.value),void 0!==J&&L.length==J?void M(L):void N.continue()):void M(L)})})})});F.exports={open:function(H,I,J){var K=promisifyRequestCall(indexedDB,'open',[H,I]),L=K.request;return L.onupgradeneeded=function(M){J&&J(new UpgradeDB(L.result,M.oldVersion,L.transaction))},K.then(function(M){return new DB(M)})},delete:function(H){return promisifyRequestCall(indexedDB,'deleteDatabase',[H])}}})()});class IDBHelper{constructor(F,G,H){if(F==void 0||G==void 0||H==void 0)throw Error('name, version, storeName must be passed to the constructor.');this._name=F,this._version=G,this._storeName=H}_getDb(){return this._dbPromise?this._dbPromise:(this._dbPromise=u.open(this._name,this._version,(F)=>{F.createObjectStore(this._storeName)}).then((F)=>{return F}),this._dbPromise)}close(){return this._dbPromise?this._dbPromise.then((F)=>{F.close(),this._dbPromise=null}):void 0}put(F,G){return this._getDb().then((H)=>{const I=H.transaction(this._storeName,'readwrite'),J=I.objectStore(this._storeName);return J.put(G,F),I.complete})}delete(F){return this._getDb().then((G)=>{const H=G.transaction(this._storeName,'readwrite'),I=H.objectStore(this._storeName);return I.delete(F),H.complete})}get(F){return this._getDb().then((G)=>{return G.transaction(this._storeName).objectStore(this._storeName).get(F)})}getAllValues(){return this._getDb().then((F)=>{return F.transaction(this._storeName).objectStore(this._storeName).getAll()})}getAllKeys(){return this._getDb().then((F)=>{return F.transaction(this._storeName).objectStore(this._storeName).getAllKeys()})}}var w=function(F){return function(){var G=F.apply(this,arguments);return new Promise(function(H,I){function step(J,K){try{var L=G[J](K),M=L.value}catch(N){return void I(N)}return L.done?void H(M):Promise.resolve(M).then(function(N){step('next',N)},function(N){step('throw',N)})}return step('next')})}};let x=(()=>{var F=w(function*({hash:G,idbObject:H,response:I,idbQDb:J}){H.response={headers:JSON.stringify([...I.headers]),status:I.status,body:yield I.blob()},J.put(G,H)});return function putResponse(){return F.apply(this,arguments)}})(),y=(()=>{var F=w(function*({id:G}){const H=new IDBHelper(getDbName(),1,'QueueStore'),I=yield H.get(G);return I&&I.response?I.response:null});return function getResponse(){return F.apply(this,arguments)}})(),z=(()=>{var F=w(function*({request:G,config:H}){let I={config:H,metadata:{creationTimestamp:Date.now()},request:{url:G.url,headers:JSON.stringify([...G.headers]),mode:G.mode,method:G.method,redirect:G.redirect}};const J=yield G.text();return 0<J.length&&(I.request.body=J),I});return function getQueueableRequest(){return F.apply(this,arguments)}})(),A=(()=>{var F=w(function*({idbRequestObject:G}){let H={mode:G.mode,method:G.method,redirect:G.redirect,headers:new Headers(JSON.parse(G.headers))};return G.body&&(H.body=G.body),new Request(G.url,H)});return function getFetchableRequest(){return F.apply(this,arguments)}})(),B=(()=>{var F=w(function*(){let G=new IDBHelper(getDbName(),1,'QueueStore'),H=yield G.get(m);return H?void(yield Promise.all(H.map((()=>{var I=w(function*(J){const K=yield G.get(J);let L=[],M=[];yield Promise.all(K.map((()=>{var N=w(function*(O){const P=yield G.get(O);P&&P.metadata&&P.metadata.creationTimestamp+P.config.maxAge<=Date.now()?M.push(G.delete(O)):L.push(O)});return function(){return N.apply(this,arguments)}})())),yield Promise.all(M),G.put(J,L)});return function(){return I.apply(this,arguments)}})()))):null});return function cleanupQueue(){return F.apply(this,arguments)}})();class RequestManager{constructor({callbacks:F,queue:G}){this._globalCallbacks=F||{},this._queue=G,this.attachSyncHandler()}attachSyncHandler(){self.addEventListener('sync',(F)=>{F.tag===h+this._queue.queueName&&F.waitUntil(this.replayRequests())})}replayRequests(){var F=this;return this._queue.queue.reduce((G,H)=>{return G.then((()=>{var I=w(function*(){const K=yield F._queue.getRequestFromQueue({hash:H});if(!K.response){const L=yield A({idbRequestObject:K.request});return fetch(L).then(function(M){return M.ok?void(x({hash:H,idbObject:K,response:M.clone(),idbQDb:F._queue.idbQDb}),F._globalCallbacks.onResponse&&F._globalCallbacks.onResponse(H,M)):Promise.resolve()}).catch(function(M){F._globalCallbacks.onRetryFailure&&F._globalCallbacks.onRetryFailure(H,M)})}});return function(){return I.apply(this,arguments)}})())},Promise.resolve())}}let C=0,D=0;class RequestQueue{constructor({config:F,queueName:I='DEFAULT_QUEUE'+'_'+D++,idbQDb:G,broadcastChannel:H}){this._isQueueNameAddedToAllQueue=!1,this._queueName=I,this._config=F,this._idbQDb=G,this._broadcastChannel=H,this._queue=[],this.initQueue()}initQueue(){var F=this;return w(function*(){const G=yield F._idbQDb.get(F._queueName);F._queue.concat(G)})()}addQueueNameToAllQueues(){var F=this;return w(function*(){if(!F._isQueueNameAddedToAllQueue){let G=yield F._idbQDb.get(m);G=G||[],G.includes(F._queueName)||G.push(F._queueName),F._idbQDb.put(m,G),F._isQueueNameAddedToAllQueue=!0}})()}saveQueue(){var F=this;return w(function*(){yield F._idbQDb.put(F._queueName,F._queue)})()}push({request:F}){var G=this;return w(function*(){s.isInstance({request:F},Request);const H=`${F.url}!${Date.now()}!${C++}`,I=yield z({request:F,config:G._config});try{G._queue.push(H),G.saveQueue(),G._idbQDb.put(H,I),yield G.addQueueNameToAllQueues(),self.registration&&self.registration.sync.register(h+G._queueName),broadcastMessage({broadcastChannel:G._broadcastChannel,type:'BACKGROUND_REQUESTED_ADDED',id:H,url:F.url})}catch(J){broadcastMessage({broadcastChannel:G._broadcastChannel,type:'BACKGROUND_REQUESTED_FAILED',id:H,url:F.url})}})()}getRequestFromQueue({hash:F}){var G=this;return w(function*(){if(s.isType({hash:F},'string'),G._queue.includes(F))return yield G._idbQDb.get(F)})()}get queue(){return Object.assign([],this._queue)}get queueName(){return this._queueName}get idbQDb(){return this._idbQDb}}let E=(()=>{var F=w(function*({dbName:G}={}){G&&(s.isType({dbName:G},'string'),setDbName(G)),yield B()});return function initialize(){return F.apply(this,arguments)}})();a.initialize=E,a.getResponse=y,a.BackgroundSyncQueue=class BackgroundSyncQueue{constructor({maxRetentionTime:I=432000000,callbacks:F,queueName:G,broadcastChannel:H}={}){G&&s.isType({queueName:G},'string'),I&&s.isType({maxRetentionTime:I},'number'),H&&s.isInstance({broadcastChannel:H},BroadcastChannel),this._queue=new RequestQueue({config:{maxAge:I},queueName:G,idbQDb:new IDBHelper(getDbName(),1,'QueueStore'),broadcastChannel:H}),this._requestManager=new RequestManager({callbacks:F,queue:this._queue})}pushIntoQueue({request:F}){return s.isInstance({request:F},Request),this._queue.push({request:F})}fetchDidFail({request:F}){return this.pushIntoQueue({request:F})}},Object.defineProperty(a,'__esModule',{value:!0})}); | ||
//# sourceMappingURL=background-sync-queue.min.js.map |
@@ -23,2 +23,315 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -44,3 +357,3 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
if (!parameters.some(parameter => object[parameter] !== undefined)) { | ||
throw Error('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
throwError('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
} | ||
@@ -53,3 +366,4 @@ } | ||
if (type !== 'function') { | ||
throw Error(`The '${parameter}' parameter must be an object that exposes ` + `a '${expectedMethod}' method.`); | ||
throwError(`The '${parameter}' parameter must be an object that exposes a | ||
'${expectedMethod}' method.`); | ||
} | ||
@@ -61,3 +375,4 @@ } | ||
if (!(object[parameter] instanceof expectedClass)) { | ||
throw Error(`The '${parameter}' parameter must be an instance of ` + `'${expectedClass.name}'`); | ||
throwError(`The '${parameter}' parameter must be an instance of | ||
'${expectedClass.name}'`); | ||
} | ||
@@ -69,3 +384,4 @@ } | ||
if (!values.includes(object[parameter])) { | ||
throw Error(`The '${parameter}' parameter must be set to one of the ` + `following: ${values}`); | ||
throwError(`The '${parameter}' parameter must be set to one of the | ||
following: ${values}`); | ||
} | ||
@@ -78,3 +394,4 @@ } | ||
if (actualType !== expectedType) { | ||
throw Error(`The '${parameter}' parameter has the wrong type. ` + `(Expected: ${expectedType}, actual: ${actualType})`); | ||
throwError(`The '${parameter}' parameter has the wrong type. (Expected: | ||
${expectedType}, actual: ${actualType})`); | ||
} | ||
@@ -91,6 +408,24 @@ } | ||
if (actualValue !== expectedValue) { | ||
throw Error(`The '${parameter}' parameter has the wrong value. ` + `(Expected: ${expectedValue}, actual: ${actualValue})`); | ||
throwError(`The '${parameter}' parameter has the wrong value. (Expected: | ||
${expectedValue}, actual: ${actualValue})`); | ||
} | ||
} | ||
function throwError(message) { | ||
const error = new Error(message); | ||
const stackFrames = errorStackParser.parse(error); | ||
// If, for some reason, we don't have all the stack information we need, | ||
// we'll just end up throwing a basic Error. | ||
if (stackFrames.length >= 3) { | ||
// Assuming we have the stack frames, set the message to include info | ||
// about what the underlying method was, and set the name to reflect | ||
// the assertion type that failed. | ||
error.message = `Invalid call to ${stackFrames[2].functionName}() — ` + message.replace(/\s+/g, ' '); | ||
error.name = stackFrames[1].functionName.replace(/^Object\./, ''); | ||
} | ||
throw error; | ||
} | ||
var assert = { | ||
@@ -97,0 +432,0 @@ atLeastOne, |
@@ -30,2 +30,315 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -51,3 +364,3 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
if (!parameters.some(parameter => object[parameter] !== undefined)) { | ||
throw Error('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
throwError('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
} | ||
@@ -60,3 +373,4 @@ } | ||
if (type !== 'function') { | ||
throw Error(`The '${parameter}' parameter must be an object that exposes ` + `a '${expectedMethod}' method.`); | ||
throwError(`The '${parameter}' parameter must be an object that exposes a | ||
'${expectedMethod}' method.`); | ||
} | ||
@@ -68,3 +382,4 @@ } | ||
if (!(object[parameter] instanceof expectedClass)) { | ||
throw Error(`The '${parameter}' parameter must be an instance of ` + `'${expectedClass.name}'`); | ||
throwError(`The '${parameter}' parameter must be an instance of | ||
'${expectedClass.name}'`); | ||
} | ||
@@ -76,3 +391,4 @@ } | ||
if (!values.includes(object[parameter])) { | ||
throw Error(`The '${parameter}' parameter must be set to one of the ` + `following: ${values}`); | ||
throwError(`The '${parameter}' parameter must be set to one of the | ||
following: ${values}`); | ||
} | ||
@@ -85,3 +401,4 @@ } | ||
if (actualType !== expectedType) { | ||
throw Error(`The '${parameter}' parameter has the wrong type. ` + `(Expected: ${expectedType}, actual: ${actualType})`); | ||
throwError(`The '${parameter}' parameter has the wrong type. (Expected: | ||
${expectedType}, actual: ${actualType})`); | ||
} | ||
@@ -98,6 +415,24 @@ } | ||
if (actualValue !== expectedValue) { | ||
throw Error(`The '${parameter}' parameter has the wrong value. ` + `(Expected: ${expectedValue}, actual: ${actualValue})`); | ||
throwError(`The '${parameter}' parameter has the wrong value. (Expected: | ||
${expectedValue}, actual: ${actualValue})`); | ||
} | ||
} | ||
function throwError(message) { | ||
const error = new Error(message); | ||
const stackFrames = errorStackParser.parse(error); | ||
// If, for some reason, we don't have all the stack information we need, | ||
// we'll just end up throwing a basic Error. | ||
if (stackFrames.length >= 3) { | ||
// Assuming we have the stack frames, set the message to include info | ||
// about what the underlying method was, and set the name to reflect | ||
// the assertion type that failed. | ||
error.message = `Invalid call to ${stackFrames[2].functionName}() — ` + message.replace(/\s+/g, ' '); | ||
error.name = stackFrames[1].functionName.replace(/^Object\./, ''); | ||
} | ||
throw error; | ||
} | ||
var assert = { | ||
@@ -124,6 +459,2 @@ atLeastOne, | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var idb = createCommonjsModule(function (module) { | ||
@@ -130,0 +461,0 @@ 'use strict'; |
@@ -23,2 +23,315 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -44,3 +357,3 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
if (!parameters.some(parameter => object[parameter] !== undefined)) { | ||
throw Error('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
throwError('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
} | ||
@@ -53,3 +366,4 @@ } | ||
if (type !== 'function') { | ||
throw Error(`The '${parameter}' parameter must be an object that exposes ` + `a '${expectedMethod}' method.`); | ||
throwError(`The '${parameter}' parameter must be an object that exposes a | ||
'${expectedMethod}' method.`); | ||
} | ||
@@ -61,3 +375,4 @@ } | ||
if (!(object[parameter] instanceof expectedClass)) { | ||
throw Error(`The '${parameter}' parameter must be an instance of ` + `'${expectedClass.name}'`); | ||
throwError(`The '${parameter}' parameter must be an instance of | ||
'${expectedClass.name}'`); | ||
} | ||
@@ -69,3 +384,4 @@ } | ||
if (!values.includes(object[parameter])) { | ||
throw Error(`The '${parameter}' parameter must be set to one of the ` + `following: ${values}`); | ||
throwError(`The '${parameter}' parameter must be set to one of the | ||
following: ${values}`); | ||
} | ||
@@ -78,3 +394,4 @@ } | ||
if (actualType !== expectedType) { | ||
throw Error(`The '${parameter}' parameter has the wrong type. ` + `(Expected: ${expectedType}, actual: ${actualType})`); | ||
throwError(`The '${parameter}' parameter has the wrong type. (Expected: | ||
${expectedType}, actual: ${actualType})`); | ||
} | ||
@@ -91,6 +408,24 @@ } | ||
if (actualValue !== expectedValue) { | ||
throw Error(`The '${parameter}' parameter has the wrong value. ` + `(Expected: ${expectedValue}, actual: ${actualValue})`); | ||
throwError(`The '${parameter}' parameter has the wrong value. (Expected: | ||
${expectedValue}, actual: ${actualValue})`); | ||
} | ||
} | ||
function throwError(message) { | ||
const error = new Error(message); | ||
const stackFrames = errorStackParser.parse(error); | ||
// If, for some reason, we don't have all the stack information we need, | ||
// we'll just end up throwing a basic Error. | ||
if (stackFrames.length >= 3) { | ||
// Assuming we have the stack frames, set the message to include info | ||
// about what the underlying method was, and set the name to reflect | ||
// the assertion type that failed. | ||
error.message = `Invalid call to ${stackFrames[2].functionName}() — ` + message.replace(/\s+/g, ' '); | ||
error.name = stackFrames[1].functionName.replace(/^Object\./, ''); | ||
} | ||
throw error; | ||
} | ||
var assert = { | ||
@@ -97,0 +432,0 @@ atLeastOne, |
@@ -21,2 +21,8 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
@@ -486,2 +492,305 @@ return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -488,0 +797,0 @@ Copyright 2016 Google Inc. All Rights Reserved. |
@@ -23,2 +23,315 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -41,6 +354,2 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var idb = createCommonjsModule(function (module) { | ||
@@ -47,0 +356,0 @@ 'use strict'; |
@@ -21,2 +21,8 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
@@ -360,2 +366,305 @@ return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -381,3 +690,3 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
if (!parameters.some(parameter => object[parameter] !== undefined)) { | ||
throw Error('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
throwError('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
} | ||
@@ -390,3 +699,4 @@ } | ||
if (type !== 'function') { | ||
throw Error(`The '${parameter}' parameter must be an object that exposes ` + `a '${expectedMethod}' method.`); | ||
throwError(`The '${parameter}' parameter must be an object that exposes a | ||
'${expectedMethod}' method.`); | ||
} | ||
@@ -398,3 +708,4 @@ } | ||
if (!(object[parameter] instanceof expectedClass)) { | ||
throw Error(`The '${parameter}' parameter must be an instance of ` + `'${expectedClass.name}'`); | ||
throwError(`The '${parameter}' parameter must be an instance of | ||
'${expectedClass.name}'`); | ||
} | ||
@@ -406,3 +717,4 @@ } | ||
if (!values.includes(object[parameter])) { | ||
throw Error(`The '${parameter}' parameter must be set to one of the ` + `following: ${values}`); | ||
throwError(`The '${parameter}' parameter must be set to one of the | ||
following: ${values}`); | ||
} | ||
@@ -415,3 +727,4 @@ } | ||
if (actualType !== expectedType) { | ||
throw Error(`The '${parameter}' parameter has the wrong type. ` + `(Expected: ${expectedType}, actual: ${actualType})`); | ||
throwError(`The '${parameter}' parameter has the wrong type. (Expected: | ||
${expectedType}, actual: ${actualType})`); | ||
} | ||
@@ -428,6 +741,24 @@ } | ||
if (actualValue !== expectedValue) { | ||
throw Error(`The '${parameter}' parameter has the wrong value. ` + `(Expected: ${expectedValue}, actual: ${actualValue})`); | ||
throwError(`The '${parameter}' parameter has the wrong value. (Expected: | ||
${expectedValue}, actual: ${actualValue})`); | ||
} | ||
} | ||
function throwError(message) { | ||
const error = new Error(message); | ||
const stackFrames = errorStackParser.parse(error); | ||
// If, for some reason, we don't have all the stack information we need, | ||
// we'll just end up throwing a basic Error. | ||
if (stackFrames.length >= 3) { | ||
// Assuming we have the stack frames, set the message to include info | ||
// about what the underlying method was, and set the name to reflect | ||
// the assertion type that failed. | ||
error.message = `Invalid call to ${stackFrames[2].functionName}() — ` + message.replace(/\s+/g, ' '); | ||
error.name = stackFrames[1].functionName.replace(/^Object\./, ''); | ||
} | ||
throw error; | ||
} | ||
var assert = { | ||
@@ -434,0 +765,0 @@ atLeastOne, |
@@ -23,2 +23,315 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -52,6 +365,2 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var idb = createCommonjsModule(function (module) { | ||
@@ -58,0 +367,0 @@ 'use strict'; |
@@ -30,2 +30,315 @@ /* | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var stackframe = createCommonjsModule(function (module, exports) { | ||
(function (root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('stackframe', [], factory); | ||
} else { | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
'use strict'; | ||
function _isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
function _capitalize(str) { | ||
return str[0].toUpperCase() + str.substring(1); | ||
} | ||
function _getter(p) { | ||
return function () { | ||
return this[p]; | ||
}; | ||
} | ||
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel']; | ||
var numericProps = ['columnNumber', 'lineNumber']; | ||
var stringProps = ['fileName', 'functionName', 'source']; | ||
var arrayProps = ['args']; | ||
function StackFrame(obj) { | ||
if (obj instanceof Object) { | ||
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps))); | ||
for (var i = 0; i < props.length; i++) { | ||
if (obj.hasOwnProperty(props[i]) && obj[props[i]] !== undefined) { | ||
this['set' + _capitalize(props[i])](obj[props[i]]); | ||
} | ||
} | ||
} | ||
} | ||
StackFrame.prototype = { | ||
getArgs: function () { | ||
return this.args; | ||
}, | ||
setArgs: function (v) { | ||
if (Object.prototype.toString.call(v) !== '[object Array]') { | ||
throw new TypeError('Args must be an Array'); | ||
} | ||
this.args = v; | ||
}, | ||
getEvalOrigin: function () { | ||
return this.evalOrigin; | ||
}, | ||
setEvalOrigin: function (v) { | ||
if (v instanceof StackFrame) { | ||
this.evalOrigin = v; | ||
} else if (v instanceof Object) { | ||
this.evalOrigin = new StackFrame(v); | ||
} else { | ||
throw new TypeError('Eval Origin must be an Object or StackFrame'); | ||
} | ||
}, | ||
toString: function () { | ||
var functionName = this.getFunctionName() || '{anonymous}'; | ||
var args = '(' + (this.getArgs() || []).join(',') + ')'; | ||
var fileName = this.getFileName() ? ('@' + this.getFileName()) : ''; | ||
var lineNumber = _isNumber(this.getLineNumber()) ? (':' + this.getLineNumber()) : ''; | ||
var columnNumber = _isNumber(this.getColumnNumber()) ? (':' + this.getColumnNumber()) : ''; | ||
return functionName + args + fileName + lineNumber + columnNumber; | ||
} | ||
}; | ||
for (var i = 0; i < booleanProps.length; i++) { | ||
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]); | ||
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) { | ||
return function (v) { | ||
this[p] = Boolean(v); | ||
}; | ||
})(booleanProps[i]); | ||
} | ||
for (var j = 0; j < numericProps.length; j++) { | ||
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]); | ||
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) { | ||
return function (v) { | ||
if (!_isNumber(v)) { | ||
throw new TypeError(p + ' must be a Number'); | ||
} | ||
this[p] = Number(v); | ||
}; | ||
})(numericProps[j]); | ||
} | ||
for (var k = 0; k < stringProps.length; k++) { | ||
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]); | ||
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) { | ||
return function (v) { | ||
this[p] = String(v); | ||
}; | ||
})(stringProps[k]); | ||
} | ||
return StackFrame; | ||
})); | ||
}); | ||
var errorStackParser = createCommonjsModule(function (module, exports) { | ||
(function(root, factory) { | ||
'use strict'; | ||
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. | ||
/* istanbul ignore next */ | ||
if (typeof undefined === 'function' && undefined.amd) { | ||
undefined('error-stack-parser', ['stackframe'], factory); | ||
} else { | ||
module.exports = factory(stackframe); | ||
} | ||
}(commonjsGlobal, function ErrorStackParser(StackFrame) { | ||
'use strict'; | ||
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; | ||
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; | ||
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; | ||
return { | ||
/** | ||
* Given an Error object, extract the most information from it. | ||
* | ||
* @param {Error} error object | ||
* @return {Array} of StackFrames | ||
*/ | ||
parse: function ErrorStackParser$$parse(error) { | ||
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { | ||
return this.parseOpera(error); | ||
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) { | ||
return this.parseV8OrIE(error); | ||
} else if (error.stack) { | ||
return this.parseFFOrSafari(error); | ||
} else { | ||
throw new Error('Cannot parse given Error object'); | ||
} | ||
}, | ||
// Separate line and column numbers from a string of the form: (URI:Line:Column) | ||
extractLocation: function ErrorStackParser$$extractLocation(urlLike) { | ||
// Fail-fast but return locations like "(native)" | ||
if (urlLike.indexOf(':') === -1) { | ||
return [urlLike]; | ||
} | ||
var regExp = /(.+?)(?:\:(\d+))?(?:\:(\d+))?$/; | ||
var parts = regExp.exec(urlLike.replace(/[\(\)]/g, '')); | ||
return [parts[1], parts[2] || undefined, parts[3] || undefined]; | ||
}, | ||
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(CHROME_IE_STACK_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
if (line.indexOf('(eval ') > -1) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); | ||
} | ||
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join(' ') || undefined; | ||
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: fileName, | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
}, | ||
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !line.match(SAFARI_NATIVE_CODE_REGEXP); | ||
}, this); | ||
return filtered.map(function(line) { | ||
// Throw away eval information until we implement stacktrace.js/stackframe#8 | ||
if (line.indexOf(' > eval') > -1) { | ||
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); | ||
} | ||
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { | ||
// Safari eval frames only have function names and nothing else | ||
return new StackFrame({ | ||
functionName: line | ||
}); | ||
} else { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionName = tokens.join('@') || undefined; | ||
return new StackFrame({ | ||
functionName: functionName, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
} | ||
}, this); | ||
}, | ||
parseOpera: function ErrorStackParser$$parseOpera(e) { | ||
if (!e.stacktrace || (e.message.indexOf('\n') > -1 && | ||
e.message.split('\n').length > e.stacktrace.split('\n').length)) { | ||
return this.parseOpera9(e); | ||
} else if (!e.stack) { | ||
return this.parseOpera10(e); | ||
} else { | ||
return this.parseOpera11(e); | ||
} | ||
}, | ||
parseOpera9: function ErrorStackParser$$parseOpera9(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)/i; | ||
var lines = e.message.split('\n'); | ||
var result = []; | ||
for (var i = 2, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push(new StackFrame({ | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
})); | ||
} | ||
} | ||
return result; | ||
}, | ||
parseOpera10: function ErrorStackParser$$parseOpera10(e) { | ||
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; | ||
var lines = e.stacktrace.split('\n'); | ||
var result = []; | ||
for (var i = 0, len = lines.length; i < len; i += 2) { | ||
var match = lineRE.exec(lines[i]); | ||
if (match) { | ||
result.push( | ||
new StackFrame({ | ||
functionName: match[3] || undefined, | ||
fileName: match[2], | ||
lineNumber: match[1], | ||
source: lines[i] | ||
}) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
// Opera 10.65+ Error.stack very similar to FF/Safari | ||
parseOpera11: function ErrorStackParser$$parseOpera11(error) { | ||
var filtered = error.stack.split('\n').filter(function(line) { | ||
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); | ||
}, this); | ||
return filtered.map(function(line) { | ||
var tokens = line.split('@'); | ||
var locationParts = this.extractLocation(tokens.pop()); | ||
var functionCall = (tokens.shift() || ''); | ||
var functionName = functionCall | ||
.replace(/<anonymous function(: (\w+))?>/, '$2') | ||
.replace(/\([^\)]*\)/g, '') || undefined; | ||
var argsRaw; | ||
if (functionCall.match(/\(([^\)]*)\)/)) { | ||
argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); | ||
} | ||
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? | ||
undefined : argsRaw.split(','); | ||
return new StackFrame({ | ||
functionName: functionName, | ||
args: args, | ||
fileName: locationParts[0], | ||
lineNumber: locationParts[1], | ||
columnNumber: locationParts[2], | ||
source: line | ||
}); | ||
}, this); | ||
} | ||
}; | ||
})); | ||
}); | ||
/* | ||
@@ -51,3 +364,3 @@ Copyright 2016 Google Inc. All Rights Reserved. | ||
if (!parameters.some(parameter => object[parameter] !== undefined)) { | ||
throw Error('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
throwError('Please set at least one of the following parameters: ' + parameters.map(p => `'${p}'`).join(', ')); | ||
} | ||
@@ -60,3 +373,4 @@ } | ||
if (type !== 'function') { | ||
throw Error(`The '${parameter}' parameter must be an object that exposes ` + `a '${expectedMethod}' method.`); | ||
throwError(`The '${parameter}' parameter must be an object that exposes a | ||
'${expectedMethod}' method.`); | ||
} | ||
@@ -68,3 +382,4 @@ } | ||
if (!(object[parameter] instanceof expectedClass)) { | ||
throw Error(`The '${parameter}' parameter must be an instance of ` + `'${expectedClass.name}'`); | ||
throwError(`The '${parameter}' parameter must be an instance of | ||
'${expectedClass.name}'`); | ||
} | ||
@@ -76,3 +391,4 @@ } | ||
if (!values.includes(object[parameter])) { | ||
throw Error(`The '${parameter}' parameter must be set to one of the ` + `following: ${values}`); | ||
throwError(`The '${parameter}' parameter must be set to one of the | ||
following: ${values}`); | ||
} | ||
@@ -85,3 +401,4 @@ } | ||
if (actualType !== expectedType) { | ||
throw Error(`The '${parameter}' parameter has the wrong type. ` + `(Expected: ${expectedType}, actual: ${actualType})`); | ||
throwError(`The '${parameter}' parameter has the wrong type. (Expected: | ||
${expectedType}, actual: ${actualType})`); | ||
} | ||
@@ -98,6 +415,24 @@ } | ||
if (actualValue !== expectedValue) { | ||
throw Error(`The '${parameter}' parameter has the wrong value. ` + `(Expected: ${expectedValue}, actual: ${actualValue})`); | ||
throwError(`The '${parameter}' parameter has the wrong value. (Expected: | ||
${expectedValue}, actual: ${actualValue})`); | ||
} | ||
} | ||
function throwError(message) { | ||
const error = new Error(message); | ||
const stackFrames = errorStackParser.parse(error); | ||
// If, for some reason, we don't have all the stack information we need, | ||
// we'll just end up throwing a basic Error. | ||
if (stackFrames.length >= 3) { | ||
// Assuming we have the stack frames, set the message to include info | ||
// about what the underlying method was, and set the name to reflect | ||
// the assertion type that failed. | ||
error.message = `Invalid call to ${stackFrames[2].functionName}() — ` + message.replace(/\s+/g, ' '); | ||
error.name = stackFrames[1].functionName.replace(/^Object\./, ''); | ||
} | ||
throw error; | ||
} | ||
var assert = { | ||
@@ -135,6 +470,2 @@ atLeastOne, | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var idb = createCommonjsModule(function (module) { | ||
@@ -141,0 +472,0 @@ 'use strict'; |
{ | ||
"name": "sw-background-sync-queue", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Queues failed requests and uses the Background Sync API to replay those requests at a later time when the network state has changed.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
566298
10768