• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const {
4  JSONParse,
5  ObjectFreeze,
6  ReflectSetPrototypeOf,
7} = primordials;
8
9const {
10  ERR_ACCESS_DENIED,
11  ERR_MANIFEST_TDZ,
12} = require('internal/errors').codes;
13const { Manifest } = require('internal/policy/manifest');
14let manifest;
15let manifestSrc;
16let manifestURL;
17
18module.exports = ObjectFreeze({
19  __proto__: null,
20  setup(src, url) {
21    manifestSrc = src;
22    manifestURL = url;
23    if (src === null) {
24      manifest = null;
25      return;
26    }
27
28    const json = JSONParse(src, (_, o) => {
29      if (o && typeof o === 'object') {
30        ReflectSetPrototypeOf(o, null);
31        ObjectFreeze(o);
32      }
33      return o;
34    });
35    manifest = new Manifest(json, url);
36
37    // process.binding() is deprecated (DEP0111) and trivially allows bypassing
38    // policies, so if policies are enabled, make this API unavailable.
39    process.binding = function binding(_module) {
40      throw new ERR_ACCESS_DENIED('process.binding');
41    };
42    process._linkedBinding = function _linkedBinding(_module) {
43      throw new ERR_ACCESS_DENIED('process._linkedBinding');
44    };
45  },
46
47  get manifest() {
48    if (typeof manifest === 'undefined') {
49      throw new ERR_MANIFEST_TDZ();
50    }
51    return manifest;
52  },
53
54  get src() {
55    if (typeof manifestSrc === 'undefined') {
56      throw new ERR_MANIFEST_TDZ();
57    }
58    return manifestSrc;
59  },
60
61  get url() {
62    if (typeof manifestURL === 'undefined') {
63      throw new ERR_MANIFEST_TDZ();
64    }
65    return manifestURL;
66  },
67
68  assertIntegrity(moduleURL, content) {
69    this.manifest.assertIntegrity(moduleURL, content);
70  },
71});
72