Source: lib/debug/asserts.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. goog.provide('goog.asserts');
  18. /**
  19. * @namespace goog.asserts
  20. * @summary An assertion framework which is compiled out for deployment.
  21. * NOTE: this is not the closure library version. This uses the same name so
  22. * the closure compiler will be able to use the conditions to assist type
  23. * checking.
  24. */
  25. /**
  26. * @define {boolean} true to enable asserts, false otherwise.
  27. */
  28. goog.define('goog.asserts.ENABLE_ASSERTS', goog.DEBUG);
  29. /** @type {function(*, string)} */
  30. goog.asserts.assert = function() {};
  31. /** @private */
  32. goog.asserts.patchAssert_ = function() {
  33. var assert = console.assert;
  34. if (!assert) {
  35. console.assert = function() {};
  36. } else if (!assert.bind) {
  37. // IE 9 does not provide a .bind for the built-in console functions.
  38. console.assert = function() {
  39. assert.apply(console, arguments);
  40. };
  41. }
  42. };
  43. // Install assert functions.
  44. if (goog.asserts.ENABLE_ASSERTS) {
  45. goog.asserts.patchAssert_();
  46. goog.asserts.assert = console.assert.bind(console);
  47. }