You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/09/11 01:57:44 UTC
[36/52] [abbrv] [partial] re-org
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/js/storage.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/js/storage.js b/src/cordova-win8/js/storage.js
deleted file mode 100644
index 3dcec4c..0000000
--- a/src/cordova-win8/js/storage.js
+++ /dev/null
@@ -1,453 +0,0 @@
-var storageParam = {
- db : null,
- dbName : null,
- path : Windows.Storage.ApplicationData.current.localFolder.path
-}
-
-
-/**
- * Create a UUID
- */
-function createUUID() {
- function UUIDcreatePart(length) {
- var uuidpart = "";
- for (var i = 0; i < length; i++) {
- var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
- if (uuidchar.length == 1) {
- uuidchar = "0" + uuidchar;
- }
- uuidpart += uuidchar;
- }
- return uuidpart;
- }
- return UUIDcreatePart(4) + '-' +
- UUIDcreatePart(2) + '-' +
- UUIDcreatePart(2) + '-' +
- UUIDcreatePart(2) + '-' +
- UUIDcreatePart(6);
-}
-
-function SQLError(error) {
- this.code = error || null;
-}
-
-SQLError.UNKNOWN_ERR = 0;
-SQLError.DATABASE_ERR = 1;
-SQLError.VERSION_ERR = 2;
-SQLError.TOO_LARGE_ERR = 3;
-SQLError.QUOTA_ERR = 4;
-SQLError.SYNTAX_ERR = 5;
-SQLError.CONSTRAINT_ERR = 6;
-SQLError.TIMEOUT_ERR = 7;
-
-
-
-/**
- * Open database
- *
- * @param name Database name
- * @param version Database version
- * @param display_name Database display name
- * @param size Database size in bytes
- * @return Database object
- */
-function openDatabase(name, version, display_name, size) {
- if (storageParam.db != null) { storageParam.db.close(); }
- if (String(name).match(new RegExp(/\?|\\|\*|\||\"|<|>|\:|\//g))) {
- return null;
- //throw new Error("invalid name error");
- };
- storageParam.dbName = storageParam.path + "\\" + name + ".sqlite";
- storageParam.db = new SQLite3.Database(storageParam.dbName);
- return new Database();
-}
-
-
-function Database() { }
-
-/**
- * Start a transaction.
- * Does not support rollback in event of failure.
- *
- * @param process {Function} The transaction function
- * @param successCallback {Function}
- * @param errorCallback {Function}
- */
-Database.prototype.transaction = function (process, errorCallback, successCallback) {
- var tx = new SQLTransaction();
- tx.successCallback = successCallback;
- tx.errorCallback = errorCallback;
- try {
- process(tx);
- } catch (e) {
-
- if (tx.errorCallback) {
- try {
- tx.errorCallback(new SQLError(SQLError.SYNTAX_ERR));
- } catch (ex) {
- console.log("Transaction error calling user error callback: " + e);
- }
- }
- }
-}
-
-
-
-function queryQueue() { };
-
-
-/**
- * Transaction object
- * PRIVATE METHOD
- * @constructor
- */
-function SQLTransaction () {
-
- // Set the id of the transaction
- this.id = createUUID();
-
- // Callbacks
- this.successCallback = null;
- this.errorCallback = null;
-
- // Query list
- this.queryList = {};
-};
-
-/**
- * Mark query in transaction as complete.
- * If all queries are complete, call the user's transaction success callback.
- *
- * @param id Query id
- */
-SQLTransaction.prototype.queryComplete = function (id) {
- delete this.queryList[id];
-
- // If no more outstanding queries, then fire transaction success
- if (this.successCallback) {
- var count = 0;
- var i;
- for (i in this.queryList) {
- if (this.queryList.hasOwnProperty(i)) {
- count++;
- }
- }
- if (count === 0) {
- try {
- this.successCallback();
- } catch (e) {
- if (typeof this.errorCallback === "function") {
- this.errorCallback(new SQLError(SQLError.UNKNOWN_ERR));
- }
- }
- }
- }
-};
-
-/**
- * Mark query in transaction as failed.
- *
- * @param id Query id
- * @param reason Error message
- */
-SQLTransaction.prototype.queryFailed = function (id, reason) {
-
- // The sql queries in this transaction have already been run, since
- // we really don't have a real transaction implemented in native code.
- // However, the user callbacks for the remaining sql queries in transaction
- // will not be called.
- this.queryList = {};
-
- if (this.errorCallback) {
- try {
- this.errorCallback(reason);
- } catch (e) {
- console.log("Transaction error calling user error callback: " + e);
- }
- }
-};
-
-/**
- * Execute SQL statement
- *
- * @param sql SQL statement to execute
- * @param params Statement parameters
- * @param successCallback Success callback
- * @param errorCallback Error callback
- */
-SQLTransaction.prototype.executeSql = function (sql, params, successCallback, errorCallback) {
-
- var isDDL = function (query) {
- var cmdHeader = String(query).toLowerCase().split(" ")[0];
- if (cmdHeader == "drop" || cmdHeader == "create" || cmdHeader == "alter" || cmdHeader == "truncate") {
- return true;
- }
- return false;
- };
-
- // Init params array
- if (typeof params === 'undefined' || params == null) {
- params = [];
- }
-
- // Create query and add to queue
- var query = new DB_Query(this);
- queryQueue[query.id] = query;
-
- // Save callbacks
- query.successCallback = successCallback;
- query.errorCallback = errorCallback;
-
- // Call native code
-
- var statement = null;
- var type = function (obj) {
- var typeString;
- typeString = Object.prototype.toString.call(obj);
- return typeString.substring(8, typeString.length - 1).toLowerCase();
- }
-
- try {
- if (isDDL(sql)) {
-
- statement = storageParam.db.prepare(sql);
- statement.step();
- if (resultCode === SQLite3.ResultCode.error) {
- if (typeof query.errorCallback === 'function') {
- query.errorCallback(new SQLError(SQLError.SYNTAX_ERR));
- }
- return;
- }
- statement.close();
- completeQuery(query.id, "");
- } else {
- statement = storageParam.db.prepare(sql);
- var index, resultCode;
- params.forEach(function (arg, i) {
- index = i + 1;
-
- switch (type(arg)) {
- case 'number':
- if (arg % 1 === 0) {
- resultCode = statement.bindInt(index, arg);
- } else {
- resultCode = statement.bindDouble(index, arg);
- }
- break;
- case 'string':
- resultCode = statement.bindText(index, arg);
- break;
- case 'null':
- resultCode = statement.bindNull(index);
- break;
- default:
- if (typeof query.errorCallback === 'function') {
- query.errorCallback(new SQLError(SQLError.DATABASE_ERR));
- }
- return;
- }
- if (resultCode !== SQLite3.ResultCode.ok) {
- if (typeof query.errorCallback === 'function') {
- query.errorCallback(new SQLError(SQLError.DATABASE_ERR));
- }
- return;
- }
- });
- // get data
- var result = new Array();
- // get the Result codes of SQLite3
- resultCode = statement.step();
- if (resultCode === SQLite3.ResultCode.row) {
- do{
- var row = new Object();
- for (var j = 0 ; j < statement.columnCount() ; j++) {
- // set corresponding type
- if (statement.columnType(j) == "1") {
- row[statement.columnName(j)] = statement.columnInt(j);
- } else if (statement.columnType(j) == "2") {
- row[statement.columnName(j)] = statement.columnDouble(j);
- } else if (statement.columnType(j) == "3") {
- row[statement.columnName(j)] = statement.columnText(j);
- } else if (statement.columnType(j) == "5") {
- row[statement.columnName(j)] = null;
- } else {
- if (typeof query.errorCallback === 'function') {
- query.errorCallback(new SQLError(SQLError.DATABASE_ERR));
- }
- return;
- }
-
- }
- result.push(row);
- } while (statement.step() === SQLite3.ResultCode.row);
- // SQL error or missing database
- } else if (resultCode === SQLite3.ResultCode.error) {
- if (typeof query.errorCallback === 'function') {
- query.errorCallback(new SQLError(SQLError.SYNTAX_ERR));
- }
- return;
- }
- completeQuery(query.id, result);
- statement.close();
- }
-
- } catch (e) {
- failQuery(e.description, query.id)
- }
-};
-
-/**
- * Callback from native code when query is complete.
- * PRIVATE METHOD
- *
- * @param id Query id
- */
-function completeQuery(id, data) {
- var query = queryQueue[id];
- if (query) {
- try {
- delete queryQueue[id];
-
- // Get transaction
- var tx = query.tx;
-
- // If transaction hasn't failed
- // Note: We ignore all query results if previous query
- // in the same transaction failed.
- if (tx && tx.queryList[id]) {
-
- // Save query results
- var r = new SQLResultSet();
- r.rows.resultSet = data;
- r.rows.length = data.length;
- try {
- if (typeof query.successCallback === 'function') {
- query.successCallback(query.tx, r);
- }
- } catch (ex) {
- console.log("executeSql error calling user success callback: " + ex);
- }
-
- tx.queryComplete(id);
- }
- } catch (e) {
- if (typeof query.errorCallback === 'function') {
- query.errorCallback(new SQLError(SQLError.UNKNOWN_ERR));
- } else {
- console.log("executeSql error: " + e);
- }
- }
- }
-}
-
-/**
- * Callback from native code when query fails
- * PRIVATE METHOD
- *
- * @param reason Error message
- * @param id Query id
- */
-function failQuery(reason, id) {
- var query = queryQueue[id];
- if (query) {
- try {
- delete queryQueue[id];
-
- // Get transaction
- var tx = query.tx;
-
- // If transaction hasn't failed
- // Note: We ignore all query results if previous query
- // in the same transaction failed.
-
- if (tx && tx.queryList[id]) {
- tx.queryList = {};
-
- try {
- if (typeof query.errorCallback === 'function') {
-
- query.errorCallback(new SQLError(SQLError.SYNTAX_ERR));
- return;
- }
- } catch (ex) {
- console.log("executeSql error calling user error callback: " + ex);
- }
-
- tx.queryFailed(id, reason);
- }
-
- } catch (e) {
- if (typeof query.errorCallback === 'function') {
- query.errorCallback(new SQLError(SQLError.UNKNOWN_ERR));
- } else {
- console.log("executeSql error: " + e);
- }
- }
- }
-}
-
-/**
- * SQL query object
- * PRIVATE METHOD
- *
- * @constructor
- * @param tx The transaction object that this query belongs to
- */
-function DB_Query(tx) {
-
- // Set the id of the query
- this.id = createUUID();
-
- // Add this query to the queue
- queryQueue[this.id] = this;
-
- // Init result
- this.resultSet = [];
-
- // Set transaction that this query belongs to
- this.tx = tx;
-
- // Add this query to transaction list
- this.tx.queryList[this.id] = this;
-
- // Callbacks
- this.successCallback = null;
- this.errorCallback = null;
-
-};
-
-/**
- * SQL result set object
- * PRIVATE METHOD
- * @constructor
- */
-function SQLResultSetList () {
- this.resultSet = []; // results array
- this.length = 0; // number of rows
-};
-
-/**
- * Get item from SQL result set
- *
- * @param row The row number to return
- * @return The row object
- */
-SQLResultSetList.prototype.item = function (row) {
- return this.resultSet[row];
-};
-
-/**
- * SQL result set that is returned to user.
- * PRIVATE METHOD
- * @constructor
- */
-function SQLResultSet () {
- this.rows = new SQLResultSetList();
-};
-
-////
-/**
- * Event fired to signify code is fully loaded
- */
-
-fireEvent("deviceready", document, "HTMLEvents");
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-agent.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-agent.js b/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-agent.js
deleted file mode 100644
index 3f25c89..0000000
--- a/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-agent.js
+++ /dev/null
@@ -1,75 +0,0 @@
-(function () {
- var init = function (root) {
-
- if (!root.modules || !root.modules["async"]) {
- throw new Error('Missing essential component, please initialize "async" module first.');
- }
-
- if (root.modules["async-agent"]) {
- return;
- }
-
- var Task = root.Async.Task;
-
- var Agent = function () {
- this._messages = [];
- this._tasks = [];
- }
- Agent.prototype = {
- receive: function () {
- var _this = this;
-
- return Task.create(function (t) {
- if (_this._messages.length > 0) {
- var msg = _this._messages.shift();
- t.complete("success", msg);
- } else {
- _this._tasks.push(t);
- }
- });
- },
-
- post: function (msg) {
- if (this._tasks.length > 0) {
- var t = this._tasks.shift();
- t.complete("success", msg);
- } else {
- this._messages.push(msg);
- }
- },
-
- currentQueueLength: function () {
- return this._messages.length;
- }
- };
-
- root.Async.Agent = Agent;
-
- root.modules["async-agent"] = true;
- }
-
- // CommonJS
- var isCommonJS = (typeof require === "function" && typeof module !== "undefined" && module.exports);
- // CommongJS Wrapping
- var isWrapping = (typeof define === "function" && !define.amd);
- // CommonJS AMD
- var isAmd = (typeof require === "function" && typeof define === "function" && define.amd);
-
- if (isCommonJS) {
- module.exports.init = init;
- } else if (isWrapping) {
- define("jscex-async-agent", ["jscex-async"], function (require, exports, module) {
- module.exports.init = init;
- });
- } else if (isAmd) {
- define("jscex-async-agent", ["jscex-async"], function () {
- return { init: init };
- });
- } else {
- if (typeof Jscex === "undefined") {
- throw new Error('Missing the root object, please load "jscex" module first.');
- }
-
- init(Jscex);
- }
-})();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-include.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-include.js b/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-include.js
deleted file mode 100644
index a076b08..0000000
--- a/src/cordova-win8/lib/Jscex/src/incubations/jscex-async-include.js
+++ /dev/null
@@ -1,63 +0,0 @@
-(function () {
-
- var init = function (root) {
- if (root.modules["async-include"]) {
- return;
- }
-
- if (!root.modules["async"]) {
- throw new Error('Missing essential components, please initialize "jscex-async" module first.');
- }
-
-
- root.modules["async-include"] = true;
-
- var Async = root.Async;
- var Task = Async.Task
- Async.include = function (path) {
- return Task.create(function (t) {
- var script = document.createElement("script");
- if(script.onload == null) {
- script.onload = function () {
- t.complete("success");
- }
- }
- else if(script.onreadystatechange == null){
- script.onreadystatechange = function () {
- if(this.readyState=='load')
- t.complete("success");
- }
- }
- script.src = path;
-
- document.getElementsByTagName("head")[0].appendChild(script);
-
- });
-
- }
- }
- // CommonJS
- var isCommonJS = (typeof require === "function" && typeof module !== "undefined" && module.exports);
- // CommongJS Wrapping
- var isWrapping = (typeof define === "function" && !define.amd);
- // CommonJS AMD
- var isAmd = (typeof require === "function" && typeof define === "function" && define.amd);
-
- if (isCommonJS) {
- module.exports.init = init;
- } else if (isWrapping) {
- define("jscex-async-include", ["jscex-async"], function (require, exports, module) {
- module.exports.init = init;
- });
- } else if (isAmd) {
- define("jscex-async-include", ["jscex-async"], function () {
- return { init: init };
- });
- } else {
- if (typeof Jscex === "undefined") {
- throw new Error('Missing the root object, please load "jscex" module first.');
- }
-
- init(Jscex);
- }
-})();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/incubations/jscex.async.xhr.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/incubations/jscex.async.xhr.js b/src/cordova-win8/lib/Jscex/src/incubations/jscex.async.xhr.js
deleted file mode 100644
index 7adc9a2..0000000
--- a/src/cordova-win8/lib/Jscex/src/incubations/jscex.async.xhr.js
+++ /dev/null
@@ -1,21 +0,0 @@
-XMLHttpRequest.prototype.receiveAsync = function () {
- var _this = this;
-
- var delegate = {
- "onStart": function (callback) {
- _this.onreadystatechange = function () {
- if (_this.readyState == 4) {
- callback("success", _this.responseText);
- }
- }
-
- _this.send();
- },
-
- "onCancel": function (callback) {
- _this.abort();
- }
- };
-
- return new Jscex.Async.Task(delegate);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.js b/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.js
deleted file mode 100644
index 86c35ba..0000000
--- a/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.js
+++ /dev/null
@@ -1,70 +0,0 @@
-Jscex.Seq = { };
-
-(function () {
-
- var SeqBuilder = function () { }
-
- var Iterator = Jscex.Seq.Iterator = function (delegate) {
- this._delegate = delegate;
- }
- Iterator.prototype.moveNext = function () {
-
- var step = this._delegate();
- if (step) {
- this._delegate = step.nextDelegate;
- this.current = step.item;
- return true;
- } else {
- delete this._delegate;
- delete this.current;
- return false;
- }
- }
-
- var TempStep = null;
-
- SeqBuilder.prototype = {
- "binder": "$yield",
-
- "Start": function (_this, step) {
-
- var delegate = function () {
- TempStep = null;
- step.next(_this, function (type, value) {
- if (type == "throw") console.log(value);
- });
-
- var tempStep = TempStep;
- TempStep = null;
- return tempStep;
- }
-
- return new Jscex.Seq.Iterator(delegate);
- },
-
- "Bind": function (value, generator) {
- return {
- "next": function (_this, callback) {
- TempStep = {
- item: value,
- nextDelegate: function () {
- TempStep = null;
- generator.call(_this).next(_this, callback);
-
- var tempStep = TempStep;
- TempStep = null;
- return tempStep;
- }
- };
- }
- };
- }
- }
-
- for (var m in Jscex.builderBase) {
- SeqBuilder.prototype[m] = Jscex.builderBase[m];
- }
-
- Jscex.builders["seq"] = new SeqBuilder();
-
-})();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.powerpack.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.powerpack.js b/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.powerpack.js
deleted file mode 100644
index 0691005..0000000
--- a/src/cordova-win8/lib/Jscex/src/incubations/jscex.seq.powerpack.js
+++ /dev/null
@@ -1,61 +0,0 @@
-(function () {
-
- var filter = eval(Jscex.compile("seq", function (iter, predicate) {
- while (iter.moveNext()) {
- if (predicate(iter.current)) {
- $yield(iter.current);
- }
- }
- }));
-
- var map = eval(Jscex.compile("seq", function (iter, mapper) {
- while (iter.moveNext()) {
- $yield(mapper(iter.current));
- }
- }));
-
- var zip = eval(Jscex.compile("seq", function (iter1, iter2) {
- while (iter1.moveNext() && iter2.moveNext()) {
- $yield([iter1.current, iter2.current]);
- }
- }));
-
- var skip = eval(Jscex.compile("seq", function (iter, n) {
- for (var i = 0; i < n; i++) {
- if (!iter.moveNext()) {
- return;
- }
- }
-
- while (iter.moveNext()) {
- $yield(iter.current);
- }
- }));
-
- var take = eval(Jscex.compile("seq", function (iter, n) {
- var count = 0;
- while (iter.moveNext()) {
- if (count++ < n) {
- $yield(iter.current);
- } else {
- return;
- }
- }
- }));
-
- var each = function (iter, action) {
- while (iter.moveNext()) {
- action(iter.current);
- }
- };
-
- var p = Jscex.Seq.Iterator.prototype;
- p.filter = function (predicate) { return filter(this, predicate); }
- p.map = function (mapper) { return map(this, mapper); }
- p.zip = function (iter) { return zip(this, iter); }
- p.skip = function (n) { return skip(this, n); }
- p.take = function (n) { return take(this, n); }
- p.each = function (action) { each(this, action); }
-
-})();
-
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/jscex-async-powerpack.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/jscex-async-powerpack.js b/src/cordova-win8/lib/Jscex/src/jscex-async-powerpack.js
deleted file mode 100644
index 5d5b2f8..0000000
--- a/src/cordova-win8/lib/Jscex/src/jscex-async-powerpack.js
+++ /dev/null
@@ -1,442 +0,0 @@
-(function () {
- "use strict";
-
- var Jscex, Task, CanceledError, _;
-
- var collectCallbackArgNames = function (args) {
- if (args.length <= 1) return null;
-
- var result = [];
- for (var i = 1; i < args.length; i++) {
- result.push(args[i]);
- }
-
- return result;
- }
-
- var collectArgs = function (args, requiredArgs) {
- var result = [];
- for (var i = 0; i < args.length; i++) {
- result.push(args[i]);
- }
-
- while (result.length < requiredArgs) {
- result.push(undefined);
- }
-
- return result;
- }
-
- // Async members
-
- var AggregateErrorTypeID = "4a73efb8-c2e2-4305-a05c-72385288650a";
- var AggregateError = function (errors) {
- this.children = [];
-
- if (errors) {
- for (var i = 0; i < errors.length; i++) {
- this.children.push(errors[i]);
- }
- }
- }
- AggregateError.prototype = {
- _typeId: AggregateErrorTypeID,
- message: "This is an error contains sub-errors, please check the 'children' collection for more details.",
- isTypeOf: function (ex) {
- return ex._typeId == AggregateErrorTypeID;
- }
- }
-
- var sleep = function (delay, /* CancellationToken */ ct) {
- return Task.create(function (t) {
- if (ct && ct.isCancellationRequested) {
- t.complete("failure", new CanceledError());
- }
-
- var seed;
- var cancelHandler;
-
- if (ct) {
- cancelHandler = function () {
- clearTimeout(seed);
- t.complete("failure", new CanceledError());
- }
- }
-
- var seed = setTimeout(function () {
- if (ct) {
- ct.unregister(cancelHandler);
- }
-
- t.complete("success");
- }, delay);
-
- if (ct) {
- ct.register(cancelHandler);
- }
- });
- }
-
- var onEvent = function (target, eventName, /* CancellationToken*/ ct) {
- return Task.create(function (t) {
- if (ct && ct.isCancellationRequested) {
- t.complete("failure", new CanceledError());
- }
-
- var cleanUp = function () {
- if (target.removeEventListener) {
- target.removeEventListener(eventName, eventHandler);
- } else if (target.removeListener) {
- target.removeListener(eventName, eventHandler);
- } else {
- target.detachEvent(eventName, eventHandler);
- }
- }
-
- var eventHandler;
- var cancelHandler;
-
- if (ct) {
- cancelHandler = function () {
- cleanUp();
- t.complete("failure", new CanceledError());
- }
- }
-
- var eventHandler = function (ev) {
- if (ct) {
- ct.unregister(cancelHandler);
- }
-
- cleanUp();
- t.complete("success", ev);
- }
-
- if (target.addEventListener) {
- target.addEventListener(eventName, eventHandler);
- } else if (target.addListener) {
- target.addListener(eventName, eventHandler);
- } else {
- target.attachEvent(eventName, eventHandler);
- }
-
- if (ct) {
- ct.register(cancelHandler);
- }
- });
- }
-
- // Task members
-
- var whenAll = function () {
- var inputTasks;
-
- if (arguments.length == 1) {
- var arg = arguments[0];
-
- if (Task.isTask(arg)) { // a single task
- inputTasks = [arg];
- } else {
- inputTasks = arg;
- }
- } else {
- inputTasks = new Array(arguments.length);
- for (var i = 0; i < arguments.length; i++) {
- inputTasks[i] = arguments[i];
- }
- }
-
- return Task.create(function (taskWhenAll) {
- var taskKeys = {};
-
- _.each(inputTasks, function (key, task) {
- if (!task) return;
-
- if (!Task.isTask(task)) {
- inputTasks[key] = task = whenAll(task);
- }
-
- taskKeys[task.id] = key;
- });
-
- // start all the tasks
- _.each(taskKeys, function (id, key) {
- var task = inputTasks[key];
- if (task.status === "ready") {
- task.start();
- }
- });
-
- var done = function () {
- var results = _.isArray(inputTasks) ? new Array(inputTasks.length) : { };
- var errors = [];
-
- _.each(taskKeys, function (id, key) {
- var task = inputTasks[key];
- if (task.error) {
- errors.push(task.error);
- } else {
- results[key] = task.result;
- }
- });
-
- if (errors.length > 0) {
- taskWhenAll.complete("failure", new AggregateError(errors));
- } else {
- taskWhenAll.complete("success", results);
- }
- }
-
- var runningNumber = 0;
-
- _.each(taskKeys, function (id, key) {
- var task = inputTasks[key];
-
- if (task.status == "running") {
- runningNumber++;
-
- task.addEventListener("complete", function () {
- if (--runningNumber == 0) {
- done();
- }
- });
- }
- });
-
- if (runningNumber == 0) {
- done();
- }
- });
- };
-
- var whenAny = function () {
-
- var tasks = { };
-
- if (arguments.length == 1) {
- var arg = arguments[0];
- if (Task.isTask(arg)) {
- tasks[0] = arg;
- } else {
- tasks = arg;
- }
- } else {
- for (var i = 0; i < arguments.length; i++)
- tasks[i] = arguments[i];
- }
-
- return Task.create(function (taskWhenAny) {
- var taskKeys = {};
- for (var key in tasks) {
- if (tasks.hasOwnProperty(key)) {
- var t = tasks[key];
- if (Task.isTask(t)) {
- taskKeys[t.id] = key;
- }
- }
- }
-
- // start all the tasks
- for (var id in taskKeys) {
- var t = tasks[taskKeys[id]];
- if (t.status == "ready") {
- t.start();
- }
- }
-
- // if there's a task already failed/succeeded, then return
- for (var id in taskKeys) {
- var key = taskKeys[id];
- var t = tasks[key];
- if (t.error || t.status == "succeeded") {
- taskWhenAny.complete("success", { key: key, task: t });
- return;
- }
- }
-
- var onComplete = function (t) {
- for (var id in taskKeys) {
- tasks[taskKeys[id]].removeEventListener("complete", onComplete);
- }
-
- taskWhenAny.complete("success", { key: taskKeys[this.id], task: this });
- }
-
- // now all the tasks are in "running" status.
- for (var id in taskKeys) {
- tasks[taskKeys[id]].addEventListener("complete", onComplete);
- }
- });
- }
-
- var then = function (nextGenerator) {
- var firstTask = this;
-
- return Task.create(function (t) {
-
- var nextOnComplete = function () {
- if (this.error) {
- t.complete("failure", this.error);
- } else {
- t.complete("success", this.result);
- }
- };
-
- var processNext = function (nextTask) {
- if (nextTask.status == "ready") {
- nextTask.start();
- }
-
- if (nextTask.status == "running") {
- nextTask.addEventListener("complete", nextOnComplete);
- } else {
- nextOnComplete.call(nextTask);
- }
- };
-
- var firstOnComplete = function () {
- if (this.error) {
- return t.complete("failure", this.error);
- }
-
- var nextTask;
- try {
- nextTask = nextGenerator(this.result);
- } catch (ex) {
- return t.complete("failure", ex);
- }
-
- processNext(nextTask);
- };
-
- if (firstTask.status == "ready") {
- firstTask.start();
- }
-
- if (firstTask.status == "running") {
- firstTask.addEventListener("complete", firstOnComplete);
- } else {
- firstOnComplete.call(firstTask);
- }
- });
- };
-
- // Binding members
-
- var fromStandard = function (fn) {
- var callbackArgNames = collectCallbackArgNames(arguments);
-
- return function () {
- var _this = this;
- var args = collectArgs(arguments, fn.length - 1);
-
- return Task.create(function (t) {
- args.push(function (error, result) {
- if (error) {
- t.complete("failure", error);
- } else if (!callbackArgNames) {
- t.complete("success", result);
- } else {
- var data = {};
- for (var i = 0; i < callbackArgNames.length; i++) {
- data[callbackArgNames[i]] = arguments[i + 1];
- }
-
- return t.complete("success", data);
- }
- });
-
- fn.apply(_this, args);
- });
- };
- };
-
- var fromCallback = function (fn) {
- var callbackArgNames = collectCallbackArgNames(arguments);
-
- return function () {
- var _this = this;
- var args = collectArgs(arguments, fn.length - 1);
-
- return Task.create(function (t) {
- args.push(function (result) {
- if (callbackArgNames) {
- var data = {};
- for (var i = 0; i < callbackArgNames.length; i++) {
- data[callbackArgNames[i]] = arguments[i];
- }
-
- t.complete("success", data);
- } else {
- t.complete("success", result);
- }
- });
-
- fn.apply(_this, args);
- });
- };
- };
-
- // 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: "async-powerpack",
- version: "0.6.5",
- exports: isCommonJS && module.exports,
- require: isCommonJS && require,
- dependencies: { async: "~0.6.5" },
- init: function () {
-
- _ = Jscex._;
- Task = Jscex.Async.Task;
- CanceledError = Jscex.Async.CanceledError;
-
- var Async = Jscex.Async;
- Async.sleep = sleep;
- Async.onEvent = onEvent;
- Async.AggregateError = AggregateError;
-
- Task.whenAll = whenAll;
- Task.whenAny = whenAny;
- Task.prototype.then = Task.prototype.continueWith = then;
-
- if (!Async.Binding) {
- Async.Binding = {};
- }
-
- var Binding = Async.Binding;
- Async.Jscexify = Binding;
-
- Binding.fromStandard = fromStandard;
- Binding.fromCallback = fromCallback;
- }
- });
- }
-
- 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();
- }
-})();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/jscex-async.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/jscex-async.js b/src/cordova-win8/lib/Jscex/src/jscex-async.js
deleted file mode 100644
index 50a6779..0000000
--- a/src/cordova-win8/lib/Jscex/src/jscex-async.js
+++ /dev/null
@@ -1,283 +0,0 @@
-(function () {
- "use strict";
-
- var Jscex;
-
- var CanceledErrorTypeID = "670a1076-712b-4edd-9b70-64b152fe1cd9";
- var isCanceledError = function (ex) { return ex._typeId == CanceledErrorTypeID; }
- var CanceledError = function () { }
- CanceledError.prototype = {
- isTypeOf: isCanceledError,
- _typeId: CanceledErrorTypeID,
- message: "The task has been cancelled."
- }
-
- var Fn = Function, global = Fn('return this')();
-
- // seed defined in global
- if (global.__jscex__async__taskIdSeed === undefined) {
- global.__jscex__async__taskIdSeed = 0;
- }
-
- var isTask = function (t) {
- return (typeof t.start === "function") && (typeof t.addEventListener) === "function" && (typeof t.removeEventListener) === "function" && (typeof t.complete) === "function";
- }
-
- var CancellationToken = function () { }
- CancellationToken.prototype = {
- register: function (handler) {
- if (this.isCancellationRequested) {
- handler();
- }
-
- if (!this._handlers) {
- this._handlers = [];
- }
-
- this._handlers.push(handler);
- },
-
- unregister: function (handler) {
- if (!this._handlers) {
- return;
- }
-
- var index = this._handlers.indexOf(handler);
- if (index >= 0) {
- this._handlers.splice(index, 1);
- }
- },
-
- cancel: function () {
- if (this.isCancellationRequested) {
- return;
- }
-
- this.isCancellationRequested = true;
-
- var handlers = this._handlers;
- delete this._handlers;
-
- for (var i = 0; i < handlers.length; i++) {
- try {
- handlers[i]();
- } catch (ex) {
- Jscex.logger.warn("[WARNING] Cancellation handler threw an error: " + ex);
- }
- }
- },
-
- throwIfCancellationRequested: function () {
- if (this.isCancellationRequested) {
- throw new CanceledError();
- }
- }
- };
-
- var Task = function (delegate) {
- this.id = (++__jscex__async__taskIdSeed);
- this._delegate = delegate;
- this._listeners = { };
- this.status = "ready";
- }
- Task.prototype = {
- start: function () {
- if (this.status != "ready") {
- throw new Error('Task can only be started in "ready" status.');
- }
-
- this.status = "running";
- this._delegate(this);
-
- return this;
- },
-
- complete: function (type, value) {
- if (this.status != "running") {
- throw new Error('The "complete" method can only be called in "running" status.');
- }
-
- var listeners = this._listeners;
- delete this._listeners;
-
- if (type == "success") {
-
- this.result = value;
- this.status = "succeeded";
- this._notify("success", listeners["success"]);
-
- } else if (type == "failure") {
-
- this.error = value;
-
- if (isCanceledError(value)) {
- this.status = "canceled";
- } else {
- this.status = "faulted";
- }
-
- this._notify("failure", listeners["failure"]);
-
- } else {
- throw new Error("Unsupported type: " + type);
- }
-
- this._notify("complete", listeners["complete"]);
-
- if (this.error && !listeners["failure"] && !listeners["complete"]) {
- Jscex.logger.warn("[WARNING] An unhandled error occurred: " + this.error);
- }
- },
-
- _notify: function (ev, listeners) {
- if (!listeners) {
- return;
- }
-
- for (var i = 0; i < listeners.length; i++) {
- listeners[i].call(this);
- }
- },
-
- addEventListener: function (ev, listener) {
- if (!this._listeners) {
- return this;
- }
-
- if (!this._listeners[ev]) {
- this._listeners[ev] = [];
- }
-
- this._listeners[ev].push(listener);
- return this;
- },
-
- removeEventListener: function (ev, listener) {
- if (!this._listeners) {
- return this;
- }
-
- var evListeners = this._listeners[ev];
- if (!evListeners) return this;
-
- var index = evListeners.indexOf(listener);
- if (index >= 0) {
- evListeners.splice(index, 1);
- }
-
- return this;
- }
- };
-
- Task.create = function (delegate) {
- return new Task(delegate);
- }
-
- Task.isTask = isTask;
-
- var AsyncBuilder = function () { }
- AsyncBuilder.prototype = {
- Start: function (_this, task) {
- return Task.create(function (t) {
- task.next(_this, function (type, value, target) {
- if (type == "normal" || type == "return") {
- t.complete("success", value);
- } else if (type == "throw") {
- t.complete("failure", value);
- } else {
- throw new Error("Unsupported type: " + type);
- }
- });
- });
- },
-
- Bind: function (task, generator) {
- return {
- next: function (_this, callback) {
-
- var onComplete = function (t) {
- if (this.error) {
- callback("throw", this.error);
- } else {
- var nextTask;
- try {
- nextTask = generator.call(_this, this.result);
- } catch (ex) {
- callback("throw", ex);
- return;
- }
-
- nextTask.next(_this, callback);
- }
- }
-
- if (task.status == "ready") {
- task.addEventListener("complete", onComplete);
- task.start();
- } else if (task.status == "running") {
- task.addEventListener("complete", onComplete);
- } else {
- onComplete(task);
- }
- }
- };
- }
- }
-
- // 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: "async",
- 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) {
- AsyncBuilder.prototype[m] = fn;
- });
-
- if (!Jscex.Async) {
- Jscex.Async = {};
- }
-
- var Async = Jscex.Async;
- Async.CancellationToken = CancellationToken;
- Async.CanceledError = CanceledError;
- Async.Task = Task;
- Async.AsyncBuilder = AsyncBuilder;
-
- Jscex.binders["async"] = "$await";
- Jscex.builders["async"] = new AsyncBuilder();
- }
- });
- }
-
- if (isCommonJS) {
- try {
- Jscex = require("./jscex");
- } catch (ex) {
- Jscex = require("jscex");
- }
-
- defineModule();
- } else if (isAmd) {
- require(["jscex"], function (jscex) {
- Jscex = jscex;
- defineModule();
- });
- } else {
- if (!global.Jscex) {
- throw new Error('Missing the root object, please load "jscex" component first.');
- }
-
- Jscex = global.Jscex;
- defineModule();
- }
-})();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-windows/blob/03bf0cde/src/cordova-win8/lib/Jscex/src/jscex-builderbase.js
----------------------------------------------------------------------
diff --git a/src/cordova-win8/lib/Jscex/src/jscex-builderbase.js b/src/cordova-win8/lib/Jscex/src/jscex-builderbase.js
deleted file mode 100644
index 41f6e5d..0000000
--- a/src/cordova-win8/lib/Jscex/src/jscex-builderbase.js
+++ /dev/null
@@ -1,334 +0,0 @@
-(function () {
- "use strict";
-
- var BuilderBase = function () { }
- BuilderBase.prototype = {
- For: function (condition, update, body) {
- return {
- next: function (_this, callback) {
-
- var loop = function (skipUpdate) {
- try {
- if (update && !skipUpdate) {
- update.call(_this);
- }
-
- if (!condition || condition.call(_this)) {
- body.next(_this, function (type, value, target) {
- if (type == "normal" || type == "continue") {
- loop(false);
- } else if (type == "throw" || type == "return") {
- callback(type, value);
- } else if (type == "break") {
- callback("normal");
- } else {
- throw new Error('Invalid type for "Loop": ' + type);
- }
- });
- } else {
- callback("normal");
- }
- } catch (ex) {
- callback("throw", ex);
- }
- }
-
- loop(true);
- }
- };
- },
-
- ForIn: function (obj, bodyGenerator) {
- return {
- next: function (_this, callback) {
-
- var keys = [];
- for (var k in obj) {
- keys.push(k);
- }
-
- var loop = function (i) {
- try {
- if (i < keys.length) {
- var body = bodyGenerator(keys[i]);
- body.next(_this, function (type, value, target) {
- if (type == "normal" || type == "continue") {
- loop(i + 1);
- } else if (type == "throw" || type == "return") {
- callback(type, value);
- } else if (type == "break") {
- callback("normal");
- } else {
- throw new Error('Invalid type for "Loop": ' + type);
- }
- });
- } else {
- callback("normal");
- }
- } catch (ex) {
- callback("throw", ex);
- }
- }
-
- loop(0);
- }
- };
- },
-
- While: function (condition, body) {
- return {
- next: function (_this, callback) {
- var loop = function () {
- try {
- if (condition.call(_this)) {
- body.next(_this, function (type, value, target) {
- if (type == "normal" || type == "continue") {
- loop();
- } else if (type == "throw" || type == "return") {
- callback(type, value);
- } else if (type == "break") {
- callback("normal");
- } else {
- throw new Error('Invalid type for "Loop": ' + type);
- }
- });
- } else {
- callback("normal");
- }
- } catch (ex) {
- callback("throw", ex);
- }
- }
-
- loop();
- }
- };
- },
-
- Do: function (body, condition) {
- return {
- next: function (_this, callback) {
-
- var loop = function () {
- body.next(_this, function (type, value, target) {
- if (type == "normal" || type == "continue") {
- try {
- if (condition.call(_this)) {
- loop();
- } else {
- callback("normal");
- }
- } catch (ex) {
- callback("throw", ex);
- }
- } else if (type == "throw" || type == "return") {
- callback(type, value);
- } else if (type == "break") {
- callback("normal");
- } else {
- throw new Error('Invalid type for "Loop": ' + type);
- }
- });
- };
-
- loop();
- }
- };
- },
-
- Delay: function (generator) {
- return {
- next: function (_this, callback) {
- try {
- var step = generator.call(_this);
- step.next(_this, callback);
- } catch (ex) {
- callback("throw", ex);
- }
- }
- };
- },
-
- Combine: function (s1, s2) {
- return {
- next: function (_this, callback) {
- s1.next(_this, function (type, value, target) {
- if (type == "normal") {
- try {
- s2.next(_this, callback);
- } catch (ex) {
- callback("throw", ex);
- }
- } else {
- callback(type, value, target);
- }
- });
- }
- };
- },
-
- Return: function (result) {
- return {
- next: function (_this, callback) {
- callback("return", result);
- }
- };
- },
-
- Normal: function () {
- return {
- next: function (_this, callback) {
- callback("normal");
- }
- };
- },
-
- Break: function () {
- return {
- next: function (_this, callback) {
- callback("break");
- }
- };
- },
-
- Continue: function () {
- return {
- next: function (_this, callback) {
- callback("continue");
- }
- };
- },
-
- Throw: function (ex) {
- return {
- next: function (_this, callback) {
- callback("throw", ex);
- }
- };
- },
-
- Try: function (tryTask, catchGenerator, finallyStep) {
- return {
- next: function (_this, callback) {
- tryTask.next(_this, function (type, value, target) {
- if (type != "throw" || !catchGenerator) {
- if (!finallyStep) {
- callback(type, value, target);
- } else {
- finallyStep.next(_this, function (finallyType, finallyValue, finallyTarget) {
- if (finallyType == "normal") {
- callback(type, value, target);
- } else {
- callback(finallyType, finallyValue, finallyTarget);
- }
- });
- }
- } else {
-
- if (catchGenerator) {
-
- var catchTask;
- try {
- catchTask = catchGenerator.call(_this, value);
- } catch (ex) {
- if (finallyStep) {
- finallyStep.next(_this, function (finallyType, finallyValue, finallyTarget) {
- if (finallyType == "normal") {
- callback("throw", ex);
- } else {
- callback(finallyType, finallyValue, finallyTarget);
- }
- });
- } else {
- callback("throw", ex);
- }
- }
-
- if (catchTask) {
- catchTask.next(_this, function (catchType, catchValue, catchTarget) {
- if (catchType == "throw") {
- if (finallyStep) {
- finallyStep.next(_this, function (finallyType, finallyValue, finallyTarget) {
- if (finallyType == "normal") {
- callback(catchType, catchValue, catchTarget);
- } else {
- callback(finallyType, finallyValue, finallyTarget);
- }
- });
- } else {
- callback(catchType, catchValue, catchTarget);
- }
- } else {
- if (finallyStep) {
- finallyStep.next(_this, function (finallyType, finallyValue, finallyTarget) {
- if (finallyType == "normal") {
- callback(catchType, catchValue, catchTarget);
- } else {
- callback(finallyType, finallyValue, finallyTarget);
- }
- });
- } else {
- callback(catchType, catchValue, catchTarget);
- }
- }
- });
- }
- } else {
- finallyStep.next(_this, function (finallyType, finallyValue, finallyTarget) {
- if (finallyType == "normal") {
- callback(type, value, target);
- } else {
- callback(finallyType, finallyValue, finallyTarget);
- }
- });
- }
- }
- });
- }
- };
- }
- }
-
- // CommonJS
- var isCommonJS = !!(typeof require === "function" && typeof module !== "undefined" && module.exports);
- // CommonJS AMD
- var isAmd = !!(typeof require === "function" && typeof define === "function" && define.amd);
-
- var Jscex;
-
- var defineModule = function () {
- Jscex.define({
- name: "builderbase",
- version: "0.6.5",
- exports: isCommonJS && module.exports,
- require: isCommonJS && require,
- coreDependency: "~0.6.5",
- init: function () {
- Jscex.BuilderBase = BuilderBase;
- }
- });
- }
-
- 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();
- }
-})();
\ No newline at end of file