| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,8 +41,10 @@ const shouldAbortOnUncaughtException = | |||
| 41 | 41 | getOptionValue('--abort-on-uncaught-exception'); | |
| 42 | 42 | const { abort, exit, _rawDebug } = process; | |
| 43 | 43 | ||
| 44 | + const kTerminate = () => null; | ||
| 45 | + | ||
| 44 | 46 | // From https://url.spec.whatwg.org/#special-scheme | |
| 45 | - const SPECIAL_SCHEMES = new SafeSet([ | ||
| 47 | + const kSpecialSchemes = new SafeSet([ | ||
| 46 | 48 | 'file:', | |
| 47 | 49 | 'ftp:', | |
| 48 | 50 | 'http:', | |
@@ -76,7 +78,7 @@ function REACTION_LOG(error) { | |||
| 76 | 78 | ||
| 77 | 79 | class Manifest { | |
| 78 | 80 | /** | |
| 79 | - * @type {Map<string, DependencyMapper>} | ||
| 81 | + * @type {Map<string | null | undefined, DependencyMapper>} | ||
| 80 | 82 | * | |
| 81 | 83 | * Used to compare a resource to the content body at the resource. | |
| 82 | 84 | * `true` is used to signify that all integrities are allowed, otherwise, | |
@@ -139,6 +141,8 @@ class Manifest { | |||
| 139 | 141 | */ | |
| 140 | 142 | constructor(obj, manifestURL) { | |
| 141 | 143 | const scopes = this.#scopeDependencies; | |
| 144 | + scopes.set(null, kTerminate); | ||
| 145 | + scopes.set(undefined, kTerminate); | ||
| 142 | 146 | const integrities = this.#resourceIntegrities; | |
| 143 | 147 | const dependencies = this.#resourceDependencies; | |
| 144 | 148 | let reaction = REACTION_THROW; | |
@@ -205,18 +209,20 @@ class Manifest { | |||
| 205 | 209 | return (toSpecifier, conditions) => { | |
| 206 | 210 | if (toSpecifier in dependencyMap !== true) { | |
| 207 | 211 | if (cascade === true) { | |
| 208 | - let scopeHREF; | ||
| 212 | + /** @type {string | null} */ | ||
| 213 | + let scopeHREF = resourceHREF; | ||
| 209 | 214 | if (typeof parentDeps === 'undefined') { | |
| 210 | 215 | do { | |
| 211 | - scopeHREF = this.#findScopeHREF(resourceHREF); | ||
| 216 | + scopeHREF = this.#findScopeHREF(scopeHREF); | ||
| 217 | + if (scopeHREF === resourceHREF) { | ||
| 218 | + scopeHREF = null; | ||
| 219 | + } | ||
| 220 | + if (scopes.has(scopeHREF)) { | ||
| 221 | + break; | ||
| 222 | + } | ||
| 212 | 223 | } while ( | |
| 213 | - scopeHREF !== null && | ||
| 214 | - scopes.has(scopeHREF) !== true | ||
| 224 | + scopeHREF !== null | ||
| 215 | 225 | ); | |
| 216 | - } | ||
| 217 | - if (scopeHREF === null) { | ||
| 218 | - parentDeps = () => null; | ||
| 219 | - } else { | ||
| 220 | 226 | parentDeps = scopes.get(scopeHREF); | |
| 221 | 227 | } | |
| 222 | 228 | return parentDeps(toSpecifier); | |
@@ -417,7 +423,7 @@ class Manifest { | |||
| 417 | 423 | protocol = currentURL.protocol; | |
| 418 | 424 | } | |
| 419 | 425 | // Only a few schemes are hierarchical | |
| 420 | - if (SPECIAL_SCHEMES.has(currentURL.protocol)) { | ||
| 426 | + if (kSpecialSchemes.has(currentURL.protocol)) { | ||
| 421 | 427 | // Make first '..' act like '.' | |
| 422 | 428 | if (!StringPrototypeEndsWith(currentURL.pathname, '/')) { | |
| 423 | 429 | currentURL.pathname += '/'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,14 @@ | |||
| 1 | + { | ||
| 2 | + "resources": { | ||
| 3 | + "../multi-deps.js": { | ||
| 4 | + "integrity": true, | ||
| 5 | + "cascade": true | ||
| 6 | + } | ||
| 7 | + }, | ||
| 8 | + "scopes": { | ||
| 9 | + "../": { | ||
| 10 | + "integrity": true, | ||
| 11 | + "dependencies": true | ||
| 12 | + } | ||
| 13 | + } | ||
| 14 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('fs'); | ||
| 3 | + require('process'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,8 +10,8 @@ const fixtures = require('../common/fixtures'); | |||
| 10 | 10 | const assert = require('assert'); | |
| 11 | 11 | const { spawnSync } = require('child_process'); | |
| 12 | 12 | ||
| 13 | - const dep = fixtures.path('policy', 'main.mjs'); | ||
| 14 | 13 | { | |
| 14 | + const dep = fixtures.path('policy', 'main.mjs'); | ||
| 15 | 15 | const depPolicy = fixtures.path( | |
| 16 | 16 | 'policy', | |
| 17 | 17 | 'dependencies', | |
@@ -24,3 +24,17 @@ const dep = fixtures.path('policy', 'main.mjs'); | |||
| 24 | 24 | ); | |
| 25 | 25 | assert.strictEqual(status, 0); | |
| 26 | 26 | } | |
| 27 | + { | ||
| 28 | + const dep = fixtures.path('policy', 'multi-deps.js'); | ||
| 29 | + const depPolicy = fixtures.path( | ||
| 30 | + 'policy', | ||
| 31 | + 'dependencies', | ||
| 32 | + 'dependencies-scopes-and-resources-policy.json'); | ||
| 33 | + const { status } = spawnSync( | ||
| 34 | + process.execPath, | ||
| 35 | + [ | ||
| 36 | + '--experimental-policy', depPolicy, dep, | ||
| 37 | + ] | ||
| 38 | + ); | ||
| 39 | + assert.strictEqual(status, 0); | ||
| 40 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments