node/lib/internal/process/policy.js
Michaël Zasso 0646eda4fc
lib: flatten access to primordials
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.

PR-URL: https://github.com/nodejs/node/pull/30610
Refs: https://github.com/nodejs/node/issues/29766
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-11-25 10:28:15 +01:00

62 lines
1.2 KiB
JavaScript

'use strict';
const {
JSONParse,
ObjectFreeze,
ReflectSetPrototypeOf,
} = primordials;
const {
ERR_MANIFEST_TDZ,
} = require('internal/errors').codes;
const { Manifest } = require('internal/policy/manifest');
let manifest;
let manifestSrc;
let manifestURL;
module.exports = ObjectFreeze({
__proto__: null,
setup(src, url) {
manifestSrc = src;
manifestURL = url;
if (src === null) {
manifest = null;
return;
}
const json = JSONParse(src, (_, o) => {
if (o && typeof o === 'object') {
ReflectSetPrototypeOf(o, null);
ObjectFreeze(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.assertIntegrity(moduleURL, content);
}
});