Permalink
Browse files

Other: Added utility to enable/disable debugging extensions to experi…

…mental debug build
  • Loading branch information...
dcodeIO committed Jan 20, 2017
1 parent fdb1a72 commit 33da148e2b750ce06591c1c66ce4c46ccecc3c8f
Showing with 27 additions and 4 deletions.
  1. +24 −4 src/index-debug.js
  2. +3 −0 tests/other_basics-debug.js
@@ -4,23 +4,43 @@
"use strict";
var protobuf = module.exports = require("./index");
// Count number of calls to any generated function
protobuf.util.codegen = (function(codegen) { return function codegen_debug() {
var codegen = protobuf.util.codegen;
// Counts number of calls to any generated function
function codegen_debug() {
codegen_debug.supported = codegen.supported;
codegen_debug.verbose = codegen.verbose;
var gen = codegen.apply(null, Array.prototype.slice.call(arguments));
gen.str = (function(str) { return function str_debug() {
return str.apply(null, Array.prototype.slice.call(arguments)).replace(/function ([^(]+)\(([^)]*)\) {/g, "function $1($2) {\n\t$1.calls=($1.calls|0)+1");
};})(gen.str);
return gen;
};})(protobuf.util.codegen);
}
/**
* Debugging utility functions. Only present in debug builds.
* @namespace
*/
var debug = protobuf.debug = {};
/**
* Enables debugging extensions.
* @returns {undefined}
*/
debug.enable = function enable() {
protobuf.util.codegen = codegen_debug;
return protobuf;
};
/**
* Disables debugging extensions.
* @returns {undefined}
*/
debug.disable = function disable() {
protobuf.util.codegen = codegen;
return protobuf;
};
/**
* Returns a list of unused types within the specified root.
* @param {NamespaceBase} ns Namespace to search
@@ -30,7 +50,7 @@ debug.unusedTypes = function unusedTypes(ns) {
/* istanbul ignore next */
if (!(ns instanceof protobuf.Namespace))
throw TypeError("ns must be a namespace");
throw TypeError("ns must be a Namespace");
/* istanbul ignore next */
if (!ns.nested)
return [];
@@ -3,6 +3,7 @@ var tape = require("tape");
var protobuf = require("../debug");
tape.test("google.protobuf.Any type", function(test) {
protobuf.debug.enable();
protobuf.load("tests/data/common.proto", function(err, root) {
if (err)
return test.fail(err.message);
@@ -93,6 +94,8 @@ tape.test("google.protobuf.Any type", function(test) {
".google.protobuf.ListValue",
".google.protobuf.Timestamp"
], "should recognize unused types (all but .google.protobuf.Any)");
protobuf.debug.disable();
test.end();
});

0 comments on commit 33da148

Please sign in to comment.