- Throw Error objects instead of Strings.

This commit is contained in:
Paulo Gustavo Veiga 2012-09-19 20:01:22 -03:00
parent 6555203a94
commit cd776073dc
5 changed files with 316 additions and 314 deletions

View File

@ -15,7 +15,7 @@ $assert = function (assert, message) {
if (!$defined(assert) || !assert) { if (!$defined(assert) || !assert) {
var stack; var stack;
try { try {
null.eval(); throw Error("Unexpected Exception");
} catch (e) { } catch (e) {
stack = e; stack = e;
} }
@ -33,7 +33,7 @@ function stackTrace(exception) {
if (!$defined(exception)) { if (!$defined(exception)) {
try { try {
throw "Dummy Exception" throw Error("Unexpected Exception");
} catch (e) { } catch (e) {
exception = e; exception = e;
} }
@ -45,6 +45,8 @@ function stackTrace(exception) {
else if (window.opera && exception.message) { //Opera else if (window.opera && exception.message) { //Opera
result = exception.message; result = exception.message;
} else { //IE and Safari } else { //IE and Safari
result = exception.sourceURL + ': ' + exception.line + "\n\n";
var currentFunction = arguments.callee.caller; var currentFunction = arguments.callee.caller;
while (currentFunction) { while (currentFunction) {
var fn = currentFunction.toString(); var fn = currentFunction.toString();

View File

@ -80,7 +80,7 @@ mindplot.IconGroup = new Class({
}, this); }, this);
if (result == null) { if (result == null) {
throw "Icon can no be found."; throw new Error("Icon can no be found:" + iconModel);
} }
return result; return result;

View File

@ -47,7 +47,7 @@ mindplot.LocalStorageManager = new Class({
// If I could not load it from a file, hard code one. // If I could not load it from a file, hard code one.
if (xml == null) { if (xml == null) {
throw "Map could not be loaded"; throw new Error("Map could not be loaded");
} }
} }

View File

@ -1,309 +1,309 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
web2d.Element = new Class({ web2d.Element = new Class({
initialize : function(peer, attributes) { initialize : function(peer, attributes) {
this._peer = peer; this._peer = peer;
if (peer == null) { if (peer == null) {
throw "Element peer can not be null"; throw new Error("Element peer can not be null");
} }
if ($defined(attributes)) { if ($defined(attributes)) {
this._initialize(attributes); this._initialize(attributes);
} }
}, },
_initialize : function(attributes) { _initialize : function(attributes) {
var batchExecute = {}; var batchExecute = {};
// Collect arguments ... // Collect arguments ...
for (var key in attributes) { for (var key in attributes) {
var funcName = this._attributeNameToFuncName(key, 'set'); var funcName = this._attributeNameToFuncName(key, 'set');
var funcArgs = batchExecute[funcName]; var funcArgs = batchExecute[funcName];
if (!$defined(funcArgs)) { if (!$defined(funcArgs)) {
funcArgs = []; funcArgs = [];
} }
var signature = web2d.Element._propertyNameToSignature[key]; var signature = web2d.Element._propertyNameToSignature[key];
var argPositions = signature[1]; var argPositions = signature[1];
if (argPositions != web2d.Element._SIGNATURE_MULTIPLE_ARGUMENTS) { if (argPositions != web2d.Element._SIGNATURE_MULTIPLE_ARGUMENTS) {
funcArgs[argPositions] = attributes[key]; funcArgs[argPositions] = attributes[key];
} else { } else {
funcArgs = attributes[key].split(' '); funcArgs = attributes[key].split(' ');
} }
batchExecute[funcName] = funcArgs; batchExecute[funcName] = funcArgs;
} }
// Call functions ... // Call functions ...
for (var key in batchExecute) { for (var key in batchExecute) {
var func = this[key]; var func = this[key];
if (!$defined(func)) { if (!$defined(func)) {
throw "Could not find function: " + key; throw new Error("Could not find function: " + key);
} }
func.apply(this, batchExecute[key]); func.apply(this, batchExecute[key]);
} }
}, },
setSize : function(width, height) { setSize : function(width, height) {
this._peer.setSize(width, height); this._peer.setSize(width, height);
}, },
setPosition : function(cx, cy) { setPosition : function(cx, cy) {
this._peer.setPosition(cx, cy); this._peer.setPosition(cx, cy);
}, },
positionRelativeTo : function(elem, options) { positionRelativeTo : function(elem, options) {
this._peer.positionRelativeTo(elem, options); this._peer.positionRelativeTo(elem, options);
}, },
/** /**
* Allows the registration of event listeners on the event target. * Allows the registration of event listeners on the event target.
* type * type
* A string representing the event type to listen for. * A string representing the event type to listen for.
* listener * listener
* The object that receives a notification when an event of the specified type occurs. This must be an object implementing the EventListener interface, or simply a function in JavaScript. * The object that receives a notification when an event of the specified type occurs. This must be an object implementing the EventListener interface, or simply a function in JavaScript.
* *
* The following events types are supported: * The following events types are supported:
* *
*/ */
addEvent : function(type, listener) { addEvent : function(type, listener) {
this._peer.addEvent(type, listener); this._peer.addEvent(type, listener);
}, },
fireEvent : function(type, event) { fireEvent : function(type, event) {
this._peer.fireEvent(type, event); this._peer.fireEvent(type, event);
}, },
cloneEvents : function(from) { cloneEvents : function(from) {
this._peer.cloneEvents(from); this._peer.cloneEvents(from);
}, },
/** /**
* *
* Allows the removal of event listeners from the event target. * Allows the removal of event listeners from the event target.
* *
* Parameters: * Parameters:
* type * type
* A string representing the event type being registered. * A string representing the event type being registered.
* listener * listener
* The listener parameter takes an interface implemented by the user which contains the methods to be called when the event occurs. * The listener parameter takes an interface implemented by the user which contains the methods to be called when the event occurs.
* This interace will be invoked passing an event as argument and the 'this' referece in the function will be the element. * This interace will be invoked passing an event as argument and the 'this' referece in the function will be the element.
*/ */
removeEvent : function(type, listener) { removeEvent : function(type, listener) {
this._peer.removeEvent(type, listener); this._peer.removeEvent(type, listener);
}, },
/** /**
* /* * /*
* Returns element type name. * Returns element type name.
*/ */
getType : function() { getType : function() {
throw "Not implemeneted yet. This method must be implemented by all the inherited objects."; throw new Error("Not implemeneted yet. This method must be implemented by all the inherited objects.");
}, },
/** /**
* Todo: Doc * Todo: Doc
*/ */
getFill : function() { getFill : function() {
return this._peer.getFill(); return this._peer.getFill();
}, },
/** /**
* Used to define the fill element color and element opacity. * Used to define the fill element color and element opacity.
* color: Fill color * color: Fill color
* opacity: Opacity of the fill. It must be less than 1. * opacity: Opacity of the fill. It must be less than 1.
*/ */
setFill : function(color, opacity) { setFill : function(color, opacity) {
this._peer.setFill(color, opacity); this._peer.setFill(color, opacity);
}, },
getPosition : function() { getPosition : function() {
return this._peer.getPosition(); return this._peer.getPosition();
}, },
/* /*
* Defines the element stroke properties. * Defines the element stroke properties.
* width: stroke width * width: stroke width
* style: "solid|dot|dash|dashdot|longdash". * style: "solid|dot|dash|dashdot|longdash".
* color: stroke color * color: stroke color
* opacity: stroke visibility * opacity: stroke visibility
*/ */
setStroke : function(width, style, color, opacity) { setStroke : function(width, style, color, opacity) {
if (style != null && style != undefined && style != 'dash' && style != 'dot' && style != 'solid' && style != 'longdash' && style != "dashdot") { if (style != null && style != undefined && style != 'dash' && style != 'dot' && style != 'solid' && style != 'longdash' && style != "dashdot") {
throw "Unsupported stroke style: '" + style + "'"; throw new Error("Unsupported stroke style: '" + style + "'");
} }
this._peer.setStroke(width, style, color, opacity); this._peer.setStroke(width, style, color, opacity);
}, },
_attributeNameToFuncName : function(attributeKey, prefix) { _attributeNameToFuncName : function(attributeKey, prefix) {
var signature = web2d.Element._propertyNameToSignature[attributeKey]; var signature = web2d.Element._propertyNameToSignature[attributeKey];
if (!$defined(signature)) { if (!$defined(signature)) {
throw "Unsupported attribute: " + attributeKey; throw "Unsupported attribute: " + attributeKey;
} }
var firstLetter = signature[0].charAt(0); var firstLetter = signature[0].charAt(0);
return prefix + firstLetter.toUpperCase() + signature[0].substring(1); return prefix + firstLetter.toUpperCase() + signature[0].substring(1);
}, },
/** /**
* All element properties can be setted using either a method invocation or attribute invocation. * All element properties can be setted using either a method invocation or attribute invocation.
* key: size, width, height, position, x, y, stroke, strokeWidth, strokeStyle, strokeColor, strokeOpacity, * key: size, width, height, position, x, y, stroke, strokeWidth, strokeStyle, strokeColor, strokeOpacity,
* fill, fillColor, fillOpacity, coordSize, coordSizeWidth, coordSizeHeight, coordOrigin, coordOriginX, coordOrigiY * fill, fillColor, fillOpacity, coordSize, coordSizeWidth, coordSizeHeight, coordOrigin, coordOriginX, coordOrigiY
*/ */
setAttribute : function(key, value) { setAttribute : function(key, value) {
var funcName = this._attributeNameToFuncName(key, 'set'); var funcName = this._attributeNameToFuncName(key, 'set');
var signature = web2d.Element._propertyNameToSignature[key]; var signature = web2d.Element._propertyNameToSignature[key];
if (signature == null) { if (signature == null) {
throw "Could not find the signature for:" + key; throw "Could not find the signature for:" + key;
} }
// Parse arguments .. // Parse arguments ..
var argPositions = signature[1]; var argPositions = signature[1];
var args = []; var args = [];
if (argPositions !== this._SIGNATURE_MULTIPLE_ARGUMENTS) { if (argPositions !== this._SIGNATURE_MULTIPLE_ARGUMENTS) {
args[argPositions] = value; args[argPositions] = value;
} }
else if (typeof value == "array") { else if (typeof value == "array") {
args = value; args = value;
} else { } else {
var strValue = String(value); var strValue = String(value);
args = strValue.split(' '); args = strValue.split(' ');
} }
// Look up method ... // Look up method ...
var setter = this[funcName]; var setter = this[funcName];
if (setter == null) { if (setter == null) {
throw "Could not find the function name:" + funcName; throw "Could not find the function name:" + funcName;
} }
setter.apply(this, args); setter.apply(this, args);
}, },
getAttribute : function(key) { getAttribute : function(key) {
var funcName = this._attributeNameToFuncName(key, 'get'); var funcName = this._attributeNameToFuncName(key, 'get');
var signature = web2d.Element._propertyNameToSignature[key]; var signature = web2d.Element._propertyNameToSignature[key];
if (signature == null) { if (signature == null) {
throw "Could not find the signature for:" + key; throw "Could not find the signature for:" + key;
} }
var getter = this[funcName]; var getter = this[funcName];
if (getter == null) { if (getter == null) {
throw "Could not find the function name:" + funcName; throw "Could not find the function name:" + funcName;
} }
var getterResult = getter.apply(this, []); var getterResult = getter.apply(this, []);
var attibuteName = signature[2]; var attibuteName = signature[2];
if (!$defined(attibuteName)) { if (!$defined(attibuteName)) {
throw "Could not find attribute mapping for:" + key; throw "Could not find attribute mapping for:" + key;
} }
var result = getterResult[attibuteName]; var result = getterResult[attibuteName];
if (!$defined(result)) { if (!$defined(result)) {
throw "Could not find attribute with name:" + attibuteName; throw "Could not find attribute with name:" + attibuteName;
} }
return result; return result;
}, },
/** /**
* Defines the element opacity. * Defines the element opacity.
* Parameters: * Parameters:
* opacity: A value between 0 and 1. * opacity: A value between 0 and 1.
*/ */
setOpacity : function(opacity) { setOpacity : function(opacity) {
this._peer.setStroke(null, null, null, opacity); this._peer.setStroke(null, null, null, opacity);
this._peer.setFill(null, opacity); this._peer.setFill(null, opacity);
}, },
setVisibility : function(isVisible) { setVisibility : function(isVisible) {
this._peer.setVisibility(isVisible); this._peer.setVisibility(isVisible);
}, },
isVisible : function() { isVisible : function() {
return this._peer.isVisible(); return this._peer.isVisible();
}, },
/** /**
* Move the element to the front * Move the element to the front
*/ */
moveToFront : function() { moveToFront : function() {
this._peer.moveToFront(); this._peer.moveToFront();
}, },
/** /**
* Move the element to the back * Move the element to the back
*/ */
moveToBack : function() { moveToBack : function() {
this._peer.moveToBack(); this._peer.moveToBack();
}, },
getStroke : function() { getStroke : function() {
return this._peer.getStroke(); return this._peer.getStroke();
}, },
setCursor : function(type) { setCursor : function(type) {
this._peer.setCursor(type); this._peer.setCursor(type);
}, },
getParent : function() { getParent : function() {
return this._peer.getParent(); return this._peer.getParent();
} }
}); });
web2d.Element._SIGNATURE_MULTIPLE_ARGUMENTS = -1; web2d.Element._SIGNATURE_MULTIPLE_ARGUMENTS = -1;
web2d.Element._supportedEvents = ["click","dblclick","mousemove","mouseout","mouseover","mousedown","mouseup"]; web2d.Element._supportedEvents = ["click","dblclick","mousemove","mouseout","mouseover","mousedown","mouseup"];
web2d.Element._propertyNameToSignature = web2d.Element._propertyNameToSignature =
{ {
// Format: [attribute name, argument position on setter, attribute name on getter] // Format: [attribute name, argument position on setter, attribute name on getter]
size: ['size',-1], size: ['size',-1],
width: ['size',0,'width'], width: ['size',0,'width'],
height: ['size',1,'height'], height: ['size',1,'height'],
position: ['position',-1], position: ['position',-1],
x: ['position',0,'x'], x: ['position',0,'x'],
y: ['position',1,'y'], y: ['position',1,'y'],
stroke:['stroke',-1], stroke:['stroke',-1],
strokeWidth:['stroke',0,'width'], strokeWidth:['stroke',0,'width'],
strokeStyle:['stroke',1,'style'], strokeStyle:['stroke',1,'style'],
strokeColor:['stroke',2,'color'], strokeColor:['stroke',2,'color'],
strokeOpacity:['stroke',3,'opacity'], strokeOpacity:['stroke',3,'opacity'],
fill:['fill',-1], fill:['fill',-1],
fillColor:['fill',0,'color'], fillColor:['fill',0,'color'],
fillOpacity:['fill',1,'opacity'], fillOpacity:['fill',1,'opacity'],
coordSize:['coordSize',-1], coordSize:['coordSize',-1],
coordSizeWidth:['coordSize',0,'width'], coordSizeWidth:['coordSize',0,'width'],
coordSizeHeight:['coordSize',1,'height'], coordSizeHeight:['coordSize',1,'height'],
coordOrigin:['coordOrigin',-1], coordOrigin:['coordOrigin',-1],
coordOriginX:['coordOrigin',0,'x'], coordOriginX:['coordOrigin',0,'x'],
coordOriginY:['coordOrigin',1,'y'], coordOriginY:['coordOrigin',1,'y'],
visibility:['visibility',0], visibility:['visibility',0],
opacity:['opacity',0] opacity:['opacity',0]
}; };

View File

@ -46,7 +46,7 @@ function buildDesigner(options) {
emulation:false, emulation:false,
urlEncoded:false urlEncoded:false
}).post(JSON.encode({ }).post(JSON.encode({
jsErrorMsg:"message: " + message + ", line:" + lineNo + ", :" + url, jsErrorMsg:"message: '" + message + "', line:'" + lineNo + "', :" + url,
jsStack:window.errorStack, jsStack:window.errorStack,
userAgent:navigator.userAgent, userAgent:navigator.userAgent,
mapId:options.mapId})); mapId:options.mapId}));