diff --git a/Bright.js b/Bright.js index d2c92bc8076a0aa17bb6da6169bc149acd39c056..bf906dc6f0ed475ace9c0e40edbb569acf4be102 100644 --- a/Bright.js +++ b/Bright.js @@ -1,6 +1,6 @@ /*! Bright.js -date 1686226515971 [Thu Jun 08 2023 20:15:15 GMT+0800 (China Standard Time)] +date 1687485630671 [Fri Jun 23 2023 10:00:30 GMT+0800 (China Standard Time)] (c) 2023 Bright_Leader Licensed under the Apache-2.0. */ @@ -37,22 +37,30 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 return !value||(typeOfValue!=="object"&&typeOfValue!==typeFunction); }; - function valueIsPrimitiveError(value){ - return( - "\x22"+ - value+ - "\x22 (type:\x20"+ - (value!==null?typeof value:value)+ - ") is not an object type (an object or a function)!" - ); - } + const returnOrThrowObjectType=function(){ - if(isPrimitive(globalObject))throw valueIsPrimitiveError(globalObject); + function valueIsPrimitiveError(value){ + return( + "\x22"+ + value+ + "\x22 (type:\x20"+ + (value!==null?typeof value:value)+ + ") is not an object type (an object or a function)!" + ); + } + + return function(value){ + if(isPrimitive(value))throw valueIsPrimitiveError(value); + else return value; + }; + }(); + + returnOrThrowObjectType(globalObject); const constructor_key="constructor", prototype_key="prototype"; - const Function_constructor=valueIsPrimitiveError[constructor_key], + const Function_constructor=exportFunction[constructor_key], Object_constructor={}[constructor_key], Array_constructor=[][constructor_key]; @@ -65,7 +73,7 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 Object_hasOwnProperty=Object_prototype.hasOwnProperty; const relinquishFunction=function(item,key,target){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); + returnOrThrowObjectType(target); let targetOriginallyHasOwnTargetProperty, targetOriginalTargetPropertyValue; targetOriginallyHasOwnTargetProperty=Function_call[call_key](Object_hasOwnProperty,target,key); @@ -88,6 +96,23 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 }; }; + const tryES5CreateNullPrototypeObject=function(){ + + const create=Object_constructor.create; + const createIsFunction=typeof create===typeFunction; + + return function(){ + try{ + return returnOrThrowObjectType( + createIsFunction&& + create(null) + ); + }catch(_){ + return new Object_constructor(); + } + }; + }(); + const arrayWithOneItem=function(item){ const newArray=new Array_constructor(1); newArray[0]=item; @@ -97,7 +122,8 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 const name="Bright"; const relinquish_key="relinquish", - useRequireJS_key="useRequireJS"; + useRequireJS_key="useRequireJS", + isAsynchronous_key="isAsynchronous"; /* eslint { "no-undef": [ @@ -111,7 +137,8 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 ESLint [ http://eslint.org/ ] configurations */ - let define_; + let define_, + isAsynchronous; const useRequireJS=( typeof define===typeFunction&& /* eslint-disable-line no-undef */ typeof (define_=define)===typeFunction&& /* eslint-disable-line no-undef */ @@ -119,23 +146,28 @@ ESLint [ http://eslint.org/ ] configurations !isPrimitive(define_.amd) ); /* RequireJS included? [ http://requirejs.org/ ] (based on version 2.0.4 [ http://requirejs.org/docs/release/2.0.4/comments/require.js ] ) */ + isAsynchronous=false; + useRequireJS?( define_( arrayWithOneItem("exports"), function(exports){ - if(isPrimitive(exports))throw valueIsPrimitiveError(exports); - exports[relinquish_key]=relinquishFunction(exports,name,globalObject); + returnOrThrowObjectType(exports)[relinquish_key]=relinquishFunction(exports,name,globalObject); exports[useRequireJS_key]=useRequireJS; + exports[isAsynchronous_key]=isAsynchronous; name in globalObject||(globalObject[name]=exports); return factory(exports,globalObject); } ) ):(globalObject[name]=function(){ - const product=new Object_constructor(); + const product=tryES5CreateNullPrototypeObject(); product[relinquish_key]=relinquishFunction(product,name,globalObject); product[useRequireJS_key]=useRequireJS; + product[isAsynchronous_key]=isAsynchronous; return factory(product,globalObject); }()); + + isAsynchronous=true; return; })( this, @@ -161,6 +193,8 @@ function isPrimitive(value){ return !value||(typeOfValue!=="object"&&typeOfValue!=="function"); } +const returnOrThrowObjectType=function(){ + function valueIsPrimitiveError(value){ return( "\x22"+ @@ -171,7 +205,13 @@ function valueIsPrimitiveError(value){ ); } -if(isPrimitive(objectToExport))throw valueIsPrimitiveError(objectToExport); + return function(value){ + if(isPrimitive(value))throw valueIsPrimitiveError(value); + else return value; + }; +}(); + +returnOrThrowObjectType(objectToExport); /* helper function(s) */ @@ -230,15 +270,12 @@ function maxTwo(valueA,valueB){ } const roundInteger=function(left,right,num){ - let leftInt, - rightInt; - leftInt=forceToInteger(left), - rightInt=forceToInteger(right); + const leftInt=forceToInteger(left), + rightInt=forceToInteger(right); const leftEdge=minTwo(leftInt,rightInt); const rightEdge=maxTwo(leftInt,rightInt); const toBeRanged=forceToInteger(num); const rangeWidth=rightEdge-leftEdge+1; - leftInt=rightInt=null; return forceToInteger( leftEdge!==rightEdge?( toBeRanged>rightEdge?( @@ -295,10 +332,11 @@ const length_key="length"; const isArrayLike=function(value){ if(isPrimitive(value))return False; const value_constructor=value[constructor_key]; + let tempKey; return value_constructor===Array_constructor||( value_constructor!==Function_constructor&& /* Functions have "length" property but should not be considered array-like objects, which is a common trap. */ - length_key in value&& - isUint32(value[length_key]) + (tempKey=length_key) in value&& + isUint32(value[tempKey]) ); }; @@ -306,6 +344,8 @@ function isFunction(value){ return typeof value==="function"; } +const returnOrThrowFunction=function(){ + function notAFunctionError(value){ return( "\x22"+ @@ -316,27 +356,30 @@ function notAFunctionError(value){ ); } + return function(value){ + if(isFunction(value))return value; + else throw notAFunctionError(value); + }; +}(); + const enumerateObjectProperties=function(callbackFn,callbackFnThisArg){ - if(!isFunction(callbackFn))throw notAFunctionError(callbackFn); - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); - let callbackFnThisArgIsEmpty,key,value; - callbackFnThisArgIsEmpty=isEmpty(callbackFnThisArg); + returnOrThrowFunction(callbackFn); + const self=returnOrThrowObjectType(this); + const callbackFnThisArgIsEmpty=isEmpty(callbackFnThisArg); + let key,value; for(key in self){ value=self[key]; if(!(callbackFnThisArgIsEmpty?callbackFn(value,key,self):Function_call[call_key](callbackFn,callbackFnThisArg,value,key,self))) return self; } - callbackFnThisArgIsEmpty=key=value=null; return self; }; const enumerateObjectOwnProperties=function(callbackFn,callbackFnThisArg){ - if(!isFunction(callbackFn))throw notAFunctionError(callbackFn); - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); - let callbackFnThisArgIsEmpty,key,value; - callbackFnThisArgIsEmpty=isEmpty(callbackFnThisArg); + returnOrThrowFunction(callbackFn); + const self=returnOrThrowObjectType(this); + const callbackFnThisArgIsEmpty=isEmpty(callbackFnThisArg); + let key,value; for(key in self){ if(Function_call[call_key](Object_hasOwnProperty,self,key)){ value=self[key]; @@ -344,17 +387,15 @@ const enumerateObjectOwnProperties=function(callbackFn,callbackFnThisArg){ return self; } } - callbackFnThisArgIsEmpty=key=value=null; return self; }; const arrayLikeIndexOf=function(searchElement,fromIndex){ /* http://262.ecma-international.org/5.1/#sec-15.4.4.14 */ - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); - let len; - if((len=toUint32(self[length_key]))===0)return -1; - let n_var; - if((n_var=isEmpty(fromIndex)?0:forceToInteger(fromIndex))>=len)return -1; + const self=returnOrThrowObjectType(this); + const len=toUint32(self[length_key]); + if(len===0)return -1; + const n_var=isEmpty(fromIndex)?0:forceToInteger(fromIndex); + if(n_var>=len)return -1; let k_var; if(n_var>=0)k_var=n_var; else{ @@ -367,36 +408,33 @@ const arrayLikeIndexOf=function(searchElement,fromIndex){ /* http://262.ecma-int } k_var+=1; } - len=n_var=k_var=null; return -1; }; const arrayLikeLastIndexOf=function(searchElement,fromIndex){ /* http://262.ecma-international.org/5.1/#sec-15.4.4.15 */ - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); - let len; - if((len=toUint32(self[length_key]))===0)return -1; - let n_var,k_var; - k_var=(n_var=isEmpty(fromIndex)?len:forceToInteger(fromIndex))>=0?minTwo(n_var,len-1):len+n_var; + const self=returnOrThrowObjectType(this); + const len=toUint32(self[length_key]); + if(len===0)return -1; + const n_var=isEmpty(fromIndex)?len:forceToInteger(fromIndex); + let k_var; + k_var=n_var>=0?minTwo(n_var,len-1):len+n_var; while(k_var>=0){ if(k_var in self){ if(self[k_var]===searchElement)return k_var; } k_var-=1; } - len=n_var=k_var=null; return -1; }; const True=true; const arrayLikeEvery=function(callbackFn,callbackFnThisArg){ /* http://262.ecma-international.org/5.1/#sec-15.4.4.16 */ - if(!isFunction(callbackFn))throw notAFunctionError(callbackFn); - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); - let len,callbackFnThisArgIsEmpty,k_var,v_var; - len=toUint32(self[length_key]); - callbackFnThisArgIsEmpty=isEmpty(callbackFnThisArg); + returnOrThrowFunction(callbackFn); + const self=returnOrThrowObjectType(this); + const len=toUint32(self[length_key]); + const callbackFnThisArgIsEmpty=isEmpty(callbackFnThisArg); + let k_var,v_var; k_var=0; while(k_var=0)k_var=n_var; else{ k_var=len+n_var; @@ -716,7 +736,6 @@ const arrayLikeIncludes=function(searchElement,fromIndex){ /* http://262.ecma-in )return True; k_var+=1; } - len=n_var=k_var=null; return False; }; @@ -726,8 +745,7 @@ const value_key="value", done_key="done"; const constructorFn=function(value,done){ - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); + const self=returnOrThrowObjectType(this); tryES5DefineProperty( self, @@ -785,9 +803,8 @@ function isSymbol(value){ } const tryES6AssignWellKnownSymbolProperty=function(target,symbolKeyName,propertyValue,writable,enumerable,configurable){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); tryES5DefineProperty( - target, + returnOrThrowObjectType(target), "@@"+symbolKeyName, propertyValue, @@ -815,7 +832,6 @@ const tryES6AssignWellKnownSymbolProperty=function(target,symbolKeyName,property writable,enumerable,configurable ) ); - tempKey=null; return target; }; @@ -831,10 +847,8 @@ const IterableIterator=function(){ /* http://262.ecma-international.org/6.0/#sec const next_key="next"; const constructorFn=(function selfFn(nextMethod,returnMethod,throwMethod,writable,enumerable,configurable){ - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); - let useDefaultDefinePropertyConfig; - useDefaultDefinePropertyConfig=arguments[length_key]=len){ tryES5DefineProperty( self, @@ -958,16 +961,15 @@ so we ignore this "if" case entirely and jump to step 9 directly. True,False,True ); if(itemKind===key_itemKind)return new IteratorResult(index,False); - let elementValue,result; - elementValue=a_var[index]; + const elementValue=a_var[index]; + let result; if(itemKind===value_itemKind)result=elementValue; else{ if(itemKind!==key_plus_value_itemKind)throw( "Unsupported array iteration kind:\x20"+ itemKind ); - result=new Array_constructor(2); - result[0]=index; + (result=new Array_constructor(2))[0]=index; result[1]=elementValue; } return new IteratorResult(result,False); @@ -1021,7 +1023,7 @@ tryES5DefineProperty( }(); const createArrayIterator=function(array,kind){ /* http://262.ecma-international.org/6.0/#sec-createarrayiterator */ - if(isPrimitive(array))throw valueIsPrimitiveError(array); + returnOrThrowObjectType(array); const iterator=new ArrayIterator(); tryES5DefineProperty( iterator, @@ -1049,9 +1051,10 @@ const createArrayIterator=function(array,kind){ /* http://262.ecma-international const arrayLike_entries_keys_values_maker=function(iterationKind){ return function(){ - const self=this; - if(isPrimitive(self))throw valueIsPrimitiveError(self); - return createArrayIterator(self,iterationKind); + return createArrayIterator( + returnOrThrowObjectType(this), + iterationKind + ); }; }; @@ -1068,13 +1071,11 @@ const assist=function(value,key,array){ }; return function(arrayLike){ - if(isPrimitive(arrayLike))throw valueIsPrimitiveError(arrayLike); return Function_call[call_key](arrayLikeFilter,arrayLike,assist); }; }(); const arrayLikeCountElementOccurrence=function(arrayLike,searchElement){ - if(isPrimitive(arrayLike))throw valueIsPrimitiveError(arrayLike); let counter,elementIndex; counter=0; elementIndex=Function_call[call_key](arrayLikeIndexOf,arrayLike,searchElement); @@ -1082,12 +1083,10 @@ const arrayLikeCountElementOccurrence=function(arrayLike,searchElement){ counter+=1; elementIndex=Function_call[call_key](arrayLikeIndexOf,arrayLike,searchElement,elementIndex+1); } - elementIndex=null; return counter; }; const arrayLikeFindElementOccurrences=function(arrayLike,searchElement){ - if(isPrimitive(arrayLike))throw valueIsPrimitiveError(arrayLike); const indices=new Array_constructor(); let counter,elementIndex; counter=0; @@ -1097,7 +1096,6 @@ const arrayLikeFindElementOccurrences=function(arrayLike,searchElement){ counter+=1; elementIndex=Function_call[call_key](arrayLikeIndexOf,arrayLike,searchElement,elementIndex+1); } - counter=elementIndex=null; return indices; }; @@ -1107,11 +1105,11 @@ const create=Object_constructor.create; /* http://262.ecma-international.org/5.1 const createIsFunction=isFunction(create); return function(){ - let objectToReturn; try{ - if(!createIsFunction)throw create; - if(isPrimitive(objectToReturn=create(null)))throw objectToReturn; - else return objectToReturn; + return returnOrThrowObjectType( + createIsFunction&& + create(null) + ); }catch(_){ return new Object_constructor(); } @@ -1124,8 +1122,8 @@ const mergeObject=function( target,source, targetPropertyIsWritable,targetPropertyIsEnumerable,targetPropertyIsConfigurable ){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); - if(isPrimitive(source))throw valueIsPrimitiveError(source); + returnOrThrowObjectType(target); + returnOrThrowObjectType(source); let key; for(key in source)( Function_call[call_key](Object_hasOwnProperty,source,key)&& @@ -1137,7 +1135,6 @@ const mergeObject=function( targetPropertyIsWritable,targetPropertyIsEnumerable,targetPropertyIsConfigurable ) ); - key=null; return target; }; @@ -1181,8 +1178,7 @@ we use "Object.prototype.toString" and "Object.prototype.toLocaleString" to repl */ const es3arrayMethodsObject=function(target){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); - target[toString_key]=toString_method; + returnOrThrowObjectType(target)[toString_key]=toString_method; target[toLocaleString_key]=toLocaleString_method; target[concat_key]=Array_concat; target[join_key]=Array_join; @@ -1198,8 +1194,7 @@ const es3arrayMethodsObject=function(target){ }; const es5arrayMethodsObject=function(target){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); - target.indexOf=arrayLikeIndexOf; + returnOrThrowObjectType(target).indexOf=arrayLikeIndexOf; target.lastIndexOf=arrayLikeLastIndexOf; target.every=arrayLikeEvery; target.some=arrayLikeSome; @@ -1220,7 +1215,7 @@ const copyWithin_key="copyWithin", values_key="values"; const getArraySymbolunscopables=function(target){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); + returnOrThrowObjectType(target); let i_var,tempArray,len; for( i_var=0, @@ -1242,8 +1237,7 @@ const getArraySymbolunscopables=function(target){ }; const es6arrayMethodsObject=function(target){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); - target[copyWithin_key]=arrayLikeCopyWithin; + returnOrThrowObjectType(target)[copyWithin_key]=arrayLikeCopyWithin; target[entries_key]=arrayLikeEntries; target[fill_key]=arrayLikeFill; target[find_key]=arrayLikeFind; @@ -1254,8 +1248,7 @@ const es6arrayMethodsObject=function(target){ }; const es7arrayMethodsObject=function(target){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); - target.includes=arrayLikeIncludes; + returnOrThrowObjectType(target).includes=arrayLikeIncludes; return target; /* @@ -1267,12 +1260,11 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_7th_edition_june_2 }; return function selfFn(target,writable,enumerable,configurable){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); + returnOrThrowObjectType(target); - let i_var,useDefaultDefinePropertyConfig, - tempArray,len; + let i_var,tempArray,len; - useDefaultDefinePropertyConfig=arguments[i_var=length_key]= 1686226515971 +- Bright.js date >= 1687485630671 */ (function exportFunction(globalObject,factory){"use strict"; /* @@ -40,22 +40,30 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 return !value||(typeOfValue!=="object"&&typeOfValue!==typeFunction); }; - function valueIsPrimitiveError(value){ - return( - "\x22"+ - value+ - "\x22 (type:\x20"+ - (value!==null?typeof value:value)+ - ") is not an object type (an object or a function)!" - ); - } + const returnOrThrowObjectType=function(){ - if(isPrimitive(globalObject))throw valueIsPrimitiveError(globalObject); + function valueIsPrimitiveError(value){ + return( + "\x22"+ + value+ + "\x22 (type:\x20"+ + (value!==null?typeof value:value)+ + ") is not an object type (an object or a function)!" + ); + } + + return function(value){ + if(isPrimitive(value))throw valueIsPrimitiveError(value); + else return value; + }; + }(); + + returnOrThrowObjectType(globalObject); const constructor_key="constructor", prototype_key="prototype"; - const Function_constructor=valueIsPrimitiveError[constructor_key], + const Function_constructor=exportFunction[constructor_key], Object_constructor={}[constructor_key]; const Function_prototype=Function_constructor[prototype_key], @@ -67,7 +75,7 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 Object_hasOwnProperty=Object_prototype.hasOwnProperty; const relinquishFunction=function(item,key,target){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); + returnOrThrowObjectType(target); let targetOriginallyHasOwnTargetProperty, targetOriginalTargetPropertyValue; targetOriginallyHasOwnTargetProperty=Function_call[call_key](Object_hasOwnProperty,target,key); @@ -90,13 +98,31 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 }; }; + const tryES5CreateNullPrototypeObject=function(){ + + const create=Object_constructor.create; + const createIsFunction=typeof create===typeFunction; + + return function(){ + try{ + return returnOrThrowObjectType( + createIsFunction&& + create(null) + ); + }catch(_){ + return new Object_constructor(); + } + }; + }(); + /* explicitly informs dependenc(y/ies) */ const dep0="Bright"; const name="DOMOperation"; const relinquish_key="relinquish", - useRequireJS_key="useRequireJS"; + useRequireJS_key="useRequireJS", + isAsynchronous_key="isAsynchronous"; /* eslint { "no-undef": [ @@ -110,7 +136,8 @@ http://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2 ESLint [ http://eslint.org/ ] configurations */ - let define_; + let define_, + isAsynchronous; const useRequireJS=( typeof define===typeFunction&& /* eslint-disable-line no-undef */ typeof (define_=define)===typeFunction&& /* eslint-disable-line no-undef */ @@ -118,35 +145,32 @@ ESLint [ http://eslint.org/ ] configurations !isPrimitive(define_.amd) ); /* RequireJS included? [ http://requirejs.org/ ] (based on version 2.0.4 [ http://requirejs.org/docs/release/2.0.4/comments/require.js ] ) */ + isAsynchronous=false; + useRequireJS?( define_( ["exports",dep0], function(exports){ - if(isPrimitive(exports))throw valueIsPrimitiveError(exports); - exports[relinquish_key]=relinquishFunction(exports,name,globalObject); + returnOrThrowObjectType(exports)[relinquish_key]=relinquishFunction(exports,name,globalObject); exports[useRequireJS_key]=useRequireJS; + exports[isAsynchronous_key]=isAsynchronous; name in globalObject||(globalObject[name]=exports); - return factory( - exports, - globalObject, - { - "Bright":arguments[1] - } - ); + const dependencies=tryES5CreateNullPrototypeObject(); + dependencies[dep0]=arguments[1]; + return factory(exports,globalObject,dependencies); } ) ):(globalObject[name]=function(){ - const product=new Object_constructor(); + const product=tryES5CreateNullPrototypeObject(); product[relinquish_key]=relinquishFunction(product,name,globalObject); product[useRequireJS_key]=useRequireJS; - return factory( - product, - globalObject, - { - "Bright":globalObject[dep0] - } - ); + product[isAsynchronous_key]=isAsynchronous; + const dependencies=tryES5CreateNullPrototypeObject(); + dependencies[dep0]=globalObject[dep0]; + return factory(product,globalObject,dependencies); }()); + + isAsynchronous=true; return; })( this, @@ -171,6 +195,8 @@ function isPrimitive(value){ return !value||(typeOfValue!=="object"&&typeOfValue!=="function"); } +const returnOrThrowObjectType=function(){ + function valueIsPrimitiveError(value){ return( "\x22"+ @@ -181,17 +207,21 @@ function valueIsPrimitiveError(value){ ); } -if(isPrimitive(objectToExport))throw valueIsPrimitiveError(objectToExport); - -if(isPrimitive(bwindow))throw valueIsPrimitiveError(bwindow); - -if(bwindow.window!==bwindow)throw "This script may not currently be in browser environment!"; + return function(value){ + if(isPrimitive(value))throw valueIsPrimitiveError(value); + else return value; + }; +}(); -if(isPrimitive(dependencies))throw valueIsPrimitiveError(dependencies); +returnOrThrowObjectType(objectToExport); -const BrightObject=dependencies.Bright; +if( + returnOrThrowObjectType(bwindow).window!==bwindow +)throw "This script may not currently be in browser environment!"; -if(isPrimitive(BrightObject))throw valueIsPrimitiveError(BrightObject); +const BrightObject=returnOrThrowObjectType( + returnOrThrowObjectType(dependencies).Bright +); /* helper function(s) */ @@ -214,8 +244,8 @@ const constructor_key="constructor", prototype_key="prototype", call_key="call"; -const True=true, - False=false; +const False=false, + True=true; const Function_constructor=isPrimitive[constructor_key], Object_constructor={}[constructor_key], @@ -266,21 +296,19 @@ const String_match=String_prototype.match; isEmpty(tempFunction)&& isObjectType(err)&& ( - Function_call[call_key]( - Object_toString, - err - )==="[object Error]"|| isArray( Function_call[call_key]( String_match, err, - new RegExp_constructor("unsafe-eval|CSP","g") + new RegExp_constructor("unsafe-eval|CSP") ) - ) + )|| + Function_call[call_key]( + Object_toString, + err + )==="[object Error]" ) ); - }finally{ - tempFunction=null; } }; }(); @@ -314,6 +342,7 @@ Passing an empty value (undefined or null) here will result in or "TypeError: can't convert null to object", regardless of whether it is in strict mode. +The reson behind this is here: [ http://262.ecma-international.org/5.1/#sec-9.10 ]. */ new RegExp_constructor("\\x3C|\\x26|\\x3E|\\x27|\\x22","g"), xmlEntitiesFilterFn @@ -336,9 +365,7 @@ function notAFunctionError(value){ ); } - return function(value){ /* -This functions comes in handy when checking foreign items from dependencies. -*/ + return function(value){ if(isFunction(value))return value; else throw notAFunctionError(value); }; @@ -462,8 +489,9 @@ const bText_prototype=bText[prototype_key]; const bText_splitText=bText_prototype.splitText; const splitTextNode=function(textNode,offset){ - if(isPrimitive(textNode))throw valueIsPrimitiveError(textNode); - if(!isTextNode(textNode))throw isNotATextNodeError(textNode); + if(!isTextNode( + returnOrThrowObjectType(textNode) + ))throw isNotATextNodeError(textNode); return Function_call[call_key]( bText_splitText, textNode, @@ -476,9 +504,8 @@ objectToExport.smartSplitTextNode=function(){ const roundInteger=returnOrThrowFunction(BrightObject.roundInteger); return function(textNode,offset){ - if(isPrimitive(textNode))throw valueIsPrimitiveError(textNode); return splitTextNode( - textNode, + returnOrThrowObjectType(textNode), roundInteger(0,textNode[length_key]-1,offset) ); }; @@ -522,11 +549,10 @@ instead of interface "Document" [ http://www.w3.org/TR/1998/REC-DOM-Level-1-1998 Therefore, this function generalizes the usage of method "getElementById" by making it depending on method "getElementsByTagName" [ http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#method-getElementsByTagName ]. */ - let tempObject, - indexFound; - indexFound=Function_call[call_key]( + const tempObject=getElementsByTagName("*",customDocument); + const indexFound=Function_call[call_key]( arrayLikeFindIndex, - tempObject=getElementsByTagName("*",customDocument), + tempObject, function(item){ let key; return( @@ -546,7 +572,7 @@ by making it depending on method "getElementsByTagName" [ http://www.w3.org/TR/1 indexFound>-1&& isObjectType(tempObject)&& indexFound in tempObject - )?tempObject[indexFound]:(tempObject=indexFound=null); + )?tempObject[indexFound]:null; }; objectToExport.getElementsByName=function(nameName,customDocument){ @@ -601,6 +627,8 @@ objectToExport.isDocumentFragment=function(value){ return; })(); +const returnOrThrowElement=function(){ + function isNotAnElementError(value){ return( "\x22"+ @@ -611,11 +639,21 @@ function isNotAnElementError(value){ ); } -const staticMethodFunction0=function(actionFunction){ +objectToExport.isNotAnElementError=isNotAnElementError; + + return function(value){ + if(isElement(value))return value; + else throw isNotAnElementError(value); + }; +}(); + +const decorator_key="decorator"; + +const staticMethodDecorator0=(function decorator(actionFunction){ returnOrThrowFunction(actionFunction); - return function selfFn(target,keys,value){ + const functionToReturn=function selfFn(target,keys,value){ let i_var,len; if(isPrimitive(keys))actionFunction(target,keys,value); else if(isArrayLike(keys)){ /* batch set, allowing you to set multiple attributes with one same value */ @@ -623,7 +661,6 @@ const staticMethodFunction0=function(actionFunction){ Function_call[call_key](Object_hasOwnProperty,keys,i_var)&& selfFn(target,keys[i_var],value) ); - i_var=len=null; }else if(isPlainObject(keys)){ /* multiple set, allowing you to set different attributes with different values */ for(i_var in keys)( Function_call[call_key](Object_hasOwnProperty,keys,i_var)&& @@ -635,15 +672,21 @@ because the recursive call will override the third argument. */ ) ); - i_var=null; }else isFunction(keys)&&keys(target,value); return target; }; -}; + + functionToReturn[decorator_key]=decorator; /* +This decorator function is so useful that +we feel guilty about keeping this marvelous tool to just ourselves. +*/ + + return functionToReturn; +}); const Array_push=Array_prototype.push; -const instanceMethodFunction0_DOMOperation=function(){ +const instanceMethodDecorator0_DOMOperation=function(){ const helperFunction=function(firstArgument,laterArguments){ const argumentsToSupply=new Array_constructor(); @@ -652,12 +695,12 @@ const helperFunction=function(firstArgument,laterArguments){ return argumentsToSupply; }; - return function(checkFunction,operationFunction){ + return function decorator(checkFunction,operationFunction){ returnOrThrowFunction(checkFunction); returnOrThrowFunction(operationFunction); - return function(){ + const functionToReturn=function(){ const self=this; if(!isArrayLike(self))return self; let i_var,len,j_var; @@ -674,9 +717,12 @@ const helperFunction=function(firstArgument,laterArguments){ ) ) ); - i_var=len=j_var=null; return self; }; + + functionToReturn[decorator_key]=decorator; + + return functionToReturn; }; }(); @@ -686,7 +732,7 @@ const defineProperty=Object_constructor.defineProperty; const definePropertyIsFunction=isFunction(defineProperty); return function(target,propertyName,propertyValue,isWritable,isEnumerable,isConfigurable){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); + returnOrThrowObjectType(target); definePropertyIsFunction?defineProperty( target, propertyName, @@ -713,17 +759,21 @@ function notAnArrayError(value){ ); } +const returnOrThrowArray=function(value){ + if(isArray(value))return value; + else throw notAnArrayError(value); +}; + return function(target,keys,values,writable,enumerable,configurable){ - if(isPrimitive(target))throw valueIsPrimitiveError(target); - if(!isArray(keys))throw notAnArrayError(keys); - if(!isArray(values))throw notAnArrayError(values); + returnOrThrowObjectType(target); + returnOrThrowArray(keys); + returnOrThrowArray(values); let i_var,len; for(i_var=0,len=keys[length_key];i_var