Browse files

* force class_() seconde parameter to be a class

  • Loading branch information...
1 parent 416a6c5 commit 9a5c478701d05fd9e468931890de948626013ad4 @jpolo committed Oct 6, 2011
Showing with 31 additions and 26 deletions.
  1. +2 −2 Deferred.js
  2. +2 −2 Dictionary.js
  3. +1 −2 Interface.js
  4. +1 −1 Url.js
  5. +1 −1 event.js
  6. +1 −1 package.json
  7. +4 −4 stj.js
  8. +19 −13 test/stj-test.js
View
4 Deferred.js
@@ -17,7 +17,7 @@ define("stj/Deferred", [ "stj" ], function (stj) {
/**
* @class Deferred
*/
- class_('Deferred', null, function (Deferred) {
+ class_('Deferred', Object, function ($class) {
/**
* Shortcuts
*/
@@ -39,7 +39,7 @@ define("stj/Deferred", [ "stj" ], function (stj) {
setNextTick = use_('event').setNextTick,
- defer = Deferred.create,
+ defer = $class.create,
proxy = function (deferred) {
return deferred;
},
View
4 Dictionary.js
@@ -13,7 +13,7 @@ define("stj/Dictionary", [ "stj" ], function (stj) {
/**
* @class Dictionary
*/
- class_('Dictionary', null, function () {
+ class_('Dictionary', Object, function () {
var
isUndefined = Object.isUndefined,
objectHas = Object.has,
@@ -99,6 +99,6 @@ define("stj/Dictionary", [ "stj" ], function (stj) {
}
});
});
-
+
return use_('Dictionary');
});
View
3 Interface.js
@@ -12,7 +12,7 @@ define("stj/Interface", [ "stj" ], function (stj) {
/**
* @class Interface
*/
- class_("Interface", null, function (Interface) {
+ class_("Interface", Object, function (Interface) {
var
//Messages
MESSAGE_NOT_INTERFACE = ' is not an interface',
@@ -40,7 +40,6 @@ define("stj/Interface", [ "stj" ], function (stj) {
ValueError = use_('error.ValueError'),
NotImplementedError = use_('error.NotImplementedError');
- //include_("stj.Object");
properties_({
/**
View
2 Url.js
@@ -13,7 +13,7 @@ define("stj/Url", [ "stj" ], function () {
//=========================================================================
// Url
//=========================================================================
- class_("Url", null, function (Url) {
+ class_("Url", Object, function (Url) {
var merge = Object.update,
size = Object.size,
View
2 event.js
@@ -39,7 +39,7 @@ define("stj/event", ["stj"], function () {
/**
* @class event.Dispatcher
*/
- class_("Dispatcher", null, function (Dispatcher) {
+ class_("Dispatcher", Object, function (Dispatcher) {
extend_({
LIMIT: 10
});
View
2 package.json
@@ -1,6 +1,6 @@
{
"name" : "stj",
- "version" : "1.3.0-1",
+ "version" : "1.3.0-2",
"author" : {
"name" : "Julien Polo",
"email" : "julien.polo@gmail.com",
View
8 stj.js
@@ -1224,7 +1224,7 @@
var result;
if (isString(pathOrModule)) {
pathOrModule = assertNotRegistered(namespaceNormalize(pathOrModule));
- parent = parent ? stj.use_(parent) : null;
+ parent = stj.use_(parent);
result = createConstructor(namespaceBase(pathOrModule));
result = moduleRegister(pathOrModule, classCreate(classInherits(result, parent)));
@@ -3193,7 +3193,7 @@
var size = Object.size,
isEmpty = Object.isEmpty,
- StringFormatter = class_('Formatter', null, function () {
+ StringFormatter = class_('Formatter', Object, function () {
var objectFormat = Object.format,
TAG_START = '{',
TAG_STOP = '}',
@@ -3681,7 +3681,7 @@
var
- DateFormatter = class_("Formatter", null, function () {
+ DateFormatter = class_("Formatter", Object, function () {
var objectGet = Object.get,
pad = function (value, length) {
return stringify(value).pad(length || 2, "0", "l");
@@ -4042,7 +4042,7 @@
* @class
* @extends {Error}
*/
- StopIteration = class_('StopIteration', null, function () {
+ StopIteration = class_('StopIteration', Object, function () {
properties_({
name: 'StopIteration'
});
View
32 test/stj-test.js
@@ -141,11 +141,17 @@ exports.StdTest = vows.describe('Std module').addBatch({
assert.throws(function () {
stj.module_(error, function () {
- stj.class_('Error', null, function () {});
+ stj.class_('Error', Object, function () {});
});
});
},
+ "should throw error when wrong arguments": function (topic) {
+ assert.throws(function () {
+ stj.class_('Error', undefined, function () {});
+ });
+
+ },
"should throw error when opening non module": function (topic) {
assert.throws(function () {
topic({});
@@ -155,7 +161,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
});
},
"should create a new class": function (topic) {
- var Class = stj.class_("Test.NewClass", null, function () {
+ var Class = stj.class_("Test.NewClass", Object, function () {
properties_({
"foo": function () {}
});
@@ -166,7 +172,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
assert.equal(Class.name, "NewClass");
},
"should return a new constructor function": function (topic) {
- var Class = topic(''),
+ var Class = topic('', Object),
obj;
property_(Class.prototype, "initialize", function (arg1, arg2) {
this.count = (this.count || 0) + 1;
@@ -175,7 +181,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
});
assert.isFunction(Class);
assert.doesNotThrow(function () {
- topic('');
+ topic('', Object);
});
//Test instance
@@ -193,11 +199,11 @@ exports.StdTest = vows.describe('Std module').addBatch({
assert.equal(obj.count, 1);
},
"should return a named function": function (topic) {
- assert.equal(topic('foo.bar.named1').getName(), "named1");
- assert.equal(topic('foo.bar.named2').getName(), "named2");
+ assert.equal(topic('foo.bar.named1', Object).getName(), "named1");
+ assert.equal(topic('foo.bar.named2', Object).getName(), "named2");
},
"should return a named class when specified": function (topic) {
- var result = topic('foo.bar.mytype'),
+ var result = topic('foo.bar.mytype', Object),
expected = stj.use_('foo.bar.mytype');
assert.equal(result, expected);
@@ -207,7 +213,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
});
},
"should handle inheritance for instance methods": function (topic) {
- var Parent = stj.class_('stj-test.Parent'),
+ var Parent = stj.class_('stj-test.Parent', Object),
Child = stj.class_('stj-test.Child', Parent),
instanceChild = new Child();
@@ -237,7 +243,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
},
"should call declaration block as (currentClass, metaModule)": function (topic) {
- var Parent = stj.class_('stj-test.Parent2'),
+ var Parent = stj.class_('stj-test.Parent2', Object),
Child = stj.class_('stj-test.Child2', Parent),
instanceChild = new Child(),
blockArgs;
@@ -452,7 +458,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
assert.isFunction(child.newMethod);
},
"should extend a class with an Object": function (topic) {
- var Test = stj.class_(''),
+ var Test = stj.class_('', Object),
instance = new Test();
stj.class_(Test, function () {
@@ -473,7 +479,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
assert.isFunction(instance.baz);
},
"should extend a class with another module": function (topic) {
- var Test = stj.class_(''),
+ var Test = stj.class_('', Object),
instance = new Test(),
included = stj.module_(''),
inc, ext;
@@ -546,7 +552,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
},
"should extend a new class with a new block": function (topic) {
- var Test = stj.class_('', null, function () {
+ var Test = stj.class_('', Object, function () {
extend_(function () {
property_('my_static', function () {
@@ -559,7 +565,7 @@ exports.StdTest = vows.describe('Std module').addBatch({
assert.isUndefined(instance.my_static);
},
"should extend a class with a new block": function (topic) {
- var Test = stj.class_(''),
+ var Test = stj.class_('', Object),
included = stj.module_(''),
instance = new Test(),
inc, ext;

0 comments on commit 9a5c478

Please sign in to comment.