Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Enhancement: added explicit string conversion for Module
Browse files Browse the repository at this point in the history
I declared toString() as an alias for getId(), which enhances log messages
printed for the failure of a module during startAll() or endAll().

This mechanism is flexible enough that if the failure is due to the module
being null undefined or the wrong kind of object, the native toString()
function is used instead.
  • Loading branch information
Eric Bréchemier committed Jan 24, 2011
1 parent 5c7eb27 commit 938e16c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.txt
Expand Up @@ -159,6 +159,7 @@ HISTORY
2011-01-07, v1.5.1, Refactoring: moved filterHtml code to base i18n templates
2011-01-13, v1.5.2, Enhanced i18n: language properties fallback in templates
2011-01-24, v1.5.3, Enhancement: catch and go on when a module fails to start
2011-XX-XX, v1.5.4, ROADMAP: Enhancement: call functions found in getString()
2011-01-24, v1.5.4, Enhancement: added explicit string conversion for Module
2011-XX-XX, v1.5.5, ROADMAP: Enhancement: call functions found in getString()
2011-XX-XX, v1.6.0, ROADMAP: add support for plugins to extend Sandbox API

3 changes: 2 additions & 1 deletion src/lb.core.Module.js
Expand Up @@ -19,7 +19,7 @@
* http://creativecommons.org/licenses/BSD/
*
* Version:
* 2011-01-05
* 2011-01-24
*/
/*requires lb.core.js */
/*jslint white:false, plusplus:false */
Expand Down Expand Up @@ -149,6 +149,7 @@ lb.core.Module = lb.core.Module || function (id, creator){

// Public methods
this.getId = getId;
this.toString = getId;
this.getSandbox = getSandbox;
this.start = start;
this.end = end;
Expand Down
14 changes: 12 additions & 2 deletions test/test.lb.core.Module.js
Expand Up @@ -4,7 +4,7 @@
* Author: Eric Bréchemier <legalbox@eric.brechemier.name>
* Copyright: Legal-Box (c) 2010-2011, All Rights Reserved
* License: BSD License - http://creativecommons.org/licenses/BSD/
* Version: 2011-01-05
* Version: 2011-01-24
*
* Based on Test Runner from bezen.org JavaScript library
* CC-BY: Eric Bréchemier - http://bezen.org/javascript/
Expand Down Expand Up @@ -199,13 +199,23 @@
"all listeners must be removed, even when end() is omitted");
}

function testToString(){
setUp();
var testId = 'testToString';
var module = new lb.core.Module(testId, createStubModule);
var ut = module.toString;

assert.equals( ut(), testId, "module id expected in toString()");
}

var tests = {
testNamespace: testNamespace,
testConstructor: testConstructor,
testGetId: testGetId,
testGetSandbox: testGetSandbox,
testStart: testStart,
testEnd: testEnd
testEnd: testEnd,
testToString: testToString
};

testrunner.define(tests, "lb.core.Module");
Expand Down

0 comments on commit 938e16c

Please sign in to comment.