Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

publish jscex-promise

  • Loading branch information...
commit b8c433119b7fa2f5eb2eae77fb7f8e43fc716e3e 1 parent 61a0dbc
@JeffreyZhao authored
View
9 bin/dev/jscex-0.6.5.js
@@ -165,7 +165,14 @@
var loadModules = function (require, modules) {
if (require) {
_.each(modules, function (i, name) {
- require("./jscex-" + name).init();
+ var m;
+ try {
+ m = require("./jscex-" + name);
+ } catch (ex) {
+ m = require("jscex-" + name);
+ }
+
+ m.init();
});
} else {
_.each(modules, function (i, m) {
View
99 bin/dev/jscex-promise-0.6.5.js
@@ -0,0 +1,99 @@
+(function () {
+ "use strict";
+
+ var Jscex;
+
+ var defaultCreate = function () {
+ throw new Error('Please set "Jscex.Promise.create" to provide a factory method for creating a promise object.');
+ }
+
+ var PromiseBuilder = function () { }
+ PromiseBuilder.prototype = {
+ Start: function (_this, task) {
+ return Jscex.Promise.create(function (complete, error) {
+ task.next(_this, function (type, value, target) {
+ if (type == "normal" || type == "return") {
+ complete(value);
+ } else if (type == "throw") {
+ error(value);
+ } else {
+ throw new Error("Unsupported type: " + type);
+ }
+ });
+ });
+ },
+
+ Bind: function (promise, generator) {
+ return {
+ next: function (_this, callback) {
+ promise.then(function (result) {
+ var nextTask;
+ try {
+ nextTask = generator.call(_this, result);
+ } catch (ex) {
+ return callback("throw", ex);
+ }
+
+ nextTask.next(_this, callback);
+ }, function (error) {
+ callback("throw", error);
+ });
+ }
+ };
+ }
+ }
+
+ // CommonJS
+ var isCommonJS = !!(typeof require === "function" && typeof module !== "undefined" && module.exports);
+ // CommonJS AMD
+ var isAmd = !!(typeof require === "function" && typeof define === "function" && define.amd);
+
+ var defineModule = function () {
+ Jscex.define({
+ name: "promise",
+ version: "0.6.5",
+ exports: isCommonJS && module.exports,
+ require: isCommonJS && require,
+ autoloads: [ "builderbase" ],
+ dependencies: { builderbase: "~0.6.5" },
+ init: function () {
+ Jscex._.each(Jscex.BuilderBase.prototype, function (m, fn) {
+ PromiseBuilder.prototype[m] = fn;
+ });
+
+ if (!Jscex.Promise) {
+ Jscex.Promise = {};
+ }
+
+ Jscex.Promise.create = defaultCreate;
+
+ Jscex.binders["promise"] = "$await";
+ Jscex.builders["promise"] = new PromiseBuilder();
+ }
+ });
+ }
+
+ if (isCommonJS) {
+ try {
+ Jscex = require("./jscex");
+ } catch (ex) {
+ Jscex = require("jscex");
+ }
+
+ defineModule();
+ } else if (isAmd) {
+ require("jscex", function (jscex) {
+ Jscex = jscex;
+ defineModule();
+ });
+ } else {
+ var Fn = Function, global = Fn('return this')();
+
+ if (!global.Jscex) {
+ throw new Error('Missing the root object, please load "jscex" component first.');
+ }
+
+ Jscex = global.Jscex;
+ defineModule();
+ }
+})();
View
99 bin/npm/jscex-promise/jscex-promise.js
@@ -0,0 +1,99 @@
+(function () {
+ "use strict";
+
+ var Jscex;
+
+ var defaultCreate = function () {
+ throw new Error('Please set "Jscex.Promise.create" to provide a factory method for creating a promise object.');
+ }
+
+ var PromiseBuilder = function () { }
+ PromiseBuilder.prototype = {
+ Start: function (_this, task) {
+ return Jscex.Promise.create(function (complete, error) {
+ task.next(_this, function (type, value, target) {
+ if (type == "normal" || type == "return") {
+ complete(value);
+ } else if (type == "throw") {
+ error(value);
+ } else {
+ throw new Error("Unsupported type: " + type);
+ }
+ });
+ });
+ },
+
+ Bind: function (promise, generator) {
+ return {
+ next: function (_this, callback) {
+ promise.then(function (result) {
+ var nextTask;
+ try {
+ nextTask = generator.call(_this, result);
+ } catch (ex) {
+ return callback("throw", ex);
+ }
+
+ nextTask.next(_this, callback);
+ }, function (error) {
+ callback("throw", error);
+ });
+ }
+ };
+ }
+ }
+
+ // CommonJS
+ var isCommonJS = !!(typeof require === "function" && typeof module !== "undefined" && module.exports);
+ // CommonJS AMD
+ var isAmd = !!(typeof require === "function" && typeof define === "function" && define.amd);
+
+ var defineModule = function () {
+ Jscex.define({
+ name: "promise",
+ version: "0.6.5",
+ exports: isCommonJS && module.exports,
+ require: isCommonJS && require,
+ autoloads: [ "builderbase" ],
+ dependencies: { builderbase: "~0.6.5" },
+ init: function () {
+ Jscex._.each(Jscex.BuilderBase.prototype, function (m, fn) {
+ PromiseBuilder.prototype[m] = fn;
+ });
+
+ if (!Jscex.Promise) {
+ Jscex.Promise = {};
+ }
+
+ Jscex.Promise.create = defaultCreate;
+
+ Jscex.binders["promise"] = "$await";
+ Jscex.builders["promise"] = new PromiseBuilder();
+ }
+ });
+ }
+
+ if (isCommonJS) {
+ try {
+ Jscex = require("./jscex");
+ } catch (ex) {
+ Jscex = require("jscex");
+ }
+
+ defineModule();
+ } else if (isAmd) {
+ require("jscex", function (jscex) {
+ Jscex = jscex;
+ defineModule();
+ });
+ } else {
+ var Fn = Function, global = Fn('return this')();
+
+ if (!global.Jscex) {
+ throw new Error('Missing the root object, please load "jscex" component first.');
+ }
+
+ Jscex = global.Jscex;
+ defineModule();
+ }
+})();
View
14 bin/npm/jscex-promise/package.json
@@ -0,0 +1,14 @@
+{
+ "author": "Jeffrey Zhao <jeffz@live.com> (http://zhaojie.me/)",
+ "homepage": "https://github.com/JeffreyZhao/jscex",
+ "bugs": {
+ "url": "https://github.com/JeffreyZhao/jscex/issues",
+ "email": "jeffz@live.com"
+ },
+ "name": "jscex-promise",
+ "version": "0.6.5",
+ "main": "jscex-promise.js",
+ "dependencies": {
+ "jscex-builderbase": "~0.6.5"
+ }
+}
View
14 bin/prod/jscex-0.6.5.min.js
@@ -1,7 +1,7 @@
-(function(){var c,f=function(){var a=function(a){return Object.prototype.toString.call(a)==="[object Array]"},b=function(a){var b=0;a=a.split(".");for(var d=0;d<3;d++)b*=100,d<a.length&&(b+=parseInt(a[d],10));return b},c=function(b,n){if(!a(n)){for(var d=Array(arguments.length-1),e=1;e<arguments.length;e++)d[e-1]=arguments[e];return c(b,d)}return b.replace(/\{{1,2}\d+\}{1,2}/g,function(a){if(a.indexOf("{{")==0&&a.indexOf("}}")==a.length-2)return a.substring(1,a.length-1);for(var b=0;a[b]=="{";)b++;
-for(var i=a.length-1;a[i]=="}";)i--;b=parseInt(a.substring(b,i+1),10);return a.replace("{"+b+"}",n[b])})};return{isArray:a,each:function(b,c){if(a(b))for(var d=0,e=b.length;d<e;d++){var g=c(d,b[d]);if(g!==void 0)return g}else for(d in b)if(b.hasOwnProperty(d)&&(g=c(d,b[d]),g!==void 0))return g},map:function(b,c,d){if(a(b)){d=Array(b.length);for(var e=0,g=b.length;e<g;e++)d[e]=c(b[e]);return d}else{e={};for(g in b)if(b.hasOwnProperty(g)){var f=b[g],s=c?c(g):g;f=d?d(f):f;e[s]=f}return e}},v2n:b,testVersion:function(a,
-c){var d=a.substring(1),e=d.split(".");e[e.length-1]="0";e[e.length-2]=(parseInt(e[e.length-2],10)+1).toString();e=e.join(".");var f=b(c);return b(d)<=f&&f<b(e)},format:c,once:function(a){var b=!1;return function(){b||(a.apply(this,arguments),b=!0)}}}}(),h={ALL:0,TRACE:1,DEBUG:2,INFO:3,WARN:4,ERROR:5,OFF:100},j=function(){this.level=h.DEBUG};j.prototype={log:function(a,b){if(this.level<=a)try{console.log(b)}catch(c){}},trace:function(a){this.log(h.TRACE,a)},debug:function(a){this.log(h.DEBUG,a)},
-info:function(a){this.log(h.INFO,a)},warn:function(a){this.log(h.WARN,a)},error:function(a){this.log(h.ERROR,a)}};var o=function(a,b){a?f.each(b,function(b,c){a("./jscex-"+c).init()}):f.each(b,function(a,b){b.init()})},l=function(a){var b=c.modules[a.name];b&&b.version!=a.version&&c.logger.warn(f.format('The module "{0}" with version "{1}" has already been initialized, skip version "{2}".',a.name,b.version,a.version));t(a);a.init();b={};k(b,a);c.modules[a.name]=b},t=function(a){if(a.coreDependency&&
-!f.testVersion(a.coreDependency,c.coreVersion))throw Error(f.format('Version of core component mismatched, expected: "{0}", actual: "{1}".',a.coreDependency,c.coreVersion));f.each(a.dependencies||[],function(a,h){var i=c.modules[a];if(!i)throw Error(f.format('Missing required module: "{0}" (expected version: "{1}").',a,h));if(!f.testVersion(h,i.version))throw Error(f.format('Version of module "{0}" mismatched, expected: "{1}", actual: "{2}".',a,h,i.version));})},k=function(a,b){a.name=b.name;a.version=
-b.version;if(b.autoloads)a.autoloads=b.autoloads;if(b.coreDependency)a.coreDependency=b.coreDependency;if(b.dependencies)a.dependencies=b.dependencies},p=!!(typeof require==="function"&&typeof module!=="undefined"&&module.exports),q=!!(typeof require==="function"&&typeof define==="function"&&define.amd),u=function(a){var b=a.autoloads||[];if(p)k(a.exports,a),a.exports.init=f.once(function(){o(a.require,b);l(a)});else if(q){var c=f.map(b,function(a){return"jscex-"+a});define("jscex-"+a.name,c,function(){var b=
-arguments,c={};k(c,a);c.init=f.once(function(){o(null,b);l(a)});return c})}else l(a)},m=function(){c.coreVersion="0.6.5";c.logger=new j;c.Logging={Logger:j,Level:h};c._=f;c.modules={};c.binders={};c.builders={};c.define=u};if(p)c=module.exports,m();else if(q)define("jscex",function(){c={};m();return c});else{var r=Function("return this")();if(r.Jscex)throw Error("There's already a Jscex root here, please load the component only once.");c=r.Jscex={};m()}})();
+(function(){var c,d=function(){var a=function(a){return Object.prototype.toString.call(a)==="[object Array]"},b=function(a){var b=0;a=a.split(".");for(var e=0;e<3;e++)b*=100,e<a.length&&(b+=parseInt(a[e],10));return b},c=function(b,j){if(!a(j)){for(var e=Array(arguments.length-1),f=1;f<arguments.length;f++)e[f-1]=arguments[f];return c(b,e)}return b.replace(/\{{1,2}\d+\}{1,2}/g,function(a){if(a.indexOf("{{")==0&&a.indexOf("}}")==a.length-2)return a.substring(1,a.length-1);for(var b=0;a[b]=="{";)b++;
+for(var i=a.length-1;a[i]=="}";)i--;b=parseInt(a.substring(b,i+1),10);return a.replace("{"+b+"}",j[b])})};return{isArray:a,each:function(b,j){if(a(b))for(var e=0,f=b.length;e<f;e++){var c=j(e,b[e]);if(c!==void 0)return c}else for(e in b)if(b.hasOwnProperty(e)&&(c=j(e,b[e]),c!==void 0))return c},map:function(b,c,e){if(a(b)){e=Array(b.length);for(var f=0,d=b.length;f<d;f++)e[f]=c(b[f]);return e}else{f={};for(d in b)if(b.hasOwnProperty(d)){var h=b[d],g=c?c(d):d;h=e?e(h):h;f[g]=h}return f}},v2n:b,testVersion:function(a,
+c){var e=a.substring(1),f=e.split(".");f[f.length-1]="0";f[f.length-2]=(parseInt(f[f.length-2],10)+1).toString();f=f.join(".");var d=b(c);return b(e)<=d&&d<b(f)},format:c,once:function(a){var b=!1;return function(){b||(a.apply(this,arguments),b=!0)}}}}(),g={ALL:0,TRACE:1,DEBUG:2,INFO:3,WARN:4,ERROR:5,OFF:100},k=function(){this.level=g.DEBUG};k.prototype={log:function(a,b){if(this.level<=a)try{console.log(b)}catch(c){}},trace:function(a){this.log(g.TRACE,a)},debug:function(a){this.log(g.DEBUG,a)},
+info:function(a){this.log(g.INFO,a)},warn:function(a){this.log(g.WARN,a)},error:function(a){this.log(g.ERROR,a)}};var o=function(a,b){a?d.each(b,function(b,c){var d;try{d=a("./jscex-"+c)}catch(e){d=a("jscex-"+c)}d.init()}):d.each(b,function(a,b){b.init()})},m=function(a){var b=c.modules[a.name];b&&b.version!=a.version&&c.logger.warn(d.format('The module "{0}" with version "{1}" has already been initialized, skip version "{2}".',a.name,b.version,a.version));s(a);a.init();b={};l(b,a);c.modules[a.name]=
+b},s=function(a){if(a.coreDependency&&!d.testVersion(a.coreDependency,c.coreVersion))throw Error(d.format('Version of core component mismatched, expected: "{0}", actual: "{1}".',a.coreDependency,c.coreVersion));d.each(a.dependencies||[],function(a,h){var i=c.modules[a];if(!i)throw Error(d.format('Missing required module: "{0}" (expected version: "{1}").',a,h));if(!d.testVersion(h,i.version))throw Error(d.format('Version of module "{0}" mismatched, expected: "{1}", actual: "{2}".',a,h,i.version));
+})},l=function(a,b){a.name=b.name;a.version=b.version;if(b.autoloads)a.autoloads=b.autoloads;if(b.coreDependency)a.coreDependency=b.coreDependency;if(b.dependencies)a.dependencies=b.dependencies},p=!!(typeof require==="function"&&typeof module!=="undefined"&&module.exports),q=!!(typeof require==="function"&&typeof define==="function"&&define.amd),t=function(a){var b=a.autoloads||[];if(p)l(a.exports,a),a.exports.init=d.once(function(){o(a.require,b);m(a)});else if(q){var c=d.map(b,function(a){return"jscex-"+
+a});define("jscex-"+a.name,c,function(){var b=arguments,c={};l(c,a);c.init=d.once(function(){o(null,b);m(a)});return c})}else m(a)},n=function(){c.coreVersion="0.6.5";c.logger=new k;c.Logging={Logger:k,Level:g};c._=d;c.modules={};c.binders={};c.builders={};c.define=t};if(p)c=module.exports,n();else if(q)define("jscex",function(){c={};n();return c});else{var r=Function("return this")();if(r.Jscex)throw Error("There's already a Jscex root here, please load the component only once.");c=r.Jscex={};n()}})();
View
3  bin/prod/jscex-promise-0.6.5.min.js
@@ -0,0 +1,3 @@
+(function(){var a,j=function(){throw Error('Please set "Jscex.Promise.create" to provide a factory method for creating a promise object.');},d=function(){};d.prototype={Start:function(c,g){return a.Promise.create(function(a,e){g.next(c,function(f,c){if(f=="normal"||f=="return")a(c);else if(f=="throw")e(c);else throw Error("Unsupported type: "+f);})})},Bind:function(a,g){return{next:function(b,e){a.then(function(a){var c;try{c=g.call(b,a)}catch(d){return e("throw",d)}c.next(b,e)},function(a){e("throw",
+a)})}}}};var h=!!(typeof require==="function"&&typeof module!=="undefined"&&module.exports),b=!!(typeof require==="function"&&typeof define==="function"&&define.amd),i=function(){a.define({name:"promise",version:"0.6.5",exports:h&&module.exports,require:h&&require,autoloads:["builderbase"],dependencies:{builderbase:"~0.6.5"},init:function(){a._.each(a.BuilderBase.prototype,function(a,b){d.prototype[a]=b});if(!a.Promise)a.Promise={};a.Promise.create=j;a.binders.promise="$await";a.builders.promise=
+new d}})};if(h){try{a=require("./jscex")}catch(k){a=require("jscex")}i()}else if(b)require("jscex",function(b){a=b;i()});else{b=Function("return this")();if(!b.Jscex)throw Error('Missing the root object, please load "jscex" component first.');a=b.Jscex;i()}})();
View
1  lib/utils.js
@@ -8,6 +8,7 @@ var fs = require("fs"),
require("../src/jscex-jit").init();
require("../src/jscex-async").init();
require("../src/jscex-async-powerpack").init();
+require("../src/jscex-promise").init();
var copySync = function (src, dest) {
var content = fs.readFileSync(src, "utf8");
View
2  scripts/build-dev.js
@@ -19,7 +19,7 @@ var coreName = "jscex-" + Jscex.coreVersion + ".js"
utils.copySync(path.join(srcDir, "jscex.js"), path.join(devDir, coreName));
console.log(coreName + " generated.");
-var moduleList = [ "parser", "jit", "builderbase", "async", "async-powerpack" ];
+var moduleList = [ "parser", "jit", "builderbase", "async", "async-powerpack", "promise" ];
_.each(moduleList, function (i, module) {
var fullName = "jscex-" + module;
View
2  scripts/build-npm.js
@@ -104,7 +104,7 @@ var buildAot = function () {
buildOne(); // core
-var modules = [ "parser", "jit", "builderbase", "async", "async-powerpack" ];
+var modules = [ "parser", "jit", "builderbase", "async", "async-powerpack", "promise" ];
_.each(modules, function (name) {
buildOne(name);
});
View
2  scripts/build-prod.js
@@ -55,4 +55,4 @@ var buildAll = eval(Jscex.compile("async", function (modules) {
}
}));
-buildAll(["", "builderbase", "async", "async-powerpack"]).start();
+buildAll(["", "builderbase", "async", "async-powerpack", "promise"]).start();
Please sign in to comment.
Something went wrong with that request. Please try again.