1 /* Licensed to the Apache Software Foundation (ASF) under one or more
  2  * contributor license agreements.  See the NOTICE file distributed with
  3  * this work for additional information regarding copyright ownership.
  4  * The ASF licenses this file to you under the Apache License, Version 2.0
  5  * (the "License"); you may not use this file except in compliance with
  6  * the License.  You may obtain a copy of the License at
  7  *
  8  *      http://www.apache.org/licenses/LICENSE-2.0
  9  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  */
 16 
 17 /**
 18  * @class
 19  * @name Impl
 20  * @memberOf myfaces._impl.core
 21  * @description Implementation singleton which implements all interface method
 22  * defined by our jsf.js API
 23  * */
 24 _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJECT, /**  @lends myfaces._impl.core.Impl.prototype */ {
 25 
 26     //third option myfaces._impl.xhrCoreAjax which will be the new core impl for now
 27     _transport      : myfaces._impl.core._Runtime.getGlobalConfig("transport", myfaces._impl.xhrCore._Transports),
 28 
 29     /**
 30      * external event listener queue!
 31      */
 32     _evtListeners   : new (myfaces._impl.core._Runtime.getGlobalConfig("eventListenerQueue", myfaces._impl._util._ListenerQueue))(),
 33 
 34     /**
 35      * external error listener queue!
 36      */
 37     _errListeners   : new (myfaces._impl.core._Runtime.getGlobalConfig("errorListenerQueue", myfaces._impl._util._ListenerQueue))(),
 38 
 39     /*CONSTANTS*/
 40 
 41     /*internal identifiers for options*/
 42     IDENT_ALL:  "@all",
 43     IDENT_NONE: "@none",
 44     IDENT_THIS: "@this",
 45     IDENT_FORM: "@form",
 46 
 47     /*
 48      * [STATIC] constants
 49      */
 50 
 51     P_PARTIAL_SOURCE:   "javax.faces.source",
 52     P_VIEWSTATE:        "javax.faces.ViewState",
 53     P_AJAX:             "javax.faces.partial.ajax",
 54     P_EXECUTE:          "javax.faces.partial.execute",
 55     P_RENDER:           "javax.faces.partial.render",
 56     P_EVT:              "javax.faces.partial.event",
 57 
 58     /* message types */
 59     ERROR: "error",
 60     EVENT: "event",
 61 
 62     /* event emitting stages */
 63     BEGIN:      "begin",
 64     COMPLETE:   "complete",
 65     SUCCESS:    "success",
 66 
 67     /*ajax errors spec 14.4.2*/
 68     HTTPERROR:      "httpError",
 69     EMPTY_RESPONSE: "emptyResponse",
 70     MALFORMEDXML:   "malformedXML",
 71     SERVER_ERROR:   "serverError",
 72     CLIENT_ERROR:   "clientError",
 73     TIMEOUT_EVENT:  "timeout",
 74 
 75 
 76     /*error reporting threshold*/
 77     _threshold: "ERROR",
 78 
 79     /*blockfilter for the passthrough filtering, the attributes given here
 80      * will not be transmitted from the options into the passthrough*/
 81     _BLOCKFILTER: {onerror: 1, onevent: 1, render: 1, execute: 1, myfaces: 1},
 82 
 83 
 84 
 85     /**
 86      * collect and encode data for a given form element (must be of type form)
 87      * find the javax.faces.ViewState element and encode its value as well!
 88      * return a concatenated string of the encoded values!
 89      *
 90      * @throws Error in case of the given element not being of type form!
 91      * https://issues.apache.org/jira/browse/MYFACES-2110
 92      */
 93     getViewState : function(form) {
 94         /**
 95          *  typecheck assert!, we opt for strong typing here
 96          *  because it makes it easier to detect bugs
 97          */
 98         if (form) {
 99             form = this._Lang.byId(form);
100         }
101 
102         if (!form
103                 || !form.nodeName
104                 || form.nodeName.toLowerCase() != "form") {
105             throw new Error(this._Lang.getMessage("ERR_VIEWSTATE"));
106         }
107 
108         var ajaxUtils = myfaces._impl.xhrCore._AjaxUtils;
109 
110         var ret = this._Lang.createFormDataDecorator([]);
111         ajaxUtils.encodeSubmittableFields(ret, form, null);
112 
113         return ret.makeFinal();
114     },
115 
116     /**
117      * this function has to send the ajax requests
118      *
119      * following request conditions must be met:
120      * <ul>
121      *  <li> the request must be sent asynchronously! </li>
122      *  <li> the request must be a POST!!! request </li>
123      *  <li> the request url must be the form action attribute </li>
124      *  <li> all requests must be queued with a client side request queue to ensure the request ordering!</li>
125      * </ul>
126      *
127      * @param {String|Node} elem any dom element no matter being it html or jsf, from which the event is emitted
128      * @param {|Event|} event any javascript event supported by that object
129      * @param {|Object|} options  map of options being pushed into the ajax cycle
130      *
131      *
132      * TODO refactoring, the passthrgh handling is only for dragging in request parameters
133      * we should rewrite this part
134      *
135      *
136      * a) transformArguments out of the function
137      * b) passThrough handling with a map copy with a filter map block map
138      */
139     request : function(elem, event, options) {
140         if(this._delayTimeout) {
141             clearTimeout(this._delayTimeout);
142             delete this._delayTimeout;
143         }
144         /*namespace remap for our local function context we mix the entire function namespace into
145          *a local function variable so that we do not have to write the entire namespace
146          *all the time
147          **/
148         var _Lang = this._Lang,
149                 _Dom = this._Dom,
150                 WINDOW_ID = "javax.faces.windowId";
151         /*assert if the onerror is set and once if it is set it must be of type function*/
152         _Lang.assertType(options.onerror, "function");
153         /*assert if the onevent is set and once if it is set it must be of type function*/
154         _Lang.assertType(options.onevent, "function");
155 
156         //options not set we define a default one with nothing
157         options = options || {};
158 
159         /*preparations for jsf 2.2 windowid handling*/
160         //pass the window id into the options if not set already
161         if (!options.windowId) {
162             var windowId = _Dom.getWindowId();
163             (windowId) ? options[WINDOW_ID] = windowId : null;
164         } else {
165             options[WINDOW_ID] = options.windowId;
166             delete options.windowId;
167         }
168 
169         /**
170          * we cross reference statically hence the mapping here
171          * the entire mapping between the functions is stateless
172          */
173         //null definitely means no event passed down so we skip the ie specific checks
174         if ('undefined' == typeof event) {
175             event = window.event || null;
176         }
177 
178         //improve the error messages if an empty elem is passed
179         if(!elem) {
180             throw _Lang.makeException(new Error(), "ArgNotSet", null, this._nameSpace, "request", _Lang.getMessage("ERR_MUST_BE_PROVIDED1","{0}: source  must be provided","jsf.ajax.request", "source element id"));
181         }
182         var oldElem = elem;
183         elem = _Dom.byIdOrName(elem);
184         if(!elem) {
185             throw _Lang.makeException(new Error(), "Notfound", null, this._nameSpace, "request", _Lang.getMessage("ERR_PPR_UNKNOWNCID","{0}: Node with id {1} could not be found from source",this._nameSpace+".request", oldElem));
186         }
187 
188         var elementId = _Dom.nodeIdOrName(elem);
189 
190         /*
191          * We make a copy of our options because
192          * we should not touch the incoming params!
193          */
194         var passThrgh = _Lang.mixMaps({}, options, true, this._BLOCKFILTER);
195 
196         if (event) {
197             passThrgh[this.P_EVT] = event.type;
198         }
199 
200         /**
201          * ajax pass through context with the source
202          * onevent and onerror
203          */
204         var context = {
205             source: elem,
206             onevent: options.onevent,
207             onerror: options.onerror,
208 
209             //TODO move the myfaces part into the _mfInternal part
210             myfaces: options.myfaces
211         };
212 
213         /**
214          * fetch the parent form
215          *
216          * note we also add an override possibility here
217          * so that people can use dummy forms and work
218          * with detached objects
219          */
220         var form = (options.myfaces && options.myfaces.form) ?
221                 _Lang.byId(options.myfaces.form) :
222                 this._getForm(elem, event);
223 
224         /**
225          * binding contract the javax.faces.source must be set
226          */
227         passThrgh[this.P_PARTIAL_SOURCE] = elementId;
228 
229         /**
230          * javax.faces.partial.ajax must be set to true
231          */
232         passThrgh[this.P_AJAX] = true;
233 
234         if (options.execute) {
235             /*the options must be a blank delimited list of strings*/
236             /*compliance with Mojarra which automatically adds @this to an execute
237              * the spec rev 2.0a however states, if none is issued nothing at all should be sent down
238              */
239             this._transformList(passThrgh, this.P_EXECUTE, options.execute + " @this", form, elementId);
240         } else {
241             passThrgh[this.P_EXECUTE] = elementId;
242         }
243 
244         if (options.render) {
245             this._transformList(passThrgh, this.P_RENDER, options.render, form, elementId);
246         }
247 
248         /**
249          * multiple transports upcoming jsf 2.x feature currently allowed
250          * default (no value) xhrQueuedPost
251          *
252          * xhrQueuedPost
253          * xhrPost
254          * xhrGet
255          * xhrQueuedGet
256          * iframePost
257          * iframeQueuedPost
258          *
259          */
260         var transportType = this._getTransportType(context, passThrgh, form);
261 
262         //additional meta information to speed things up, note internal non jsf
263         //pass through options are stored under _mfInternal in the context
264         context._mfInternal = {};
265         var mfInternal = context._mfInternal;
266 
267         mfInternal["_mfSourceFormId"] = form.id;
268         mfInternal["_mfSourceControlId"] = elementId;
269         mfInternal["_mfTransportType"] = transportType;
270 
271         //mojarra compatibility, mojarra is sending the form id as well
272         //this is not documented behavior but can be determined by running
273         //mojarra under blackbox conditions
274         //i assume it does the same as our formId_submit=1 so leaving it out
275         //wont hurt but for the sake of compatibility we are going to add it
276         passThrgh[form.id] = form.id;
277 
278         //delay handling is an experimental feature which will most likely
279         //make it into jsf 2.2
280         /* jsf2.2 only: options.delay || */
281         var delayTimeout = this._RT.getLocalOrGlobalConfig(context, "delay", false);
282         if (delayTimeout) {
283             this._delayTimeout = setTimeout(_Lang.hitch(this, function() {
284                 this._transport[transportType](elem, form, context, passThrgh);
285             }), delayTimeout);
286         } else {
287             this._transport[transportType](elem, form, context, passThrgh);
288         }
289     },
290 
291     /**
292      * fetches the form in an unprecise manner depending
293      * on an element or event target
294      *
295      * @param elem
296      * @param event
297      */
298     _getForm: function(elem, event) {
299         var _Dom = this._Dom;
300         var _Lang = this._Lang;
301         var form = _Dom.fuzzyFormDetection(elem);
302 
303         if (!form && event) {
304             //in case of no form is given we retry over the issuing event
305             form = _Dom.fuzzyFormDetection(_Lang.getEventTarget(event));
306             if (!form) {
307                 throw _Lang.makeException(new Error(), null, null, this._nameSpace, "_getForm", _Lang.getMessage("ERR_FORM"));
308             }
309         } else if (!form) {
310             throw _Lang.makeException(new Error(), null, null, this._nameSpace, "_getForm", _Lang.getMessage("ERR_FORM"));
311 
312         }
313         return form;
314     },
315 
316     /**
317      * determines the transport type to be called
318      * for the ajax call
319      *
320      * @param context the context
321      * @param passThrgh  pass through values
322      * @param form the form which issues the request
323      */
324     _getTransportType: function(context, passThrgh, form) {
325         /**
326          * if execute or render exist
327          * we have to pass them down as a blank delimited string representation
328          * of an array of ids!
329          */
330             //for now we turn off the transport auto selection, to enable 2.0 backwards compatibility
331             //on protocol level, the file upload only can be turned on if the auto selection is set to true
332         var getConfig = this._RT.getLocalOrGlobalConfig,
333                 _Lang = this._Lang,
334                 _Dom = this._Dom;
335 
336         var transportAutoSelection = getConfig(context, "transportAutoSelection", false);
337         var isMultipart = (transportAutoSelection && _Dom.getAttribute(form, "enctype") == "multipart/form-data") ?
338                 _Dom.isMultipartCandidate(passThrgh[this.P_EXECUTE]) :
339                 false;
340 
341         /**
342          * multiple transports upcoming jsf 2.1 feature currently allowed
343          * default (no value) xhrQueuedPost
344          *
345          * xhrQueuedPost
346          * xhrPost
347          * xhrGet
348          * xhrQueuedGet
349          * iframePost
350          * iframeQueuedPost
351          *
352          */
353         var transportType = (!isMultipart) ?
354                 getConfig(context, "transportType", "xhrQueuedPost") :
355                 getConfig(context, "transportType", "multipartQueuedPost");
356         if (!this._transport[transportType]) {
357             //throw new Error("Transport type " + transportType + " does not exist");
358             throw new Error(_Lang.getMessage("ERR_TRANSPORT", null, transportType));
359         }
360         return transportType;
361 
362     },
363 
364     /**
365      * transforms the list to the expected one
366      * with the proper none all form and this handling
367      * (note we also could use a simple string replace but then
368      * we would have had double entries under some circumstances)
369      *
370      * @param passThrgh
371      * @param target
372      * @param srcStr
373      * @param form
374      * @param elementId
375      */
376     _transformList: function(passThrgh, target, srcStr, form, elementId) {
377         var _Lang = this._Lang;
378         //this is probably the fastest transformation method
379         //it uses an array and an index to position all elements correctly
380         //the offset variable is there to prevent 0 which results in a javascript
381         //false
382         var offset = 1,
383                 vals = (srcStr) ? srcStr.split(/\s+/) : [],
384                 idIdx = (vals.length) ? _Lang.arrToMap(vals, offset) : {},
385 
386             //helpers to improve speed and compression
387                 none = idIdx[this.IDENT_NONE],
388                 all = idIdx[this.IDENT_ALL],
389                 theThis = idIdx[this.IDENT_THIS],
390                 theForm = idIdx[this.IDENT_FORM];
391 
392         if (none) {
393             //in case of none only one value is returned
394             passThrgh[target] = this.IDENT_NONE;
395             return passThrgh;
396         }
397         if (all) {
398             //in case of all only one value is returned
399             passThrgh[target] = this.IDENT_ALL;
400             return passThrgh;
401         }
402 
403         if (theForm) {
404             //the form is replaced with the proper id but the other
405             //values are not touched
406             vals[theForm - offset] = form.id;
407         }
408         if (theThis && !idIdx[elementId]) {
409             //in case of this, the element id is set
410             vals[theThis - offset] = elementId;
411         }
412 
413         //the final list must be blank separated
414         passThrgh[target] = vals.join(" ");
415         return passThrgh;
416     },
417 
418     addOnError : function(/*function*/errorListener) {
419         /*error handling already done in the assert of the queue*/
420         this._errListeners.enqueue(errorListener);
421     },
422 
423     addOnEvent : function(/*function*/eventListener) {
424         /*error handling already done in the assert of the queue*/
425         this._evtListeners.enqueue(eventListener);
426     },
427 
428 
429 
430     /**
431      * implementation triggering the error chain
432      *
433      * @param {Object} request the request object which comes from the xhr cycle
434      * @param {Object} context (Map) the context object being pushed over the xhr cycle keeping additional metadata
435      * @param {String} name the error name
436      * @param {String} serverErrorName the server error name in case of a server error
437      * @param {String} serverErrorMessage the server error message in case of a server error
438      * @param {String} caller optional caller reference for extended error messages
439      * @param {String} callFunc optional caller Function reference for extended error messages
440      *
441      *  handles the errors, in case of an onError exists within the context the onError is called as local error handler
442      *  the registered error handlers in the queue receiv an error message to be dealt with
443      *  and if the projectStage is at development an alert box is displayed
444      *
445      *  note: we have additional functionality here, via the global config myfaces.config.defaultErrorOutput a function can be provided
446      *  which changes the default output behavior from alert to something else
447      *
448      *
449      */
450     sendError : function sendError(/*Object*/request, /*Object*/ context, /*String*/ name, /*String*/ serverErrorName, /*String*/ serverErrorMessage, caller, callFunc) {
451         var _Lang = myfaces._impl._util._Lang;
452         var UNKNOWN = _Lang.getMessage("UNKNOWN");
453 
454         var eventData = {};
455         //we keep this in a closure because we might reuse it for our serverErrorMessage
456         var malFormedMessage = function() {
457             return (name && name === myfaces._impl.core.Impl.MALFORMEDXML) ? _Lang.getMessage("ERR_MALFORMEDXML") : "";
458         };
459 
460         //by setting unknown values to unknown we can handle cases
461         //better where a simulated context is pushed into the system
462         eventData.type = this.ERROR;
463 
464         eventData.status = name || UNKNOWN;
465         eventData.serverErrorName = serverErrorName || UNKNOWN;
466         eventData.serverErrorMessage = serverErrorMessage || UNKNOWN;
467 
468 
469 
470         try {
471             eventData.source = context.source || UNKNOWN;
472             eventData.responseCode = request.status || UNKNOWN;
473             eventData.responseText = request.responseText || UNKNOWN;
474             eventData.responseXML = request.responseXML || UNKNOWN;
475         } catch (e) {
476             // silently ignore: user can find out by examining the event data
477         }
478          //extended error message only in dev mode
479         if(jsf.getProjectStage() === "Development") {
480             eventData.serverErrorMessage = eventData.serverErrorMessage || "";
481             eventData.serverErrorMessage = (caller)?  eventData.serverErrorMessage + "\nCalling class: "+caller:eventData.serverErrorMessage;
482             eventData.serverErrorMessage = (callFunc)? eventData.serverErrorMessage + "\n Calling function: "+callFunc :eventData.serverErrorMessage;
483         }
484 
485         /**/
486         if (context["onerror"]) {
487             context.onerror(eventData);
488         }
489 
490         /*now we serve the queue as well*/
491         this._errListeners.broadcastEvent(eventData);
492 
493         if (jsf.getProjectStage() === "Development" && this._errListeners.length() == 0 && !context["onerror"]) {
494             var DIVIDER = "--------------------------------------------------------",
495                     defaultErrorOutput = myfaces._impl.core._Runtime.getGlobalConfig("defaultErrorOutput", alert),
496                     finalMessage = [],
497                     //we remap the function to achieve a better compressability
498                     pushMsg = _Lang.hitch(finalMessage, finalMessage.push);
499 
500             (serverErrorMessage) ? pushMsg(_Lang.getMessage("MSG_ERROR_MESSAGE") +" "+ serverErrorMessage +"\n") : null;
501             
502             pushMsg(DIVIDER);
503 
504             (caller)? pushMsg("Calling class:"+ caller): null;
505             (callFunc)? pushMsg("Calling function:"+ callFunc): null;
506             (name) ? pushMsg(_Lang.getMessage("MSG_ERROR_NAME") +" "+name ): null;
507             (serverErrorName && name != serverErrorName) ? pushMsg("Server error name: "+ serverErrorName ) : null;
508 
509 
510             pushMsg(malFormedMessage());
511             pushMsg(DIVIDER);
512             pushMsg(_Lang.getMessage("MSG_DEV_MODE"));
513             defaultErrorOutput(finalMessage.join("\n"));
514         }
515     },
516 
517     /**
518      * sends an event
519      */
520     sendEvent : function sendEvent(/*Object*/request, /*Object*/ context, /*event name*/ name) {
521         var _Lang = myfaces._impl._util._Lang;
522         var eventData = {};
523         var UNKNOWN = _Lang.getMessage("UNKNOWN");
524 
525         eventData.type = this.EVENT;
526 
527         eventData.status = name;
528         eventData.source = context.source;
529 
530         if (name !== this.BEGIN) {
531 
532             try {
533                 //we bypass a problem with ie here, ie throws an exception if no status is given on the xhr object instead of just passing a value
534                 var getValue = function(value, key) {
535                     try {
536                         return value[key]
537                     } catch (e) {
538                         return UNKNOWN;
539                     }
540                 };
541 
542                 eventData.responseCode = getValue(request, "status");
543                 eventData.responseText = getValue(request, "responseText");
544                 eventData.responseXML = getValue(request, "responseXML");
545 
546             } catch (e) {
547                 var impl = myfaces._impl.core._Runtime.getGlobalConfig("jsfAjaxImpl", myfaces._impl.core.Impl);
548                 impl.sendError(request, context, this.CLIENT_ERROR, "ErrorRetrievingResponse",
549                         _Lang.getMessage("ERR_CONSTRUCT", e.toString()));
550 
551                 //client errors are not swallowed
552                 throw e;
553             }
554 
555         }
556 
557         /**/
558         if (context.onevent) {
559             /*calling null to preserve the original scope*/
560             context.onevent.call(null, eventData);
561         }
562 
563         /*now we serve the queue as well*/
564         this._evtListeners.broadcastEvent(eventData);
565     },
566 
567 
568     /**
569      * Spec. 13.3.3
570      * Examining the response markup and updating the DOM tree
571      * @param {XMLHttpRequest} request - the ajax request
572      * @param {Object} context - the ajax context
573      */
574     response : function(request, context) {
575         this._RT.getLocalOrGlobalConfig(context, "responseHandler", myfaces._impl.xhrCore._AjaxResponse).processResponse(request, context);
576     },
577 
578     /**
579      * @return the project stage also emitted by the server:
580      * it cannot be cached and must be delivered over the server
581      * The value for it comes from the request parameter of the jsf.js script called "stage".
582      */
583     getProjectStage : function() {
584         //since impl is a singleton we only have to do it once at first access
585 
586         if(!this._projectStage) {
587             var PRJ_STAGE = "projectStage",
588                     STG_PROD = "Production",
589 
590                     scriptTags = document.getElementsByTagName("script"),
591                     getConfig = myfaces._impl.core._Runtime.getGlobalConfig,
592                     projectStage = null,
593                     found = false,
594                     allowedProjectStages = {STG_PROD:1,"Development":1, "SystemTest":1,"UnitTest":1};
595 
596             /* run through all script tags and try to find the one that includes jsf.js */
597             for (var i = 0; i < scriptTags.length && !found; i++) {
598                 if (scriptTags[i].src.search(/\/javax\.faces\.resource\/jsf\.js.*ln=javax\.faces/) != -1) {
599                     var result = scriptTags[i].src.match(/stage=([^&;]*)/);
600                     //alert("result found");
601                     //alert(result);
602                     found = true;
603                     if (result) {
604                         // we found stage=XXX
605                         // return only valid values of ProjectStage
606                         projectStage = (allowedProjectStages[result[1]]) ? result[1] : null;
607 
608                     }
609                     else {
610                         //we found the script, but there was no stage parameter -- Production
611                         //(we also add an override here for testing purposes, the default, however is Production)
612                         projectStage = getConfig(PRJ_STAGE, STG_PROD);
613                     }
614                 }
615             }
616             /* we could not find anything valid --> return the default value */
617             this._projectStage = projectStage || getConfig(PRJ_STAGE, STG_PROD);
618         }
619         return this._projectStage;
620     },
621 
622     /**
623      * implementation of the external chain function
624      * moved into the impl
625      *
626      *  @param {Object} source the source which also becomes
627      * the scope for the calling function (unspecified side behavior)
628      * the spec states here that the source can be any arbitrary code block.
629      * Which means it either is a javascript function directly passed or a code block
630      * which has to be evaluated separately.
631      *
632      * After revisiting the code additional testing against components showed that
633      * the this parameter is only targeted at the component triggering the eval
634      * (event) if a string code block is passed. This is behavior we have to resemble
635      * in our function here as well, I guess.
636      *
637      * @param {Event} event the event object being passed down into the the chain as event origin
638      *   the spec is contradicting here, it on one hand defines event, and on the other
639      *   it says it is optional, after asking, it meant that event must be passed down
640      *   but can be undefined
641      */
642     chain : function(source, event) {
643         var len         = arguments.length;
644         var _Lang       = this._Lang;
645         var throwErr    = function(msgKey) {
646             throw Error("jsf.util.chain: "+ _Lang.getMessage(msgKey));
647         };
648         /**
649          * generic error condition checker which raises
650          * an exception if the condition is met
651          * @param assertion
652          * @param message
653          */
654         var errorCondition = function(assertion, message) {
655             if(assertion === true) throwErr(message);
656         };
657         var FUNC    = 'function';
658         var ISSTR   = _Lang.isString;
659         
660         //the spec is contradicting here, it on one hand defines event, and on the other
661         //it says it is optional, I have cleared this up now
662         //the spec meant the param must be passed down, but can be 'undefined'
663 
664         errorCondition(len < 2, "ERR_EV_OR_UNKNOWN");
665         errorCondition(len < 3 && (FUNC == typeof event || ISSTR(event)), "ERR_EVT_PASS");
666         if (len < 3) {
667             //nothing to be done here, move along
668             return true;
669         }
670         //now we fetch from what is given from the parameter list
671         //we cannot work with splice here in any performant way so we do it the hard way
672         //arguments only are give if not set to undefined even null values!
673 
674         //assertions source either null or set as dom element:
675         errorCondition('undefined' == typeof source, "ERR_SOURCE_DEF_NULL");
676         errorCondition(FUNC == typeof source, "ERR_SOURCE_FUNC");
677         errorCondition(ISSTR(source), "ERR_SOURCE_NOSTR");
678 
679         //assertion if event is a function or a string we already are in our function elements
680         //since event either is undefined, null or a valid event object
681         errorCondition(FUNC == typeof event || ISSTR(event), "ERR_EV_OR_UNKNOWN");
682 
683         for (var cnt = 2; cnt < len; cnt++) {
684             //we do not change the scope of the incoming functions
685             //but we reuse the argument array capabilities of apply
686             var ret;
687 
688             if (FUNC == typeof arguments[cnt]) {
689                 ret = arguments[cnt].call(source, event);
690             } else {
691                 //either a function or a string can be passed in case of a string we have to wrap it into another function
692                 ret = new Function("event", arguments[cnt]).call(source, event);
693             }
694             //now if one function returns false in between we stop the execution of the cycle
695             //here, note we do a strong comparison here to avoid constructs like 'false' or null triggering
696             if (ret === false /*undefined check implicitly done here by using a strong compare*/) {
697                 return false;
698             }
699         }
700         return true;
701     },
702 
703     /**
704      * error handler behavior called internally
705      * and only into the impl it takes care of the
706      * internal message transformation to a myfaces internal error
707      * and then uses the standard send error mechanisms
708      * also a double error logging prevention is done as well
709      *
710      * @param request the request currently being processed
711      * @param context the context affected by this error
712      * @param exception the exception being thrown
713      */
714     stdErrorHandler: function(request, context, exception) {
715             //newer browsers do not allow to hold additional values on native objects like exceptions
716             //we hence capsule it into the request, which is gced automatically
717             //on ie as well, since the stdErrorHandler usually is called between requests
718             //this is a valid approach
719             if (this._threshold == "ERROR") {
720                 var mfInternal = exception._mfInternal || {};
721                 //TODO clean the name mess here
722                 var finalMsg = [];
723 
724 
725 
726                 finalMsg.push(exception.message);
727                 this.sendError(request, context,
728                         mfInternal.title || this.CLIENT_ERROR, mfInternal.name || exception.name, finalMsg.join("\n"), mfInternal.caller, mfInternal.callFunc);
729             }
730     }
731 });
732 
733 
734