@@ -274,6 +274,15 @@ function generateContentFn(directive) {
274
274
if ( directive === 'true' ) {
275
275
return Promise . resolve ( randomize ( 10 ) ) ;
276
276
}
277
+ if ( directive === 'emptyObj' ) {
278
+ return Promise . resolve ( '{}' ) ;
279
+ }
280
+ if ( directive === 'emptyArr' ) {
281
+ return Promise . resolve ( '[]' ) ;
282
+ }
283
+ if ( directive === 'emptyStr' ) {
284
+ return Promise . resolve ( '' ) ;
285
+ }
277
286
if ( directive . startsWith ( 'length:' ) ) {
278
287
const match = / ^ l e n g t h : ( \d + ) (?: - ( \d + ) ) ? $ / . exec ( directive ) ;
279
288
if ( match ) {
@@ -1829,7 +1838,7 @@ builtinScriptlets.push({
1829
1838
} ) ;
1830
1839
function noFetchIf (
1831
1840
propsToMatch = '' ,
1832
- directive = ''
1841
+ responseBody = ''
1833
1842
) {
1834
1843
if ( typeof propsToMatch !== 'string' ) { return ; }
1835
1844
const safe = safeSelf ( ) ;
@@ -1886,7 +1895,17 @@ function noFetchIf(
1886
1895
if ( proceed ) {
1887
1896
return Reflect . apply ( target , thisArg , args ) ;
1888
1897
}
1889
- return generateContentFn ( directive ) . then ( text => {
1898
+ let responseType = '' ;
1899
+ if ( details . mode === undefined || details . mode === 'cors' ) {
1900
+ try {
1901
+ const desURL = new URL ( details . url ) ;
1902
+ responseType = desURL . origin !== document . location . origin
1903
+ ? 'cors'
1904
+ : 'basic' ;
1905
+ } catch ( _ ) {
1906
+ }
1907
+ }
1908
+ return generateContentFn ( responseBody ) . then ( text => {
1890
1909
const response = new Response ( text , {
1891
1910
statusText : 'OK' ,
1892
1911
headers : {
@@ -1896,6 +1915,11 @@ function noFetchIf(
1896
1915
Object . defineProperty ( response , 'url' , {
1897
1916
value : details . url
1898
1917
} ) ;
1918
+ if ( responseType !== '' ) {
1919
+ Object . defineProperty ( response , 'type' , {
1920
+ value : responseType
1921
+ } ) ;
1922
+ }
1899
1923
return response ;
1900
1924
} ) ;
1901
1925
}
0 commit comments