1- /*globals window, global*/
1+ /*globals window, global, require */
22
33/**
44 * CryptoJS core components.
@@ -13,39 +13,37 @@ var CryptoJS = CryptoJS || (function (Math, undefined) {
1313 var cryptoSecureRandomInt = function ( ) {
1414 var crypto ;
1515
16- // Native crypto module in Browser environment
17- try {
18- if ( typeof window !== 'undefined' ) {
19- if ( window . crypto ) {
20- // Use global crypto module
21- crypto = window . crypto ;
22- } else if ( window . msCrypto ) {
23- // Support experimental crypto module in IE 11
24- crypto = window . msCrypto ;
25- }
26- }
27- } catch ( err ) { }
28-
29- // Native crypto module on NodeJS environment
30- try {
31- if ( typeof global !== 'undefined' && global . crypto ) {
32- // Native crypto from global
33- crypto = global . crypto ;
34- } else if ( typeof require === 'function' ) {
35- // Native crypto import via require
16+ // Native crypto from window (Browser)
17+ if ( typeof window !== 'undefined' && window . crypto ) {
18+ crypto = window . crypto ;
19+ }
20+
21+ // Native (experimental IE 11) crypto from window (Browser)
22+ if ( ! crypto && typeof window !== 'undefined' && window . msCrypto ) {
23+ crypto = window . msCrypto ;
24+ }
25+
26+ // Native crypto from global (NodeJS)
27+ if ( ! crypto && typeof global !== 'undefined' && global . crypto ) {
28+ crypto = global . crypto ;
29+ }
30+
31+ // Native crypto import via require (NodeJS)
32+ if ( ! crypto && typeof require === 'function' ) {
33+ try {
3634 crypto = require ( 'crypto' ) ;
37- }
38- } catch ( err ) { }
35+ } catch ( err ) { }
36+ }
3937
4038 if ( crypto ) {
41- // Use getRandomValues method
39+ // Use getRandomValues method (Browser)
4240 if ( typeof crypto . getRandomValues === 'function' ) {
4341 try {
4442 return crypto . getRandomValues ( new Uint32Array ( 1 ) ) [ 0 ] ;
4543 } catch ( err ) { }
4644 }
4745
48- // Use randomBytes method
46+ // Use randomBytes method (NodeJS)
4947 if ( typeof crypto . randomBytes === 'function' ) {
5048 try {
5149 return crypto . randomBytes ( 4 ) . readInt32LE ( ) ;
0 commit comments