Kernel.st 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173
  1. nil subclass: #Object
  2. instanceVariableNames: ''
  3. category: 'Kernel'!
  4. !Object methodsFor: 'accessing'!
  5. yourself
  6. ^self
  7. !
  8. class
  9. <return self.klass>
  10. !
  11. size
  12. self error: 'Object not indexable'
  13. !
  14. instVarAt: aString
  15. <return self['@'+aString]>
  16. !
  17. instVarAt: aString put: anObject
  18. <self['@' + aString] = anObject>
  19. !
  20. basicAt: aString
  21. <return self[aString]>
  22. !
  23. basicAt: aString put: anObject
  24. <return self[aString] = anObject>
  25. !
  26. basicDelete: aString
  27. <delete self[aString]>
  28. ! !
  29. !Object methodsFor: 'comparing'!
  30. = anObject
  31. ^self == anObject
  32. !
  33. ~= anObject
  34. ^(self = anObject) = false
  35. !
  36. == anObject
  37. <return self === anObject>
  38. !
  39. ~~ anObject
  40. ^(self == anObject) = false
  41. ! !
  42. !Object methodsFor: 'converting'!
  43. -> anObject
  44. ^Association key: self value: anObject
  45. !
  46. asString
  47. ^self printString
  48. !
  49. asJavascript
  50. ^self asString
  51. !
  52. asJSON
  53. <return JSON.stringify(self._asJSONObject())>
  54. !
  55. asJSONObject
  56. | object |
  57. object := Object new.
  58. self class instanceVariableNames do: [:each |
  59. object basicAt: each put: (self instVarAt: each) asJSONObject].
  60. ^object
  61. ! !
  62. !Object methodsFor: 'copying'!
  63. copy
  64. ^self shallowCopy postCopy
  65. !
  66. shallowCopy
  67. <
  68. var copy = self.klass._new();
  69. for(var i in self) {
  70. if(/^@.+/.test(i)) {
  71. copy[i] = self[i];
  72. }
  73. }
  74. return copy;
  75. >
  76. !
  77. deepCopy
  78. <
  79. var copy = self.klass._new();
  80. for(var i in self) {
  81. if(/^@.+/.test(i)) {
  82. copy[i] = self[i]._deepCopy();
  83. }
  84. }
  85. return copy;
  86. >
  87. !
  88. postCopy
  89. ! !
  90. !Object methodsFor: 'error handling'!
  91. error: aString
  92. Error signal: aString
  93. !
  94. subclassResponsibility
  95. self error: 'This method is a responsibility of a subclass'
  96. !
  97. shouldNotImplement
  98. self error: 'This method should not be implemented in ', self class name
  99. !
  100. try: aBlock catch: anotherBlock
  101. <try{aBlock()} catch(e) {anotherBlock(e)}>
  102. !
  103. doesNotUnderstand: aMessage
  104. MessageNotUnderstood new
  105. receiver: self;
  106. message: aMessage;
  107. signal
  108. !
  109. halt
  110. self error: 'Halt encountered'
  111. !
  112. deprecatedAPI
  113. "Just a simple way to deprecate methods.
  114. #deprecatedAPI is in the 'error handling' protocol even if it doesn't throw an error,
  115. but it could in the future."
  116. console warn: thisContext home asString, ' is deprecated!!'
  117. ! !
  118. !Object methodsFor: 'initialization'!
  119. initialize
  120. ! !
  121. !Object methodsFor: 'message handling'!
  122. perform: aSymbol
  123. ^self perform: aSymbol withArguments: #()
  124. !
  125. perform: aSymbol withArguments: aCollection
  126. ^self basicPerform: aSymbol asSelector withArguments: aCollection
  127. !
  128. basicPerform: aSymbol
  129. ^self basicPerform: aSymbol withArguments: #()
  130. !
  131. basicPerform: aSymbol withArguments: aCollection
  132. <return self[aSymbol].apply(self, aCollection);>
  133. ! !
  134. !Object methodsFor: 'printing'!
  135. printString
  136. ^'a ', self class name
  137. !
  138. printNl
  139. <console.log(self)>
  140. !
  141. log: aString block: aBlock
  142. | result |
  143. console log: aString, ' time: ', (Date millisecondsToRun: [result := aBlock value]) printString.
  144. ^result
  145. ! !
  146. !Object methodsFor: 'testing'!
  147. isKindOf: aClass
  148. ^(self isMemberOf: aClass)
  149. ifTrue: [true]
  150. ifFalse: [self class inheritsFrom: aClass]
  151. !
  152. isMemberOf: aClass
  153. ^self class = aClass
  154. !
  155. ifNil: aBlock
  156. "inlined in the Compiler"
  157. ^self
  158. !
  159. ifNil: aBlock ifNotNil: anotherBlock
  160. "inlined in the Compiler"
  161. ^anotherBlock value
  162. !
  163. ifNotNil: aBlock
  164. "inlined in the Compiler"
  165. ^aBlock value
  166. !
  167. ifNotNil: aBlock ifNil: anotherBlock
  168. "inlined in the Compiler"
  169. ^aBlock value
  170. !
  171. isNil
  172. ^false
  173. !
  174. notNil
  175. ^self isNil not
  176. !
  177. isClass
  178. ^false
  179. !
  180. isMetaclass
  181. ^false
  182. !
  183. isNumber
  184. ^false
  185. !
  186. isString
  187. ^false
  188. !
  189. isParseFailure
  190. ^false
  191. ! !
  192. !Object class methodsFor: 'initialization'!
  193. initialize
  194. "no op"
  195. ! !
  196. Object subclass: #Smalltalk
  197. instanceVariableNames: ''
  198. category: 'Kernel'!
  199. !Smalltalk methodsFor: 'accessing'!
  200. classes
  201. <return self.classes()>
  202. !
  203. readJSON: anObject
  204. <return self.readJSObject(anObject)>
  205. !
  206. at: aString
  207. <return self[aString]>
  208. !
  209. basicParse: aString
  210. <return smalltalk.parser.parse(aString)>
  211. !
  212. parse: aString
  213. | result |
  214. self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
  215. ^result
  216. !
  217. parseError: anException parsing: aString
  218. | row col message lines badLine code |
  219. <row = anException.line;
  220. col = anException.column;
  221. message = anException.message;>.
  222. lines := aString lines.
  223. badLine := lines at: row.
  224. badLine := (badLine copyFrom: 1 to: col - 1), ' ===>', (badLine copyFrom: col to: badLine size).
  225. lines at: row put: badLine.
  226. code := String streamContents: [:s |
  227. lines withIndexDo: [:l :i |
  228. s nextPutAll: i asString, ': ', l, String lf]].
  229. ^ Error new messageText: ('Parse error on line ' , row , ' column ' , col , ' : ' , message , ' Below is code with line numbers and ===> marker inserted:' , String lf, code)
  230. !
  231. reservedWords
  232. "JavaScript reserved words"
  233. <return self.reservedWords>
  234. ! !
  235. !Smalltalk methodsFor: 'classes'!
  236. removeClass: aClass
  237. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  238. aClass methodDictionary values do: [:each |
  239. aClass removeCompiledMethod: each].
  240. aClass class methodDictionary values do: [:each |
  241. aClass class removeCompiledMethod: each].
  242. self basicDelete: aClass name
  243. ! !
  244. !Smalltalk methodsFor: 'packages'!
  245. packages
  246. "Return all Package instances in the system."
  247. <return self.packages.all()>
  248. !
  249. packageAt: packageName
  250. <return self.packages[packageName]>
  251. !
  252. packageAt: packageName ifAbsent: aBlock
  253. ^(self packageAt: packageName) ifNil: aBlock
  254. !
  255. removePackage: packageName
  256. "Removes a package and all its classes."
  257. | pkg |
  258. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  259. pkg classes do: [:each |
  260. self removeClass: each].
  261. self deletePackage: packageName
  262. !
  263. renamePackage: packageName to: newName
  264. "Rename a package."
  265. | pkg |
  266. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  267. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  268. <smalltalk.packages[newName] = smalltalk.packages[packageName]>.
  269. pkg name: newName.
  270. self deletePackage: packageName.
  271. ! !
  272. !Smalltalk methodsFor: 'private'!
  273. createPackage: packageName
  274. "Create and bind a new package with given name and return it."
  275. <return smalltalk.addPackage(packageName)>
  276. !
  277. deletePackage: packageName
  278. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  279. To remove a package, use #removePackage instead."
  280. <delete smalltalk.packages[packageName]>
  281. ! !
  282. Smalltalk class instanceVariableNames: 'current'!
  283. !Smalltalk class methodsFor: 'accessing'!
  284. current
  285. <return smalltalk>
  286. ! !
  287. Object subclass: #Package
  288. instanceVariableNames: ''
  289. category: 'Kernel'!
  290. !Package commentStamp!
  291. A Package is similar to a "class category" typically found in other Smalltalks like Pharo or Squeak. Amber does not have class categories anymore, it had in the beginning but now each class in the system knows which package it belongs to.
  292. A Package has a name, an Array of "requires", a comment and a Dictionary with other optional key value attributes. A Package can also be queried for its classes, but it will then resort to a reverse scan of all classes to find them.
  293. Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
  294. Smalltalk current packageAt: 'Kernel'
  295. ...but you can also use:
  296. Package named: 'Kernel'
  297. A Package differs slightly from a Monticello package which can span multiple class categories using a naming convention based on hyphenation. But just as in Monticello a Package supports "class extensions" so a Package
  298. can define behaviors in foreign classes using a naming convention for method categories where the category starts with an asterisk and then the name of the owning package follows. This can easily be seen in for example class
  299. String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.!
  300. !Package methodsFor: 'accessing'!
  301. name
  302. <return self.pkgName || nil>
  303. !
  304. requires
  305. <return self.requires || nil>
  306. !
  307. name: aString
  308. <return self.pkgName = aString>
  309. ! !
  310. !Package methodsFor: 'classes'!
  311. classes
  312. "We need to do a reverse scan."
  313. ^Smalltalk current classes select: [:c | c package == self]
  314. ! !
  315. !Package methodsFor: 'printing'!
  316. printString
  317. ^self name
  318. ! !
  319. !Package class methodsFor: 'not yet classified'!
  320. named: aPackageName
  321. ^Smalltalk current packageAt: aPackageName
  322. !
  323. named: aPackageName ifAbsent: aBlock
  324. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  325. ! !
  326. Object subclass: #Behavior
  327. instanceVariableNames: ''
  328. category: 'Kernel'!
  329. !Behavior methodsFor: 'accessing'!
  330. name
  331. <return self.className || nil>
  332. !
  333. superclass
  334. <return self.superclass || nil>
  335. !
  336. subclasses
  337. <return smalltalk.subclasses(self)>
  338. !
  339. allSubclasses
  340. | result |
  341. result := self subclasses.
  342. self subclasses do: [:each |
  343. result addAll: each allSubclasses].
  344. ^result
  345. !
  346. withAllSubclasses
  347. ^(Array with: self) addAll: self allSubclasses; yourself
  348. !
  349. prototype
  350. <return self.fn.prototype>
  351. !
  352. methodDictionary
  353. <var dict = smalltalk.Dictionary._new();
  354. var methods = self.fn.prototype.methods;
  355. for(var i in methods) {
  356. if(methods[i].selector) {
  357. dict._at_put_(methods[i].selector, methods[i]);
  358. }
  359. };
  360. return dict>
  361. !
  362. methodsFor: aString
  363. ^ClassCategoryReader new
  364. class: self category: aString;
  365. yourself
  366. !
  367. addCompiledMethod: aMethod
  368. <smalltalk.addMethod(aMethod.selector._asSelector(), aMethod, self)>
  369. !
  370. instanceVariableNames
  371. <return self.iVarNames>
  372. !
  373. comment
  374. ^(self basicAt: 'comment') ifNil: ['']
  375. !
  376. comment: aString
  377. self basicAt: 'comment' put: aString
  378. !
  379. commentStamp
  380. ^ClassCommentReader new
  381. class: self;
  382. yourself
  383. !
  384. removeCompiledMethod: aMethod
  385. <delete self.fn.prototype[aMethod.selector._asSelector()];
  386. delete self.fn.prototype.methods[aMethod.selector];
  387. smalltalk.init(self);>
  388. !
  389. protocols
  390. | protocols |
  391. protocols := Array new.
  392. self methodDictionary do: [:each |
  393. (protocols includes: each category) ifFalse: [
  394. protocols add: each category]].
  395. ^protocols sort
  396. !
  397. protocolsDo: aBlock
  398. "Execute aBlock for each method category with
  399. its collection of methods in the sort order of category name."
  400. | methodsByCategory |
  401. methodsByCategory := Dictionary new.
  402. self methodDictionary values do: [:m |
  403. (methodsByCategory at: m category ifAbsentPut: [Array new])
  404. add: m].
  405. self protocols do: [:category |
  406. aBlock value: category value: (methodsByCategory at: category)]
  407. !
  408. allInstanceVariableNames
  409. | result |
  410. result := self instanceVariableNames copy.
  411. self superclass ifNotNil: [
  412. result addAll: self superclass allInstanceVariableNames].
  413. ^result
  414. !
  415. methodAt: aString
  416. <return smalltalk.methods(self)[aString]>
  417. !
  418. methodsFor: aString stamp: aStamp
  419. "Added for compatibility, right now ignores stamp."
  420. ^self methodsFor: aString
  421. !
  422. commentStamp: aStamp prior: prior
  423. ^self commentStamp
  424. ! !
  425. !Behavior methodsFor: 'compiling'!
  426. compile: aString
  427. self compile: aString category: ''
  428. !
  429. compile: aString category: anotherString
  430. | method |
  431. method := Compiler new load: aString forClass: self.
  432. method category: anotherString.
  433. self addCompiledMethod: method
  434. ! !
  435. !Behavior methodsFor: 'instance creation'!
  436. new
  437. ^self basicNew initialize
  438. !
  439. basicNew
  440. <return new self.fn()>
  441. !
  442. inheritsFrom: aClass
  443. ^aClass allSubclasses includes: self
  444. ! !
  445. Behavior subclass: #Class
  446. instanceVariableNames: ''
  447. category: 'Kernel'!
  448. !Class methodsFor: 'accessing'!
  449. category
  450. ^self package ifNil: ['Unclassified'] ifNotNil: [self package name]
  451. !
  452. rename: aString
  453. <
  454. smalltalk[aString] = self;
  455. delete smalltalk[self.className];
  456. self.className = aString;
  457. >
  458. !
  459. package
  460. <return self.pkg>
  461. !
  462. package: aPackage
  463. <self.pkg = aPackage>
  464. ! !
  465. !Class methodsFor: 'class creation'!
  466. subclass: aString instanceVariableNames: anotherString
  467. "Kept for compatibility."
  468. ^self subclass: aString instanceVariableNames: anotherString package: nil
  469. !
  470. subclass: aString instanceVariableNames: aString2 category: aString3
  471. "Kept for compatibility."
  472. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  473. !
  474. subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
  475. "Just ignore class variables and pools. Added for compatibility."
  476. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  477. !
  478. subclass: aString instanceVariableNames: aString2 package: aString3
  479. ^ClassBuilder new
  480. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  481. ! !
  482. !Class methodsFor: 'printing'!
  483. printString
  484. ^self name
  485. ! !
  486. !Class methodsFor: 'testing'!
  487. isClass
  488. ^true
  489. ! !
  490. Behavior subclass: #Metaclass
  491. instanceVariableNames: ''
  492. category: 'Kernel'!
  493. !Metaclass methodsFor: 'accessing'!
  494. instanceClass
  495. <return self.instanceClass>
  496. !
  497. instanceVariableNames: aCollection
  498. ClassBuilder new
  499. class: self instanceVariableNames: aCollection
  500. ! !
  501. !Metaclass methodsFor: 'printing'!
  502. printString
  503. ^self instanceClass name, ' class'
  504. ! !
  505. !Metaclass methodsFor: 'testing'!
  506. isMetaclass
  507. ^true
  508. ! !
  509. Object subclass: #CompiledMethod
  510. instanceVariableNames: ''
  511. category: 'Kernel'!
  512. !CompiledMethod methodsFor: 'accessing'!
  513. source
  514. ^(self basicAt: 'source') ifNil: ['']
  515. !
  516. source: aString
  517. self basicAt: 'source' put: aString
  518. !
  519. category
  520. ^(self basicAt: 'category') ifNil: ['']
  521. !
  522. category: aString
  523. self basicAt: 'category' put: aString
  524. !
  525. selector
  526. ^self basicAt: 'selector'
  527. !
  528. selector: aString
  529. self basicAt: 'selector' put: aString
  530. !
  531. fn
  532. ^self basicAt: 'fn'
  533. !
  534. fn: aBlock
  535. self basicAt: 'fn' put: aBlock
  536. !
  537. messageSends
  538. ^self basicAt: 'messageSends'
  539. !
  540. methodClass
  541. ^self basicAt: 'methodClass'
  542. !
  543. referencedClasses
  544. ^self basicAt: 'referencedClasses'
  545. !
  546. arguments
  547. <return self.args || []>
  548. ! !
  549. Object subclass: #Number
  550. instanceVariableNames: ''
  551. category: 'Kernel'!
  552. !Number methodsFor: 'arithmetic'!
  553. + aNumber
  554. "Inlined in the Compiler"
  555. <return self + aNumber>
  556. !
  557. - aNumber
  558. "Inlined in the Compiler"
  559. <return self - aNumber>
  560. !
  561. * aNumber
  562. "Inlined in the Compiler"
  563. <return self * aNumber>
  564. !
  565. / aNumber
  566. "Inlined in the Compiler"
  567. <return self / aNumber>
  568. !
  569. max: aNumber
  570. <return Math.max(self, aNumber);>
  571. !
  572. min: aNumber
  573. <return Math.min(self, aNumber);>
  574. !
  575. negated
  576. ^0 - self
  577. !
  578. \\ aNumber
  579. <return self % aNumber>
  580. ! !
  581. !Number methodsFor: 'comparing'!
  582. = aNumber
  583. aNumber class = self class ifFalse: [^false].
  584. <return Number(self) == aNumber>
  585. !
  586. > aNumber
  587. "Inlined in the Compiler"
  588. <return self >> aNumber>
  589. !
  590. < aNumber
  591. "Inlined in the Compiler"
  592. <return self < aNumber>
  593. !
  594. >= aNumber
  595. "Inlined in the Compiler"
  596. <return self >>= aNumber>
  597. !
  598. <= aNumber
  599. "Inlined in the Compiler"
  600. <return self <= aNumber>
  601. !
  602. == aNumber
  603. aNumber class = self class ifFalse: [^false].
  604. <return Number(self) === Number(aNumber)>
  605. ! !
  606. !Number methodsFor: 'converting'!
  607. rounded
  608. <return Math.round(self);>
  609. !
  610. truncated
  611. |result|
  612. self >= 0
  613. ifTrue: [<result = Math.floor(self);>]
  614. ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
  615. ^ result
  616. !
  617. to: aNumber
  618. | array first last count |
  619. first := self truncated.
  620. last := aNumber truncated + 1.
  621. count := 1.
  622. array := Array new.
  623. (last - first) timesRepeat: [
  624. array at: count put: first.
  625. count := count + 1.
  626. first := first + 1].
  627. ^array
  628. !
  629. asString
  630. ^self printString
  631. !
  632. asJavascript
  633. ^'(', self printString, ')'
  634. !
  635. atRandom
  636. ^(Random new next * self) truncated + 1
  637. !
  638. @ aNumber
  639. ^Point x: self y: aNumber
  640. !
  641. asPoint
  642. ^Point x: self y: self
  643. !
  644. asJSONObject
  645. ^self
  646. !
  647. to: stop by: step
  648. | array value pos |
  649. value := self.
  650. array := Array new.
  651. pos := 1.
  652. step = 0 ifTrue: [self error: 'step must be non-zero'].
  653. step < 0
  654. ifTrue: [[ value >= stop ] whileTrue: [
  655. array at: pos put: value.
  656. pos := pos + 1.
  657. value := value + step]]
  658. ifFalse: [[ value <= stop ] whileTrue: [
  659. array at: pos put: value.
  660. pos := pos + 1.
  661. value := value + step]].
  662. ^array
  663. !
  664. to: stop by: step do: aBlock
  665. | value |
  666. value := self.
  667. step = 0 ifTrue: [self error: 'step must be non-zero'].
  668. step < 0
  669. ifTrue: [[ value >= stop ] whileTrue: [
  670. aBlock value: value.
  671. value := value + step]]
  672. ifFalse: [[ value <= stop ] whileTrue: [
  673. aBlock value: value.
  674. value := value + step]]
  675. ! !
  676. !Number methodsFor: 'enumerating'!
  677. timesRepeat: aBlock
  678. | integer count |
  679. integer := self truncated.
  680. count := 1.
  681. [count > self] whileFalse: [
  682. aBlock value.
  683. count := count + 1]
  684. !
  685. to: stop do: aBlock
  686. "Evaluate aBlock for each number from self to aNumber."
  687. | nextValue |
  688. nextValue := self.
  689. [nextValue <= stop]
  690. whileTrue:
  691. [aBlock value: nextValue.
  692. nextValue := nextValue + 1]
  693. ! !
  694. !Number methodsFor: 'printing'!
  695. printString
  696. <return String(self)>
  697. !
  698. printShowingDecimalPlaces: placesDesired
  699. <return self.toFixed(placesDesired)>
  700. ! !
  701. !Number methodsFor: 'testing'!
  702. isNumber
  703. ^true
  704. !
  705. even
  706. ^ 0 = (self \\ 2)
  707. !
  708. odd
  709. ^ self even not
  710. ! !
  711. !Number methodsFor: 'timeouts/intervals'!
  712. clearInterval
  713. <clearInterval(Number(self))>
  714. !
  715. clearTimeout
  716. <clearTimeout(Number(self))>
  717. ! !
  718. !Number class methodsFor: 'instance creation'!
  719. pi
  720. <return Math.PI>
  721. ! !
  722. Object subclass: #BlockClosure
  723. instanceVariableNames: ''
  724. category: 'Kernel'!
  725. !BlockClosure methodsFor: 'accessing'!
  726. compiledSource
  727. <return self.toString()>
  728. ! !
  729. !BlockClosure methodsFor: 'controlling'!
  730. whileTrue: aBlock
  731. "inlined in the Compiler"
  732. <while(self()) {aBlock()}>
  733. !
  734. whileFalse: aBlock
  735. "inlined in the Compiler"
  736. <while(!!self()) {aBlock()}>
  737. !
  738. whileFalse
  739. "inlined in the Compiler"
  740. self whileFalse: []
  741. !
  742. whileTrue
  743. "inlined in the Compiler"
  744. self whileTrue: []
  745. ! !
  746. !BlockClosure methodsFor: 'error handling'!
  747. on: anErrorClass do: aBlock
  748. self try: self catch: [:error |
  749. (error isKindOf: anErrorClass)
  750. ifTrue: [aBlock value: error]
  751. ifFalse: [error signal]]
  752. ! !
  753. !BlockClosure methodsFor: 'evaluating'!
  754. value
  755. "inlined in the Compiler"
  756. <return self();>
  757. !
  758. value: anArg
  759. "inlined in the Compiler"
  760. <return self(anArg);>
  761. !
  762. value: firstArg value: secondArg
  763. "inlined in the Compiler"
  764. <return self(firstArg, secondArg);>
  765. !
  766. value: firstArg value: secondArg value: thirdArg
  767. "inlined in the Compiler"
  768. <return self(firstArg, secondArg, thirdArg);>
  769. !
  770. valueWithPossibleArguments: aCollection
  771. <return self.apply(null, aCollection);>
  772. !
  773. new
  774. "Use the receiver as a JS constructor.
  775. *Do not* use this method to instanciate Smalltalk objects!!"
  776. <return new self()>
  777. !
  778. applyTo: anObject arguments: aCollection
  779. <return self.apply(anObject, aCollection)>
  780. !
  781. timeToRun
  782. "Answer the number of milliseconds taken to execute this block."
  783. ^ Date millisecondsToRun: self
  784. ! !
  785. !BlockClosure methodsFor: 'timeout/interval'!
  786. valueWithTimeout: aNumber
  787. <return setTimeout(self, aNumber)>
  788. !
  789. valueWithInterval: aNumber
  790. <return setInterval(self, aNumber)>
  791. ! !
  792. Object subclass: #Boolean
  793. instanceVariableNames: ''
  794. category: 'Kernel'!
  795. !Boolean methodsFor: 'comparing'!
  796. = aBoolean
  797. aBoolean class = self class ifFalse: [^false].
  798. <return Boolean(self == true) == aBoolean>
  799. !
  800. == aBoolean
  801. aBoolean class = self class ifFalse: [^false].
  802. <return Boolean(self == true) === Boolean(aBoolean == true)>
  803. ! !
  804. !Boolean methodsFor: 'controlling'!
  805. ifTrue: aBlock
  806. "inlined in the Compiler"
  807. ^self ifTrue: aBlock ifFalse: []
  808. !
  809. ifFalse: aBlock
  810. "inlined in the Compiler"
  811. ^self ifTrue: [] ifFalse: aBlock
  812. !
  813. ifFalse: aBlock ifTrue: anotherBlock
  814. "inlined in the Compiler"
  815. ^self ifTrue: anotherBlock ifFalse: aBlock
  816. !
  817. ifTrue: aBlock ifFalse: anotherBlock
  818. "inlined in the Compiler"
  819. <
  820. if(self == true) {
  821. return aBlock();
  822. } else {
  823. return anotherBlock();
  824. }
  825. >
  826. !
  827. and: aBlock
  828. ^self = true
  829. ifTrue: aBlock
  830. ifFalse: [false]
  831. !
  832. or: aBlock
  833. ^self = true
  834. ifTrue: [true]
  835. ifFalse: aBlock
  836. !
  837. not
  838. ^self = false
  839. !
  840. & aBoolean
  841. <
  842. if(self == true) {
  843. return aBoolean;
  844. } else {
  845. return false;
  846. }
  847. >
  848. !
  849. | aBoolean
  850. <
  851. if(self == true) {
  852. return true;
  853. } else {
  854. return aBoolean;
  855. }
  856. >
  857. ! !
  858. !Boolean methodsFor: 'converting'!
  859. asJSONObject
  860. ^self
  861. ! !
  862. !Boolean methodsFor: 'copying'!
  863. shallowCopy
  864. ^self
  865. !
  866. deepCopy
  867. ^self
  868. ! !
  869. !Boolean methodsFor: 'printing'!
  870. printString
  871. <return self.toString()>
  872. ! !
  873. Object subclass: #Date
  874. instanceVariableNames: ''
  875. category: 'Kernel'!
  876. !Date commentStamp!
  877. The Date class is used to work with dates and times.!
  878. !Date methodsFor: 'accessing'!
  879. year
  880. <return self.getFullYear()>
  881. !
  882. month
  883. <return self.getMonth() + 1>
  884. !
  885. month: aNumber
  886. <self.setMonth(aNumber - 1)>
  887. !
  888. day
  889. ^self dayOfWeek
  890. !
  891. dayOfWeek
  892. <return self.getDay() + 1>
  893. !
  894. dayOfWeek: aNumber
  895. <return self.setDay(aNumber - 1)>
  896. !
  897. day: aNumber
  898. self day: aNumber
  899. !
  900. year: aNumber
  901. <self.setFullYear(aNumber)>
  902. !
  903. dayOfMonth
  904. <return self.getDate()>
  905. !
  906. dayOfMonth: aNumber
  907. <self.setDate(aNumber)>
  908. !
  909. time
  910. <return self.getTime()>
  911. !
  912. time: aNumber
  913. <self.setTime(aNumber)>
  914. !
  915. hours: aNumber
  916. <self.setHours(aNumber)>
  917. !
  918. minutes: aNumber
  919. <self.setMinutes(aNumber)>
  920. !
  921. seconds: aNumber
  922. <self.setSeconds(aNumber)>
  923. !
  924. milliseconds: aNumber
  925. <self.setMilliseconds(aNumber)>
  926. !
  927. hours
  928. <return self.getHours()>
  929. !
  930. minutes
  931. <return self.getMinutes()>
  932. !
  933. seconds
  934. <return self.getSeconds()>
  935. !
  936. milliseconds
  937. <return self.getMilliseconds()>
  938. ! !
  939. !Date methodsFor: 'arithmetic'!
  940. - aDate
  941. <return self - aDate>
  942. !
  943. + aDate
  944. <return self + aDate>
  945. ! !
  946. !Date methodsFor: 'comparing'!
  947. < aDate
  948. <return self < aDate>
  949. !
  950. > aDate
  951. <return self >> aDate>
  952. !
  953. <= aDate
  954. <return self <= aDate>
  955. !
  956. >= aDate
  957. <return self >>= aDate>
  958. ! !
  959. !Date methodsFor: 'converting'!
  960. asString
  961. <return self.toString()>
  962. !
  963. asMilliseconds
  964. ^self time
  965. !
  966. asDateString
  967. <return self.toDateString()>
  968. !
  969. asTimeString
  970. <return self.toTimeString()>
  971. !
  972. asLocaleString
  973. <return self.toLocaleString()>
  974. !
  975. asNumber
  976. ^self asMilliseconds
  977. !
  978. asJSONObject
  979. ^self
  980. ! !
  981. !Date methodsFor: 'printing'!
  982. printString
  983. ^self asString
  984. ! !
  985. !Date class methodsFor: 'instance creation'!
  986. new: anObject
  987. <return new Date(anObject)>
  988. !
  989. fromString: aString
  990. "Example: Date fromString('2011/04/15 00:00:00')"
  991. ^self new: aString
  992. !
  993. fromSeconds: aNumber
  994. ^self fromMilliseconds: aNumber * 1000
  995. !
  996. fromMilliseconds: aNumber
  997. ^self new: aNumber
  998. !
  999. today
  1000. ^self new
  1001. !
  1002. now
  1003. ^self today
  1004. !
  1005. millisecondsToRun: aBlock
  1006. | t |
  1007. t := Date now.
  1008. aBlock value.
  1009. ^Date now - t
  1010. ! !
  1011. Object subclass: #UndefinedObject
  1012. instanceVariableNames: ''
  1013. category: 'Kernel'!
  1014. !UndefinedObject methodsFor: 'class creation'!
  1015. subclass: aString instanceVariableNames: anotherString
  1016. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1017. !
  1018. subclass: aString instanceVariableNames: aString2 category: aString3
  1019. "Kept for compatibility."
  1020. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1021. !
  1022. subclass: aString instanceVariableNames: aString2 package: aString3
  1023. ^ClassBuilder new
  1024. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  1025. ! !
  1026. !UndefinedObject methodsFor: 'copying'!
  1027. shallowCopy
  1028. ^self
  1029. !
  1030. deepCopy
  1031. ^self
  1032. ! !
  1033. !UndefinedObject methodsFor: 'printing'!
  1034. printString
  1035. ^'nil'
  1036. ! !
  1037. !UndefinedObject methodsFor: 'testing'!
  1038. ifNil: aBlock
  1039. "inlined in the Compiler"
  1040. ^self ifNil: aBlock ifNotNil: []
  1041. !
  1042. ifNotNil: aBlock
  1043. "inlined in the Compiler"
  1044. ^self
  1045. !
  1046. ifNil: aBlock ifNotNil: anotherBlock
  1047. "inlined in the Compiler"
  1048. ^aBlock value
  1049. !
  1050. ifNotNil: aBlock ifNil: anotherBlock
  1051. "inlined in the Compiler"
  1052. ^anotherBlock value
  1053. !
  1054. isNil
  1055. ^true
  1056. !
  1057. notNil
  1058. ^false
  1059. ! !
  1060. !UndefinedObject class methodsFor: 'instance creation'!
  1061. new
  1062. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1063. ! !
  1064. Object subclass: #Collection
  1065. instanceVariableNames: ''
  1066. category: 'Kernel'!
  1067. !Collection methodsFor: 'accessing'!
  1068. size
  1069. self subclassResponsibility
  1070. !
  1071. readStream
  1072. ^self stream
  1073. !
  1074. writeStream
  1075. ^self stream
  1076. !
  1077. stream
  1078. ^self streamClass on: self
  1079. !
  1080. streamClass
  1081. ^self class streamClass
  1082. ! !
  1083. !Collection methodsFor: 'adding/removing'!
  1084. add: anObject
  1085. self subclassResponsibility
  1086. !
  1087. addAll: aCollection
  1088. aCollection do: [:each |
  1089. self add: each].
  1090. ^aCollection
  1091. !
  1092. remove: anObject
  1093. self subclassResponsibility
  1094. ! !
  1095. !Collection methodsFor: 'converting'!
  1096. asArray
  1097. | array index |
  1098. array := Array new.
  1099. index := 0.
  1100. self do: [:each |
  1101. index := index + 1.
  1102. array at: index put: each].
  1103. ^array
  1104. !
  1105. asSet
  1106. ^Set withAll: self
  1107. ! !
  1108. !Collection methodsFor: 'copying'!
  1109. , aCollection
  1110. ^self copy
  1111. addAll: aCollection;
  1112. yourself
  1113. !
  1114. copyWith: anObject
  1115. ^self copy add: anObject; yourself
  1116. !
  1117. copyWithAll: aCollection
  1118. ^self copy addAll: aCollection; yourself
  1119. !
  1120. copyWithoutAll: aCollection
  1121. "Answer a copy of the receiver that does not contain any elements
  1122. equal to those in aCollection."
  1123. ^ self reject: [:each | aCollection includes: each]
  1124. ! !
  1125. !Collection methodsFor: 'enumerating'!
  1126. do: aBlock
  1127. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  1128. !
  1129. collect: aBlock
  1130. | newCollection |
  1131. newCollection := self class new.
  1132. self do: [:each |
  1133. newCollection add: (aBlock value: each)].
  1134. ^newCollection
  1135. !
  1136. detect: aBlock
  1137. ^self detect: aBlock ifNone: [self errorNotFound]
  1138. !
  1139. detect: aBlock ifNone: anotherBlock
  1140. <
  1141. for(var i = 0; i < self.length; i++)
  1142. if(aBlock(self[i]))
  1143. return self[i];
  1144. return anotherBlock();
  1145. >
  1146. !
  1147. do: aBlock separatedBy: anotherBlock
  1148. | first |
  1149. first := true.
  1150. self do: [:each |
  1151. first
  1152. ifTrue: [first := false]
  1153. ifFalse: [anotherBlock value].
  1154. aBlock value: each]
  1155. !
  1156. inject: anObject into: aBlock
  1157. | result |
  1158. result := anObject.
  1159. self do: [:each |
  1160. result := aBlock value: result value: each].
  1161. ^result
  1162. !
  1163. reject: aBlock
  1164. ^self select: [:each | (aBlock value: each) = false]
  1165. !
  1166. select: aBlock
  1167. | stream |
  1168. stream := self class new writeStream.
  1169. self do: [:each |
  1170. (aBlock value: each) ifTrue: [
  1171. stream nextPut: each]].
  1172. ^stream contents
  1173. ! !
  1174. !Collection methodsFor: 'error handling'!
  1175. errorNotFound
  1176. self error: 'Object is not in the collection'
  1177. ! !
  1178. !Collection methodsFor: 'testing'!
  1179. includes: anObject
  1180. <
  1181. var i = self.length;
  1182. while (i--) {
  1183. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1184. }
  1185. return false
  1186. >
  1187. !
  1188. notEmpty
  1189. ^self isEmpty not
  1190. !
  1191. isEmpty
  1192. ^self size = 0
  1193. !
  1194. ifNotEmpty: aBlock
  1195. self notEmpty ifTrue: aBlock.
  1196. !
  1197. ifEmpty: aBlock
  1198. self isEmpty ifTrue: aBlock.
  1199. ! !
  1200. !Collection class methodsFor: 'accessing'!
  1201. streamClass
  1202. ^Stream
  1203. ! !
  1204. !Collection class methodsFor: 'instance creation'!
  1205. with: anObject
  1206. ^self new
  1207. add: anObject;
  1208. yourself
  1209. !
  1210. with: anObject with: anotherObject
  1211. ^self new
  1212. add: anObject;
  1213. add: anotherObject;
  1214. yourself
  1215. !
  1216. with: firstObject with: secondObject with: thirdObject
  1217. ^self new
  1218. add: firstObject;
  1219. add: secondObject;
  1220. add: thirdObject;
  1221. yourself
  1222. !
  1223. withAll: aCollection
  1224. ^self new
  1225. addAll: aCollection;
  1226. yourself
  1227. ! !
  1228. Collection subclass: #SequenceableCollection
  1229. instanceVariableNames: ''
  1230. category: 'Kernel'!
  1231. !SequenceableCollection methodsFor: 'accessing'!
  1232. at: anIndex
  1233. ^self at: anIndex ifAbsent: [
  1234. self errorNotFound]
  1235. !
  1236. at: anIndex ifAbsent: aBlock
  1237. self subclassResponsibility
  1238. !
  1239. at: anIndex put: anObject
  1240. self subclassResponsibility
  1241. !
  1242. first
  1243. ^self at: 1
  1244. !
  1245. fourth
  1246. ^self at: 4
  1247. !
  1248. last
  1249. ^self at: self size
  1250. !
  1251. second
  1252. ^self at: 2
  1253. !
  1254. third
  1255. ^self at: 3
  1256. !
  1257. allButFirst
  1258. ^self copyFrom: 2 to: self size
  1259. !
  1260. allButLast
  1261. ^self copyFrom: 1 to: self size - 1
  1262. !
  1263. indexOf: anObject
  1264. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1265. !
  1266. indexOf: anObject ifAbsent: aBlock
  1267. <
  1268. for(var i=0;i<self.length;i++){
  1269. if(self[i].__eq(anObject)) {return i+1}
  1270. }
  1271. return aBlock();
  1272. >
  1273. !
  1274. indexOf: anObject startingAt: start ifAbsent: aBlock
  1275. <
  1276. for(var i=start-1;i<self.length;i++){
  1277. if(self[i].__eq(anObject)) {return i+1}
  1278. }
  1279. return aBlock();
  1280. >
  1281. !
  1282. indexOf: anObject startingAt: start
  1283. "Answer the index of the first occurence of anElement after start
  1284. within the receiver. If the receiver does not contain anElement,
  1285. answer 0."
  1286. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1287. ! !
  1288. !SequenceableCollection methodsFor: 'adding'!
  1289. removeLast
  1290. self remove: self last
  1291. !
  1292. addLast: anObject
  1293. self add: anObject
  1294. ! !
  1295. !SequenceableCollection methodsFor: 'converting'!
  1296. reversed
  1297. self subclassResponsibility
  1298. ! !
  1299. !SequenceableCollection methodsFor: 'copying'!
  1300. copyFrom: anIndex to: anotherIndex
  1301. self subclassResponsibility
  1302. ! !
  1303. !SequenceableCollection methodsFor: 'enumerating'!
  1304. withIndexDo: aBlock
  1305. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1306. ! !
  1307. SequenceableCollection subclass: #String
  1308. instanceVariableNames: ''
  1309. category: 'Kernel'!
  1310. !String methodsFor: 'accessing'!
  1311. size
  1312. <return self.length>
  1313. !
  1314. at: anIndex
  1315. <return self[anIndex - 1]>
  1316. !
  1317. at: anIndex put: anObject
  1318. self errorReadOnly
  1319. !
  1320. at: anIndex ifAbsent: aBlock
  1321. (self at: anIndex) ifNil: [aBlock]
  1322. !
  1323. escaped
  1324. <return escape(self)>
  1325. !
  1326. unescaped
  1327. <return unescape(self)>
  1328. !
  1329. asciiValue
  1330. <return self.charCodeAt(0);>
  1331. ! !
  1332. !String methodsFor: 'adding'!
  1333. add: anObject
  1334. self errorReadOnly
  1335. !
  1336. remove: anObject
  1337. self errorReadOnly
  1338. ! !
  1339. !String methodsFor: 'comparing'!
  1340. = aString
  1341. aString class = self class ifFalse: [^false].
  1342. <return String(self) == aString>
  1343. !
  1344. > aString
  1345. <return String(self) >> aString>
  1346. !
  1347. < aString
  1348. <return String(self) < aString>
  1349. !
  1350. >= aString
  1351. <return String(self) >>= aString>
  1352. !
  1353. <= aString
  1354. <return String(self) <= aString>
  1355. !
  1356. == aString
  1357. aString class = self class ifFalse: [^false].
  1358. <return String(self) === String(aString)>
  1359. ! !
  1360. !String methodsFor: 'converting'!
  1361. asSelector
  1362. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1363. | selector |
  1364. selector := '_', self.
  1365. selector := selector replace: ':' with: '_'.
  1366. selector := selector replace: '[+]' with: '_plus'.
  1367. selector := selector replace: '-' with: '_minus'.
  1368. selector := selector replace: '[*]' with: '_star'.
  1369. selector := selector replace: '[/]' with: '_slash'.
  1370. selector := selector replace: '>' with: '_gt'.
  1371. selector := selector replace: '<' with: '_lt'.
  1372. selector := selector replace: '=' with: '_eq'.
  1373. selector := selector replace: ',' with: '_comma'.
  1374. selector := selector replace: '[@]' with: '_at'.
  1375. ^selector
  1376. !
  1377. asJavascript
  1378. <
  1379. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1380. return "unescape(\"" + escape(self) + "\")";
  1381. else
  1382. return "\"" + self + "\"";
  1383. >
  1384. !
  1385. tokenize: aString
  1386. <return self.split(aString)>
  1387. !
  1388. asString
  1389. ^self
  1390. !
  1391. asNumber
  1392. <return Number(self)>
  1393. !
  1394. asJSONObject
  1395. ^self
  1396. !
  1397. asLowercase
  1398. <return self.toLowerCase()>
  1399. !
  1400. asUppercase
  1401. <return self.toUpperCase()>
  1402. !
  1403. reversed
  1404. <return self.split("").reverse().join("")>
  1405. !
  1406. asJavaScriptSelector
  1407. ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
  1408. ! !
  1409. !String methodsFor: 'copying'!
  1410. , aString
  1411. <return self + aString>
  1412. !
  1413. copyFrom: anIndex to: anotherIndex
  1414. <return self.substring(anIndex - 1, anotherIndex)>
  1415. !
  1416. shallowCopy
  1417. ^self class fromString: self
  1418. !
  1419. deepCopy
  1420. ^self shallowCopy
  1421. ! !
  1422. !String methodsFor: 'error handling'!
  1423. errorReadOnly
  1424. self error: 'Object is read-only'
  1425. ! !
  1426. !String methodsFor: 'printing'!
  1427. printString
  1428. ^'''', self, ''''
  1429. !
  1430. printNl
  1431. <console.log(self)>
  1432. ! !
  1433. !String methodsFor: 'regular expressions'!
  1434. replace: aString with: anotherString
  1435. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1436. !
  1437. replaceRegexp: aRegexp with: aString
  1438. <return self.replace(aRegexp, aString)>
  1439. !
  1440. match: aRegexp
  1441. <return self.search(aRegexp) !!= -1>
  1442. !
  1443. trimLeft: separators
  1444. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1445. !
  1446. trimRight: separators
  1447. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1448. !
  1449. trimLeft
  1450. ^self trimLeft: '\s'
  1451. !
  1452. trimRight
  1453. ^self trimRight: '\s'
  1454. !
  1455. trimBoth
  1456. ^self trimBoth: '\s'
  1457. !
  1458. trimBoth: separators
  1459. ^(self trimLeft: separators) trimRight: separators
  1460. ! !
  1461. !String methodsFor: 'split join'!
  1462. join: aCollection
  1463. ^ String
  1464. streamContents: [:stream | aCollection
  1465. do: [:each | stream nextPutAll: each asString]
  1466. separatedBy: [stream nextPutAll: self]]
  1467. !
  1468. lineIndicesDo: aBlock
  1469. "execute aBlock with 3 arguments for each line:
  1470. - start index of line
  1471. - end index of line without line delimiter
  1472. - end index of line including line delimiter(s) CR, LF or CRLF"
  1473. | cr lf start sz nextLF nextCR |
  1474. start := 1.
  1475. sz := self size.
  1476. cr := String cr.
  1477. nextCR := self indexOf: cr startingAt: 1.
  1478. lf := String lf.
  1479. nextLF := self indexOf: lf startingAt: 1.
  1480. [ start <= sz ] whileTrue: [
  1481. (nextLF = 0 and: [ nextCR = 0 ])
  1482. ifTrue: [ "No more CR, nor LF, the string is over"
  1483. aBlock value: start value: sz value: sz.
  1484. ^self ].
  1485. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1486. ifTrue: [ "Found a LF"
  1487. aBlock value: start value: nextLF - 1 value: nextLF.
  1488. start := 1 + nextLF.
  1489. nextLF := self indexOf: lf startingAt: start ]
  1490. ifFalse: [ 1 + nextCR = nextLF
  1491. ifTrue: [ "Found a CR-LF pair"
  1492. aBlock value: start value: nextCR - 1 value: nextLF.
  1493. start := 1 + nextLF.
  1494. nextCR := self indexOf: cr startingAt: start.
  1495. nextLF := self indexOf: lf startingAt: start ]
  1496. ifFalse: [ "Found a CR"
  1497. aBlock value: start value: nextCR - 1 value: nextCR.
  1498. start := 1 + nextCR.
  1499. nextCR := self indexOf: cr startingAt: start ]]]
  1500. !
  1501. linesDo: aBlock
  1502. "Execute aBlock with each line in this string. The terminating line
  1503. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1504. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1505. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1506. !
  1507. lines
  1508. "Answer an array of lines composing this receiver without the line ending delimiters."
  1509. | lines |
  1510. lines := Array new.
  1511. self linesDo: [:aLine | lines add: aLine].
  1512. ^lines
  1513. !
  1514. lineNumber: anIndex
  1515. "Answer a string containing the characters in the given line number."
  1516. | lineCount |
  1517. lineCount := 0.
  1518. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1519. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1520. ^nil
  1521. ! !
  1522. !String methodsFor: 'testing'!
  1523. isString
  1524. ^true
  1525. !
  1526. includesSubString: subString
  1527. < return self.indexOf(subString) !!= -1 >
  1528. ! !
  1529. !String class methodsFor: 'accessing'!
  1530. streamClass
  1531. ^StringStream
  1532. !
  1533. cr
  1534. <return '\r'>
  1535. !
  1536. lf
  1537. <return '\n'>
  1538. !
  1539. space
  1540. <return ' '>
  1541. !
  1542. tab
  1543. <return '\t'>
  1544. !
  1545. crlf
  1546. <return '\r\n'>
  1547. ! !
  1548. !String class methodsFor: 'instance creation'!
  1549. fromString: aString
  1550. <return new self.fn(aString)>
  1551. !
  1552. streamContents: blockWithArg
  1553. |stream|
  1554. stream := (self streamClass on: String new).
  1555. blockWithArg value: stream.
  1556. ^ stream contents
  1557. !
  1558. value: aUTFCharCode
  1559. <return String.fromCharCode(aUTFCharCode);>
  1560. ! !
  1561. SequenceableCollection subclass: #Array
  1562. instanceVariableNames: ''
  1563. category: 'Kernel'!
  1564. !Array methodsFor: 'accessing'!
  1565. size
  1566. <return self.length>
  1567. !
  1568. at: anIndex put: anObject
  1569. <return self[anIndex - 1] = anObject>
  1570. !
  1571. at: anIndex ifAbsent: aBlock
  1572. <
  1573. var value = self[anIndex - 1];
  1574. if(value === undefined) {
  1575. return aBlock();
  1576. } else {
  1577. return value;
  1578. }
  1579. >
  1580. ! !
  1581. !Array methodsFor: 'adding/removing'!
  1582. add: anObject
  1583. <self.push(anObject); return anObject;>
  1584. !
  1585. remove: anObject
  1586. <
  1587. for(var i=0;i<self.length;i++) {
  1588. if(self[i] == anObject) {
  1589. self.splice(i,1);
  1590. break;
  1591. }
  1592. }
  1593. >
  1594. !
  1595. removeFrom: aNumber to: anotherNumber
  1596. <self.splice(aNumber - 1,anotherNumber - 1)>
  1597. ! !
  1598. !Array methodsFor: 'comparing'!
  1599. = aCollection
  1600. (self class = aCollection class and: [
  1601. self size = aCollection size]) ifFalse: [^false].
  1602. self withIndexDo: [:each :i |
  1603. (aCollection at: i) = each ifFalse: [^false]].
  1604. ^true
  1605. ! !
  1606. !Array methodsFor: 'converting'!
  1607. asJavascript
  1608. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1609. !
  1610. asJSONObject
  1611. ^self collect: [:each | each asJSONObject]
  1612. !
  1613. reversed
  1614. <return self._copy().reverse()>
  1615. ! !
  1616. !Array methodsFor: 'copying'!
  1617. shallowCopy
  1618. | newCollection |
  1619. newCollection := self class new.
  1620. self do: [:each | newCollection add: each].
  1621. ^newCollection
  1622. !
  1623. deepCopy
  1624. | newCollection |
  1625. newCollection := self class new.
  1626. self do: [:each | newCollection add: each deepCopy].
  1627. ^newCollection
  1628. !
  1629. copyFrom: anIndex to: anotherIndex
  1630. | array |
  1631. array := self class new.
  1632. anIndex to: anotherIndex do: [:each |
  1633. array add: (self at: each)].
  1634. ^array
  1635. ! !
  1636. !Array methodsFor: 'enumerating'!
  1637. join: aString
  1638. <return self.join(aString)>
  1639. !
  1640. sort
  1641. ^self basicPerform: 'sort'
  1642. !
  1643. sort: aBlock
  1644. <
  1645. return self.sort(function(a, b) {
  1646. if(aBlock(a,b)) {return -1} else {return 1}
  1647. })
  1648. >
  1649. !
  1650. sorted
  1651. ^self copy sort
  1652. !
  1653. sorted: aBlock
  1654. ^self copy sort: aBlock
  1655. !
  1656. printString
  1657. | str |
  1658. str := '' writeStream.
  1659. str nextPutAll: super printString, ' ('.
  1660. self
  1661. do: [:each | str nextPutAll: each printString]
  1662. separatedBy: [str nextPutAll: ' '].
  1663. str nextPutAll: ')'.
  1664. ^str contents
  1665. ! !
  1666. Object subclass: #RegularExpression
  1667. instanceVariableNames: ''
  1668. category: 'Kernel'!
  1669. !RegularExpression methodsFor: 'evaluating'!
  1670. compile: aString
  1671. <return self.compile(aString)>
  1672. !
  1673. exec: aString
  1674. <return self.exec(aString) || nil>
  1675. !
  1676. test: aString
  1677. <return self.test(aString)>
  1678. ! !
  1679. !RegularExpression class methodsFor: 'instance creation'!
  1680. fromString: aString flag: anotherString
  1681. <return new RegExp(aString, anotherString)>
  1682. !
  1683. fromString: aString
  1684. ^self fromString: aString flag: ''
  1685. ! !
  1686. Object subclass: #Error
  1687. instanceVariableNames: 'messageText'
  1688. category: 'Kernel'!
  1689. !Error methodsFor: 'accessing'!
  1690. messageText
  1691. ^messageText
  1692. !
  1693. messageText: aString
  1694. messageText := aString
  1695. !
  1696. context
  1697. <return self.context>
  1698. ! !
  1699. !Error methodsFor: 'signaling'!
  1700. signal
  1701. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1702. ! !
  1703. !Error class methodsFor: 'instance creation'!
  1704. signal: aString
  1705. ^self new
  1706. messageText: aString;
  1707. signal
  1708. ! !
  1709. Object subclass: #MethodContext
  1710. instanceVariableNames: ''
  1711. category: 'Kernel'!
  1712. !MethodContext methodsFor: 'accessing'!
  1713. receiver
  1714. <return self.receiver>
  1715. !
  1716. selector
  1717. <return smalltalk.convertSelector(self.selector)>
  1718. !
  1719. home
  1720. <return self.homeContext>
  1721. !
  1722. temps
  1723. <return self.temps>
  1724. !
  1725. printString
  1726. ^super printString, '(', self asString, ')'
  1727. !
  1728. asString
  1729. ^self receiver class printString, ' >> ', self selector
  1730. ! !
  1731. Object subclass: #Association
  1732. instanceVariableNames: 'key value'
  1733. category: 'Kernel'!
  1734. !Association methodsFor: 'accessing'!
  1735. key: aKey
  1736. key := aKey
  1737. !
  1738. key
  1739. ^key
  1740. !
  1741. value: aValue
  1742. value := aValue
  1743. !
  1744. value
  1745. ^value
  1746. ! !
  1747. !Association methodsFor: 'comparing'!
  1748. = anAssociation
  1749. ^self class = anAssociation class and: [
  1750. self key = anAssociation key and: [
  1751. self value = anAssociation value]]
  1752. ! !
  1753. !Association class methodsFor: 'instance creation'!
  1754. key: aKey value: aValue
  1755. ^self new
  1756. key: aKey;
  1757. value: aValue;
  1758. yourself
  1759. ! !
  1760. Collection subclass: #Dictionary
  1761. instanceVariableNames: 'keys'
  1762. category: 'Kernel'!
  1763. !Dictionary methodsFor: 'accessing'!
  1764. size
  1765. ^keys size
  1766. !
  1767. associations
  1768. | associations |
  1769. associations := #().
  1770. keys do: [:each |
  1771. associations add: (Association key: each value: (self at: each))].
  1772. ^associations
  1773. !
  1774. keys
  1775. ^keys copy
  1776. !
  1777. values
  1778. ^keys collect: [:each | self at: each]
  1779. !
  1780. at: aKey put: aValue
  1781. (keys includes: aKey) ifFalse: [keys add: aKey].
  1782. ^self basicAt: aKey put: aValue
  1783. !
  1784. at: aKey ifAbsent: aBlock
  1785. ^(self keys includes: aKey)
  1786. ifTrue: [self basicAt: aKey]
  1787. ifFalse: aBlock
  1788. !
  1789. at: aKey ifAbsentPut: aBlock
  1790. ^self at: aKey ifAbsent: [
  1791. self at: aKey put: aBlock value]
  1792. !
  1793. at: aKey ifPresent: aBlock
  1794. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1795. !
  1796. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1797. ^(self basicAt: aKey)
  1798. ifNil: anotherBlock
  1799. ifNotNil: [aBlock value: (self at: aKey)]
  1800. !
  1801. at: aKey
  1802. ^self at: aKey ifAbsent: [self errorNotFound]
  1803. ! !
  1804. !Dictionary methodsFor: 'adding/removing'!
  1805. add: anAssociation
  1806. self at: anAssociation key put: anAssociation value
  1807. !
  1808. addAll: aDictionary
  1809. super addAll: aDictionary associations.
  1810. ^aDictionary
  1811. !
  1812. remove: aKey
  1813. self removeKey: aKey
  1814. !
  1815. removeKey: aKey
  1816. keys remove: aKey
  1817. ! !
  1818. !Dictionary methodsFor: 'comparing'!
  1819. = aDictionary
  1820. self class = aDictionary class ifFalse: [^false].
  1821. self size = aDictionary size ifFalse: [^false].
  1822. ^self associations = aDictionary associations
  1823. ! !
  1824. !Dictionary methodsFor: 'converting'!
  1825. asJSONObject
  1826. | object |
  1827. object := Object new.
  1828. self keysAndValuesDo: [:key :value |
  1829. object basicAt: key put: value asJSONObject].
  1830. ^object
  1831. ! !
  1832. !Dictionary methodsFor: 'copying'!
  1833. shallowCopy
  1834. | copy |
  1835. copy := self class new.
  1836. self associationsDo: [:each |
  1837. copy at: each key put: each value].
  1838. ^copy
  1839. !
  1840. , aCollection
  1841. self shouldNotImplement
  1842. !
  1843. copyFrom: anIndex to: anotherIndex
  1844. self shouldNotImplement
  1845. ! !
  1846. !Dictionary methodsFor: 'enumerating'!
  1847. associationsDo: aBlock
  1848. self associations do: aBlock
  1849. !
  1850. keysAndValuesDo: aBlock
  1851. self associationsDo: [:each |
  1852. aBlock value: each key value: each value]
  1853. !
  1854. do: aBlock
  1855. self values do: aBlock
  1856. !
  1857. select: aBlock
  1858. | newDict |
  1859. newDict := self class new.
  1860. self keysAndValuesDo: [:key :value |
  1861. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1862. ^newDict
  1863. !
  1864. collect: aBlock
  1865. | newDict |
  1866. newDict := self class new.
  1867. self keysAndValuesDo: [:key :value |
  1868. newDict at: key put: (aBlock value: value)].
  1869. ^newDict
  1870. !
  1871. detect: aBlock ifNone: anotherBlock
  1872. ^self values detect: aBlock ifNone: anotherBlock
  1873. !
  1874. includes: anObject
  1875. ^self values includes: anObject
  1876. ! !
  1877. !Dictionary methodsFor: 'initialization'!
  1878. initialize
  1879. super initialize.
  1880. keys := #()
  1881. ! !
  1882. !Dictionary methodsFor: 'printing'!
  1883. printString
  1884. ^ String streamContents: [:aStream|
  1885. aStream
  1886. nextPutAll: super printString;
  1887. nextPutAll: '('.
  1888. self associations
  1889. do: [:anAssociation|
  1890. aStream
  1891. nextPutAll: anAssociation key printString;
  1892. nextPutAll: ' -> ';
  1893. nextPutAll: anAssociation value printString]
  1894. separatedBy: [aStream nextPutAll: ' , '].
  1895. aStream nextPutAll: ')'.
  1896. ]
  1897. ! !
  1898. !Dictionary class methodsFor: 'instance creation'!
  1899. fromPairs: aCollection
  1900. | dict |
  1901. dict := self new.
  1902. aCollection do: [:each | dict add: each].
  1903. ^dict
  1904. ! !
  1905. Object subclass: #ClassBuilder
  1906. instanceVariableNames: ''
  1907. category: 'Kernel'!
  1908. !ClassBuilder methodsFor: 'class creation'!
  1909. superclass: aClass subclass: aString
  1910. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  1911. !
  1912. class: aClass instanceVariableNames: aString
  1913. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1914. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1915. self setupClass: aClass
  1916. !
  1917. superclass: aClass subclass: aString instanceVariableNames: aString2 module: aString3
  1918. | newClass |
  1919. newClass := self addSubclassOf: aClass
  1920. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1921. module: (aString3 ifNil: ['unclassified']).
  1922. self setupClass: newClass
  1923. !
  1924. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  1925. | newClass |
  1926. newClass := self addSubclassOf: aClass
  1927. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1928. package: (aString3 ifNil: ['unclassified']).
  1929. self setupClass: newClass
  1930. ! !
  1931. !ClassBuilder methodsFor: 'private'!
  1932. instanceVariableNamesFor: aString
  1933. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1934. !
  1935. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1936. <smalltalk.addClass(aString, aClass, aCollection);
  1937. return smalltalk[aString]>
  1938. !
  1939. setupClass: aClass
  1940. <smalltalk.init(aClass);>
  1941. !
  1942. addSubclassOf: aClass named: aString instanceVariableNames: aCollection module: moduleName
  1943. <smalltalk.addClass(aString, aClass, aCollection, moduleName);
  1944. return smalltalk[aString]>
  1945. !
  1946. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  1947. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  1948. return smalltalk[aString]>
  1949. ! !
  1950. Object subclass: #ClassCategoryReader
  1951. instanceVariableNames: 'class category chunkParser'
  1952. category: 'Kernel'!
  1953. !ClassCategoryReader methodsFor: 'accessing'!
  1954. class: aClass category: aString
  1955. class := aClass.
  1956. category := aString
  1957. ! !
  1958. !ClassCategoryReader methodsFor: 'fileIn'!
  1959. scanFrom: aChunkParser
  1960. | chunk |
  1961. [chunk := aChunkParser nextChunk.
  1962. chunk isEmpty] whileFalse: [
  1963. self compileMethod: chunk]
  1964. ! !
  1965. !ClassCategoryReader methodsFor: 'initialization'!
  1966. initialize
  1967. super initialize.
  1968. chunkParser := ChunkParser new.
  1969. ! !
  1970. !ClassCategoryReader methodsFor: 'private'!
  1971. compileMethod: aString
  1972. | method |
  1973. method := Compiler new load: aString forClass: class.
  1974. method category: category.
  1975. class addCompiledMethod: method
  1976. ! !
  1977. Object subclass: #Stream
  1978. instanceVariableNames: 'collection position streamSize'
  1979. category: 'Kernel'!
  1980. !Stream methodsFor: 'accessing'!
  1981. collection
  1982. ^collection
  1983. !
  1984. setCollection: aCollection
  1985. collection := aCollection
  1986. !
  1987. position
  1988. ^position ifNil: [position := 0]
  1989. !
  1990. position: anInteger
  1991. position := anInteger
  1992. !
  1993. streamSize
  1994. ^streamSize
  1995. !
  1996. setStreamSize: anInteger
  1997. streamSize := anInteger
  1998. !
  1999. contents
  2000. ^self collection
  2001. copyFrom: 1
  2002. to: self streamSize
  2003. !
  2004. size
  2005. ^self streamSize
  2006. ! !
  2007. !Stream methodsFor: 'actions'!
  2008. reset
  2009. self position: 0
  2010. !
  2011. close
  2012. !
  2013. flush
  2014. !
  2015. resetContents
  2016. self reset.
  2017. self setStreamSize: 0
  2018. ! !
  2019. !Stream methodsFor: 'enumerating'!
  2020. do: aBlock
  2021. [self atEnd] whileFalse: [aBlock value: self next]
  2022. ! !
  2023. !Stream methodsFor: 'positioning'!
  2024. setToEnd
  2025. self position: self size
  2026. !
  2027. skip: anInteger
  2028. self position: ((self position + anInteger) min: self size max: 0)
  2029. ! !
  2030. !Stream methodsFor: 'reading'!
  2031. next
  2032. self position: self position + 1.
  2033. ^collection at: self position
  2034. !
  2035. next: anInteger
  2036. | tempCollection |
  2037. tempCollection := self collection class new.
  2038. anInteger timesRepeat: [
  2039. self atEnd ifFalse: [
  2040. tempCollection add: self next]].
  2041. ^tempCollection
  2042. !
  2043. peek
  2044. ^self atEnd ifFalse: [
  2045. self collection at: self position + 1]
  2046. ! !
  2047. !Stream methodsFor: 'testing'!
  2048. atEnd
  2049. ^self position = self size
  2050. !
  2051. atStart
  2052. ^self position = 0
  2053. !
  2054. isEmpty
  2055. ^self size = 0
  2056. ! !
  2057. !Stream methodsFor: 'writing'!
  2058. nextPut: anObject
  2059. self position: self position + 1.
  2060. self collection at: self position put: anObject.
  2061. self setStreamSize: (self streamSize max: self position)
  2062. !
  2063. nextPutAll: aCollection
  2064. aCollection do: [:each |
  2065. self nextPut: each]
  2066. ! !
  2067. !Stream class methodsFor: 'instance creation'!
  2068. on: aCollection
  2069. ^self new
  2070. setCollection: aCollection;
  2071. setStreamSize: aCollection size;
  2072. yourself
  2073. ! !
  2074. Stream subclass: #StringStream
  2075. instanceVariableNames: ''
  2076. category: 'Kernel'!
  2077. !StringStream methodsFor: 'reading'!
  2078. next: anInteger
  2079. | tempCollection |
  2080. tempCollection := self collection class new.
  2081. anInteger timesRepeat: [
  2082. self atEnd ifFalse: [
  2083. tempCollection := tempCollection, self next]].
  2084. ^tempCollection
  2085. ! !
  2086. !StringStream methodsFor: 'writing'!
  2087. nextPut: aString
  2088. self nextPutAll: aString
  2089. !
  2090. nextPutAll: aString
  2091. self setCollection:
  2092. (self collection copyFrom: 1 to: self position),
  2093. aString,
  2094. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  2095. self position: self position + aString size.
  2096. self setStreamSize: (self streamSize max: self position)
  2097. !
  2098. cr
  2099. ^self nextPutAll: String cr
  2100. !
  2101. crlf
  2102. ^self nextPutAll: String crlf
  2103. !
  2104. lf
  2105. ^self nextPutAll: String lf
  2106. !
  2107. space
  2108. self nextPut: ' '
  2109. ! !
  2110. Object subclass: #ClassCommentReader
  2111. instanceVariableNames: 'class chunkParser'
  2112. category: 'Kernel'!
  2113. !ClassCommentReader methodsFor: 'accessing'!
  2114. class: aClass
  2115. class := aClass
  2116. ! !
  2117. !ClassCommentReader methodsFor: 'fileIn'!
  2118. scanFrom: aChunkParser
  2119. | chunk |
  2120. chunk := aChunkParser nextChunk.
  2121. chunk isEmpty ifFalse: [
  2122. self setComment: chunk].
  2123. ! !
  2124. !ClassCommentReader methodsFor: 'initialization'!
  2125. initialize
  2126. super initialize.
  2127. chunkParser := ChunkParser new.
  2128. ! !
  2129. !ClassCommentReader methodsFor: 'private'!
  2130. setComment: aString
  2131. class comment: aString
  2132. ! !
  2133. Object subclass: #Random
  2134. instanceVariableNames: ''
  2135. category: 'Kernel'!
  2136. !Random methodsFor: 'accessing'!
  2137. next
  2138. <return Math.random()>
  2139. !
  2140. next: anInteger
  2141. ^(1 to: anInteger) collect: [:each | self next]
  2142. ! !
  2143. Object subclass: #Point
  2144. instanceVariableNames: 'x y'
  2145. category: 'Kernel'!
  2146. !Point methodsFor: 'accessing'!
  2147. x
  2148. ^x
  2149. !
  2150. y
  2151. ^y
  2152. !
  2153. y: aNumber
  2154. y := aNumber
  2155. !
  2156. x: aNumber
  2157. x := aNumber
  2158. ! !
  2159. !Point methodsFor: 'arithmetic'!
  2160. * aPoint
  2161. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2162. !
  2163. + aPoint
  2164. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2165. !
  2166. - aPoint
  2167. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2168. !
  2169. / aPoint
  2170. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2171. !
  2172. = aPoint
  2173. ^aPoint class = self class and: [
  2174. (aPoint x = self x) & (aPoint y = self y)]
  2175. ! !
  2176. !Point methodsFor: 'converting'!
  2177. asPoint
  2178. ^self
  2179. ! !
  2180. !Point class methodsFor: 'instance creation'!
  2181. x: aNumber y: anotherNumber
  2182. ^self new
  2183. x: aNumber;
  2184. y: anotherNumber;
  2185. yourself
  2186. ! !
  2187. Object subclass: #Message
  2188. instanceVariableNames: 'selector arguments'
  2189. category: 'Kernel'!
  2190. !Message methodsFor: 'accessing'!
  2191. selector
  2192. ^selector
  2193. !
  2194. selector: aString
  2195. selector := aString
  2196. !
  2197. arguments: anArray
  2198. arguments := anArray
  2199. !
  2200. arguments
  2201. ^arguments
  2202. ! !
  2203. !Message methodsFor: 'printing'!
  2204. printString
  2205. ^ String streamContents: [:aStream|
  2206. aStream
  2207. nextPutAll: super printString;
  2208. nextPutAll: '(';
  2209. nextPutAll: selector;
  2210. nextPutAll: ')' ]
  2211. ! !
  2212. !Message class methodsFor: 'instance creation'!
  2213. selector: aString arguments: anArray
  2214. ^self new
  2215. selector: aString;
  2216. arguments: anArray;
  2217. yourself
  2218. ! !
  2219. Error subclass: #MessageNotUnderstood
  2220. instanceVariableNames: 'message receiver'
  2221. category: 'Kernel'!
  2222. !MessageNotUnderstood methodsFor: 'accessing'!
  2223. message
  2224. ^message
  2225. !
  2226. message: aMessage
  2227. message := aMessage
  2228. !
  2229. receiver
  2230. ^receiver
  2231. !
  2232. receiver: anObject
  2233. receiver := anObject
  2234. !
  2235. messageText
  2236. ^self receiver asString, ' does not understand #', self message selector
  2237. ! !
  2238. Object subclass: #ErrorHandler
  2239. instanceVariableNames: ''
  2240. category: 'Kernel'!
  2241. !ErrorHandler methodsFor: 'error handling'!
  2242. handleError: anError
  2243. anError context ifNotNil: [self logErrorContext: anError context].
  2244. self logError: anError
  2245. ! !
  2246. !ErrorHandler methodsFor: 'private'!
  2247. logContext: aContext
  2248. aContext home ifNotNil: [
  2249. self logContext: aContext home].
  2250. self log: aContext receiver asString, '>>', aContext selector
  2251. !
  2252. logErrorContext: aContext
  2253. aContext ifNotNil: [
  2254. aContext home ifNotNil: [
  2255. self logContext: aContext home]]
  2256. !
  2257. logError: anError
  2258. self log: anError messageText
  2259. !
  2260. log: aString
  2261. console log: aString
  2262. ! !
  2263. ErrorHandler class instanceVariableNames: 'current'!
  2264. !ErrorHandler class methodsFor: 'accessing'!
  2265. current
  2266. ^current ifNil: [current := self new]
  2267. !
  2268. setCurrent: anHandler
  2269. current := anHandler
  2270. ! !
  2271. !ErrorHandler class methodsFor: 'initialization'!
  2272. initialize
  2273. self register
  2274. !
  2275. register
  2276. ErrorHandler setCurrent: self new
  2277. ! !
  2278. Object subclass: #JSObjectProxy
  2279. instanceVariableNames: 'jsObject'
  2280. category: 'Kernel'!
  2281. !JSObjectProxy methodsFor: 'accessing'!
  2282. jsObject: aJSObject
  2283. jsObject := aJSObject
  2284. !
  2285. jsObject
  2286. ^jsObject
  2287. !
  2288. at: aString
  2289. <return self['@jsObject'][aString]>
  2290. !
  2291. at: aString put: anObject
  2292. <self['@jsObject'][aString] = anObject>
  2293. ! !
  2294. !JSObjectProxy methodsFor: 'proxy'!
  2295. printString
  2296. ^self jsObject toString
  2297. !
  2298. inspectOn: anInspector
  2299. | variables |
  2300. variables := Dictionary new.
  2301. variables at: '#self' put: self jsObject.
  2302. anInspector setLabel: self printString.
  2303. <for(var i in self['@jsObject']) {
  2304. variables._at_put_(i, self['@jsObject'][i]);
  2305. }>.
  2306. anInspector setVariables: variables
  2307. !
  2308. doesNotUnderstand: aMessage
  2309. | obj selector jsSelector arguments |
  2310. obj := self jsObject.
  2311. selector := aMessage selector.
  2312. jsSelector := selector asJavaScriptSelector.
  2313. arguments := aMessage arguments.
  2314. <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
  2315. super doesNotUnderstand: aMessage
  2316. ! !
  2317. !JSObjectProxy class methodsFor: 'instance creation'!
  2318. on: aJSObject
  2319. ^self new
  2320. jsObject: aJSObject;
  2321. yourself
  2322. ! !
  2323. Collection subclass: #Set
  2324. instanceVariableNames: 'elements'
  2325. category: 'Kernel'!
  2326. !Set methodsFor: 'accessing'!
  2327. size
  2328. ^elements size
  2329. ! !
  2330. !Set methodsFor: 'adding/removing'!
  2331. add: anObject
  2332. <
  2333. var found;
  2334. for(var i in self['@elements']) {
  2335. if(anObject == self['@elements'][i]) {
  2336. found = true;
  2337. break;
  2338. }
  2339. }
  2340. if(!!found) {self['@elements'].push(anObject)}
  2341. >
  2342. !
  2343. remove: anObject
  2344. elements remove: anObject
  2345. ! !
  2346. !Set methodsFor: 'comparing'!
  2347. = aCollection
  2348. ^self class = aCollection class and: [
  2349. elements = aCollection asArray]
  2350. ! !
  2351. !Set methodsFor: 'converting'!
  2352. asArray
  2353. ^elements copy
  2354. ! !
  2355. !Set methodsFor: 'enumerating'!
  2356. detect: aBlock ifNone: anotherBlock
  2357. ^elements detect: aBlock ifNone: anotherBlock
  2358. !
  2359. do: aBlock
  2360. elements do: aBlock
  2361. ! !
  2362. !Set methodsFor: 'initialization'!
  2363. initialize
  2364. super initialize.
  2365. elements := #()
  2366. ! !
  2367. !Set methodsFor: 'testing'!
  2368. includes: anObject
  2369. ^elements includes: anObject
  2370. ! !
  2371. Object subclass: #Transcript
  2372. instanceVariableNames: 'textarea'
  2373. category: 'Kernel'!
  2374. Transcript class instanceVariableNames: 'current'!
  2375. !Transcript class methodsFor: 'instance creation'!
  2376. open
  2377. self current open
  2378. !
  2379. new
  2380. self shouldNotImplement
  2381. !
  2382. current
  2383. ^current
  2384. !
  2385. register: aTranscript
  2386. current := aTranscript
  2387. ! !
  2388. !Transcript class methodsFor: 'printing'!
  2389. show: anObject
  2390. self current show: anObject
  2391. !
  2392. cr
  2393. self current show: String cr
  2394. !
  2395. clear
  2396. self current clear
  2397. ! !
  2398. Object subclass: #ConsoleTranscript
  2399. instanceVariableNames: 'textarea'
  2400. category: 'Kernel'!
  2401. !ConsoleTranscript methodsFor: 'actions'!
  2402. open
  2403. ! !
  2404. !ConsoleTranscript methodsFor: 'printing'!
  2405. clear
  2406. "no op"
  2407. !
  2408. cr
  2409. "no op"
  2410. !
  2411. show: anObject
  2412. <console.log(String(anObject._asString()))>
  2413. ! !
  2414. !ConsoleTranscript class methodsFor: 'initialization'!
  2415. initialize
  2416. Transcript register: self new
  2417. ! !