Exemplo n.º 1
0
  _onMessage(message) {
    if (message.id) {
      const { resolve, reject } = this._commandResponsePromises.get(message.id);
      this._commandResponsePromises.delete(message.id);
      if (message.result)
        resolve(message.result);
      else
        reject(message.error);
    } else {
      if (message.method === 'Debugger.scriptParsed') {
        const { scriptId, url } = message.params;
        this._scriptsIdsByUrl.set(scriptId, url);
        const fileUrl = url.startsWith('file:') ?
          url : getURLFromFilePath(url).toString();
        if (fileUrl === this.scriptURL().toString()) {
          this.mainScriptId = scriptId;
        }
      }

      if (this._notificationCallback) {
        // In case callback needs to install another
        const callback = this._notificationCallback;
        this._notificationCallback = null;
        callback(message);
      } else {
        this._unprocessedNotifications.push(message);
      }
    }
  }
Exemplo n.º 2
0
function getBase() {
  try {
    return getURLFromFilePath(`${process.cwd()}/`).href;
  } catch (e) {
    e.stack;
    // If the current working directory no longer exists.
    if (e.code === 'ENOENT') {
      return undefined;
    }
    throw e;
  }
}
Exemplo n.º 3
0
exports.resolve = (specifier, parentURL) => {
  if (NativeModule.nonInternalExists(specifier)) {
    return {
      url: specifier,
      format: 'builtin'
    };
  }

  let url;
  try {
    url = search(specifier, parentURL);
  } catch (e) {
    if (e.message && e.message.startsWith('Cannot find module'))
      e.code = 'MODULE_NOT_FOUND';
    throw e;
  }

  if (url.protocol !== 'file:') {
    throw new errors.Error('ERR_INVALID_PROTOCOL',
                           url.protocol, 'file:');
  }

  if (!preserveSymlinks) {
    const real = realpathSync(internalURLModule.getPathFromURL(url), {
      [internalFS.realpathCacheKey]: realpathCache
    });
    const old = url;
    url = internalURLModule.getURLFromFilePath(real);
    url.search = old.search;
    url.hash = old.hash;
  }

  const ext = extname(url.pathname);
  switch (ext) {
    case '.mjs':
      return { url: `${url}`, format: 'esm' };
    case '.json':
      return { url: `${url}`, format: 'json' };
    case '.node':
      return { url: `${url}`, format: 'addon' };
    case '.js':
      return { url: `${url}`, format: 'cjs' };
    default:
      throw new errors.Error('ERR_UNKNOWN_FILE_EXTENSION',
                             internalURLModule.getPathFromURL(url));
  }
};
Exemplo n.º 4
0
function normalizeReferrerURL(referrer) {
  if (typeof referrer === 'string' && path.isAbsolute(referrer)) {
    return getURLFromFilePath(referrer).href;
  }
  return new URL(referrer).href;
}
Exemplo n.º 5
0
 scriptURL() {
   return getURLFromFilePath(this.scriptPath());
 }