From 0e71f5efd68d06679944600cff2c65e6dac093c4 Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Sun, 15 Jan 2023 16:04:22 -0800 Subject: [PATCH] chore: cleanup JS runtime v2 - chore: drop old JS facade - chore: drop old JS facade config --- .../embedded/runtime/abort-controller.js | 389 ------------------ .../elide/embedded/runtime/globals.js | 5 - .../META-INF/elide/embedded/runtime/invoke.js | 14 - .../elide/embedded/runtime/preamble.js | 29 -- .../elide/embedded/runtime/runtime-js.json | 4 - 5 files changed, 441 deletions(-) delete mode 100644 packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/abort-controller.js delete mode 100644 packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/globals.js delete mode 100644 packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/invoke.js delete mode 100644 packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/preamble.js delete mode 100644 packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/runtime-js.json diff --git a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/abort-controller.js b/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/abort-controller.js deleted file mode 100644 index 886ce4bd57..0000000000 --- a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/abort-controller.js +++ /dev/null @@ -1,389 +0,0 @@ -(function (factory) { - typeof define === "function" && define.amd ? define(factory) : factory(); -})(function () { - "use strict"; - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - Object.defineProperty(Constructor, "prototype", { - writable: false, - }); - return Constructor; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function"); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - writable: true, - configurable: true, - }, - }); - Object.defineProperty(subClass, "prototype", { - writable: false, - }); - if (superClass) _setPrototypeOf(subClass, superClass); - } - - function _getPrototypeOf(o) { - _getPrototypeOf = Object.setPrototypeOf - ? Object.getPrototypeOf.bind() - : function _getPrototypeOf(o) { - return o.__proto__ || Object.getPrototypeOf(o); - }; - return _getPrototypeOf(o); - } - - function _setPrototypeOf(o, p) { - _setPrototypeOf = Object.setPrototypeOf - ? Object.setPrototypeOf.bind() - : function _setPrototypeOf(o, p) { - o.__proto__ = p; - return o; - }; - return _setPrototypeOf(o, p); - } - - function _isNativeReflectConstruct() { - if (typeof Reflect === "undefined" || !Reflect.construct) return false; - if (Reflect.construct.sham) return false; - if (typeof Proxy === "function") return true; - - try { - Boolean.prototype.valueOf.call( - Reflect.construct(Boolean, [], function () {}) - ); - return true; - } catch (e) { - return false; - } - } - - function _assertThisInitialized(self) { - if (self === void 0) { - throw new ReferenceError( - "this hasn't been initialised - super() hasn't been called" - ); - } - - return self; - } - - function _possibleConstructorReturn(self, call) { - if (call && (typeof call === "object" || typeof call === "function")) { - return call; - } else if (call !== void 0) { - throw new TypeError( - "Derived constructors may only return object or undefined" - ); - } - - return _assertThisInitialized(self); - } - - function _createSuper(Derived) { - var hasNativeReflectConstruct = _isNativeReflectConstruct(); - - return function _createSuperInternal() { - var Super = _getPrototypeOf(Derived), - result; - - if (hasNativeReflectConstruct) { - var NewTarget = _getPrototypeOf(this).constructor; - - result = Reflect.construct(Super, arguments, NewTarget); - } else { - result = Super.apply(this, arguments); - } - - return _possibleConstructorReturn(this, result); - }; - } - - function _superPropBase(object, property) { - while (!Object.prototype.hasOwnProperty.call(object, property)) { - object = _getPrototypeOf(object); - if (object === null) break; - } - - return object; - } - - function _get() { - if (typeof Reflect !== "undefined" && Reflect.get) { - _get = Reflect.get.bind(); - } else { - _get = function _get(target, property, receiver) { - var base = _superPropBase(target, property); - - if (!base) return; - var desc = Object.getOwnPropertyDescriptor(base, property); - - if (desc.get) { - return desc.get.call(arguments.length < 3 ? target : receiver); - } - - return desc.value; - }; - } - - return _get.apply(this, arguments); - } - - var Emitter = /*#__PURE__*/ (function () { - function Emitter() { - _classCallCheck(this, Emitter); - - Object.defineProperty(this, "listeners", { - value: {}, - writable: true, - configurable: true, - }); - } - - _createClass(Emitter, [ - { - key: "addEventListener", - value: function addEventListener(type, callback, options) { - if (!(type in this.listeners)) { - this.listeners[type] = []; - } - - this.listeners[type].push({ - callback: callback, - options: options, - }); - }, - }, - { - key: "removeEventListener", - value: function removeEventListener(type, callback) { - if (!(type in this.listeners)) { - return; - } - - var stack = this.listeners[type]; - - for (var i = 0, l = stack.length; i < l; i++) { - if (stack[i].callback === callback) { - stack.splice(i, 1); - return; - } - } - }, - }, - { - key: "dispatchEvent", - value: function dispatchEvent(event) { - if (!(event.type in this.listeners)) { - return; - } - - var stack = this.listeners[event.type]; - var stackToCall = stack.slice(); - - for (var i = 0, l = stackToCall.length; i < l; i++) { - var listener = stackToCall[i]; - - try { - listener.callback.call(this, event); - } catch (e) { - Promise.resolve().then(function () { - throw e; - }); - } - - if (listener.options && listener.options.once) { - this.removeEventListener(event.type, listener.callback); - } - } - - return !event.defaultPrevented; - }, - }, - ]); - - return Emitter; - })(); - - var AbortSignal = /*#__PURE__*/ (function (_Emitter) { - _inherits(AbortSignal, _Emitter); - - var _super = _createSuper(AbortSignal); - - function AbortSignal() { - var _this; - - _classCallCheck(this, AbortSignal); - - _this = _super.call(this); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent - // constructor has failed to run, then "this.listeners" will still be undefined and then we call - // the parent constructor directly instead as a workaround. For general details, see babel bug: - // https://github.com/babel/babel/issues/3041 - // This hack was added as a fix for the issue described here: - // https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042 - - if (!_this.listeners) { - Emitter.call(_assertThisInitialized(_this)); - } // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and - // we want Object.keys(new AbortController().signal) to be [] for compat with the native impl - - Object.defineProperty(_assertThisInitialized(_this), "aborted", { - value: false, - writable: true, - configurable: true, - }); - Object.defineProperty(_assertThisInitialized(_this), "onabort", { - value: null, - writable: true, - configurable: true, - }); - return _this; - } - - _createClass(AbortSignal, [ - { - key: "toString", - value: function toString() { - return "[object AbortSignal]"; - }, - }, - { - key: "dispatchEvent", - value: function dispatchEvent(event) { - if (event.type === "abort") { - this.aborted = true; - - if (typeof this.onabort === "function") { - this.onabort.call(this, event); - } - } - - _get( - _getPrototypeOf(AbortSignal.prototype), - "dispatchEvent", - this - ).call(this, event); - }, - }, - ]); - - return AbortSignal; - })(Emitter); - var AbortController = /*#__PURE__*/ (function () { - function AbortController() { - _classCallCheck(this, AbortController); - - // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and - // we want Object.keys(new AbortController()) to be [] for compat with the native impl - Object.defineProperty(this, "signal", { - value: new AbortSignal(), - writable: true, - configurable: true, - }); - } - - _createClass(AbortController, [ - { - key: "abort", - value: function abort() { - var event; - - try { - event = new Event("abort"); - } catch (e) { - if (typeof document !== "undefined") { - if (!document.createEvent) { - // For Internet Explorer 8: - event = document.createEventObject(); - event.type = "abort"; - } else { - // For Internet Explorer 11: - event = document.createEvent("Event"); - event.initEvent("abort", false, false); - } - } else { - // Fallback where document isn't available: - event = { - type: "abort", - bubbles: false, - cancelable: false, - }; - } - } - - this.signal.dispatchEvent(event); - }, - }, - { - key: "toString", - value: function toString() { - return "[object AbortController]"; - }, - }, - ]); - - return AbortController; - })(); - - if (typeof Symbol !== "undefined" && Symbol.toStringTag) { - // These are necessary to make sure that we get correct output for: - // Object.prototype.toString.call(new AbortController()) - AbortController.prototype[Symbol.toStringTag] = "AbortController"; - AbortSignal.prototype[Symbol.toStringTag] = "AbortSignal"; - } - - function polyfillNeeded(self) { - if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { - console.log( - "__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill" - ); - return true; - } // Note that the "unfetch" minimal fetch polyfill defines fetch() without - // defining window.Request, and this polyfill need to work on top of unfetch - // so the below feature detection needs the !self.AbortController part. - // The Request.prototype check is also needed because Safari versions 11.1.2 - // up to and including 12.1.x has a window.AbortController present but still - // does NOT correctly implement abortable fetch: - // https://bugs.webkit.org/show_bug.cgi?id=174980#c2 - - return ( - (typeof self.Request === "function" && - !self.Request.prototype.hasOwnProperty("signal")) || - !self.AbortController - ); - } - - (function (self) { - if (!polyfillNeeded(self)) { - return; - } - - self.AbortController = AbortController; - self.AbortSignal = AbortSignal; - })(typeof self !== "undefined" ? self : global); -}); - -const AbortController = global["AbortController"]; -const AbortSignal = global["AbortSignal"]; diff --git a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/globals.js b/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/globals.js deleted file mode 100644 index 8183c53358..0000000000 --- a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/globals.js +++ /dev/null @@ -1,5 +0,0 @@ -// define an empty object called 'process' -globalThis.process = {} - -// define the 'Buffer' global symbol -globalThis.Buffer = require('buffer').Buffer; diff --git a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/invoke.js b/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/invoke.js deleted file mode 100644 index 5ca5bee530..0000000000 --- a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/invoke.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Invoke the user's `renderContent` entrypoint function after setting up runtime state. - */ -function embeddedExecute() { - // noinspection JSUnresolvedFunction,JSUnresolvedVariable - const renderContent = embedded.renderContent; - // noinspection JSUnresolvedFunction,JSUnresolvedVariable - const renderStream = embedded.renderStream; - return { - renderContent, - renderStream, - }; -} -embeddedExecute(); diff --git a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/preamble.js b/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/preamble.js deleted file mode 100644 index fc9407a86c..0000000000 --- a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/preamble.js +++ /dev/null @@ -1,29 +0,0 @@ -const process = this["process"] || { - pid: -1, - cwd: () => "", - env: {}, - NODE_DEBUG: false, - NODE_ENV: "production", - noDeprecation: false, - browser: false, - version: 'v18.9.0' -}; - -globalThis.process = process; - -const window = undefined; -const global = globalThis || this; -const self = globalThis || this; - -let gc = null; - -const Elide = { - process, - global, - self, - context: { - build: false, - runtime: true - } -}; -globalThis.Elide = Elide; diff --git a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/runtime-js.json b/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/runtime-js.json deleted file mode 100644 index 0f20f1a11c..0000000000 --- a/packages/graalvm/src/main/resources/META-INF/elide/embedded/runtime/runtime-js.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "artifacts": [{ "name": "preamble.js" }, { "name": "abort-controller.js" }], - "entry": "invoke.js" -}