Skip to content

Commit 35fdfb4

Browse files
bmeckcodebytere
authored andcommitted
policy: increase tests via permutation matrix
PR-URL: #34404 Reviewed-By: James M Snell <[email protected]>
1 parent 10f29e7 commit 35fdfb4

File tree

7 files changed

+437
-438
lines changed

7 files changed

+437
-438
lines changed

lib/internal/modules/cjs/loader.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,13 @@ function readPackage(requestPath) {
262262
const existing = packageJsonCache.get(jsonPath);
263263
if (existing !== undefined) return existing;
264264

265-
const result = packageJsonReader.read(path.toNamespacedPath(jsonPath));
265+
const result = packageJsonReader.read(jsonPath);
266266
const json = result.containsKeys === false ? '{}' : result.string;
267267
if (json === undefined) {
268268
packageJsonCache.set(jsonPath, false);
269269
return false;
270270
}
271271

272-
if (manifest) {
273-
const jsonURL = pathToFileURL(jsonPath);
274-
manifest.assertIntegrity(jsonURL, json);
275-
}
276-
277272
try {
278273
const parsed = JSONParse(json);
279274
const filtered = {

lib/internal/modules/esm/get_source.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
'use strict';
22

3+
const { getOptionValue } = require('internal/options');
4+
const manifest = getOptionValue('--experimental-policy') ?
5+
require('internal/process/policy').manifest :
6+
null;
7+
38
const { Buffer } = require('buffer');
49

510
const fs = require('fs');
@@ -15,20 +20,22 @@ const DATA_URL_PATTERN = /^[^/]+\/[^,;]+(?:[^,]*?)(;base64)?,([\s\S]*)$/;
1520

1621
async function defaultGetSource(url, { format } = {}, defaultGetSource) {
1722
const parsed = new URL(url);
23+
let source;
1824
if (parsed.protocol === 'file:') {
19-
return {
20-
source: await readFileAsync(parsed)
21-
};
25+
source = await readFileAsync(parsed);
2226
} else if (parsed.protocol === 'data:') {
2327
const match = DATA_URL_PATTERN.exec(parsed.pathname);
2428
if (!match) {
2529
throw new ERR_INVALID_URL(url);
2630
}
2731
const [ , base64, body ] = match;
28-
return {
29-
source: Buffer.from(body, base64 ? 'base64' : 'utf8')
30-
};
32+
source = Buffer.from(body, base64 ? 'base64' : 'utf8');
33+
} else {
34+
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
35+
}
36+
if (manifest) {
37+
manifest.assertIntegrity(parsed, source);
3138
}
32-
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
39+
return { source };
3340
}
3441
exports.defaultGetSource = defaultGetSource;

lib/internal/modules/package_json_reader.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,35 @@
22

33
const { SafeMap } = primordials;
44
const { internalModuleReadJSON } = internalBinding('fs');
5+
const { pathToFileURL } = require('url');
6+
const { toNamespacedPath } = require('path');
57

68
const cache = new SafeMap();
79

810
/**
911
*
10-
* @param {string} path
12+
* @param {string} jsonPath
1113
*/
12-
function read(path) {
13-
if (cache.has(path)) {
14-
return cache.get(path);
14+
function read(jsonPath) {
15+
if (cache.has(jsonPath)) {
16+
return cache.get(jsonPath);
1517
}
1618

17-
const [string, containsKeys] = internalModuleReadJSON(path);
19+
const [string, containsKeys] = internalModuleReadJSON(
20+
toNamespacedPath(jsonPath)
21+
);
1822
const result = { string, containsKeys };
19-
cache.set(path, result);
23+
const { getOptionValue } = require('internal/options');
24+
if (string !== undefined) {
25+
const manifest = getOptionValue('--experimental-policy') ?
26+
require('internal/process/policy').manifest :
27+
null;
28+
if (manifest) {
29+
const jsonURL = pathToFileURL(jsonPath);
30+
manifest.assertIntegrity(jsonURL, string);
31+
}
32+
}
33+
cache.set(jsonPath, result);
2034
return result;
2135
}
2236

lib/internal/worker.js

+3
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ class Worker extends EventEmitter {
205205
cwdCounter: cwdCounter || workerIo.sharedCwdCounter,
206206
workerData: options.workerData,
207207
publicPort: port2,
208+
manifestURL: getOptionValue('--experimental-policy') ?
209+
require('internal/process/policy').url :
210+
null,
208211
manifestSrc: getOptionValue('--experimental-policy') ?
209212
require('internal/process/policy').src :
210213
null,

0 commit comments

Comments
 (0)