Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 35ff592

Browse filesBrowse files
bmeckaddaleax
authored andcommitted
policy: increase tests via permutation matrix
PR-URL: #34404 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 90a44e1 commit 35ff592
Copy full SHA for 35ff592

File tree

Expand file treeCollapse file tree

7 files changed

+437
-438
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+437
-438
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,13 @@ function readPackage(requestPath) {
246246
const existing = packageJsonCache.get(jsonPath);
247247
if (existing !== undefined) return existing;
248248

249-
const result = packageJsonReader.read(path.toNamespacedPath(jsonPath));
249+
const result = packageJsonReader.read(jsonPath);
250250
const json = result.containsKeys === false ? '{}' : result.string;
251251
if (json === undefined) {
252252
packageJsonCache.set(jsonPath, false);
253253
return false;
254254
}
255255

256-
if (manifest) {
257-
const jsonURL = pathToFileURL(jsonPath);
258-
manifest.assertIntegrity(jsonURL, json);
259-
}
260-
261256
try {
262257
const parsed = JSONParse(json);
263258
const filtered = {
Collapse file

‎lib/internal/modules/esm/get_source.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/get_source.js
+14-7Lines changed: 14 additions & 7 deletions
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;
Collapse file

‎lib/internal/modules/package_json_reader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/package_json_reader.js
+20-6Lines changed: 20 additions & 6 deletions
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

Collapse file

‎lib/internal/worker.js‎

Copy file name to clipboardExpand all lines: lib/internal/worker.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ class Worker extends EventEmitter {
199199
cwdCounter: cwdCounter || workerIo.sharedCwdCounter,
200200
workerData: options.workerData,
201201
publicPort: port2,
202+
manifestURL: getOptionValue('--experimental-policy') ?
203+
require('internal/process/policy').url :
204+
null,
202205
manifestSrc: getOptionValue('--experimental-policy') ?
203206
require('internal/process/policy').src :
204207
null,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.