Sha256: 6aa8dea52ad19064b3454eec4fada28e4af260289340484d6af11c72c3208b69

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

"use strict";
/* eslint-disable no-process-exit */

const util = require("util");

const jsdom = require("../../jsdom");
const xhrSymbols = require("./xmlhttprequest-symbols");
const tough = require("tough-cookie");

const doc = jsdom.jsdom();
const xhr = new doc.defaultView.XMLHttpRequest();

const chunks = [];

process.stdin.on("data", chunk => {
  chunks.push(chunk);
});

process.stdin.on("end", () => {
  const buffer = Buffer.concat(chunks);
  const flag = JSON.parse(buffer.toString(), (k, v) => {
    if (v && v.type === "Buffer" && v.data) {
      return new Buffer(v.data);
    }
    if (k === "cookieJar" && v) {
      return tough.CookieJar.fromJSON(v);
    }
    return v;
  });
  flag.synchronous = false;
  xhr[xhrSymbols.flag] = flag;
  const properties = xhr[xhrSymbols.properties];
  properties.readyState = doc.defaultView.XMLHttpRequest.OPENED;
  try {
    xhr.addEventListener("loadend", () => {
      if (properties.error) {
        properties.error = properties.error.stack || util.inspect(properties.error);
      }
      process.stdout.write(JSON.stringify({ properties }), () => {
        process.exit(0);
      });
    }, false);
    xhr.send(flag.body);
  } catch (error) {
    properties.error += error.stack || util.inspect(error);
    process.stdout.write(JSON.stringify({ properties }), () => {
      process.exit(0);
    });
  }
});

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/jsdom/lib/jsdom/living/xhr-sync-worker.js
lanes-0.8.0 node_modules/jsdom/lib/jsdom/living/xhr-sync-worker.js
select_all-rails-0.3.1 node_modules/jsdom/lib/jsdom/living/xhr-sync-worker.js