util.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2009 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Utility methods for Protocol Buffer 2 implementation.
  16. */
  17. goog.provide('goog.proto2.Util');
  18. goog.require('goog.asserts');
  19. /**
  20. * @define {boolean} Defines a PBCHECK constant that can be turned off by
  21. * clients of PB2. This for is clients that do not want assertion/checking
  22. * running even in non-COMPILED builds.
  23. */
  24. goog.define('goog.proto2.Util.PBCHECK', !COMPILED);
  25. /**
  26. * Asserts that the given condition is true, if and only if the PBCHECK
  27. * flag is on.
  28. *
  29. * @param {*} condition The condition to check.
  30. * @param {string=} opt_message Error message in case of failure.
  31. * @throws {Error} Assertion failed, the condition evaluates to false.
  32. */
  33. goog.proto2.Util.assert = function(condition, opt_message) {
  34. if (goog.proto2.Util.PBCHECK) {
  35. goog.asserts.assert(condition, opt_message);
  36. }
  37. };
  38. /**
  39. * Returns true if debug assertions (checks) are on.
  40. *
  41. * @return {boolean} The value of the PBCHECK constant.
  42. */
  43. goog.proto2.Util.conductChecks = function() {
  44. return goog.proto2.Util.PBCHECK;
  45. };