Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 161x 96x 96x 96x 1x 1x 1x 95x 95x 95x 95x 95x 95x 95x 95x 96x 25x 25x 1x 1x 1x 25x 92x 92x 96x 5x 96x 65x 87x 13x 13x 13x 22x 9x 9x 9x 9x 9x 9x 9x 9x 9x 91x 92x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 96x 13x 13x 13x 13x 13x 90x 90x 90x 90x 96x 161x 161x 8x 2x 2x 6x 8x 161x 161x 70x 2x 2x 68x 70x 161x 161x 19x 2x 2x 17x 1x 1x 16x 19x 161x 161x 162x 1x 1x 161x 162x 161x 161x 5x 1x 1x 5x 2x 2x 2x 5x 161x 161x 61x 1x 1x 60x 61x 1x 1x 61x 1x 1x 50x 47x 61x 161x 161x 35x 1x 1x 34x 34x 34x 34x 35x 30x 35x 3x 3x 33x 33x 33x 35x 35x 35x 1x 1x 1x 1x 31x 35x 161x 161x 5x 1x 1x 5x 5x 2x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 161x 161x 161x 161x 161x 2x 2x 2x 2x 2x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 7x 7x 7x 89x 104x 104x 1x 1x 1x 1x 88x 104x 6x 6x 6x 6x 6x 6x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 82x 57x 57x 57x 28x 28x 1x 1x 28x 1x 1x 28x 1x 1x 25x 18x 18x 25x 57x 57x 57x 57x 57x 54x 57x 3x 3x 57x 57x 57x 82x 82x 82x 104x 2x 2x 4x 1x 1x 3x 2x 2x 3x 4x 2x 2x 150x 1x 1x 150x 2x 2x 150x 10x 10x 137x 150x 2x 2x 5x 1x 1x 5x 4x 5x 2x 2x 2x 2x 2x 2x 1x 1x 1x 2x 2x 161x 161x 161x 17x 17x 1x 1x 1x 17x 16x 2x 1x 1x 1x 1x 16x 16x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 17x 161x 161x 12x 1x 1x 11x 12x 1x 1x 3x 12x 161x 161x 36133x 36133x 114x 60x 54x 54x 114x 2x 2x 6x 4x 36133x 36133x 36133x 161x 161x 161x 161x 161x 161x 161x 161x | 'use strict'; const assert = require('internal/assert'); const { ArrayIsArray, ArrayPrototypeForEach, ArrayPrototypeIndexOf, ArrayPrototypeSome, ObjectCreate, ObjectDefineProperty, ObjectGetPrototypeOf, ObjectSetPrototypeOf, PromiseAll, ReflectApply, SafeWeakMap, Symbol, SymbolToStringTag, TypeError, } = primordials; const { isContext } = internalBinding('contextify'); const { isModuleNamespaceObject, isArrayBufferView, } = require('internal/util/types'); const { customInspectSymbol, emitExperimentalWarning, getConstructorOf, kEmptyObject, } = require('internal/util'); const { ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, ERR_VM_MODULE_ALREADY_LINKED, ERR_VM_MODULE_DIFFERENT_CONTEXT, ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA, ERR_VM_MODULE_LINK_FAILURE, ERR_VM_MODULE_NOT_MODULE, ERR_VM_MODULE_STATUS, } = require('internal/errors').codes; const { validateBoolean, validateFunction, validateInt32, validateObject, validateUint32, validateString, } = require('internal/validators'); const binding = internalBinding('module_wrap'); const { ModuleWrap, kUninstantiated, kInstantiating, kInstantiated, kEvaluating, kEvaluated, kErrored, } = binding; const STATUS_MAP = { [kUninstantiated]: 'unlinked', [kInstantiating]: 'linking', [kInstantiated]: 'linked', [kEvaluating]: 'evaluating', [kEvaluated]: 'evaluated', [kErrored]: 'errored', }; let globalModuleId = 0; const defaultModuleName = 'vm:module'; const wrapToModuleMap = new SafeWeakMap(); const kWrap = Symbol('kWrap'); const kContext = Symbol('kContext'); const kPerContextModuleId = Symbol('kPerContextModuleId'); const kLink = Symbol('kLink'); class Module { constructor(options) { emitExperimentalWarning('VM Modules'); if (new.target === Module) { // eslint-disable-next-line no-restricted-syntax throw new TypeError('Module is not a constructor'); } const { context, sourceText, syntheticExportNames, syntheticEvaluationSteps, } = options; if (context !== undefined) { validateObject(context, 'context'); if (!isContext(context)) { throw new ERR_INVALID_ARG_TYPE('options.context', 'vm.Context', context); } } let { identifier } = options; if (identifier !== undefined) { validateString(identifier, 'options.identifier'); } else if (context === undefined) { identifier = `${defaultModuleName}(${globalModuleId++})`; } else if (context[kPerContextModuleId] !== undefined) { const curId = context[kPerContextModuleId]; identifier = `${defaultModuleName}(${curId})`; context[kPerContextModuleId] += 1; } else { identifier = `${defaultModuleName}(0)`; ObjectDefineProperty(context, kPerContextModuleId, { __proto__: null, value: 1, writable: true, enumerable: false, configurable: true, }); } if (sourceText !== undefined) { this[kWrap] = new ModuleWrap(identifier, context, sourceText, options.lineOffset, options.columnOffset, options.cachedData); binding.callbackMap.set(this[kWrap], { initializeImportMeta: options.initializeImportMeta, importModuleDynamically: options.importModuleDynamically ? importModuleDynamicallyWrap(options.importModuleDynamically) : undefined, }); } else { assert(syntheticEvaluationSteps); this[kWrap] = new ModuleWrap(identifier, context, syntheticExportNames, syntheticEvaluationSteps); } wrapToModuleMap.set(this[kWrap], this); this[kContext] = context; } get identifier() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } return this[kWrap].url; } get context() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } return this[kContext]; } get namespace() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (this[kWrap].getStatus() < kInstantiated) { throw new ERR_VM_MODULE_STATUS('must not be unlinked or linking'); } return this[kWrap].getNamespace(); } get status() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } return STATUS_MAP[this[kWrap].getStatus()]; } get error() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (this[kWrap].getStatus() !== kErrored) { throw new ERR_VM_MODULE_STATUS('must be errored'); } return this[kWrap].getError(); } async link(linker) { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } validateFunction(linker, 'linker'); if (this.status === 'linked') { throw new ERR_VM_MODULE_ALREADY_LINKED(); } if (this.status !== 'unlinked') { throw new ERR_VM_MODULE_STATUS('must be unlinked'); } await this[kLink](linker); this[kWrap].instantiate(); } async evaluate(options = kEmptyObject) { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } validateObject(options, 'options'); let timeout = options.timeout; if (timeout === undefined) { timeout = -1; } else { validateUint32(timeout, 'options.timeout', true); } const { breakOnSigint = false } = options; validateBoolean(breakOnSigint, 'options.breakOnSigint'); const status = this[kWrap].getStatus(); if (status !== kInstantiated && status !== kEvaluated && status !== kErrored) { throw new ERR_VM_MODULE_STATUS( 'must be one of linked, evaluated, or errored' ); } await this[kWrap].evaluate(timeout, breakOnSigint); } [customInspectSymbol](depth, options) { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (typeof depth === 'number' && depth < 0) return this; const constructor = getConstructorOf(this) || Module; const o = ObjectCreate({ constructor }); o.status = this.status; o.identifier = this.identifier; o.context = this.context; ObjectSetPrototypeOf(o, ObjectGetPrototypeOf(this)); ObjectDefineProperty(o, SymbolToStringTag, { __proto__: null, value: constructor.name, configurable: true }); // Lazy to avoid circular dependency const { inspect } = require('internal/util/inspect'); return inspect(o, { ...options, customInspect: false }); } } const kDependencySpecifiers = Symbol('kDependencySpecifiers'); const kNoError = Symbol('kNoError'); class SourceTextModule extends Module { #error = kNoError; #statusOverride; constructor(sourceText, options = kEmptyObject) { validateString(sourceText, 'sourceText'); validateObject(options, 'options'); const { lineOffset = 0, columnOffset = 0, initializeImportMeta, importModuleDynamically, context, identifier, cachedData, } = options; validateInt32(lineOffset, 'options.lineOffset'); validateInt32(columnOffset, 'options.columnOffset'); if (initializeImportMeta !== undefined && typeof initializeImportMeta !== 'function') { throw new ERR_INVALID_ARG_TYPE( 'options.initializeImportMeta', 'function', initializeImportMeta); } if (importModuleDynamically !== undefined && typeof importModuleDynamically !== 'function') { throw new ERR_INVALID_ARG_TYPE( 'options.importModuleDynamically', 'function', importModuleDynamically); } if (cachedData !== undefined && !isArrayBufferView(cachedData)) { throw new ERR_INVALID_ARG_TYPE( 'options.cachedData', ['Buffer', 'TypedArray', 'DataView'], cachedData ); } super({ sourceText, context, identifier, lineOffset, columnOffset, cachedData, initializeImportMeta, importModuleDynamically, }); this[kLink] = async (linker) => { this.#statusOverride = 'linking'; const promises = this[kWrap].link(async (identifier, assert) => { const module = await linker(identifier, this, { assert }); if (module[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (module.context !== this.context) { throw new ERR_VM_MODULE_DIFFERENT_CONTEXT(); } if (module.status === 'errored') { throw new ERR_VM_MODULE_LINK_FAILURE(`request for '${identifier}' resolved to an errored module`, module.error); } if (module.status === 'unlinked') { await module[kLink](linker); } return module[kWrap]; }); try { if (promises !== undefined) { await PromiseAll(promises); } } catch (e) { this.#error = e; throw e; } finally { this.#statusOverride = undefined; } }; this[kDependencySpecifiers] = undefined; } get dependencySpecifiers() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (this[kDependencySpecifiers] === undefined) { this[kDependencySpecifiers] = this[kWrap].getStaticDependencySpecifiers(); } return this[kDependencySpecifiers]; } get status() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (this.#error !== kNoError) { return 'errored'; } if (this.#statusOverride) { return this.#statusOverride; } return super.status; } get error() { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (this.#error !== kNoError) { return this.#error; } return super.error; } createCachedData() { const { status } = this; if (status === 'evaluating' || status === 'evaluated' || status === 'errored') { throw new ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA(); } return this[kWrap].createCachedData(); } } class SyntheticModule extends Module { constructor(exportNames, evaluateCallback, options = kEmptyObject) { if (!ArrayIsArray(exportNames) || ArrayPrototypeSome(exportNames, (e) => typeof e !== 'string')) { throw new ERR_INVALID_ARG_TYPE('exportNames', 'Array of unique strings', exportNames); } else { ArrayPrototypeForEach(exportNames, (name, i) => { if (ArrayPrototypeIndexOf(exportNames, name, i + 1) !== -1) { throw new ERR_INVALID_ARG_VALUE(`exportNames.${name}`, name, 'is duplicated'); } }); } validateFunction(evaluateCallback, 'evaluateCallback'); validateObject(options, 'options'); const { context, identifier } = options; super({ syntheticExportNames: exportNames, syntheticEvaluationSteps: evaluateCallback, context, identifier, }); this[kLink] = () => this[kWrap].link(() => { assert.fail('link callback should not be called'); }); } setExport(name, value) { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } validateString(name, 'name'); if (this[kWrap].getStatus() < kInstantiated) { throw new ERR_VM_MODULE_STATUS('must be linked'); } this[kWrap].setExport(name, value); } } function importModuleDynamicallyWrap(importModuleDynamically) { const importModuleDynamicallyWrapper = async (...args) => { const m = await ReflectApply(importModuleDynamically, this, args); if (isModuleNamespaceObject(m)) { return m; } if (!m || m[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } if (m.status === 'errored') { throw m.error; } return m.namespace; }; return importModuleDynamicallyWrapper; } module.exports = { Module, SourceTextModule, SyntheticModule, importModuleDynamicallyWrap, getModuleFromWrap: (wrap) => wrapToModuleMap.get(wrap), }; |