diff --git a/lib/std.js b/lib/std.js index 9c0c1f9..d6e6d6f 100644 --- a/lib/std.js +++ b/lib/std.js @@ -346,10 +346,11 @@ StdEvent.CAPTURING_PHASE = 1; // Not used but to be compatible StdEvent.AT_TARGET = 2; StdEvent.BUBBLING_PHASE = 3; // Not used but to be compatible -function StdEventTarget() { +// maybe, the "EventTarget" is preserved word +function StdEventableObject() { this.__events__ = []; - this.dispatchEvent = function(event) { + this.dispatchEvent = function(event, __exception__) { event.target = this; event.isTrusted = false; event.eventPhase = StdEvent.AT_TARGET; @@ -357,7 +358,11 @@ function StdEventTarget() { for (var i = 0; i < this.__events__.length; i++) { var e = this.__events__[i]; if (e.type == event.type && typeof(e.listener) === "function") { - e.listener(event); + try { + e.listener(event, __exception__); + } catch (ex) { + this.dispatchEvent(new StdEvent("error"), ex); + } } } }; @@ -367,9 +372,9 @@ function StdEventTarget() { this.__events__.push({ "type": type, "listener": listener, - "counter": StdEventTarget.__counter__ + "counter": StdEventableObject.__counter__ }); - StdEventTarget.__counter__++; + StdEventableObject.__counter__++; } else { throw new TypeError("EventListener must be a function"); } @@ -388,7 +393,7 @@ function StdEventTarget() { } }; }; -StdEventTarget.__counter__ = 0; +StdEventableObject.__counter__ = 0; function AsyncFunction(f, _filename) { this.f = f; @@ -450,12 +455,12 @@ global.splitLn = splitLn; global.addslashes = addslashes; global.AsyncFunction = AsyncFunction; -exports.VERSIONINFO = "Standard Library (std.js) version 0.7.1"; +exports.VERSIONINFO = "Standard Library (std.js) version 0.7.2"; exports.global = global; exports.require = global.require; exports.Event = StdEvent; -exports.EventTarget = StdEventTarget; +exports.EventableObject = StdEventableObject; exports.alert = alert; exports.cartesian = cartesian;