@@ -48,7 +48,16 @@ var goog = goog || {};
48
48
* @type {!Global }
49
49
* @deprecated Use `globalThis` directly; this version will be deleted.
50
50
*/
51
- goog . global = globalThis ;
51
+ goog . global =
52
+ // Check `this` first for backwards compatibility.
53
+ // Valid unless running as an ES module or in a function wrapper called
54
+ // without setting `this` properly.
55
+ // Note that base.js can't usefully be imported as an ES module, but it may
56
+ // be compiled into bundles that are loadable as ES modules.
57
+ this ||
58
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/self
59
+ // For in-page browser environments and workers.
60
+ self ;
52
61
53
62
54
63
/**
@@ -72,7 +81,7 @@ goog.global = globalThis;
72
81
*
73
82
* @type {!Object<string, (string|number|boolean)>|null|undefined }
74
83
*/
75
- globalThis . CLOSURE_DEFINES ;
84
+ goog . global . CLOSURE_DEFINES ;
76
85
77
86
78
87
/**
@@ -87,12 +96,12 @@ globalThis.CLOSURE_DEFINES;
87
96
* controls whether object should overwrite the implicitly constructed
88
97
* namespace or be merged into it. Defaults to false.
89
98
* @param {?Object= } objectToExportTo The object to add the path to; if this
90
- * field is not specified, its value defaults to `globalThis `.
99
+ * field is not specified, its value defaults to `goog.global `.
91
100
* @private
92
101
*/
93
102
goog . exportPath_ = function ( name , object , overwriteImplicit , objectToExportTo ) {
94
103
var parts = name . split ( '.' ) ;
95
- var cur = objectToExportTo || globalThis ;
104
+ var cur = objectToExportTo || goog . global ;
96
105
97
106
// Internet Explorer exhibits strange behavior when throwing errors from
98
107
// methods externed in this manner. See the testExportSymbolExceptions in
@@ -144,7 +153,7 @@ goog.exportPath_ = function(name, object, overwriteImplicit, objectToExportTo) {
144
153
goog . define = function ( name , defaultValue ) {
145
154
var value = defaultValue ;
146
155
if ( ! COMPILED ) {
147
- var defines = globalThis . CLOSURE_DEFINES ;
156
+ var defines = goog . global . CLOSURE_DEFINES ;
148
157
if ( defines &&
149
158
// Anti DOM-clobbering runtime check (b/37736576).
150
159
/** @type {? } */ ( defines ) . nodeType === undefined &&
@@ -535,13 +544,13 @@ if (!COMPILED) {
535
544
*
536
545
* @param {string } name The fully qualified name.
537
546
* @param {!Object= } opt_obj The object within which to look; default is
538
- * globalThis .
547
+ * goog.global .
539
548
* @return {? } The value (object or primitive) or, if not found, null.
540
549
* @deprecated Prefer non-reflective access.
541
550
*/
542
551
goog . getObjectByName = function ( name , opt_obj ) {
543
552
var parts = name . split ( '.' ) ;
544
- var cur = opt_obj || globalThis ;
553
+ var cur = opt_obj || goog . global ;
545
554
for ( var i = 0 ; i < parts . length ; i ++ ) {
546
555
cur = cur [ parts [ i ] ] ;
547
556
if ( cur == null ) {
@@ -701,7 +710,7 @@ goog.cssNameMappingStyle_;
701
710
*
702
711
* @type {(function(string):string)|undefined }
703
712
*/
704
- globalThis . CLOSURE_CSS_NAME_MAP_FN ;
713
+ goog . global . CLOSURE_CSS_NAME_MAP_FN ;
705
714
706
715
707
716
/**
@@ -773,8 +782,8 @@ goog.getCssName = function(className, opt_modifier) {
773
782
774
783
// The special CLOSURE_CSS_NAME_MAP_FN allows users to specify further
775
784
// processing of the class name.
776
- if ( globalThis . CLOSURE_CSS_NAME_MAP_FN ) {
777
- return globalThis . CLOSURE_CSS_NAME_MAP_FN ( result ) ;
785
+ if ( goog . global . CLOSURE_CSS_NAME_MAP_FN ) {
786
+ return goog . global . CLOSURE_CSS_NAME_MAP_FN ( result ) ;
778
787
}
779
788
780
789
return result ;
@@ -822,12 +831,12 @@ goog.setCssNameMapping = function(mapping, opt_style) {
822
831
* A hook for overriding the CSS name mapping.
823
832
* @type {!Object<string, string>|undefined }
824
833
*/
825
- globalThis . CLOSURE_CSS_NAME_MAPPING ;
834
+ goog . global . CLOSURE_CSS_NAME_MAPPING ;
826
835
827
- if ( ! COMPILED && globalThis . CLOSURE_CSS_NAME_MAPPING ) {
836
+ if ( ! COMPILED && goog . global . CLOSURE_CSS_NAME_MAPPING ) {
828
837
// This does not call goog.setCssNameMapping() because the JSCompiler
829
838
// requires that goog.setCssNameMapping() be called with an object literal.
830
- goog . cssNameMapping_ = globalThis . CLOSURE_CSS_NAME_MAPPING ;
839
+ goog . cssNameMapping_ = goog . global . CLOSURE_CSS_NAME_MAPPING ;
831
840
}
832
841
833
842
@@ -982,7 +991,7 @@ goog.getMsgWithFallback = function(a, b) {
982
991
* @param {string } publicPath Unobfuscated name to export.
983
992
* @param {* } object Object the name should point to.
984
993
* @param {?Object= } objectToExportTo The object to add the path to; default
985
- * is globalThis .
994
+ * is goog.global .
986
995
*/
987
996
goog . exportSymbol = function ( publicPath , object , objectToExportTo ) {
988
997
goog . exportPath_ (
0 commit comments