Skip to content

Commit

Permalink
declare when not building snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Feb 16, 2025
1 parent c89ce29 commit af7bb75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/web/exposed-wildcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
} = primordials;

const {
doWhenNotBUildingSnapshot,
exposeInterface,
exposeLazyInterfaces,
exposeNamespace,
Expand All @@ -27,7 +28,7 @@ const { URL, URLSearchParams } = require('internal/url');
exposeInterface(globalThis, 'URL', URL);
// https://url.spec.whatwg.org/#urlsearchparams
exposeInterface(globalThis, 'URLSearchParams', URLSearchParams);
exposeLazyDOMExceptionProperty(globalThis);
doWhenNotBUildingSnapshot(() => exposeLazyDOMExceptionProperty(globalThis));

// https://dom.spec.whatwg.org/#interface-abortcontroller
// Lazy ones.
Expand Down
19 changes: 18 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const {
const { signals } = internalBinding('constants').os;
const {
guessHandleType: _guessHandleType,
defineLazyProperties,
defineLazyProperties: _defineLazyProperties,
privateSymbols: {
arrow_message_private_symbol,
decorated_private_symbol,
Expand All @@ -66,6 +66,10 @@ const { isNativeError, isPromise } = internalBinding('types');
const { getOptionValue } = require('internal/options');
const assert = require('internal/assert');
const { encodings } = internalBinding('string_decoder');
const {
isBuildingSnapshot,
addDeserializeCallback,
} = require('internal/v8/startup_snapshot').namespace;

const noCrypto = !process.versions.openssl;
const noTypeScript = !process.versions.amaro;
Expand Down Expand Up @@ -611,6 +615,18 @@ function exposeGetterAndSetter(target, name, getter, setter = undefined) {
});
}

function doWhenNotBUildingSnapshot(fn) {
if (isBuildingSnapshot()) {
addDeserializeCallback(fn);
} else {
fn();
}
}

function defineLazyProperties(...args) {
doWhenNotBUildingSnapshot(() => ReflectApply(_defineLazyProperties, this, args));
}

function defineReplaceableLazyAttribute(target, id, keys, writable = true, check) {
let mod;
for (let i = 0; i < keys.length; i++) {
Expand Down Expand Up @@ -852,6 +868,7 @@ module.exports = {
defineReplaceableLazyAttribute,
deprecate,
deprecateInstantiation,
doWhenNotBUildingSnapshot,
emitExperimentalWarning,
encodingsMap,
exposeInterface,
Expand Down

0 comments on commit af7bb75

Please # to comment.