Kernel.st 51 KB

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