Changeset 23
- Timestamp:
- 11/17/05 15:28:54 (3 years ago)
- Files:
-
- jsolait/trunk/jsolait/jsolait.js (modified) (51 diffs)
- jsolait/trunk/jsolait/lib/codecs.js (modified) (8 diffs)
- jsolait/trunk/jsolait/lib/iter.js (modified) (26 diffs)
- jsolait/trunk/jsolait/lib/operators.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
jsolait/trunk/jsolait/jsolait.js
r20 r23 1 1 /* 2 2 Copyright (c) 2003-2005 Jan-Klaas Kollhof 3 3 4 4 This file is part of the JavaScript O Lait library(jsolait). 5 5 6 6 jsolait is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU Lesser General Public License as published by 8 8 the Free Software Foundation; either version 2.1 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This software is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU Lesser General Public License for more details. 15 15 16 16 You should have received a copy of the GNU Lesser General Public License 17 17 along with this software; if not, write to the Free Software … … 22 22 The main jsolait script. 23 23 It provides the core functionalities for creating classes, modules and for importing modules. 24 24 25 25 @author Jan-Klaas Kollhof 26 26 @version 2.0 … … 34 34 Creates a new class object which inherits from superClass. 35 35 @param name="anonymous" The name of the new class. 36 If the created class is a public member of a module then 36 If the created class is a public member of a module then 37 37 the __name__ property of that class is automatically set by Module(). 38 38 @param bases * The base classes. 39 39 @param classScope(-1) A function which is executed for class construction. 40 As 1st parameter it will get the new class' protptype for 40 As 1st parameter it will get the new class' protptype for 41 41 overrideing or extending the super class. As 2nd parameter it will get 42 42 the super class' wrapper for calling inherited methods. … … 49 49 50 50 classScope = args.pop(); 51 51 var classID = Class.__idcount__++; 52 52 53 if((args.length>0) && (typeof args[0] =='string')){ 53 54 name=args.shift(); 54 55 }else{ 55 name="anonymous" ;56 name="anonymous" + classID; 56 57 } 57 58 58 59 var bases = args; 59 60 60 61 //set up the 'public static' fields of the class 61 62 var __class__={__isArray__ : false, 62 63 __name__ : name, 63 64 __bases__: bases, 64 __id__: Class.__idcount__++,65 __id__:classID, 65 66 __hash__: function(){ 66 67 return this.__id__; … … 70 71 } 71 72 }; 72 73 73 74 var baseProtos=[];//stores the prototypes of all the base classes 74 75 var proto; //the prototype to use for the new class … … 83 84 __class__.__bases__=[Object]; 84 85 }else{ //inherit from all base classes 85 //inheritance is done by 86 //inheritance is done by 86 87 var baseProto; 87 88 for(var i=0;i<bases.length;i++){ … … 95 96 } 96 97 __class__.__isArray__ = __class__.__isArray__ || baseClass.__isArray__; 97 98 98 99 if(i==0){//for the first base class just use it's proto as the final proto 99 100 proto = baseProto; … … 105 106 } 106 107 } 107 //extend the new class' static interface 108 //extend the new class' static interface 108 109 //todo: any props that should not be copied 109 110 for(var key in baseClass){ … … 113 114 } 114 115 } 115 //make sure the toString points to __str__, this will make overwriting __str__ after object construction impossible (todo ?) 116 //make sure the toString points to __str__, this will make overwriting __str__ after object construction impossible (todo ?) 116 117 //but will be faster than having toString call __str__, also overwriting methods unless they are ment to be overridden is not cool anyways. 117 118 proto.toString=proto.__str__; … … 127 128 } 128 129 proto.__class__=__class__; 129 130 130 131 var privId = '__priv__' + __class__.__id__; 131 132 132 133 //run teh class setup function provided as classScope 133 134 if(classScope.length-1 > baseProtos.length){ … … 136 137 classScope.apply(this,[proto].concat(baseProtos)); 137 138 } 138 139 139 140 //allthough a single constructor would suffice for generating normal objects, Arrays and callables, 140 141 //we use 3 different ones. This will minimize the code inside the constructor and therefore 141 142 //minimize object construction time 142 143 if(proto.__call__){ 143 //if the callable interface is implemented we need a class constructor 144 //if the callable interface is implemented we need a class constructor 144 145 //which generates a function upon construction 145 146 var NewClass = function(calledBy){ … … 148 149 return rslt.__call__.apply(rslt, arguments); 149 150 }; 150 151 151 152 var privId='__priv__' + arguments.callee.__id__; 152 153 rslt[privId]={}; 153 154 154 155 var proto=arguments.callee.prototype; 155 156 for(var n in proto){ … … 166 167 }else if(__class__.__isArray__){ 167 168 //Since we cannot inherit from Array directly we take the same approach as with the callable above 168 //and just have a constructor which creates an Array 169 //and just have a constructor which creates an Array 169 170 var NewClass = function(calledBy){ 170 171 if(calledBy !== Class){ 171 172 rslt=[]; 172 173 173 174 var privId='__priv__' + arguments.callee.__id__; 174 175 rslt[privId]={}; 175 176 176 177 var proto=arguments.callee.prototype; 177 178 for(var n in proto){ … … 195 196 }; 196 197 }else{ 197 //this is a 'normal' object constructor which does nothing but call the __init__ method 198 //this is a 'normal' object constructor which does nothing but call the __init__ method 198 199 //unless it does not exsit or the constructor was used for prototyping 199 200 var NewClass = function(calledBy){ … … 203 204 if(this.__init__){ 204 205 this.__init__.apply(this, arguments); 205 } 206 } 206 207 } 207 208 }; 208 209 } 209 210 210 211 //reset the constructor for new objects to the actual constructor. 211 212 proto.constructor = NewClass; 212 213 proto.__class__= NewClass;//no, it is not needed, just like __str__ is not, but it is nicer than constructor 213 214 214 215 //this is where the inheritance realy happens 215 216 NewClass.prototype = proto; 216 217 217 218 //apply all the static fileds 218 219 for(var key in __class__){ … … 220 221 } 221 222 NewClass.toString=__class__.__str__; 222 223 223 224 return NewClass; 224 }; 225 }; 225 226 Class.__idcount__=0; 226 227 Class.toString = function(){ … … 228 229 }; 229 230 230 Class.__createProto__=function(){ 231 Class.__createProto__=function(){ 231 232 throw "Can't use Class as a base class."; 232 233 }; … … 245 246 @param version The version of a module. 246 247 @param moduleScope A function which is executed for module creation. 247 As 1st parameter it will get the module variable. 248 As 1st parameter it will get the module variable. 248 249 The imported modules(imports) will be passed to the moduleScope starting with the 2nd parameter. 249 250 **/ … … 253 254 newMod.version = version; 254 255 newMod.__sourceURI__ = Module.currentURI; 255 256 256 257 newMod.toString=function(){ 257 258 //todo:SVN adaption 258 return "[module '%s' version: %s]".format(this.name, this.version);259 return "[module '%s' version: %s]".format(this.name, (this.version+'').replace(/\$Revision:\s(\d+) \$/, "rev.$1")); 259 260 }; 260 261 … … 263 264 publ.module = newMod; 264 265 }); 265 266 266 267 try{//to execute the scope of the module 267 268 moduleScope.call(newMod, newMod); … … 269 270 throw new Module.ModuleScopeExecFailed(newMod, e); 270 271 } 271 272 272 273 //set __name__ for methods and classes 273 274 for(var n in newMod){ … … 285 286 }; 286 287 287 Module.__createProto__=function(){ 288 Module.__createProto__=function(){ 288 289 throw "Can't use Module as a base class."; 289 290 }; 290 291 291 292 292 293 /** 293 294 Base class for all module-Exceptions. … … 306 307 this.trace = trace; 307 308 }; 308 309 309 310 310 311 publ.__str__=function(){ 311 312 var s = "%s %s".format(this.name, this.module); … … 318 319 publ.toTraceString=function(indent){ 319 320 indent = indent==null ? 0 : indent; 320 321 321 322 //todo:use constructor.__name__ 322 323 var s="%s in %s:\n%s".format(this.name, this.module, this.message.indent(4)).indent(indent); … … 330 331 return s; 331 332 }; 332 333 334 333 334 335 335 336 ///The name of the Exception. 336 337 publ.name;//todo is that needed? … … 340 341 publ.module="jsolait"; 341 342 ///The error which caused the Exception or undefined. 342 publ.trace; 343 publ.trace; 343 344 }); 344 345 … … 359 360 publ.module; 360 361 }); 361 362 362 363 363 364 /** 364 365 365 366 @author Jan-Klaas Kollhof 366 367 @lastchangedby $LastChangedBy$ … … 369 370 Module("jsolait", "$Revision$", function(mod){ 370 371 jsolait=mod; 372 371 373 mod.modules={}; 372 374 373 375 ///The paths of the modules that come with jsolait. 374 376 //do not edit the following lines, it will be replaced by the build script … … 385 387 "urllib":"%(baseURI)s/lib/urllib.js", 386 388 "xml":"%(baseURI)s/lib/xml.js", 387 "xmlrpc":"%(baseURI)s/lib/xmlrpc.js"}; 388 /*@moduleURIs end*/ 389 389 "xmlrpc":"%(baseURI)s/lib/xmlrpc.js"}; 390 /*@moduleURIs end*/ 391 390 392 ///The base URIs to search for modules in. They may contain StringFormating symbols e.g '%(baseURI)s/lib' 391 393 mod.moduleSearchURIs = [".", "%(baseURI)s/lib"]; 392 394 393 395 ///The location where jsolait is installed. 394 396 //do not edit the following lines, it will be replaced by the build script … … 396 398 mod.baseURI="./jsolait"; 397 399 /*@baseURI end*/ 398 400 399 401 /** 400 402 Creates an HTTP request object for retreiving files. … … 413 415 }catch(e){ 414 416 try{// to get the old MS HTTP request object 415 obj = new ActiveXObject("microsoft.XMLHTTP"); 417 obj = new ActiveXObject("microsoft.XMLHTTP"); 416 418 }catch(e){ 417 419 throw new mod.Exception("Unable to get an HTTP request object."); 418 420 } 419 } 421 } 420 422 } 421 423 } 422 424 return obj; 423 425 }; 424 426 425 427 /** 426 428 Retrieves a file given its URL. … … 437 439 xmlhttp.open("GET", uri, false); 438 440 for(var i=0;i< headers.length;i++){ 439 xmlhttp.setRequestHeader(headers[i][0], headers[i][1]); 441 xmlhttp.setRequestHeader(headers[i][0], headers[i][1]); 440 442 } 441 443 xmlhttp.send(""); … … 451 453 } 452 454 }; 453 455 454 456 /** 455 457 Thrown when a file could not be loaded. … … 469 471 publ.sourceURI; 470 472 }); 471 472 473 474 473 475 /** 474 476 Imports a module given its name(someModule.someSubModule). 475 477 A module's file location is determined by treating each module name as a directory. 476 478 Only the last one is assumed to point to a file. 477 If the module's URL is not known (i.e the module name was not found in jsolait.knownModuleURIs) 479 If the module's URL is not known (i.e the module name was not found in jsolait.knownModuleURIs) 478 480 then it will be searched using all URIs found in jsolait.moduleSearchURIs. 479 481 @param name The name of the module to load. … … 495 497 } 496 498 } 497 499 498 500 if(src == null){//go through the search paths and try loading the module 499 501 var failedURIs=[]; … … 511 513 } 512 514 } 513 515 514 516 try{//interpret the script 515 517 var srcURI = src.__sourceURI__; … … 520 522 throw new mod.ImportFailed(name, [srcURI], e); 521 523 } 522 523 return mod.modules[name]; 524 } 525 }; 526 527 524 525 return mod.modules[name]; 526 } 527 }; 528 529 528 530 /** 529 531 Thrown when a module could not be found. … … 546 548 publ.moduleURIs; 547 549 }); 548 550 549 551 /** 550 552 Imports a module given its name. … … 556 558 return mod.__imprt__(name); 557 559 }; 558 560 559 561 mod.__registerModule__=function(modObj, modName){ 560 562 if(modName != 'jsolait'){ … … 562 564 } 563 565 }; 564 566 565 567 mod.registerModule=function(modObj, modName){ 566 568 modName = modName===undefined?modObj.name : modName; … … 569 571 570 572 571 //---------------------------------------------------String Format ------------------------------------------------------- 572 /** 573 Creates a format specifier object. 573 //---------------------------------------------------String Format ------------------------------------------------------- 574 /** 575 Creates a format specifier object. 574 576 **/ 575 577 var FormatSpecifier=function(s){ … … 582 584 this.paddingFlag = s[2]; 583 585 if(this.paddingFlag==""){ 584 this.paddingFlag =" "; 586 this.paddingFlag =" "; 585 587 } 586 588 this.signed=(s[3] == "+"); … … 603 605 Usage: 604 606 resultString = formatString.format(value1, v2, ...); 605 607 606 608 Each formatString can contain any number of formatting specifiers which are 607 609 replaced with the formated values. 608 609 specifier([...]-items are optional): 610 611 specifier([...]-items are optional): 610 612 "%[(key)][flag][sign][min][percision]typeOfValue" 611 612 (key) If specified the 1st argument is treated as an object/associative array and the formating values 613 614 (key) If specified the 1st argument is treated as an object/associative array and the formating values 613 615 are retrieved from that object using the key. 614 616 615 617 flag: 616 618 0 Use 0s for padding. … … 620 622 + Numeric values will contain a +|- infront of the number. 621 623 min: 622 l The string will be padded with the padding character until it has a minimum length of l. 624 l The string will be padded with the padding character until it has a minimum length of l. 623 625 percision: 624 626 .x Where x is the percision for floating point numbers and the lenght for 0 padding for integers. 625 627 typeOfValue: 626 d Signed integer decimal. 627 i Signed integer decimal. 628 d Signed integer decimal. 629 i Signed integer decimal. 628 630 b Unsigned binary. //This does not exist in python! 629 o Unsigned octal. 630 u Unsigned decimal. 631 x Unsigned hexidecimal (lowercase). 632 X Unsigned hexidecimal (uppercase). 633 e Floating point exponential format (lowercase). 634 E Floating point exponential format (uppercase). 635 f Floating point decimal format. 636 F Floating point decimal format. 637 c Single character (accepts byte or single character string). 638 s String (converts any object using object.toString()). 631 o Unsigned octal. 632 u Unsigned decimal. 633 x Unsigned hexidecimal (lowercase). 634 X Unsigned hexidecimal (uppercase). 635 e Floating point exponential format (lowercase). 636 E Floating point exponential format (uppercase). 637 f Floating point decimal format. 638 F Floating point decimal format. 639 c Single character (accepts byte or single character string). 640 s String (converts any object using object.toString()). 639 641 Examples: 640 642 "%02d".format(8) == "08" 641 643 "%05.2f".format(1.234) == "01.23" 642 644 "123 in binary is: %08b".format(123) == "123 in binary is: 01111011" 643 644 @param * Each parameter is treated as a formating value. 645 646 @param * Each parameter is treated as a formating value. 645 647 @return The formated String. 646 648 **/ … … 660 662 var frmt; 661 663 var sign=""; 662 664 663 665 for(var i=0;i<sf.length;i++){ 664 666 s=sf[i]; … … 694 696 } 695 697 } 696 698 697 699 if(frmt.type == "s"){//String 698 700 if (obj === null){ … … 702 704 } 703 705 s=obj.toString().pad(frmt.paddingFlag, frmt.minLength); 704 706 705 707 }else if(frmt.type == "c"){//Character 706 708 if(frmt.paddingFlag == "0"){ … … 724 726 sign = "-"; //negative signs are always needed 725 727 }else if(frmt.signed){ 726 sign = "+"; // if sign is always wanted add it 728 sign = "+"; // if sign is always wanted add it 727 729 }else{ 728 730 sign = ""; … … 782 784 return rslt; 783 785 }; 784 786 785 787 /** 786 788 Padds a String with a character to have a minimum length. 787 789 788 790 @param flag "-": to padd with " " and left justify the string. 789 Other: the character to use for padding. 791 Other: the character to use for padding. 790 792 @param len The minimum length of the resulting string. 791 793 **/ … … 807 809 return s; 808 810 }; 809 811 810 812 String.prototype.indent=function(indent){ 811 813 var out=[]; … … 816 818 return out.join('\n'); 817 819 }; 818 820 819 821 String.prototype.mul=function(l){ 820 822 var a=new Array(l+1); 821 823 return a.join(this); 822 824 }; 823 824 ///Tests the module. 825 mod.test=function(){ 826 827 }; 825 828 826 }); 829 827 828 jsolait/trunk/jsolait/lib/codecs.js
r9 r23 1 1 /* 2 2 Copyright (c) 2004-2005 Jan-Klaas Kollhof 3 3 4 4 This file is part of the JavaScript o lait library(jsolait). 5 5 6 6 jsolait is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU Lesser General Public License as published by 8 8 the Free Software Foundation; either version 2.1 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This software is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU Lesser General Public License for more details. 15 15 16 16 You should have received a copy of the GNU Lesser General Public License 17 17 along with this software; if not, write to the Free Software … … 55 55 return c; 56 56 }; 57 57 58 58 /** 59 59 Decodes an encoded string. … … 73 73 } 74 74 }; 75 75 76 76 /** 77 77 Encodes a string. … … 91 91 } 92 92 }; 93 93 94 94 /** 95 95 Decodes a Base64 encoded string to a byte string. … … 119 119 } 120 120 }; 121 121 122 122 /** 123 123 Encodes a string using Base64. … … 145 145 var ri=0; 146 146 for(var i=0;i<s.length; i+=3){ 147 sbin=((s.charCodeAt(i) & 0xff) << 16) | ((s.charCodeAt(i+1) & 0xff ) << 8) | (s.charCodeAt(i+2) & 0xff); 147 sbin=((s.charCodeAt(i) & 0xff) << 16) | ((s.charCodeAt(i+1) & 0xff ) << 8) | (s.charCodeAt(i+2) & 0xff); 148 148 rslt[ri] = (base64[(sbin >> 18) & 0x3f] + base64[(sbin >> 12) & 0x3f] + base64[(sbin >>6) & 0x3f] + base64[sbin & 0x3f]); 149 149 ri++; … … 162 162 return decodeURIComponent(this); 163 163 }; 164 164 165 165 /** 166 166 Encodes a URI using encodeURIComponent. … … 169 169 return encodeURIComponent(this); 170 170 }; 171 172 mod.__main__=function(){ 173 } 171 174 }); jsolait/trunk/jsolait/lib/iter.js
r17 r23 1 1 /* 2 2 Copyright (c) 2004 Jan-Klaas Kollhof 3 3 4 4 This is free software; you can redistribute it and/or modify 5 5 it under the terms of the GNU General Public License as published by 6 6 the Free Software Foundation; either version 2 of the License, or 7 7 (at your option) any later version. 8 8 9 9 This software is distributed in the hope that it will be useful, 10 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 GNU General Public License for more details. 13 13 14 14 You should have received a copy of the GNU General Public License 15 15 along with this software; if not, write to the Free Software 16 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 18 18 */ 19 19 … … 23 23 if given a callback asynchronously. 24 24 An iterable object is an object which has an iterator function (__iter__) which returns an Iterator object. 25 25 26 26 The Range class is there to create an iterable object over a range of numbers. 27 27 28 28 @creator Jan-Klaas Kollhof 29 29 @created 2004-12-08 … … 32 32 */ 33 33 Module("iter", "$Revision$", function(mod){ 34 34 35 35 /** 36 36 Base class for Iterators. … … 51 51 }; 52 52 }); 53 53 54 54 /** 55 55 A simple range class to iterate over a range of numbers. … … 82 82 this.current=this.start - this.step; 83 83 }; 84 84 85 85 publ.next = function(){ 86 86 if(this.current + this.step > this.end){ … … 92 92 } 93 93 }; 94 95 }); 96 94 95 }); 96 97 97 Range = mod.Range; 98 98 99 99 /** 100 100 Iterator for Arrays. … … 114 114 }; 115 115 }); 116 116 117 117 /** 118 118 Iterator for Objects. … … 125 125 this.keys.push(n); 126 126 } 127 127 128 128 this.index = -1; 129 129 }; 130 130 131 131 publ.next = function(){ 132 132 this.index += 1; … … 144 144 }; 145 145 }); 146 146 147 147 Array.prototype.__iter__ = function(){ 148 148 return new mod.ArrayItereator(this); 149 149 }; 150 150 151 151 /** 152 152 Interface of a IterationCallback. … … 155 155 */ 156 156 mod.IterationCallback = function(item, iteration){}; 157 157 158 158 /** 159 159 Iteration class for handling iteration steps and callbacks. … … 174 174 this.iterator = new mod.ObjectIterator(iterable); 175 175 } 176 176 177 177 this.callback = callback; 178 178 }; 179 179 180 180 ///Resumes a stoped iteration. 181 181 publ.resume = function(){ … … 192 192 } 193 193 }; 194 194 195 195 ///Stops an iteration 196 196 publ.stop = function(){ 197 197 this.doStop = true; 198 198 }; 199 200 ///Starts/resumes an iteration 199 200 ///Starts/resumes an iteration 201 201 publ.start = function(){ 202 202 this.resume(); 203 203 }; 204 204 }); 205 205 206 206 /** 207 207 Class for handling asynchronous iterations. … … 212 212 @param iterable An itaratable object. 213 213 @param interval The time in ms betwen each step. 214 @param thisObj 214 @param thisObj 215 215 @param callback An IterationCallback object. 216 216 */ … … 227 227 this.isRunning = false; 228 228 }; 229 229 230 230 publ.stop=function(){ 231 231 if(this.isRunning){ 232 232 this.isRunning = false; 233 clearTimeout(this.timeout); 233 clearTimeout(this.timeout); 234 234 delete iter.iterations[this.id]; 235 235 } 236 236 }; 237 237 238 238 publ.resume = function(){ 239 239 if(this.isRunning == false){ … … 249 249 } 250 250 }; 251 251 252 252 publ.handleAsyncStep = function(){ 253 253 if(this.isRunning){ … … 263 263 }; 264 264 }); 265 266 265 266 267 267 /** 268 268 Iterates over an iterable object and calls a callback for each item. … … 282 282 } 283 283 if(delay >-1){ 284 var it = new mod.AsyncIteration(iterable, delay, thisObj, cb); 284 var it = new mod.AsyncIteration(iterable, delay, thisObj, cb); 285 285 }else{ 286 286 var it = new mod.Iteration(iterable, thisObj, cb); … … 289 289 return it; 290 290 }; 291 291 292 292 iter.handleAsyncStep = function(id){ 293 293 if(iter.iterations[id]){ … … 297 297 ///Helper object containing all async. iteration objects. 298 298 iter.iterations = {}; 299 300 299 300 301 301 mod.__main__=function(){ 302 303 302 303 304 304 var testing = imprt('testing'); 305 305 var task=function(){ … … 309 309 } 310 310 }; 311 311 312 312 r = []; 313 313 for(var i=0;i<100;i++){ 314 314 r[i] = i; 315 315 } 316 317 print("for loop \t\t\t" + testing. timeExec(100,function(){316 317 print("for loop \t\t\t" + testing.profile(function(){ 318 318 var s=''; 319 319 for(var i=0;i<100;i++){ … … 322 322 } 323 323 })); 324 325 print("Range iter \t\t" + testing. timeExec(100,function(){324 325 print("Range iter \t\t" + testing.profile(function(){ 326 326 var s=''; 327 327 iter(new mod.Range(100), function(item,i){ … … 330 330 }); 331 331 })); 332 333 print("Array iter \t\t\t" + testing. timeExec(100,function(){332 333 print("Array iter \t\t\t" + testing.profile(function(){ 334 334 var s=''; 335 335 iter(r , function(item,i){ … … 337 337 task(); 338 338 }); 339 340 })); 341 342 print("for in on Array \t\t" + testing. timeExec(100,function(){339 340 })); 341 342 print("for in on Array \t\t" + testing.profile(function(){ 343 343 var s=''; 344 344 for(var i in r){ … … 347 347 } 348 348 })); 349 349 350 350 r = []; 351 351 for(var i=0;i<100;i++){ 352 352 r["k"+i] = i; 353 353 } 354 355 print("for in on as.Array \t" + testing. timeExec(100,function(){354 355 print("for in on as.Array \t" + testing.profile(function(){ 356 356 var s=''; 357 357 for(var i in r){ … … 360 360 } 361 361 })); 362 362 363 363 r = {}; 364 364 for(var i=0;i<100;i++){ 365 365 r["k"+i] = i; 366 366 } 367 368 print("for in on dictionary \t" + testing. timeExec(100,function(){367 368 print("for in on dictionary \t" + testing.profile(function(){ 369 369 var s=''; 370 370 for(var i in r){ … … 373 373 } 374 374 })); 375 375 376 376 r = []; 377 377 for(var i=0;i<100;i++){ 378 378 r[i] = i; 379 379 } 380 381 print("for on Array + iter \t" + testing. timeExec(100,function(){380 381 print("for on Array + iter \t" + testing.profile(function(){ 382 382 var s=''; 383 383 for(i=r.__iter__(); item=i.next() !==undefined;){ jsolait/trunk/jsolait/lib/operators.js
r21 r23 1 Module("operators", "0.0.1", function(mod){ 1 /* 2 Copyright (c) 2005 Jan-Klaas Kollhof 3 4 This file is part of the JavaScript O Lait library(jsolait). 5 6 jsolait is free software; you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as published by 8 the Free Software Foundation; either version 2.1 of the License, or 9 (at your option) any later version. 10 11 This software is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with this software; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 Module("operators", "$Revision: 20 $",
