Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #738 from sonatype/nx-assert
Browse files Browse the repository at this point in the history
Add NX.assert() helper
  • Loading branch information
jdillon committed Feb 5, 2013
2 parents 3f50fa5 + 0664d2b commit c98c381
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions nexus-webapp/src/main/webapp/js/lib/nx-assert.js
@@ -0,0 +1,52 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2007-2012 Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/

/*global Ext,NX,global,require */

Ext.ns('NX');

/**
* Exception thrown when assertion is triggered.
*
* @param message
* @constructor
*
* @since 2.4
*/
function AssertError(message) {
this.name = 'AssertError';
this.message = message || 'Assertion failure';
}
AssertError.prototype = new Error();
AssertError.prototype.constructor = AssertError;

/**
* Assertion helpers.
*/
Ext.apply(NX, {

/**
* Assert a condition. When the condition expression is false and exception is thrown.
*
* @param expression Condition expression
* @param message Exception message
*
* @since 2.4
*/
assert: function (expression, message) {
if (!expression) {
throw new AssertError(message);
}
}

});

0 comments on commit c98c381

Please sign in to comment.