Skip to content

Commit

Permalink
FLUID-4197, FLUID-4151, FLUID-4187: Removed json2.js as a core depend…
Browse files Browse the repository at this point in the history
…ency of the framework, in favour of using the "enhanced API" for console.log wherever it is supported (on all browsers other than IE). Implemented "notrycatch" system as found in qunit applied framework-wide via new wrapping function fluid.tryCatch. On this basis, implemented "activity tracing system" throughout the IoC system, allowing a traceback of framework intentions in the case a fluid.fail is received. Corrected implementation of UploaderCompatibilityTests to use a mocked context tag rather than the browser's live one. General delinting and tidying. Corrected a bug in listener sorting that would cause a non-deteministic failure on browsers without a stable sort (Chrome, and possibly IE8) where listener order was expected to be honoured where no priority was supplied.
  • Loading branch information
amb26 committed May 12, 2011
1 parent bed0945 commit 3e45b80
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 100 deletions.
1 change: 0 additions & 1 deletion src/webapp/components/uploader/html/Uploader.html
Expand Up @@ -11,7 +11,6 @@
<link rel="stylesheet" type="text/css" href="../css/Uploader.css" />

<!-- Fluid and jQuery Dependencies -->
<script type="text/javascript" src="../../../lib/json/js/json2.js"></script>
<script type="text/javascript" src="../../../lib/jquery/core/js/jquery.js"></script>
<script type="text/javascript" src="../../../lib/jquery/ui/js/jquery.ui.core.js"></script>
<script type="text/javascript" src="../../../framework/core/js/jquery.keyboard-a11y.js"></script>
Expand Down
107 changes: 78 additions & 29 deletions src/webapp/framework/core/js/Fluid.js
Expand Up @@ -42,14 +42,20 @@ var fluid = fluid || fluid_1_4;

var softFailure = [false];

// This function will be patched from FluidIoC.js in order to describe complex activities
fluid.describeActivity = function() {
return [];
};

/**
* Causes an error message to be logged to the console and a real runtime error to be thrown.
*
* @param {String|Error} message the error message to log
* @param ... Additional arguments
*/
fluid.fail = function (message) {
fluid.fail = function (message /*, ... */) {
fluid.setLogging(true);
fluid.log(message.message ? message.message : message);
fluid.log.apply(null, ["ASSERTION FAILED: "].concat(fluid.makeArray(arguments)).concat(fluid.describeActivity()));
if (softFailure[0]) {
throw new Error(message);
} else {
Expand All @@ -65,23 +71,53 @@ var fluid = fluid || fluid_1_4;
}
};

fluid.notrycatch = false;

// A wrapper for the try/catch/finally language feature, to aid debugging on environments
// such as IE, where any try will destroy stack information for errors
fluid.tryCatch = function(tryfun, catchfun, finallyfun) {
finallyfun = finallyfun || fluid.identity;
if (fluid.notrycatch) {
var togo = tryfun();
finallyfun();
return togo;
}
else {
try {
return tryfun();
}
catch (e) {
if (catchfun) {
catchfun(e);
}
else {
throw(e);
}
}
finally {
finallyfun();
}
}
};

// TODO: rescued from kettleCouchDB.js - clean up in time
fluid.expect = function (name, members, target) {
fluid.transform($.makeArray(members), function (key) {
fluid.transform(fluid.makeArray(members), function (key) {
if (typeof target[key] === "undefined") {
fluid.fail(name + " missing required parameter " + key);
}
});
};

// Logging

var logging;

/** Returns whether logging is enabled **/
fluid.isLogging = function() {
return logging;
};

var logging;
/** method to allow user to enable logging (off by default) */
fluid.setLogging = function (enabled) {
if (typeof enabled === "boolean") {
Expand All @@ -94,16 +130,20 @@ var fluid = fluid || fluid_1_4;
/** Log a message to a suitable environmental console. If the standard "console"
* stream is available, the message will be sent there - otherwise either the
* YAHOO logger or the Opera "postError" stream will be used. Logging must first
* be enabled with a call fo the fluid.setLogging(true) function.
* be enabled with a call to the fluid.setLogging(true) function.
*/
fluid.log = function (str) {
fluid.log = function (message /*, ... */) {
if (logging) {
str = fluid.renderTimestamp(new Date()) + ": " + str;
var arg0 = fluid.renderTimestamp(new Date()) + ": ";
var args = [arg0].concat(fluid.makeArray(arguments));
var str = args.join("");
if (typeof (console) !== "undefined") {
if (console.debug) {
console.debug(str);
console.debug.apply(console, args);
} else if (typeof (console.log) === "function") {
console.log.apply(console, args);
} else {
console.log(str);
console.log(str); // this branch executes on IE, console.log is synthetic
}
} else if (typeof (YAHOO) !== "undefined") {
YAHOO.log(str);
Expand Down Expand Up @@ -360,7 +400,7 @@ var fluid = fluid || fluid_1_4;
if (value === thisValue) {
return true;
}
}): undefined;
}) : undefined;
};

/**
Expand Down Expand Up @@ -703,8 +743,8 @@ var fluid = fluid || fluid_1_4;
return listener.$$guid;
};

fluid.event.mapPriority = function (priority) {
return (priority === null || priority === undefined ? 0 :
fluid.event.mapPriority = function (priority, count) {
return (priority === null || priority === undefined ? -count :
(priority === "last" ? -Number.MAX_VALUE :
(priority === "first" ? Number.MAX_VALUE : priority)));
};
Expand Down Expand Up @@ -740,7 +780,7 @@ var fluid = fluid || fluid_1_4;
var lisrec = listeners[i];
var listener = lisrec.listener;
if (typeof(listener) === "string") {
listenerFunc = fluid.getGlobalValue(listener);
var listenerFunc = fluid.getGlobalValue(listener);
if (!listenerFunc) {
fluid.fail("Unable to look up name " + listener + " as a global function");
}
Expand All @@ -751,17 +791,20 @@ var fluid = fluid || fluid_1_4;
if (lisrec.predicate && !lisrec.predicate(listener, args)) {
continue;
}
try {
var value = fluid.tryCatch(function() {
var ret = (wrapper ? wrapper(listener) : listener).apply(null, args);
if (preventable && ret === false) {
return false;
}
if (unicast) {
return ret;
}
} catch (e) {
}, function (e) {
fluid.log("FireEvent received exception " + e.message + " e " + e + " firing to listener " + i);
throw (e);
});
if (value !== undefined) {
return value;
}
}
}
Expand All @@ -779,7 +822,7 @@ var fluid = fluid || fluid_1_4;
}

listeners[namespace] = {listener: listener, predicate: predicate, priority:
fluid.event.mapPriority(priority)};
fluid.event.mapPriority(priority, sortedListeners.length)};
sortedListeners = fluid.event.sortListeners(listeners);
},

Expand Down Expand Up @@ -855,8 +898,8 @@ var fluid = fluid || fluid_1_4;
var event;
if (isIoCEvent && pass === "IoC") {
if (!fluid.event.resolveEvent) {
fluid.fail("fluid.event.resolveEvent could not be loaded - please include FluidIoC.js in order to operate IoC-driven event with descriptor " +
JSON.stringify(eventSpec));
fluid.fail("fluid.event.resolveEvent could not be loaded - please include FluidIoC.js in order to operate IoC-driven event with descriptor ",
eventSpec);
} else {
event = fluid.event.resolveEvent(that, eventKey, eventSpec);
}
Expand Down Expand Up @@ -941,16 +984,14 @@ var fluid = fluid || fluid_1_4;
};

fluid.rootMergePolicy = fluid.transform(fluid.lifecycleFunctions, function() {
return fluid.mergeLifecycleFunction;
}
);
return fluid.mergeLifecycleFunction;
});

// unsupported, NON-API function
fluid.makeLifecycleFirers = function() {
return fluid.transform(fluid.lifecycleFunctions, function() {
return fluid.event.getEventFirer()
}
);
return fluid.event.getEventFirer();
});
};

// unsupported, NON-API function
Expand Down Expand Up @@ -1270,18 +1311,18 @@ var fluid = fluid || fluid_1_4;
* minimal form of Fluid component */

fluid.typeTag = function (name) {
return {
return name ? {
typeName: name,
id: fluid.allocateGuid()
};
} : null;
};

/** A combined "component and grade name" which allows type tags to be declaratively constructed
* from options material */

fluid.typeFount = function (options) {
var that = fluid.initLittleComponent("fluid.typeFount", options);
return that.options.targetTypeName? fluid.typeTag(that.options.targetTypeName) : null;
return fluid.typeTag(that.options.targetTypeName);
};

/**
Expand Down Expand Up @@ -1411,6 +1452,14 @@ var fluid = fluid || fluid_1_4;

// **** VIEW-DEPENDENT DEFINITIONS BELOW HERE

fluid.checkTryCatchParameter = function() {
var location = window.location || { search: "", protocol: "file:" };
var GETParams = location.search.slice(1).split('&');
return fluid.contains(GETParams, "notrycatch");
};

fluid.notrycatch = fluid.checkTryCatchParameter();

/**
* Fetches a single container element and returns it as a jQuery.
*
Expand All @@ -1432,8 +1481,8 @@ var fluid = fluid || fluid_1_4;
var count = container.length !== undefined ? container.length : 0;
fluid.fail({
name: "NotOne",
message: count > 1 ? "More than one (" + count + ") container elements were "
: "No container element was found for selector " + containerSpec
message: (count > 1 ? "More than one (" + count + ") container elements were"
: "No container element was") + " found for selector " + containerSpec
});
}
if (!fluid.isDOMNode(container[0])) {
Expand Down

0 comments on commit 3e45b80

Please sign in to comment.