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