@@ -36,6 +36,21 @@ var COMPILED = false;
36
36
var goog = goog || { } ;
37
37
38
38
39
+ /**
40
+ * Reference to the global object.
41
+ * https://www.ecma-international.org/ecma-262/9.0/index.html#sec-global-object
42
+ *
43
+ * More info on this implementation here:
44
+ * https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI/edit
45
+ *
46
+ * @const
47
+ * @suppress {undefinedVars} self won't be referenced unless `this` is falsy.
48
+ * @type {!Global }
49
+ * @deprecated Use `globalThis` directly; this version will be deleted.
50
+ */
51
+ goog . global = globalThis ;
52
+
53
+
39
54
/**
40
55
* A hook for overriding the define values in uncompiled or compiled mode.
41
56
*
@@ -203,6 +218,12 @@ goog.DEBUG = goog.define('goog.DEBUG', true);
203
218
*/
204
219
goog . LOCALE = goog . define ( 'goog.LOCALE' , 'en' ) ; // default to en
205
220
221
+ /**
222
+ * @define {boolean} Whether code that calls {@link goog.setTestOnly } should
223
+ * be disallowed in the compilation unit.
224
+ */
225
+ goog . DISALLOW_TEST_ONLY_CODE =
226
+ goog . define ( 'goog.DISALLOW_TEST_ONLY_CODE' , COMPILED && ! goog . DEBUG ) ;
206
227
207
228
/**
208
229
* Defines a global namespace in Closure.
@@ -260,7 +281,7 @@ goog.constructNamespace_ = function(name, object, overwriteImplicit) {
260
281
261
282
var namespace = name ;
262
283
while ( ( namespace = namespace . substring ( 0 , namespace . lastIndexOf ( '.' ) ) ) ) {
263
- if ( goog . getObjectByName_ ( namespace ) ) {
284
+ if ( goog . getObjectByName ( namespace ) ) {
264
285
break ;
265
286
}
266
287
goog . implicitNamespaces_ [ namespace ] = true ;
@@ -368,7 +389,7 @@ goog.module.getInternal_ = function(name) {
368
389
if ( name in goog . loadedModules_ ) {
369
390
return goog . loadedModules_ [ name ] ;
370
391
} else if ( ! goog . implicitNamespaces_ [ name ] ) {
371
- var ns = goog . getObjectByName_ ( name ) ;
392
+ var ns = goog . getObjectByName ( name ) ;
372
393
return ns != null ? ns : null ;
373
394
}
374
395
}
@@ -415,6 +436,27 @@ goog.module.declareLegacyNamespace = function() {
415
436
} ;
416
437
417
438
439
+ /**
440
+ * Marks that the current file should only be used for testing, and never for
441
+ * live code in production.
442
+ *
443
+ * In the case of unit tests, the message may optionally be an exact namespace
444
+ * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra
445
+ * provide (if not explicitly defined in the code).
446
+ *
447
+ * @param {string= } opt_message Optional message to add to the error that's
448
+ * raised when used in production code.
449
+ */
450
+ goog . setTestOnly = function ( opt_message ) {
451
+ if ( goog . DISALLOW_TEST_ONLY_CODE ) {
452
+ opt_message = opt_message || '' ;
453
+ throw new Error (
454
+ 'Importing test-only code into non-debug environment' +
455
+ ( opt_message ? ': ' + opt_message : '.' ) ) ;
456
+ }
457
+ } ;
458
+
459
+
418
460
/**
419
461
* Forward declares a symbol. This is an indication to the compiler that the
420
462
* symbol may be used in the source yet is not required and may not be provided
@@ -449,7 +491,7 @@ if (!COMPILED) {
449
491
goog . isProvided_ = function ( name ) {
450
492
return ( name in goog . loadedModules_ ) ||
451
493
( ! goog . implicitNamespaces_ [ name ] &&
452
- goog . getObjectByName_ ( name ) != null ) ;
494
+ goog . getObjectByName ( name ) != null ) ;
453
495
} ;
454
496
455
497
/**
@@ -479,9 +521,9 @@ if (!COMPILED) {
479
521
* @param {!Object= } opt_obj The object within which to look; default is
480
522
* globalThis.
481
523
* @return {? } The value (object or primitive) or, if not found, null.
482
- * @private
524
+ * @deprecated Prefer non-reflective access.
483
525
*/
484
- goog . getObjectByName_ = function ( name , opt_obj ) {
526
+ goog . getObjectByName = function ( name , opt_obj ) {
485
527
var parts = name . split ( '.' ) ;
486
528
var cur = opt_obj || globalThis ;
487
529
for ( var i = 0 ; i < parts . length ; i ++ ) {
0 commit comments