Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.lang.assert");
14
dojo.require("dojo.lang.common");
15
dojo.require("dojo.lang.array");
16
dojo.require("dojo.lang.type");
17
dojo.lang.assert = function (booleanValue, message) {
18
	if (!booleanValue) {
19
		var errorMessage = "An assert statement failed.\n" + "The method dojo.lang.assert() was called with a 'false' value.\n";
20
		if (message) {
21
			errorMessage += "Here's the assert message:\n" + message + "\n";
22
		}
23
		throw new Error(errorMessage);
24
	}
25
};
26
dojo.lang.assertType = function (value, type, keywordParameters) {
27
	if (dojo.lang.isString(keywordParameters)) {
28
		dojo.deprecated("dojo.lang.assertType(value, type, \"message\")", "use dojo.lang.assertType(value, type) instead", "0.5");
29
	}
30
	if (!dojo.lang.isOfType(value, type, keywordParameters)) {
31
		if (!dojo.lang.assertType._errorMessage) {
32
			dojo.lang.assertType._errorMessage = "Type mismatch: dojo.lang.assertType() failed.";
33
		}
34
		dojo.lang.assert(false, dojo.lang.assertType._errorMessage);
35
	}
36
};
37
dojo.lang.assertValidKeywords = function (object, expectedProperties, message) {
38
	var key;
39
	if (!message) {
40
		if (!dojo.lang.assertValidKeywords._errorMessage) {
41
			dojo.lang.assertValidKeywords._errorMessage = "In dojo.lang.assertValidKeywords(), found invalid keyword:";
42
		}
43
		message = dojo.lang.assertValidKeywords._errorMessage;
44
	}
45
	if (dojo.lang.isArray(expectedProperties)) {
46
		for (key in object) {
47
			if (!dojo.lang.inArray(expectedProperties, key)) {
48
				dojo.lang.assert(false, message + " " + key);
49
			}
50
		}
51
	} else {
52
		for (key in object) {
53
			if (!(key in expectedProperties)) {
54
				dojo.lang.assert(false, message + " " + key);
55
			}
56
		}
57
	}
58
};
59