- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbundle.js
More file actions
Latest commit
251 lines (235 loc) · 11.2 KB
/
Copy pathbundle.js
File metadata and controls
251 lines (235 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
(function(){functionr(e,n,t){functiono(i,f){if(!n[i]){if(!e[i]){varc="function"==typeofrequire&&require;if(!f&&c)returnc(i,!0);if(u)returnu(i,!0);vara=newError("Cannot find module '"+i+"'");throwa.code="MODULE_NOT_FOUND",a}varp=n[i]={exports:{}};e[i][0].call(p.exports,function(r){varn=e[i][1][r];returno(n||r)},p,p.exports,r,e,n,t)}returnn[i].exports}for(varu="function"==typeofrequire&&require,i=0;i<t.length;i++)o(t[i]);returno}returnr})()({1:[function(require,module,exports){
conststackframes=require('..')
document.body.innerHTML=`<xmp>${demo}\ndemo()</xmp><hr><h2>open devtools console to check results:</h2>`//'<h1> open devtools console: </h1>'
demo()
functiondemo(){
varerror
try{
functionfoobarbaz(){thrownewError('foobar')}
functionbazbarfoo(){foobarbaz()}
bazbarfoo()
}catch(e){
error=e
}
example()
functionexample(){foo()}
functionfoo(){bar()}
functionbar(){baz()}
functionbaz(){
constdefaultFlags=stackframes.defaultFlags
console.log(defaultFlags)
constflags=defaultFlags.filter((_,i)=>i%2)// take every second flag
console.log('0',stackframes(error,flags))
console.log('1',stackframes())
console.log('2',stackframes({exclude: foo}))
console.log('3',stackframes({exclude: example}))
console.log('4',stackframes({depths: 2,exclude: baz}))
console.log('5',stackframes({depths: 2}))
console.log('6',stackframes(null,flags))
}
}
},{"..":3}],2:[function(require,module,exports){
module.exports=jsonloop
functionjsonloop(specialChar='.'){
constsafeSpecialChar='\\x'+('0'+specialChar.charCodeAt(0).toString(16)).slice(-2)
constescapedSafeSpecialChar='\\'+safeSpecialChar
constspecialCharRG=newRegExp(safeSpecialChar,'g')
constsafeSpecialCharRG=newRegExp(escapedSafeSpecialChar,'g')
constsafeStartWithSpecialCharRG=newRegExp('(?:^|([^\\\\]))'+escapedSafeSpecialChar)
constindexOf=[].indexOf||function(v){
for(vari=this.length;i--&&this[i]!==v;);
returni
}
return{ stringify, parse }
functionparse(text,reviver){
returnJSON.parse(text,generateReviver(reviver))
}
functionstringify(value,replacer,space){
constreplace=generateReplacer(value,replacer)
returnJSON.stringify(value,replace,space)
}
functiongenerateReplacer(value,replacer,resolve){
replacer=typeofreplacer==='object' ? (key,value)=>key!==''&&indexOf.call(replacer,key)<0 ? void0 : value : replacer
constpath=[]
constall=[value]
constseen=[value]
constmapp=[specialChar]
vardoNotIgnore=false
varlast=value
varlvl=1
vari
returnfunction(key,value){
try{
// the replacer has rights to decide
// if a new object should be returned
// or if there's some key to drop
// let's call it here rather than "too late"
if(replacer)value=replacer.call(this,key,value)
if(doNotIgnore){// first pass should be ignored, since it's just the initial object
if(last!==this){
i=lvl-indexOf.call(all,this)-1
lvl-=i
all.splice(lvl,all.length)
path.splice(lvl-1,path.length)
last=this
}
if(typeofvalue==='object'&&value){
// if object isn't referring to parent object, add to the
// object path stack. Otherwise it is already there.
if(indexOf.call(all,value)<0)all.push(last=value)
lvl=all.length
i=indexOf.call(seen,value)
if(i<0){
i=seen.push(value)-1
// key cannot contain specialChar but could be not a string
path.push((''+key).replace(specialCharRG,safeSpecialChar))
mapp[i]=specialChar+path.join(specialChar)
}else{
value=`#${mapp[i]}`// https://tools.ietf.org/html/rfc6901
}
}else{
if(typeofvalue==='string'&&resolve){
// ensure no special char involved on deserialization
// in this case only first char is important
// no need to replace all value (better performance)
value=value.replace(safeSpecialChar,escapedSafeSpecialChar).replace(specialChar,safeSpecialChar)
}
}
}else{
doNotIgnore=true
}
returnvalue
}catch(e){
console.log('ERROR',e)
returnvalue
}
}
}
functionretrieveFromPath(current,keys){
for(vari=0,length=keys.length;i<length;i++){
// keys should be normalized back here
current=current[keys[i].replace(safeSpecialCharRG,specialChar)]
}
returncurrent
}
functiongenerateReviver(reviver){
returnfunction(key,value){
varisString=typeofvalue==='string'
if(isString&&value.charAt(0)==='#'&&value.charAt(1)===specialChar)returnnewString(value.slice(2))
if(key==='')value=regenerate(value,value,{})
// again, only one needed, do not use the RegExp for this replacement
// only keys need the RegExp
if(isString)value=value.replace(safeStartWithSpecialCharRG,'$1'+specialChar).replace(escapedSafeSpecialChar,safeSpecialChar)
returnreviver ? reviver.call(this,key,value) : value
}
}
functionregenerateArray(root,current,retrieve){
for(vari=0,length=current.length;i<length;i++)current[i]=regenerate(root,current[i],retrieve)
returncurrent
}
functionregenerateObject(root,current,retrieve){
for(varkeyincurrent)if(current.hasOwnProperty(key))current[key]=regenerate(root,current[key],retrieve)
returncurrent
}
functionregenerate(root,current,retrieve){
returncurrentinstanceofArray
? regenerateArray(root,current,retrieve)// fast Array reconstruction
: currentinstanceofString
? current.length// root is an empty string
? retrieve.hasOwnProperty(current)
? retrieve[current]
: retrieve[current]=retrieveFromPath(root,current.split(specialChar))
: root
: currentinstanceofObject// dedicated Object parser
? regenerateObject(root,current,retrieve)
: current// value as it is
}
}
},{}],3:[function(require,module,exports){
constjsonloop=require('jsonloop')
constcJSON=jsonloop()
constmethods={
"getThis": callsite=>{// getThis: returns the value of this
constself=callsite.getThis()
constctor=self.constructor
constctorName=ctor ? `:${ctor.name}` : ''
constisGlobal=self===globalThis
consttype=`${isGlobal ? 'global' : 'local'}${ctorName}`
varjson
try{
json=isGlobal ? `${self}` : cJSON.stringify(self)
}catch(error){
json=`${self}:${error}`
}
return{ type, json }
},
"getTypeName": callsite=>callsite.getTypeName(),// getTypeName: returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object’s [[Class]] internal property.
"getFunctionSource": callsite=>{// getFunction: returns the current function
constgetF=callsite.getFunction()
if(getF)return`${getF}`
},
"getFunction": callsite=>{// getFunction: returns the current function
constgetF=callsite.getFunction()
if(getF){
constname=getF.name||'(anonymous)'
constctor=getF.constructor
if(ctor)return{async: false, name }
constctorName=ctor.name==="AsyncFunction"
return{type: ctorName, name }
}
},
"getFunctionName": callsite=>callsite.getFunctionName(),// getFunctionName: returns the name of the current function, typically its name property. If a name property is not available an attempt is made to infer a name from the function’s context.
"getMethodName": callsite=>callsite.getMethodName(),// getMethodName: returns the name of the property of this or one of its prototypes that holds the current function
"getFileName": callsite=>callsite.getFileName(),// getFileName: if this function was defined in a script returns the name of the script
"getLineNumber": callsite=>callsite.getLineNumber(),// getLineNumber: if this function was defined in a script returns the current line number
"getColumnNumber": callsite=>callsite.getColumnNumber(),// getColumnNumber: if this function was defined in a script returns the current column number
"getEvalOrigin": callsite=>callsite.getEvalOrigin(),// getEvalOrigin: if this function was created using a call to eval returns a string representing the location where eval was called
"isToplevel": callsite=>callsite.isToplevel(),// isToplevel: is this a top-level invocation, that is, is this the global object?
"isEval": callsite=>callsite.isEval(),// isEval: does this call take place in code defined by a call to eval?
"isNative": callsite=>callsite.isNative(),// isNative: is this call in native V8 code?
"isConstructor": callsite=>callsite.isConstructor(),// isConstructor: is this a constructor call?
"isAsync": callsite=>callsite.isAsync(),// isAsync: is this an async call (i.e. await or Promise.all())?
"isPromiseAll": callsite=>callsite.isPromiseAll(),// isPromiseAll: is this an async call to Promise.all()?
"getPromiseIndex": callsite=>callsite.getPromiseIndex(),// getPromiseIndex: returns the index of the promise element that was followed in Promise.all() for async stack traces, or null if the CallSite is not a Promise.all() call.
"NameOrSourceURL": callsite=>callsite.getScriptNameOrSourceURL(),
"getPosition": callsite=>callsite.getPosition()
}
constdefaultFlags=Object.keys(methods)
stackframes.defaultFlags=defaultFlags
module.exports=stackframes
functionstackframes(err={},flags=defaultFlags){
vardepths,exclude
if(!(errinstanceofError)){
if(!err)err={}
depths=err.depths
exclude=err.exclude
err=void0
}
if(!(depths>-1))depths=Infinity
if(typeoferr==="number")(depths=err,err=void0)
constexclude_this_and_below=exclude||stackframes
constoldLimit=Error.stackTraceLimit
constv8Handler=Error.prepareStackTrace
Error.stackTraceLimit=depths
Error.prepareStackTrace=prepareStackTrace
if(!err)(err={},Error.captureStackTrace(err,exclude_this_and_below))
constextractor=extract.bind(flags)
constframes=err.stack.map(extractor)
Error.prepareStackTrace=v8Handler
Error.stackTraceLimit=oldLimit
returnframes
}
functionprepareStackTrace(_,stack){
returnstack
}
functionextract(callsite){
constflags=this
constframe={}
for(vari=0,len=flags.length;i<len;i++){
constflag=flags[i]
constfn=methods[flag]
if(fn)frame[flag]=fn(callsite)
}
returnframe
}
},{"jsonloop":2}]},{},[1]);