Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Aug 3, 2021
1 parent eaa22a7 commit 574381b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion lib/internal/policy/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class DependencyMapperInstance {
* @type {DependencyMap | undefined}
*/
#dependencies;
/**
* @type {PatternDependencyMap | undefined}
*/
#patternDependencies;
/**
* @type {DependencyMapperInstance | null | undefined}
*/
Expand All @@ -107,14 +111,44 @@ class DependencyMapperInstance {
* @type {boolean}
*/
allowSameHREFScope;
/**
*
* @param {string} parentHREF
* @param {DependencyMap | undefined} dependencies
* @param {boolean} cascade
* @param {boolean} allowSameHREFScope
*/
constructor(
parentHREF,
dependencies,
cascade = false,
allowSameHREFScope = false
) {
this.href = parentHREF;
this.#dependencies = dependencies;
if (dependencies === kFallThrough || dependencies === undefined) {
this.#dependencies = dependencies;
this.#patternDependencies = undefined;
} else {
let patterns = [];
let direct = ObjectCreate(null);
for (const [key, value] of Object.entries(dependencies)) {
if (key.endsWith('*')) {
let target = /^([^*]*)\*([^*]*)$/.exec(value);
if (!target) {
throw new Error('pattern needs to have a single "*" in target');
}
let prefix = target[1];
let suffix = target[2];
patterns.push([
target.slice(0, -1),
[prefix, suffix]
]);
}
}
patterns.sort((a, b) => a[0] < b[0] ? -1 : 1);
this.#dependencies = dependencies;
this.#patternDependencies = patterns;
}
this.cascade = cascade;
this.allowSameHREFScope = allowSameHREFScope;
ObjectFreeze(this);
Expand Down Expand Up @@ -303,6 +337,7 @@ function findScopeHREF(href, scopeStore, allowSame) {

/**
* @typedef {Record<string, string> | typeof kFallThrough} DependencyMap
* @typedef {Array<[string, [string, string]]>} PatternDependencyMap
* @typedef {Record<string, string> | null | true} JSONDependencyMap
*/
/**
Expand Down

0 comments on commit 574381b

Please sign in to comment.