From 976065d9cb88a118c0238a8518a2570b28cce817 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 29 Nov 2018 05:27:18 +0800 Subject: [PATCH] lib: do not register DOMException in a module Instead of registering it in a global scope of a native module and expecting that it only gets evaluated when the module is actually compiled and run and will not be evaluated because the module can be cached, directly register the DOMException constructor onto Environment during bootstrap for clarity, since this is a side effect that has to happen during bootstrap. PR-URL: https://github.com/nodejs/node/pull/24708 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/internal/bootstrap/node.js | 4 +++- lib/internal/domexception.js | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 98d4b3c1d9c283..67093089f7af08 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -566,7 +566,9 @@ function setupDOMException() { // Registers the constructor with C++. - NativeModule.require('internal/domexception'); + const DOMException = NativeModule.require('internal/domexception'); + const { registerDOMException } = internalBinding('messaging'); + registerDOMException(DOMException); } function setupInspector(originalConsole, wrappedConsole) { diff --git a/lib/internal/domexception.js b/lib/internal/domexception.js index 3f9d3f36018264..9845919e498dae 100644 --- a/lib/internal/domexception.js +++ b/lib/internal/domexception.js @@ -1,6 +1,5 @@ 'use strict'; -const { registerDOMException } = internalBinding('messaging'); const { ERR_INVALID_THIS } = require('internal/errors').codes; const internalsMap = new WeakMap(); @@ -85,5 +84,3 @@ for (const [name, codeName, value] of [ } module.exports = DOMException; - -registerDOMException(DOMException);