@@ -30,6 +30,7 @@ var AMDLoader;
30
30
this . _isNode = false ;
31
31
this . _isElectronRenderer = false ;
32
32
this . _isWebWorker = false ;
33
+ this . _isElectronNodeIntegrationWebWorker = false ;
33
34
}
34
35
Object . defineProperty ( Environment . prototype , "isWindows" , {
35
36
get : function ( ) {
@@ -63,6 +64,14 @@ var AMDLoader;
63
64
enumerable : false ,
64
65
configurable : true
65
66
} ) ;
67
+ Object . defineProperty ( Environment . prototype , "isElectronNodeIntegrationWebWorker" , {
68
+ get : function ( ) {
69
+ this . _detect ( ) ;
70
+ return this . _isElectronNodeIntegrationWebWorker ;
71
+ } ,
72
+ enumerable : false ,
73
+ configurable : true
74
+ } ) ;
66
75
Environment . prototype . _detect = function ( ) {
67
76
if ( this . _detected ) {
68
77
return ;
@@ -72,6 +81,7 @@ var AMDLoader;
72
81
this . _isNode = ( typeof module !== 'undefined' && ! ! module . exports ) ;
73
82
this . _isElectronRenderer = ( typeof process !== 'undefined' && typeof process . versions !== 'undefined' && typeof process . versions . electron !== 'undefined' && process . type === 'renderer' ) ;
74
83
this . _isWebWorker = ( typeof AMDLoader . global . importScripts === 'function' ) ;
84
+ this . _isElectronNodeIntegrationWebWorker = this . _isWebWorker && ( typeof process !== 'undefined' && typeof process . versions !== 'undefined' && typeof process . versions . electron !== 'undefined' && process . type === 'worker' ) ;
75
85
} ;
76
86
Environment . _isWindows = function ( ) {
77
87
if ( typeof navigator !== 'undefined' ) {
@@ -705,35 +715,52 @@ var AMDLoader;
705
715
return this . _cachedCanUseEval ;
706
716
} ;
707
717
WorkerScriptLoader . prototype . load = function ( moduleManager , scriptSrc , callback , errorback ) {
708
- var trustedTypesPolicy = moduleManager . getConfig ( ) . getOptionsLiteral ( ) . trustedTypesPolicy ;
709
- var isCrossOrigin = ( / ^ ( ( h t t p : ) | ( h t t p s : ) | ( f i l e : ) ) / . test ( scriptSrc ) && scriptSrc . substring ( 0 , self . origin . length ) !== self . origin ) ;
710
- if ( ! isCrossOrigin && this . _canUseEval ( moduleManager ) ) {
711
- // use `fetch` if possible because `importScripts`
712
- // is synchronous and can lead to deadlocks on Safari
713
- fetch ( scriptSrc ) . then ( function ( response ) {
714
- if ( response . status !== 200 ) {
715
- throw new Error ( response . statusText ) ;
716
- }
717
- return response . text ( ) ;
718
- } ) . then ( function ( text ) {
719
- text = text + "\n//# sourceURL=" + scriptSrc ;
720
- var func = ( trustedTypesPolicy
721
- ? self . eval ( trustedTypesPolicy . createScript ( '' , text ) )
722
- : new Function ( text ) ) ;
723
- func . call ( self ) ;
724
- callback ( ) ;
725
- } ) . then ( undefined , errorback ) ;
726
- return ;
727
- }
728
- try {
729
- if ( trustedTypesPolicy ) {
730
- scriptSrc = trustedTypesPolicy . createScriptURL ( scriptSrc ) ;
718
+ if ( / ^ n o d e \| / . test ( scriptSrc ) ) {
719
+ var opts = moduleManager . getConfig ( ) . getOptionsLiteral ( ) ;
720
+ var nodeRequire = ensureRecordedNodeRequire ( moduleManager . getRecorder ( ) , ( opts . nodeRequire || AMDLoader . global . nodeRequire ) ) ;
721
+ var pieces = scriptSrc . split ( '|' ) ;
722
+ var moduleExports_2 = null ;
723
+ try {
724
+ moduleExports_2 = nodeRequire ( pieces [ 1 ] ) ;
731
725
}
732
- importScripts ( scriptSrc ) ;
726
+ catch ( err ) {
727
+ errorback ( err ) ;
728
+ return ;
729
+ }
730
+ moduleManager . enqueueDefineAnonymousModule ( [ ] , function ( ) { return moduleExports_2 ; } ) ;
733
731
callback ( ) ;
734
732
}
735
- catch ( e ) {
736
- errorback ( e ) ;
733
+ else {
734
+ var trustedTypesPolicy_1 = moduleManager . getConfig ( ) . getOptionsLiteral ( ) . trustedTypesPolicy ;
735
+ var isCrossOrigin = ( / ^ ( ( h t t p : ) | ( h t t p s : ) | ( f i l e : ) ) / . test ( scriptSrc ) && scriptSrc . substring ( 0 , self . origin . length ) !== self . origin ) ;
736
+ if ( ! isCrossOrigin && this . _canUseEval ( moduleManager ) ) {
737
+ // use `fetch` if possible because `importScripts`
738
+ // is synchronous and can lead to deadlocks on Safari
739
+ fetch ( scriptSrc ) . then ( function ( response ) {
740
+ if ( response . status !== 200 ) {
741
+ throw new Error ( response . statusText ) ;
742
+ }
743
+ return response . text ( ) ;
744
+ } ) . then ( function ( text ) {
745
+ text = text + "\n//# sourceURL=" + scriptSrc ;
746
+ var func = ( trustedTypesPolicy_1
747
+ ? self . eval ( trustedTypesPolicy_1 . createScript ( '' , text ) )
748
+ : new Function ( text ) ) ;
749
+ func . call ( self ) ;
750
+ callback ( ) ;
751
+ } ) . then ( undefined , errorback ) ;
752
+ return ;
753
+ }
754
+ try {
755
+ if ( trustedTypesPolicy_1 ) {
756
+ scriptSrc = trustedTypesPolicy_1 . createScriptURL ( scriptSrc ) ;
757
+ }
758
+ importScripts ( scriptSrc ) ;
759
+ callback ( ) ;
760
+ }
761
+ catch ( e ) {
762
+ errorback ( e ) ;
763
+ }
737
764
}
738
765
} ;
739
766
return WorkerScriptLoader ;
@@ -831,15 +858,15 @@ var AMDLoader;
831
858
var recorder = moduleManager . getRecorder ( ) ;
832
859
if ( / ^ n o d e \| / . test ( scriptSrc ) ) {
833
860
var pieces = scriptSrc . split ( '|' ) ;
834
- var moduleExports_2 = null ;
861
+ var moduleExports_3 = null ;
835
862
try {
836
- moduleExports_2 = nodeRequire ( pieces [ 1 ] ) ;
863
+ moduleExports_3 = nodeRequire ( pieces [ 1 ] ) ;
837
864
}
838
865
catch ( err ) {
839
866
errorback ( err ) ;
840
867
return ;
841
868
}
842
- moduleManager . enqueueDefineAnonymousModule ( [ ] , function ( ) { return moduleExports_2 ; } ) ;
869
+ moduleManager . enqueueDefineAnonymousModule ( [ ] , function ( ) { return moduleExports_3 ; } ) ;
843
870
callback ( ) ;
844
871
}
845
872
else {
@@ -1489,7 +1516,7 @@ var AMDLoader;
1489
1516
ModuleManager . prototype . _onLoadError = function ( moduleId , err ) {
1490
1517
var error = this . _createLoadError ( moduleId , err ) ;
1491
1518
if ( ! this . _modules2 [ moduleId ] ) {
1492
- this . _modules2 [ moduleId ] = new Module ( moduleId , this . _moduleIdProvider . getStrModuleId ( moduleId ) , [ ] , function ( ) { } , function ( ) { } , null ) ;
1519
+ this . _modules2 [ moduleId ] = new Module ( moduleId , this . _moduleIdProvider . getStrModuleId ( moduleId ) , [ ] , function ( ) { } , null , null ) ;
1493
1520
}
1494
1521
// Find any 'local' error handlers, walk the entire chain of inverse dependencies if necessary.
1495
1522
var seenModuleId = [ ] ;
@@ -1880,9 +1907,7 @@ var AMDLoader;
1880
1907
RequireFunc . getStats = function ( ) {
1881
1908
return moduleManager . getLoaderEvents ( ) ;
1882
1909
} ;
1883
- RequireFunc . define = function ( ) {
1884
- return DefineFunc . apply ( null , arguments ) ;
1885
- } ;
1910
+ RequireFunc . define = DefineFunc ;
1886
1911
function init ( ) {
1887
1912
if ( typeof AMDLoader . global . require !== 'undefined' || typeof require !== 'undefined' ) {
1888
1913
var _nodeRequire = ( AMDLoader . global . require || require ) ;
@@ -1894,7 +1919,7 @@ var AMDLoader;
1894
1919
RequireFunc . __$__nodeRequire = nodeRequire ;
1895
1920
}
1896
1921
}
1897
- if ( env . isNode && ! env . isElectronRenderer ) {
1922
+ if ( env . isNode && ! env . isElectronRenderer && ! env . isElectronNodeIntegrationWebWorker ) {
1898
1923
module . exports = RequireFunc ;
1899
1924
require = RequireFunc ;
1900
1925
}
0 commit comments