()
| 220 | } |
| 221 | |
| 222 | finalize() { |
| 223 | this.finalized = true; |
| 224 | // Compact funktions as we no longer need access via start byte position. |
| 225 | this.funktions = this.funktions.filter(each => true); |
| 226 | let parent = null; |
| 227 | let maxNesting = 0; |
| 228 | // Iterate over the Funktions in byte position order. |
| 229 | this.funktions.forEach(fn => { |
| 230 | fn.isEval = this.isEval; |
| 231 | if (parent === null) { |
| 232 | parent = fn; |
| 233 | } else { |
| 234 | // Walk up the nested chain of Funktions to find the parent. |
| 235 | while (parent !== null && !fn.isNestedIn(parent)) { |
| 236 | parent = parent.parent; |
| 237 | } |
| 238 | fn.parent = parent; |
| 239 | if (parent) { |
| 240 | maxNesting = Math.max(maxNesting, parent.addNestedFunktion(fn)); |
| 241 | } |
| 242 | parent = fn; |
| 243 | } |
| 244 | }); |
| 245 | // Sanity checks to ensure that scripts are executed and parsed before any |
| 246 | // of its funktions. |
| 247 | let funktionFirstParseEventTimestamp = -1; |
| 248 | // Second iteration step to finalize the funktions once the proper |
| 249 | // hierarchy has been set up. |
| 250 | this.funktions.forEach(fn => { |
| 251 | fn.finalize(); |
| 252 | |
| 253 | funktionFirstParseEventTimestamp = this.timestampMin( |
| 254 | funktionFirstParseEventTimestamp, fn.firstParseEventTimestamp); |
| 255 | |
| 256 | this.lastParseEventTimestamp = this.timestampMax( |
| 257 | this.lastParseEventTimestamp, fn.lastParseEventTimestamp); |
| 258 | |
| 259 | this.lastEventTimestamp = |
| 260 | this.timestampMax(this.lastEventTimestamp, fn.lastEventTimestamp); |
| 261 | }); |
| 262 | this.maxNestingLevel = maxNesting; |
| 263 | |
| 264 | // Initialize sizes. |
| 265 | if (this.ownBytes === -1) console.error('Invalid ownBytes'); |
| 266 | if (this.funktions.length == 0) { |
| 267 | this.bytesTotal = this.ownBytes = 0; |
| 268 | return; |
| 269 | } |
| 270 | let toplevelFunktionBytes = this.funktions.reduce( |
| 271 | (bytes, each) => bytes + (each.isToplevel() ? each.getBytes() : 0), 0); |
| 272 | if (this.isDeserialized || this.isEval || this.isStreamingCompiled) { |
| 273 | if (this.getBytes() === -1) { |
| 274 | this.bytesTotal = toplevelFunktionBytes; |
| 275 | } |
| 276 | } |
| 277 | this.ownBytes = this.bytesTotal - toplevelFunktionBytes; |
| 278 | // Initialize common properties. |
| 279 | super.finalize(); |
no test coverage detected