mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +00:00

PR-URL: https://github.com/nodejs/node/pull/27146 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
58 lines
1.1 KiB
JavaScript
58 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const { JSON, Object, Reflect } = primordials;
|
|
|
|
const {
|
|
ERR_MANIFEST_TDZ,
|
|
} = require('internal/errors').codes;
|
|
const { Manifest } = require('internal/policy/manifest');
|
|
let manifest;
|
|
let manifestSrc;
|
|
let manifestURL;
|
|
|
|
module.exports = Object.freeze({
|
|
__proto__: null,
|
|
setup(src, url) {
|
|
manifestSrc = src;
|
|
manifestURL = url;
|
|
if (src === null) {
|
|
manifest = null;
|
|
return;
|
|
}
|
|
|
|
const json = JSON.parse(src, (_, o) => {
|
|
if (o && typeof o === 'object') {
|
|
Reflect.setPrototypeOf(o, null);
|
|
Object.freeze(o);
|
|
}
|
|
return o;
|
|
});
|
|
manifest = new Manifest(json, url);
|
|
},
|
|
|
|
get manifest() {
|
|
if (typeof manifest === 'undefined') {
|
|
throw new ERR_MANIFEST_TDZ();
|
|
}
|
|
return manifest;
|
|
},
|
|
|
|
get src() {
|
|
if (typeof manifestSrc === 'undefined') {
|
|
throw new ERR_MANIFEST_TDZ();
|
|
}
|
|
return manifestSrc;
|
|
},
|
|
|
|
get url() {
|
|
if (typeof manifestURL === 'undefined') {
|
|
throw new ERR_MANIFEST_TDZ();
|
|
}
|
|
return manifestURL;
|
|
},
|
|
|
|
assertIntegrity(moduleURL, content) {
|
|
this.manifest.matchesIntegrity(moduleURL, content);
|
|
}
|
|
});
|