44"use strict" ;
55var protobuf = module . exports = require ( "./index" ) ;
66
7- // Count number of calls to any generated function
8- protobuf . util . codegen = ( function ( codegen ) { return function codegen_debug ( ) {
7+ var codegen = protobuf . util . codegen ;
8+
9+ // Counts number of calls to any generated function
10+ function codegen_debug ( ) {
911 codegen_debug . supported = codegen . supported ;
1012 codegen_debug . verbose = codegen . verbose ;
1113 var gen = codegen . apply ( null , Array . prototype . slice . call ( arguments ) ) ;
1214 gen . str = ( function ( str ) { return function str_debug ( ) {
1315 return str . apply ( null , Array . prototype . slice . call ( arguments ) ) . replace ( / f u n c t i o n ( [ ^ ( ] + ) \( ( [ ^ ) ] * ) \) { / g, "function $1($2) {\n\t$1.calls=($1.calls|0)+1" ) ;
1416 } ; } ) ( gen . str ) ;
1517 return gen ;
16- } ; } ) ( protobuf . util . codegen ) ;
18+ }
1719
1820/**
1921 * Debugging utility functions. Only present in debug builds.
2022 * @namespace
2123 */
2224var debug = protobuf . debug = { } ;
2325
26+ /**
27+ * Enables debugging extensions.
28+ * @returns {undefined }
29+ */
30+ debug . enable = function enable ( ) {
31+ protobuf . util . codegen = codegen_debug ;
32+ return protobuf ;
33+ } ;
34+
35+ /**
36+ * Disables debugging extensions.
37+ * @returns {undefined }
38+ */
39+ debug . disable = function disable ( ) {
40+ protobuf . util . codegen = codegen ;
41+ return protobuf ;
42+ } ;
43+
2444/**
2545 * Returns a list of unused types within the specified root.
2646 * @param {NamespaceBase } ns Namespace to search
@@ -30,7 +50,7 @@ debug.unusedTypes = function unusedTypes(ns) {
3050
3151 /* istanbul ignore next */
3252 if ( ! ( ns instanceof protobuf . Namespace ) )
33- throw TypeError ( "ns must be a namespace " ) ;
53+ throw TypeError ( "ns must be a Namespace " ) ;
3454 /* istanbul ignore next */
3555 if ( ! ns . nested )
3656 return [ ] ;
0 commit comments