@@ -22,19 +22,23 @@ const kReactions = new SafeWeakMap();
22
22
const kRelativeURLStringPattern = / ^ \. { 0 , 2 } \/ / ;
23
23
const { shouldAbortOnUncaughtException } = internalBinding ( 'config' ) ;
24
24
const { abort, exit, _rawDebug } = process ;
25
+
25
26
function REACTION_THROW ( error ) {
26
27
throw error ;
27
28
}
29
+
28
30
function REACTION_EXIT ( error ) {
29
31
REACTION_LOG ( error ) ;
30
32
if ( shouldAbortOnUncaughtException ) {
31
33
abort ( ) ;
32
34
}
33
35
exit ( 1 ) ;
34
36
}
37
+
35
38
function REACTION_LOG ( error ) {
36
39
_rawDebug ( error . stack ) ;
37
40
}
41
+
38
42
class Manifest {
39
43
constructor ( obj , manifestURL ) {
40
44
const integrities = {
@@ -44,6 +48,7 @@ class Manifest {
44
48
__proto__ : null ,
45
49
integrity : REACTION_THROW ,
46
50
} ;
51
+
47
52
if ( obj . onerror ) {
48
53
const behavior = obj . onerror ;
49
54
if ( behavior === 'throw' ) {
@@ -55,8 +60,10 @@ class Manifest {
55
60
throw new ERR_MANIFEST_UNKNOWN_ONERROR ( behavior ) ;
56
61
}
57
62
}
63
+
58
64
kReactions . set ( this , Object . freeze ( reactions ) ) ;
59
65
const manifestEntries = entries ( obj . resources ) ;
66
+
60
67
for ( var i = 0 ; i < manifestEntries . length ; i ++ ) {
61
68
let url = manifestEntries [ i ] [ 0 ] ;
62
69
const integrity = manifestEntries [ i ] [ 1 ] . integrity ;
@@ -65,10 +72,12 @@ class Manifest {
65
72
if ( RegExpTest ( kRelativeURLStringPattern , url ) ) {
66
73
url = new URL ( url , manifestURL ) . href ;
67
74
}
75
+
68
76
const sri = Object . freeze ( SRI . parse ( integrity ) ) ;
69
77
if ( url in integrities ) {
70
78
const old = integrities [ url ] ;
71
79
let mismatch = false ;
80
+
72
81
if ( old . length !== sri . length ) {
73
82
mismatch = true ;
74
83
} else {
@@ -85,6 +94,7 @@ class Manifest {
85
94
break compare;
86
95
}
87
96
}
97
+
88
98
if ( mismatch ) {
89
99
throw new ERR_MANIFEST_INTEGRITY_MISMATCH ( url ) ;
90
100
}
@@ -96,10 +106,12 @@ class Manifest {
96
106
kIntegrities . set ( this , integrities ) ;
97
107
Object . freeze ( this ) ;
98
108
}
109
+
99
110
assertIntegrity ( url , content ) {
100
111
debug ( `Checking integrity of ${ url } ` ) ;
101
112
const integrities = kIntegrities . get ( this ) ;
102
113
const realIntegrities = new Map ( ) ;
114
+
103
115
if ( integrities && url in integrities ) {
104
116
const integrityEntries = integrities [ url ] ;
105
117
// Avoid clobbered Symbol.iterator
@@ -122,6 +134,7 @@ class Manifest {
122
134
kReactions . get ( this ) . integrity ( error ) ;
123
135
}
124
136
}
137
+
125
138
// Lock everything down to avoid problems even if reference is leaked somehow
126
139
Object . setPrototypeOf ( Manifest , null ) ;
127
140
Object . setPrototypeOf ( Manifest . prototype , null ) ;
0 commit comments