2
0

Kernel.st 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106
  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. ! !