Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.lang.assert");
12
dojo.require("dojo.lang.common");
13
dojo.require("dojo.lang.array");
14
dojo.require("dojo.lang.type");
15
dojo.lang.assert = function (booleanValue, message) {
16
	if (!booleanValue) {
17
		var errorMessage = "An assert statement failed.\n" + "The method dojo.lang.assert() was called with a 'false' value.\n";
18
		if (message) {
19
			errorMessage += "Here's the assert message:\n" + message + "\n";
20
		}
21
		throw new Error(errorMessage);
22
	}
23
};
24
dojo.lang.assertType = function (value, type, keywordParameters) {
25
	if (dojo.lang.isString(keywordParameters)) {
26
		dojo.deprecated("dojo.lang.assertType(value, type, \"message\")", "use dojo.lang.assertType(value, type) instead", "0.5");
27
	}
28
	if (!dojo.lang.isOfType(value, type, keywordParameters)) {
29
		if (!dojo.lang.assertType._errorMessage) {
30
			dojo.lang.assertType._errorMessage = "Type mismatch: dojo.lang.assertType() failed.";
31
		}
32
		dojo.lang.assert(false, dojo.lang.assertType._errorMessage);
33
	}
34
};
35
dojo.lang.assertValidKeywords = function (object, expectedProperties, message) {
36
	var key;
37
	if (!message) {
38
		if (!dojo.lang.assertValidKeywords._errorMessage) {
39
			dojo.lang.assertValidKeywords._errorMessage = "In dojo.lang.assertValidKeywords(), found invalid keyword:";
40
		}
41
		message = dojo.lang.assertValidKeywords._errorMessage;
42
	}
43
	if (dojo.lang.isArray(expectedProperties)) {
44
		for (key in object) {
45
			if (!dojo.lang.inArray(expectedProperties, key)) {
46
				dojo.lang.assert(false, message + " " + key);
47
			}
48
		}
49
	} else {
50
		for (key in object) {
51
			if (!(key in expectedProperties)) {
52
				dojo.lang.assert(false, message + " " + key);
53
			}
54
		}
55
	}
56
};
57