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