4
4
"use strict" ;
5
5
var protobuf = module . exports = require ( "./index" ) ;
6
6
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 ( ) {
9
11
codegen_debug . supported = codegen . supported ;
10
12
codegen_debug . verbose = codegen . verbose ;
11
13
var gen = codegen . apply ( null , Array . prototype . slice . call ( arguments ) ) ;
12
14
gen . str = ( function ( str ) { return function str_debug ( ) {
13
15
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" ) ;
14
16
} ; } ) ( gen . str ) ;
15
17
return gen ;
16
- } ; } ) ( protobuf . util . codegen ) ;
18
+ }
17
19
18
20
/**
19
21
* Debugging utility functions. Only present in debug builds.
20
22
* @namespace
21
23
*/
22
24
var debug = protobuf . debug = { } ;
23
25
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
+
24
44
/**
25
45
* Returns a list of unused types within the specified root.
26
46
* @param {NamespaceBase } ns Namespace to search
@@ -30,7 +50,7 @@ debug.unusedTypes = function unusedTypes(ns) {
30
50
31
51
/* istanbul ignore next */
32
52
if ( ! ( ns instanceof protobuf . Namespace ) )
33
- throw TypeError ( "ns must be a namespace " ) ;
53
+ throw TypeError ( "ns must be a Namespace " ) ;
34
54
/* istanbul ignore next */
35
55
if ( ! ns . nested )
36
56
return [ ] ;
0 commit comments