quixote
Version:
CSS unit and integration testing
45 lines (37 loc) • 1.51 kB
JavaScript
// Copyright (c) 2014 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file.
;
// can't use ensure.js due to circular dependency
var shim = require("./shim.js");
exports.className = function(constructor) {
if (typeof constructor !== "function") throw new Error("Not a constructor");
return shim.Function.name(constructor);
};
exports.instanceName = function(obj) {
var prototype = shim.Object.getPrototypeOf(obj);
if (prototype === null) return "<no prototype>";
var constructor = prototype.constructor;
if (constructor === undefined || constructor === null) return "<anon>";
return shim.Function.name(constructor);
};
exports.extendFn = function extendFn(parentConstructor) {
return function(childConstructor) {
childConstructor.prototype = shim.Object.create(parentConstructor.prototype);
childConstructor.prototype.constructor = childConstructor;
};
};
exports.makeAbstract = function makeAbstract(constructor, methods) {
var name = shim.Function.name(constructor);
shim.Array.forEach(methods, function(method) {
constructor.prototype[method] = function() {
throw new Error(name + " subclasses must implement " + method + "() method");
};
});
constructor.prototype.checkAbstractMethods = function checkAbstractMethods() {
var unimplemented = [];
var self = this;
shim.Array.forEach(methods, function(name) {
if (self[name] === constructor.prototype[name]) unimplemented.push(name + "()");
});
return unimplemented;
};
};