Permalink
Browse files

Autoloader & Traceur

Autoloader with Traceur support is working.

Removing Joose/proxy stuff
  • Loading branch information...
1 parent 5beaf0d commit 0fd146419c1d0fba17a2094197724ea086793635 @aikar committed Jun 23, 2011
Showing 723 changed files with 28,340 additions and 67,884 deletions.
View
@@ -1,23 +1,17 @@
-
// load all our modules.
var autoloadModules = [
- 'joose',
- 'joosex-attribute',
- 'joosex-class-simpleconstructor',
- 'joosex-class-singleton',
- 'joosex-meta-lazy',
- 'joosex-simplerequest',
- 'joosex-namespace-depended',
- 'joosex-observable',
+ 'traceur',
'autoloader',
];
autoloadModules.forEach(function (mod) {
require(mod);
})
-// load main Cosmos class
-
-registerAutoloader('Cosmos', __dirname + '/classes');
+registerAutoloader(__dirname + '/classes');
+var origTraceurCreateClass = traceur.runtime.createClass;
+traceur.runtime.createClass = function (className) {
+ return global[className] = origTraceurCreateClass.apply(this, arguments);
+}
View
@@ -1,9 +1,11 @@
-Singleton({
- methods: {
- init: function () {
- console.log("COSMOS INIT");
- }
+class Cosmos {
+ new() {
+ console.log("NEW COSMOS")
}
-});
+ init() {
+
+ }
+};
+module.exports = Cosmos
@@ -0,0 +1,6 @@
+class Cosmos_Db {
+ new() {
+ console.log("NEW COSMOS DB")
+ }
+}
+
@@ -10,173 +10,51 @@
* because of the
*
*/
-var Proxy = require("harmonyproxy"),
+var
fs = require("fs"),
- sys = require("sys"),
- path = require("path"),
- undef, extensions = [".js", ".class.js"];
+ path = require("path");
-function isFunction(fn) {
- return !!(typeof fn == 'function');
-}
-
-function isScalar(fn) {
- switch (typeof fn) {
- case "function":
- case "object":
- return false;
- }
- return true;
-}
-function inPath(file) {
- var i = 0, l = extensions.length;
-
- for (;i<l;++i) {
- if (path.existsSync(file + extensions[i])) {
- return file + extensions[i];
- }
- }
- return false;
-}
// make sure its loaded first
-
-require('joose');
-
-var LAST_CLASS;
-
-var orig = {};
-var overloaded = {};
-// joose globals to overload.
-var overload = ['Class', 'Role','Singleton', 'LazyClass', 'LazyRole', 'Module'];
-
-
-overload.forEach(function (key) {
- orig[key] = global[key];
- overloaded[key] = function() {
- var args = [].slice.call(arguments);
- if (typeof args[0] == 'string') {
- args.shift();
+var fileCache = {};
+
+function defineGlobalGetter(name, fn) {
+ global.__defineGetter__(name, function() {
+ delete global[name];
+ var val = fn();
+ // if the callback function set the global for us, don't overwrite it.
+ if (global[name] == undefined) {
+ global[name] = val;
}
- LAST_CLASS = orig[key].apply(this, args);
- return LAST_CLASS;
- }
-});
-
-function overloadJoose() {
-
- overload.forEach(function (key) {
- global[key] = overloaded[key];
+ return global[name];
});
}
-function restoreJoose() {
- overload.forEach(function (key) {
- global[key] = orig[key];
- });
-}
-function loadJooseClass(file) {
- LAST_CLASS = null;
- overloadJoose();
- var obj;
- if ((file = inPath(file)) !== false) {
- obj = require(file);
- }
- restoreJoose();
- if ((!obj || !Object.keys(obj).length) && LAST_CLASS) {
- obj = LAST_CLASS;
- }
- return obj;
-}
-function namespace(filePath, properties) {
- properties = properties || {};
-
- var scalar = isScalar(properties),
- func = isFunction(filePath),
- handlers = {
- get: function(rec, name) {
- /*try {
- a.b = 1;
- } catch (e) {
- //console.error("get", filePath, name);
- //console.error(e.stack)
- }*/
- if (name === "valueOf" || name === "toString") {
- return function(){
- //console.error("returning valueof")
- return properties[name].call(this);
- };
- }
- if (!(name in properties)) {
- if (func) {
- properties[name] = filePath(name, properties);
- } else {
- //sys.puts(name);
- var file = path.join(filePath, name),
- stat, obj;
-
- obj = loadJooseClass(file);
-
- if (!obj) {
- try{
- // would work if it was a directory
- stat = fs.statSync(file);
- // this allows you to use an
- // object as a namespace as well
- return namespace(file);
- } catch(e) {
- return undef;
- }
- } else {
- properties[name] = obj;
- }
- }
- }
- if (!isScalar(properties[name]) && !Proxy.isProxy(properties[name])) {
- return namespace(path.join(filePath, name), properties[name]);
+
+function registerAutoloader(path, subpath) {
+ subpath = subpath || '/';
+ var basePath = path + subpath;
+ var files = fs.readdirSync(basePath);
+ files.forEach(function(file) {
+ var fullPath = basePath + file;
+ var stat = fs.statSync(fullPath);
+ if (stat.isDirectory()) {
+ registerAutoloader(path, subpath + file + '/');
+ } else {
+ var extLoc = file.lastIndexOf('.');
+ if (extLoc != -1) {
+ var ext = file.substr(extLoc);
+ if (require.extensions[ext]) {
+ var varName = (subpath.substr(1) + file.substr(0, extLoc));
+ varName = varName.replace(/[^a-z0-9]/gi,'_');
+ defineGlobalGetter(varName, function() {
+ return require(fullPath);
+ });
}
- console.error("returning", properties[name]);
- return properties[name];
-
- },
- has: function(name) {
- //console.error("has", name);
- return name === "valueOf" ||
- name === "toString" ||
- inPath(path.join(filePath, name));
- },
- set: function(rec, name, value) {
- //console.log("setting", name, value)
- properties[name] = value;
- },
- "delete": function(name) {
- delete properties[name];
- },
- enumerate: function() {
- return Object.keys(properties);
- },
- fix: function() {
- return undef;
}
- };
-
- if (isFunction(properties)) {
- return Proxy.createFunction(handlers, function(name) {
- console.error("calling", filePath, name)
- return properties.apply(this, arguments);
- }, function() {
- console.error("constructing", filePath, properties);
- var instance = Object.create(properties.prototype);
- properties.apply(instance, arguments);
- return instance;
- });
- } else {
- return Proxy.create(handlers, properties.constructor.prototype);
- }
-};
-global.registerAutoloader = function(globalName, path) {
- var cls = loadJooseClass(path + '/' + globalName);
- global[globalName] = namespace(path, cls);
+ }
+ });
}
+global.registerAutoloader = registerAutoloader;
@@ -1,3 +0,0 @@
-*.node
-src/build
-src/.lock-wscript
@@ -1,15 +0,0 @@
-all:
- @echo "BUILDING: C++ Component"
- @rm -rf src/build/
- @rm -rf src/.lock-wscript
- @rm -rf lib/node-proxy.node
- @cd src;node-waf configure build;cd ..
- @cp src/build/default/node-proxy.node lib/node-proxy.node
-
-clean:
- rm -rf src/build/
- rm -rf src/.lock-wscript
- rm -rf lib/node-proxy.node
-
-test: all
- node test/test.js
@@ -1,52 +0,0 @@
-node-proxy is an implementation of Harmony Proxies http://wiki.ecmascript.org/doku.php?id=harmony:proxies
-that allows the developer to create "catch-all" property handlers for an object or a function in node.js.
-
-Author: Sam Shull
-Repository: http://github.com/samshull/node-proxy
-Issues: http://github.com/samshull/node-proxy/issues
-
-*** This does not work appropriately in node versions 0.1.100 - 0.1.102. You will need to install node_version.h in $PREFIX/include/node
-
-Methods:
-
-Object create(ProxyHandler handler [, Object proto ] ) throws Error, TypeError
-
-Function createFunction(ProxyHandler handler, Function callTrap [, Function constructTrap ] ) throws Error, TypeError
-
-Boolean isTrapping(Object obj) throws Error
-
-
-Additional Methods (for ECMAScript 5 compatibliity): @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
-
-Boolean freeze(Object obj) throws Error, TypeError
-
-Boolean seal(Object obj) throws Error, TypeError
-
-Boolean preventExtensions(Object obj) throws Error, TypeError
-
-Boolean isFrozen(Object obj) throws Error, TypeError
-
-Boolean isSealed(Object obj) throws Error, TypeError
-
-Boolean isExtensible(Object obj) throws Error, TypeError
-
-PropertyDescriptor getOwnPropertyDescriptor(Object obj, String name) throws Error, TypeError
-
-Boolean defineProperty(Object obj, String name, PropertyDescriptor pd) throws Error, TypeError
-
-Boolean defineProperties(Object obj, Object descriptors) throws Error, TypeError
-
-
-More methods:
-
-Object hidden(Object obj, String name [, Object value ] ) throws Error
-- Set or retrieve a hidden property on an Object
-
-Object clone(Object obj) throws Error
-- Create a shallow copy of an Object
-
-Boolean isProxy(Object obj)
-- determine if an object was created by Proxy
-
-Boolean setPrototype(Object obj, Object obj) throws Error
--set the prototype of a given object to the second given object
Oops, something went wrong. Retry.

0 comments on commit 0fd1464

Please sign in to comment.