edge-runtime
Advanced tools
Comparing version 1.1.0-beta.3 to 1.1.0-beta.4
import type { DispatchFetch } from './types'; | ||
import type { Primitives } from '@edge-runtime/vm'; | ||
import type { EdgeVMOptions } from '@edge-runtime/vm'; | ||
import type { Primitives, EdgeVMOptions } from '@edge-runtime/vm'; | ||
import { EdgeVM } from '@edge-runtime/vm'; | ||
@@ -5,0 +4,0 @@ interface Options<T extends Primitives> extends EdgeVMOptions<T> { |
@@ -10,3 +10,4 @@ "use strict"; | ||
*/ | ||
let HANDLERS; | ||
let unhandledRejectionHandlers; | ||
let uncaughtExceptionHandlers; | ||
/** | ||
@@ -26,12 +27,15 @@ * An EdgeVM that also allows to add and remove event listeners for unhandled | ||
}); | ||
Object.defineProperty(this.context, '__onUnhandledRejectionHandler', { | ||
value: (handlers) => (HANDLERS = handlers), | ||
configurable: false, | ||
enumerable: false, | ||
writable: true, | ||
defineHandlerProps({ | ||
object: this, | ||
setterName: '__onUnhandledRejectionHandler', | ||
setter: (handlers) => (unhandledRejectionHandlers = handlers), | ||
getterName: '__rejectionHandlers', | ||
getter: () => unhandledRejectionHandlers, | ||
}); | ||
Object.defineProperty(this, '__rejectionHandlers', { | ||
get: () => HANDLERS, | ||
configurable: false, | ||
enumerable: false, | ||
defineHandlerProps({ | ||
object: this, | ||
setterName: '__onErrorHandler', | ||
setter: (handlers) => (uncaughtExceptionHandlers = handlers), | ||
getterName: '__errorHandlers', | ||
getter: () => uncaughtExceptionHandlers, | ||
}); | ||
@@ -53,13 +57,17 @@ Object.defineProperty(this.context, 'VercelRuntime', { | ||
/** | ||
* Define a system-level handler to make sure that we report to the user | ||
* whenever there is an unhandled rejection before the process crashes. | ||
* Define system-level handlers to make sure that we report to the user | ||
* whenever there is an unhandled rejection or exception before the process crashes. | ||
*/ | ||
process.on('unhandledRejection', (reason, promise) => { | ||
HANDLERS === null || HANDLERS === void 0 ? void 0 : HANDLERS.forEach((handler) => handler(reason, promise)); | ||
process.on('unhandledRejection', function invokeRejectionHandlers(reason, promise) { | ||
unhandledRejectionHandlers === null || unhandledRejectionHandlers === void 0 ? void 0 : unhandledRejectionHandlers.forEach((handler) => handler(reason, promise)); | ||
}); | ||
process.on('uncaughtException', function invokeErrorHandlers(error) { | ||
uncaughtExceptionHandlers === null || uncaughtExceptionHandlers === void 0 ? void 0 : uncaughtExceptionHandlers.forEach((handler) => handler(error)); | ||
}); | ||
/** | ||
* Generates polyfills for addEventListener and removeEventListener. It keeps | ||
* all listeners in hidden property __listeners. It will also call a hook | ||
* `__onUnhandledRejectionHandler` when unhandled rejection events are added | ||
* or removed and prevent from having more than one FetchEvent handler. | ||
* `__onUnhandledRejectionHandler` and `__onErrorHandler` when unhandled rejection | ||
* events are added or removed and prevent from having more than one FetchEvent | ||
* handler. | ||
*/ | ||
@@ -75,2 +83,10 @@ function getDefineEventListenersCode() { | ||
function conditionallyUpdatesHandlerList(eventType) { | ||
if (eventType === 'unhandledrejection') { | ||
self.__onUnhandledRejectionHandler = self.__listeners[eventType]; | ||
} else if (eventType === 'error') { | ||
self.__onErrorHandler = self.__listeners[eventType]; | ||
} | ||
} | ||
function addEventListener(type, handler) { | ||
@@ -84,6 +100,3 @@ const eventType = type.toLowerCase(); | ||
self.__listeners[eventType].push(handler); | ||
if (eventType === 'unhandledrejection') { | ||
self.__onUnhandledRejectionHandler(self.__listeners.unhandledrejection) | ||
} | ||
conditionallyUpdatesHandlerList(eventType); | ||
} | ||
@@ -102,6 +115,3 @@ | ||
} | ||
if (eventType === 'unhandledrejection') { | ||
self.__onUnhandledRejectionHandler(self.__listeners.unhandledrejection) | ||
} | ||
conditionallyUpdatesHandlerList(eventType); | ||
} | ||
@@ -147,2 +157,18 @@ `; | ||
} | ||
/** | ||
* Defines a readable property on the VM and the corresponding writable property | ||
* on the VM's context. These properties are not enumerable nor updatable. | ||
*/ | ||
function defineHandlerProps({ object: instance, setterName, setter: setter, getterName, getter, }) { | ||
Object.defineProperty(instance.context, setterName, { | ||
set: setter, | ||
configurable: false, | ||
enumerable: false, | ||
}); | ||
Object.defineProperty(instance, getterName, { | ||
get: getter, | ||
configurable: false, | ||
enumerable: false, | ||
}); | ||
} | ||
//# sourceMappingURL=edge-runtime.js.map |
@@ -25,1 +25,4 @@ import type { Colors } from 'picocolors/types'; | ||
} | ||
export interface ErrorHandler { | ||
(error?: {} | null): void; | ||
} |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "1.1.0-beta.3"; | ||
export declare const VERSION = "1.1.0-beta.4"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VERSION = void 0; | ||
exports.VERSION = "1.1.0-beta.3"; | ||
exports.VERSION = "1.1.0-beta.4"; | ||
//# sourceMappingURL=version.js.map |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://edge-runtime.vercel.app/packages/runtime", | ||
"version": "1.1.0-beta.3", | ||
"version": "1.1.0-beta.4", | ||
"main": "dist/index.js", | ||
@@ -26,3 +26,3 @@ "bin": { | ||
"@edge-runtime/format": "^1.0.0", | ||
"@edge-runtime/vm": "^1.1.0-beta.3", | ||
"@edge-runtime/vm": "^1.1.0-beta.4", | ||
"exit-hook": "2.2.1", | ||
@@ -65,3 +65,3 @@ "http-status": "~1.5.0", | ||
"types": "dist/index.d.ts", | ||
"gitHead": "5f4c615ce2dff17b5427fb236495f6e8c37803c4" | ||
"gitHead": "bfcddeda00aece1f9a58d16e29331f7450755e75" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76030
645