Commit d0422855 authored by Romain Courteaud's avatar Romain Courteaud

Add ScopeError

This will simplify error catching.
parent cabb9e43
...@@ -10,6 +10,19 @@ ...@@ -10,6 +10,19 @@
Event, URL) { Event, URL) {
"use strict"; "use strict";
/////////////////////////////////////////////////////////////////
// Error
/////////////////////////////////////////////////////////////////
function ScopeError(message) {
this.name = "scopeerror";
if ((message !== undefined) && (typeof message !== "string")) {
throw new TypeError('You must pass a string.');
}
this.message = message || "Scope Error";
}
ScopeError.prototype = new Error();
ScopeError.prototype.constructor = ScopeError;
function ensurePushableQueue(callback, argument_list, context) { function ensurePushableQueue(callback, argument_list, context) {
var result; var result;
try { try {
...@@ -1130,13 +1143,15 @@ ...@@ -1130,13 +1143,15 @@
.declareMethod('getDeclaredGadget', .declareMethod('getDeclaredGadget',
function getDeclaredGadget(gadget_scope) { function getDeclaredGadget(gadget_scope) {
if (!this.__sub_gadget_dict.hasOwnProperty(gadget_scope)) { if (!this.__sub_gadget_dict.hasOwnProperty(gadget_scope)) {
throw new Error("Gadget scope '" + gadget_scope + "' is not known."); throw new ScopeError("Gadget scope '" + gadget_scope +
"' is not known.");
} }
return this.__sub_gadget_dict[gadget_scope]; return this.__sub_gadget_dict[gadget_scope];
}) })
.declareMethod('dropGadget', function dropGadget(gadget_scope) { .declareMethod('dropGadget', function dropGadget(gadget_scope) {
if (!this.__sub_gadget_dict.hasOwnProperty(gadget_scope)) { if (!this.__sub_gadget_dict.hasOwnProperty(gadget_scope)) {
throw new Error("Gadget scope '" + gadget_scope + "' is not known."); throw new ScopeError("Gadget scope '" + gadget_scope +
"' is not known.");
} }
// http://perfectionkills.com/understanding-delete/ // http://perfectionkills.com/understanding-delete/
delete this.__sub_gadget_dict[gadget_scope]; delete this.__sub_gadget_dict[gadget_scope];
...@@ -1453,6 +1468,7 @@ ...@@ -1453,6 +1468,7 @@
// global // global
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
renderJS.Mutex = Mutex; renderJS.Mutex = Mutex;
renderJS.ScopeError = ScopeError;
window.rJS = window.renderJS = renderJS; window.rJS = window.renderJS = renderJS;
window.__RenderJSGadget = RenderJSGadget; window.__RenderJSGadget = RenderJSGadget;
window.__RenderJSEmbeddedGadget = RenderJSEmbeddedGadget; window.__RenderJSEmbeddedGadget = RenderJSEmbeddedGadget;
......
...@@ -5777,7 +5777,7 @@ ...@@ -5777,7 +5777,7 @@
ok(false, "getDeclaredGadget should fail"); ok(false, "getDeclaredGadget should fail");
}) })
.fail(function (e) { .fail(function (e) {
ok(e instanceof Error); ok(e instanceof rJS.ScopeError);
equal(e.message, "Gadget scope 'foo' is not known."); equal(e.message, "Gadget scope 'foo' is not known.");
}) })
.always(function () { .always(function () {
...@@ -5820,7 +5820,7 @@ ...@@ -5820,7 +5820,7 @@
ok(false, "dropGadget should fail"); ok(false, "dropGadget should fail");
}) })
.fail(function (e) { .fail(function (e) {
ok(e instanceof Error); ok(e instanceof rJS.ScopeError);
equal(e.message, "Gadget scope 'foo' is not known."); equal(e.message, "Gadget scope 'foo' is not known.");
}) })
.always(function () { .always(function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment