"use strict";
/**
 * @module fly
 * @private
 */
Object.defineProperty(exports, "__esModule", { value: true });
// import dispatcherInit from './fly/dispatcher'
const bridge_1 = require("./bridge");
const events_1 = require("./events");
const streams_1 = require("./streams");
const console_1 = require("./console");
const index_1 = require("./fly/index");
const universal_url_lite_1 = require("universal-url-lite"); //'whatwg-url'
const headers_1 = require("./headers");
const text_encoding_1 = require("./text-encoding");
const fetch_1 = require("./fetch");
const body_mixin_1 = require("./body_mixin");
const blob_1 = require("./blob");
const form_data_1 = require("./form_data");
const crypto_1 = require("./crypto");
const response_1 = require("./response");
const request_1 = require("./request");
const cache_1 = require("./cache");
const timers_1 = require("./timers");
const document_1 = require("./document");
const middleware_1 = require("./middleware");
global.middleware = {};
global.bootstrapBridge = function bootstrapBridge(ivm, dispatch) {
    delete global.bootstrapBridge;
    bridge_1.default(ivm, dispatch);
};
global.bootstrap = function bootstrap() {
    // Cleanup, early!
    delete global.bootstrap;
    // Sets up `Error.prepareStacktrace`, for source map support
    require('./error');
    global.fly = index_1.default();
    global.console = console_1.console;
    Object.assign(global, {
        setTimeout: timers_1.setTimeout, clearTimeout: timers_1.clearTimeout, setImmediate: timers_1.setImmediate, setInterval: timers_1.setInterval, clearInterval: timers_1.clearInterval,
        ReadableStream: streams_1.ReadableStream, WritableStream: streams_1.WritableStream, TransformStream: streams_1.TransformStream,
        TextEncoder: text_encoding_1.TextEncoder, TextDecoder: text_encoding_1.TextDecoder,
        Headers: headers_1.default, Request: request_1.Request, Response: response_1.Response, fetch: fetch_1.fetch, Body: body_mixin_1.default,
        Blob: blob_1.default, FormData: form_data_1.default, URL: universal_url_lite_1.URL, URLSearchParams: universal_url_lite_1.URLSearchParams,
        cache: cache_1.default, crypto: crypto_1.crypto, TimeoutError: fetch_1.TimeoutError,
        MiddlewareChain: middleware_1.MiddlewareChain // ugh
    });
    // Events
    global.fireFetchEvent = events_1.fireFetchEvent;
    global.addEventListener = events_1.addEventListener;
    global.dispatchEvent = events_1.dispatchEvent;
    global.FetchEvent = events_1.FetchEvent;
    // DOM
    global.Document = document_1.Document;
    global.Element = document_1.Element;
    global.getHeapStatistics = function getHeapStatistics() {
        return new Promise((resolve, reject) => {
            global.bridge.dispatch("getHeapStatistics", function getHeapStatisticsPromise(err, heap) {
                if (err) {
                    reject(err);
                    return;
                }
                resolve(heap);
            });
        });
    };
};
//# sourceMappingURL=index.js.map