Skip to content

Commit 3eabb7e

Browse files
bmeckcodebytere
authored andcommitted
policy: increase tests via permutation matrix
PR-URL: #34404 Reviewed-By: James M Snell <[email protected]>
1 parent 338994f commit 3eabb7e

File tree

7 files changed

+437
-438
lines changed

7 files changed

+437
-438
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,13 @@ function readPackage(requestPath){
262262
constexisting=packageJsonCache.get(jsonPath);
263263
if(existing!==undefined)returnexisting;
264264

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

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

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

Lines 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+
constmanifest=getOptionValue('--experimental-policy') ?
5+
require('internal/process/policy').manifest :
6+
null;
7+
38
const{ Buffer }=require('buffer');
49

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

1621
asyncfunctiondefaultGetSource(url,{ format }={},defaultGetSource){
1722
constparsed=newURL(url);
23+
letsource;
1824
if(parsed.protocol==='file:'){
19-
return{
20-
source: awaitreadFileAsync(parsed)
21-
};
25+
source=awaitreadFileAsync(parsed);
2226
}elseif(parsed.protocol==='data:'){
2327
constmatch=DATA_URL_PATTERN.exec(parsed.pathname);
2428
if(!match){
2529
thrownewERR_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+
thrownewERR_INVALID_URL_SCHEME(['file','data']);
35+
}
36+
if(manifest){
37+
manifest.assertIntegrity(parsed,source);
3138
}
32-
thrownewERR_INVALID_URL_SCHEME(['file','data']);
39+
return{ source };
3340
}
3441
exports.defaultGetSource=defaultGetSource;

‎lib/internal/modules/package_json_reader.js‎

Lines 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
constcache=newSafeMap();
79

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

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

‎lib/internal/worker.js‎

Lines changed: 3 additions & 0 deletions
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)