Kernel.st 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070
  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. (first <= last) ifFalse: [self error: 'Wrong interval'].
  623. array := Array new.
  624. (last - first) timesRepeat: [
  625. array at: count put: first.
  626. count := count + 1.
  627. first := first + 1].
  628. ^array
  629. !
  630. asString
  631. ^self printString
  632. !
  633. asJavascript
  634. ^'(', self printString, ')'
  635. !
  636. atRandom
  637. ^(Random new next * self) truncated + 1
  638. !
  639. @ aNumber
  640. ^Point x: self y: aNumber
  641. !
  642. asPoint
  643. ^Point x: self y: self
  644. !
  645. asJSONObject
  646. ^self
  647. ! !
  648. !Number methodsFor: 'enumerating'!
  649. timesRepeat: aBlock
  650. | integer count |
  651. integer := self truncated.
  652. count := 1.
  653. [count > self] whileFalse: [
  654. aBlock value.
  655. count := count + 1]
  656. !
  657. to: aNumber do: aBlock
  658. ^(self to: aNumber) do: aBlock
  659. ! !
  660. !Number methodsFor: 'printing'!
  661. printString
  662. <return String(self)>
  663. !
  664. printShowingDecimalPlaces: placesDesired
  665. <return self.toFixed(placesDesired)>
  666. ! !
  667. !Number methodsFor: 'testing'!
  668. isNumber
  669. ^true
  670. !
  671. even
  672. ^ 0 = (self \\ 2)
  673. !
  674. odd
  675. ^ self even not
  676. ! !
  677. !Number methodsFor: 'timeouts/intervals'!
  678. clearInterval
  679. <clearInterval(Number(self))>
  680. !
  681. clearTimeout
  682. <clearTimeout(Number(self))>
  683. ! !
  684. !Number class methodsFor: 'instance creation'!
  685. pi
  686. <return Math.PI>
  687. ! !
  688. Object subclass: #BlockClosure
  689. instanceVariableNames: ''
  690. category: 'Kernel'!
  691. !BlockClosure methodsFor: 'accessing'!
  692. compiledSource
  693. <return self.toString()>
  694. ! !
  695. !BlockClosure methodsFor: 'controlling'!
  696. whileTrue: aBlock
  697. "inlined in the Compiler"
  698. <while(self()) {aBlock()}>
  699. !
  700. whileFalse: aBlock
  701. "inlined in the Compiler"
  702. <while(!!self()) {aBlock()}>
  703. !
  704. whileFalse
  705. "inlined in the Compiler"
  706. self whileFalse: []
  707. !
  708. whileTrue
  709. "inlined in the Compiler"
  710. self whileTrue: []
  711. ! !
  712. !BlockClosure methodsFor: 'error handling'!
  713. on: anErrorClass do: aBlock
  714. self try: self catch: [:error |
  715. (error isKindOf: anErrorClass)
  716. ifTrue: [aBlock value: error]
  717. ifFalse: [error signal]]
  718. ! !
  719. !BlockClosure methodsFor: 'evaluating'!
  720. value
  721. "inlined in the Compiler"
  722. <return self();>
  723. !
  724. value: anArg
  725. "inlined in the Compiler"
  726. <return self(anArg);>
  727. !
  728. value: firstArg value: secondArg
  729. "inlined in the Compiler"
  730. <return self(firstArg, secondArg);>
  731. !
  732. value: firstArg value: secondArg value: thirdArg
  733. "inlined in the Compiler"
  734. <return self(firstArg, secondArg, thirdArg);>
  735. !
  736. valueWithPossibleArguments: aCollection
  737. <return self.apply(null, aCollection);>
  738. !
  739. new
  740. "Use the receiver as a JS constructor.
  741. *Do not* use this method to instanciate Smalltalk objects!!"
  742. <return new self()>
  743. !
  744. applyTo: anObject arguments: aCollection
  745. <return self.apply(anObject, aCollection)>
  746. !
  747. timeToRun
  748. "Answer the number of milliseconds taken to execute this block."
  749. ^ Date millisecondsToRun: self
  750. ! !
  751. !BlockClosure methodsFor: 'timeout/interval'!
  752. valueWithTimeout: aNumber
  753. <return setTimeout(self, aNumber)>
  754. !
  755. valueWithInterval: aNumber
  756. <return setInterval(self, aNumber)>
  757. ! !
  758. Object subclass: #Boolean
  759. instanceVariableNames: ''
  760. category: 'Kernel'!
  761. !Boolean methodsFor: 'comparing'!
  762. = aBoolean
  763. aBoolean class = self class ifFalse: [^false].
  764. <return Boolean(self == true) == aBoolean>
  765. !
  766. == aBoolean
  767. aBoolean class = self class ifFalse: [^false].
  768. <return Boolean(self == true) === Boolean(aBoolean == true)>
  769. ! !
  770. !Boolean methodsFor: 'controlling'!
  771. ifTrue: aBlock
  772. "inlined in the Compiler"
  773. ^self ifTrue: aBlock ifFalse: []
  774. !
  775. ifFalse: aBlock
  776. "inlined in the Compiler"
  777. ^self ifTrue: [] ifFalse: aBlock
  778. !
  779. ifFalse: aBlock ifTrue: anotherBlock
  780. "inlined in the Compiler"
  781. ^self ifTrue: anotherBlock ifFalse: aBlock
  782. !
  783. ifTrue: aBlock ifFalse: anotherBlock
  784. "inlined in the Compiler"
  785. <
  786. if(self == true) {
  787. return aBlock();
  788. } else {
  789. return anotherBlock();
  790. }
  791. >
  792. !
  793. and: aBlock
  794. ^self = true
  795. ifTrue: aBlock
  796. ifFalse: [false]
  797. !
  798. or: aBlock
  799. ^self = true
  800. ifTrue: [true]
  801. ifFalse: aBlock
  802. !
  803. not
  804. ^self = false
  805. !
  806. & aBoolean
  807. <
  808. if(self == true) {
  809. return aBoolean;
  810. } else {
  811. return false;
  812. }
  813. >
  814. !
  815. | aBoolean
  816. <
  817. if(self == true) {
  818. return true;
  819. } else {
  820. return aBoolean;
  821. }
  822. >
  823. ! !
  824. !Boolean methodsFor: 'converting'!
  825. asJSONObject
  826. ^self
  827. ! !
  828. !Boolean methodsFor: 'copying'!
  829. shallowCopy
  830. ^self
  831. !
  832. deepCopy
  833. ^self
  834. ! !
  835. !Boolean methodsFor: 'printing'!
  836. printString
  837. <return self.toString()>
  838. ! !
  839. Object subclass: #Date
  840. instanceVariableNames: ''
  841. category: 'Kernel'!
  842. !Date commentStamp!
  843. The Date class is used to work with dates and times.!
  844. !Date methodsFor: 'accessing'!
  845. year
  846. <return self.getFullYear()>
  847. !
  848. month
  849. <return self.getMonth() + 1>
  850. !
  851. month: aNumber
  852. <self.setMonth(aNumber - 1)>
  853. !
  854. day
  855. ^self dayOfWeek
  856. !
  857. dayOfWeek
  858. <return self.getDay() + 1>
  859. !
  860. dayOfWeek: aNumber
  861. <return self.setDay(aNumber - 1)>
  862. !
  863. day: aNumber
  864. self day: aNumber
  865. !
  866. year: aNumber
  867. <self.setFullYear(aNumber)>
  868. !
  869. dayOfMonth
  870. <return self.getDate()>
  871. !
  872. dayOfMonth: aNumber
  873. <self.setDate(aNumber)>
  874. !
  875. time
  876. <return self.getTime()>
  877. !
  878. time: aNumber
  879. <self.setTime(aNumber)>
  880. !
  881. hours: aNumber
  882. <self.setHours(aNumber)>
  883. !
  884. minutes: aNumber
  885. <self.setMinutes(aNumber)>
  886. !
  887. seconds: aNumber
  888. <self.setSeconds(aNumber)>
  889. !
  890. milliseconds: aNumber
  891. <self.setMilliseconds(aNumber)>
  892. !
  893. hours
  894. <return self.getHours()>
  895. !
  896. minutes
  897. <return self.getMinutes()>
  898. !
  899. seconds
  900. <return self.getSeconds()>
  901. !
  902. milliseconds
  903. <return self.getMilliseconds()>
  904. ! !
  905. !Date methodsFor: 'arithmetic'!
  906. - aDate
  907. <return self - aDate>
  908. !
  909. + aDate
  910. <return self + aDate>
  911. ! !
  912. !Date methodsFor: 'comparing'!
  913. < aDate
  914. <return self < aDate>
  915. !
  916. > aDate
  917. <return self >> aDate>
  918. !
  919. <= aDate
  920. <self <= aDate>
  921. !
  922. >= aDate
  923. <self >>= aDate>
  924. ! !
  925. !Date methodsFor: 'converting'!
  926. asString
  927. <return self.toString()>
  928. !
  929. asMilliseconds
  930. ^self time
  931. !
  932. asDateString
  933. <return self.toDateString()>
  934. !
  935. asTimeString
  936. <return self.toTimeString()>
  937. !
  938. asLocaleString
  939. <return self.toLocaleString()>
  940. !
  941. asNumber
  942. ^self asMilliseconds
  943. !
  944. asJSONObject
  945. ^self
  946. ! !
  947. !Date methodsFor: 'printing'!
  948. printString
  949. ^self asString
  950. ! !
  951. !Date class methodsFor: 'instance creation'!
  952. new: anObject
  953. <return new Date(anObject)>
  954. !
  955. fromString: aString
  956. "Example: Date fromString('2011/04/15 00:00:00')"
  957. ^self new: aString
  958. !
  959. fromSeconds: aNumber
  960. ^self fromMilliseconds: aNumber * 1000
  961. !
  962. fromMilliseconds: aNumber
  963. ^self new: aNumber
  964. !
  965. today
  966. ^self new
  967. !
  968. now
  969. ^self today
  970. !
  971. millisecondsToRun: aBlock
  972. | t |
  973. t := Date now.
  974. aBlock value.
  975. ^Date now - t
  976. ! !
  977. Object subclass: #UndefinedObject
  978. instanceVariableNames: ''
  979. category: 'Kernel'!
  980. !UndefinedObject methodsFor: 'class creation'!
  981. subclass: aString instanceVariableNames: anotherString
  982. ^self subclass: aString instanceVariableNames: anotherString package: nil
  983. !
  984. subclass: aString instanceVariableNames: aString2 category: aString3
  985. "Kept for compatibility."
  986. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  987. !
  988. subclass: aString instanceVariableNames: aString2 package: aString3
  989. ^ClassBuilder new
  990. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  991. ! !
  992. !UndefinedObject methodsFor: 'copying'!
  993. shallowCopy
  994. ^self
  995. !
  996. deepCopy
  997. ^self
  998. ! !
  999. !UndefinedObject methodsFor: 'printing'!
  1000. printString
  1001. ^'nil'
  1002. ! !
  1003. !UndefinedObject methodsFor: 'testing'!
  1004. ifNil: aBlock
  1005. "inlined in the Compiler"
  1006. ^self ifNil: aBlock ifNotNil: []
  1007. !
  1008. ifNotNil: aBlock
  1009. "inlined in the Compiler"
  1010. ^self
  1011. !
  1012. ifNil: aBlock ifNotNil: anotherBlock
  1013. "inlined in the Compiler"
  1014. ^aBlock value
  1015. !
  1016. ifNotNil: aBlock ifNil: anotherBlock
  1017. "inlined in the Compiler"
  1018. ^anotherBlock value
  1019. !
  1020. isNil
  1021. ^true
  1022. !
  1023. notNil
  1024. ^false
  1025. ! !
  1026. !UndefinedObject class methodsFor: 'instance creation'!
  1027. new
  1028. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1029. ! !
  1030. Object subclass: #Collection
  1031. instanceVariableNames: ''
  1032. category: 'Kernel'!
  1033. !Collection methodsFor: 'accessing'!
  1034. size
  1035. self subclassResponsibility
  1036. !
  1037. readStream
  1038. ^self stream
  1039. !
  1040. writeStream
  1041. ^self stream
  1042. !
  1043. stream
  1044. ^self streamClass on: self
  1045. !
  1046. streamClass
  1047. ^self class streamClass
  1048. ! !
  1049. !Collection methodsFor: 'adding/removing'!
  1050. add: anObject
  1051. self subclassResponsibility
  1052. !
  1053. addAll: aCollection
  1054. aCollection do: [:each |
  1055. self add: each].
  1056. ^aCollection
  1057. !
  1058. remove: anObject
  1059. self subclassResponsibility
  1060. ! !
  1061. !Collection methodsFor: 'converting'!
  1062. asArray
  1063. | array index |
  1064. array := Array new.
  1065. index := 0.
  1066. self do: [:each |
  1067. index := index + 1.
  1068. array at: index put: each].
  1069. ^array
  1070. !
  1071. asSet
  1072. ^Set withAll: self
  1073. ! !
  1074. !Collection methodsFor: 'copying'!
  1075. , aCollection
  1076. ^self copy
  1077. addAll: aCollection;
  1078. yourself
  1079. !
  1080. copyWith: anObject
  1081. ^self copy add: anObject; yourself
  1082. !
  1083. copyWithAll: aCollection
  1084. ^self copy addAll: aCollection; yourself
  1085. !
  1086. copyWithoutAll: aCollection
  1087. "Answer a copy of the receiver that does not contain any elements
  1088. equal to those in aCollection."
  1089. ^ self reject: [:each | aCollection includes: each]
  1090. ! !
  1091. !Collection methodsFor: 'enumerating'!
  1092. do: aBlock
  1093. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  1094. !
  1095. collect: aBlock
  1096. | newCollection |
  1097. newCollection := self class new.
  1098. self do: [:each |
  1099. newCollection add: (aBlock value: each)].
  1100. ^newCollection
  1101. !
  1102. detect: aBlock
  1103. ^self detect: aBlock ifNone: [self errorNotFound]
  1104. !
  1105. detect: aBlock ifNone: anotherBlock
  1106. <
  1107. for(var i = 0; i < self.length; i++)
  1108. if(aBlock(self[i]))
  1109. return self[i];
  1110. return anotherBlock();
  1111. >
  1112. !
  1113. do: aBlock separatedBy: anotherBlock
  1114. | first |
  1115. first := true.
  1116. self do: [:each |
  1117. first
  1118. ifTrue: [first := false]
  1119. ifFalse: [anotherBlock value].
  1120. aBlock value: each]
  1121. !
  1122. inject: anObject into: aBlock
  1123. | result |
  1124. result := anObject.
  1125. self do: [:each |
  1126. result := aBlock value: result value: each].
  1127. ^result
  1128. !
  1129. reject: aBlock
  1130. ^self select: [:each | (aBlock value: each) = false]
  1131. !
  1132. select: aBlock
  1133. | stream |
  1134. stream := self class new writeStream.
  1135. self do: [:each |
  1136. (aBlock value: each) ifTrue: [
  1137. stream nextPut: each]].
  1138. ^stream contents
  1139. ! !
  1140. !Collection methodsFor: 'error handling'!
  1141. errorNotFound
  1142. self error: 'Object is not in the collection'
  1143. ! !
  1144. !Collection methodsFor: 'testing'!
  1145. includes: anObject
  1146. <
  1147. var i = self.length;
  1148. while (i--) {
  1149. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1150. }
  1151. return false
  1152. >
  1153. !
  1154. notEmpty
  1155. ^self isEmpty not
  1156. !
  1157. isEmpty
  1158. ^self size = 0
  1159. !
  1160. ifNotEmpty: aBlock
  1161. self notEmpty ifTrue: aBlock.
  1162. !
  1163. ifEmpty: aBlock
  1164. self isEmpty ifTrue: aBlock.
  1165. ! !
  1166. !Collection class methodsFor: 'accessing'!
  1167. streamClass
  1168. ^Stream
  1169. ! !
  1170. !Collection class methodsFor: 'instance creation'!
  1171. with: anObject
  1172. ^self new
  1173. add: anObject;
  1174. yourself
  1175. !
  1176. with: anObject with: anotherObject
  1177. ^self new
  1178. add: anObject;
  1179. add: anotherObject;
  1180. yourself
  1181. !
  1182. with: firstObject with: secondObject with: thirdObject
  1183. ^self new
  1184. add: firstObject;
  1185. add: secondObject;
  1186. add: thirdObject;
  1187. yourself
  1188. !
  1189. withAll: aCollection
  1190. ^self new
  1191. addAll: aCollection;
  1192. yourself
  1193. ! !
  1194. Collection subclass: #SequenceableCollection
  1195. instanceVariableNames: ''
  1196. category: 'Kernel'!
  1197. !SequenceableCollection methodsFor: 'accessing'!
  1198. at: anIndex
  1199. ^self at: anIndex ifAbsent: [
  1200. self errorNotFound]
  1201. !
  1202. at: anIndex ifAbsent: aBlock
  1203. self subclassResponsibility
  1204. !
  1205. at: anIndex put: anObject
  1206. self subclassResponsibility
  1207. !
  1208. first
  1209. ^self at: 1
  1210. !
  1211. fourth
  1212. ^self at: 4
  1213. !
  1214. last
  1215. ^self at: self size
  1216. !
  1217. second
  1218. ^self at: 2
  1219. !
  1220. third
  1221. ^self at: 3
  1222. !
  1223. allButFirst
  1224. ^self copyFrom: 2 to: self size
  1225. !
  1226. allButLast
  1227. ^self copyFrom: 1 to: self size - 1
  1228. !
  1229. indexOf: anObject
  1230. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1231. !
  1232. indexOf: anObject ifAbsent: aBlock
  1233. <
  1234. for(var i=0;i<self.length;i++){
  1235. if(self[i].__eq(anObject)) {return i+1}
  1236. }
  1237. return aBlock();
  1238. >
  1239. !
  1240. indexOf: anObject startingAt: start ifAbsent: aBlock
  1241. <
  1242. for(var i=start-1;i<self.length;i++){
  1243. if(self[i].__eq(anObject)) {return i+1}
  1244. }
  1245. return aBlock();
  1246. >
  1247. !
  1248. indexOf: anObject startingAt: start
  1249. "Answer the index of the first occurence of anElement after start
  1250. within the receiver. If the receiver does not contain anElement,
  1251. answer 0."
  1252. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1253. ! !
  1254. !SequenceableCollection methodsFor: 'adding'!
  1255. removeLast
  1256. self remove: self last
  1257. !
  1258. addLast: anObject
  1259. self add: anObject
  1260. ! !
  1261. !SequenceableCollection methodsFor: 'converting'!
  1262. reversed
  1263. self subclassResponsibility
  1264. ! !
  1265. !SequenceableCollection methodsFor: 'copying'!
  1266. copyFrom: anIndex to: anotherIndex
  1267. self subclassResponsibility
  1268. ! !
  1269. !SequenceableCollection methodsFor: 'enumerating'!
  1270. withIndexDo: aBlock
  1271. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1272. ! !
  1273. SequenceableCollection subclass: #String
  1274. instanceVariableNames: ''
  1275. category: 'Kernel'!
  1276. !String methodsFor: 'accessing'!
  1277. size
  1278. <return self.length>
  1279. !
  1280. at: anIndex
  1281. <return self[anIndex - 1]>
  1282. !
  1283. at: anIndex put: anObject
  1284. self errorReadOnly
  1285. !
  1286. at: anIndex ifAbsent: aBlock
  1287. (self at: anIndex) ifNil: [aBlock]
  1288. !
  1289. escaped
  1290. <return escape(self)>
  1291. !
  1292. unescaped
  1293. <return unescape(self)>
  1294. !
  1295. asciiValue
  1296. <return self.charCodeAt(0);>
  1297. ! !
  1298. !String methodsFor: 'adding'!
  1299. add: anObject
  1300. self errorReadOnly
  1301. !
  1302. remove: anObject
  1303. self errorReadOnly
  1304. ! !
  1305. !String methodsFor: 'comparing'!
  1306. = aString
  1307. aString class = self class ifFalse: [^false].
  1308. <return String(self) == aString>
  1309. !
  1310. > aString
  1311. <return String(self) >> aString>
  1312. !
  1313. < aString
  1314. <return String(self) < aString>
  1315. !
  1316. >= aString
  1317. <return String(self) >>= aString>
  1318. !
  1319. <= aString
  1320. <return String(self) <= aString>
  1321. !
  1322. == aString
  1323. aString class = self class ifFalse: [^false].
  1324. <return String(self) === String(aString)>
  1325. ! !
  1326. !String methodsFor: 'converting'!
  1327. asSelector
  1328. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1329. | selector |
  1330. selector := '_', self.
  1331. selector := selector replace: ':' with: '_'.
  1332. selector := selector replace: '[+]' with: '_plus'.
  1333. selector := selector replace: '-' with: '_minus'.
  1334. selector := selector replace: '[*]' with: '_star'.
  1335. selector := selector replace: '[/]' with: '_slash'.
  1336. selector := selector replace: '>' with: '_gt'.
  1337. selector := selector replace: '<' with: '_lt'.
  1338. selector := selector replace: '=' with: '_eq'.
  1339. selector := selector replace: ',' with: '_comma'.
  1340. selector := selector replace: '[@]' with: '_at'.
  1341. ^selector
  1342. !
  1343. asJavascript
  1344. <
  1345. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1346. return "unescape(\"" + escape(self) + "\")";
  1347. else
  1348. return "\"" + self + "\"";
  1349. >
  1350. !
  1351. tokenize: aString
  1352. <return self.split(aString)>
  1353. !
  1354. asString
  1355. ^self
  1356. !
  1357. asNumber
  1358. <return Number(self)>
  1359. !
  1360. asJSONObject
  1361. ^self
  1362. !
  1363. asLowercase
  1364. <return self.toLowerCase()>
  1365. !
  1366. asUppercase
  1367. <return self.toUpperCase()>
  1368. !
  1369. reversed
  1370. <return self.split("").reverse().join("")>
  1371. !
  1372. asJavaScriptSelector
  1373. ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
  1374. ! !
  1375. !String methodsFor: 'copying'!
  1376. , aString
  1377. <return self + aString>
  1378. !
  1379. copyFrom: anIndex to: anotherIndex
  1380. <return self.substring(anIndex - 1, anotherIndex)>
  1381. !
  1382. shallowCopy
  1383. ^self class fromString: self
  1384. !
  1385. deepCopy
  1386. ^self shallowCopy
  1387. ! !
  1388. !String methodsFor: 'error handling'!
  1389. errorReadOnly
  1390. self error: 'Object is read-only'
  1391. ! !
  1392. !String methodsFor: 'printing'!
  1393. printString
  1394. ^'''', self, ''''
  1395. !
  1396. printNl
  1397. <console.log(self)>
  1398. ! !
  1399. !String methodsFor: 'regular expressions'!
  1400. replace: aString with: anotherString
  1401. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1402. !
  1403. replaceRegexp: aRegexp with: aString
  1404. <return self.replace(aRegexp, aString)>
  1405. !
  1406. match: aRegexp
  1407. <return self.search(aRegexp) !!= -1>
  1408. !
  1409. trimLeft: separators
  1410. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1411. !
  1412. trimRight: separators
  1413. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1414. !
  1415. trimLeft
  1416. ^self trimLeft: '\s'
  1417. !
  1418. trimRight
  1419. ^self trimRight: '\s'
  1420. !
  1421. trimBoth
  1422. ^self trimBoth: '\s'
  1423. !
  1424. trimBoth: separators
  1425. ^(self trimLeft: separators) trimRight: separators
  1426. ! !
  1427. !String methodsFor: 'split join'!
  1428. join: aCollection
  1429. ^ String
  1430. streamContents: [:stream | aCollection
  1431. do: [:each | stream nextPutAll: each asString]
  1432. separatedBy: [stream nextPutAll: self]]
  1433. !
  1434. lineIndicesDo: aBlock
  1435. "execute aBlock with 3 arguments for each line:
  1436. - start index of line
  1437. - end index of line without line delimiter
  1438. - end index of line including line delimiter(s) CR, LF or CRLF"
  1439. | cr lf start sz nextLF nextCR |
  1440. start := 1.
  1441. sz := self size.
  1442. cr := String cr.
  1443. nextCR := self indexOf: cr startingAt: 1.
  1444. lf := String lf.
  1445. nextLF := self indexOf: lf startingAt: 1.
  1446. [ start <= sz ] whileTrue: [
  1447. (nextLF = 0 and: [ nextCR = 0 ])
  1448. ifTrue: [ "No more CR, nor LF, the string is over"
  1449. aBlock value: start value: sz value: sz.
  1450. ^self ].
  1451. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1452. ifTrue: [ "Found a LF"
  1453. aBlock value: start value: nextLF - 1 value: nextLF.
  1454. start := 1 + nextLF.
  1455. nextLF := self indexOf: lf startingAt: start ]
  1456. ifFalse: [ 1 + nextCR = nextLF
  1457. ifTrue: [ "Found a CR-LF pair"
  1458. aBlock value: start value: nextCR - 1 value: nextLF.
  1459. start := 1 + nextLF.
  1460. nextCR := self indexOf: cr startingAt: start.
  1461. nextLF := self indexOf: lf startingAt: start ]
  1462. ifFalse: [ "Found a CR"
  1463. aBlock value: start value: nextCR - 1 value: nextCR.
  1464. start := 1 + nextCR.
  1465. nextCR := self indexOf: cr startingAt: start ]]]
  1466. !
  1467. linesDo: aBlock
  1468. "Execute aBlock with each line in this string. The terminating line
  1469. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1470. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1471. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1472. !
  1473. lines
  1474. "Answer an array of lines composing this receiver without the line ending delimiters."
  1475. | lines |
  1476. lines := Array new.
  1477. self linesDo: [:aLine | lines add: aLine].
  1478. ^lines
  1479. !
  1480. lineNumber: anIndex
  1481. "Answer a string containing the characters in the given line number."
  1482. | lineCount |
  1483. lineCount := 0.
  1484. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1485. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1486. ^nil
  1487. ! !
  1488. !String methodsFor: 'testing'!
  1489. isString
  1490. ^true
  1491. !
  1492. includesSubString: subString
  1493. < return self.indexOf(subString) !!= -1 >
  1494. ! !
  1495. !String class methodsFor: 'accessing'!
  1496. streamClass
  1497. ^StringStream
  1498. !
  1499. cr
  1500. <return '\r'>
  1501. !
  1502. lf
  1503. <return '\n'>
  1504. !
  1505. space
  1506. <return ' '>
  1507. !
  1508. tab
  1509. <return '\t'>
  1510. !
  1511. crlf
  1512. <return '\r\n'>
  1513. ! !
  1514. !String class methodsFor: 'instance creation'!
  1515. fromString: aString
  1516. <return new self.fn(aString)>
  1517. !
  1518. streamContents: blockWithArg
  1519. |stream|
  1520. stream := (self streamClass on: String new).
  1521. blockWithArg value: stream.
  1522. ^ stream contents
  1523. !
  1524. value: aUTFCharCode
  1525. <return String.fromCharCode(aUTFCharCode);>
  1526. ! !
  1527. SequenceableCollection subclass: #Array
  1528. instanceVariableNames: ''
  1529. category: 'Kernel'!
  1530. !Array methodsFor: 'accessing'!
  1531. size
  1532. <return self.length>
  1533. !
  1534. at: anIndex put: anObject
  1535. <return self[anIndex - 1] = anObject>
  1536. !
  1537. at: anIndex ifAbsent: aBlock
  1538. <
  1539. var value = self[anIndex - 1];
  1540. if(value === undefined) {
  1541. return aBlock();
  1542. } else {
  1543. return value;
  1544. }
  1545. >
  1546. ! !
  1547. !Array methodsFor: 'adding/removing'!
  1548. add: anObject
  1549. <self.push(anObject); return anObject;>
  1550. !
  1551. remove: anObject
  1552. <
  1553. for(var i=0;i<self.length;i++) {
  1554. if(self[i] == anObject) {
  1555. self.splice(i,1);
  1556. break;
  1557. }
  1558. }
  1559. >
  1560. !
  1561. removeFrom: aNumber to: anotherNumber
  1562. <self.splice(aNumber - 1,anotherNumber - 1)>
  1563. ! !
  1564. !Array methodsFor: 'comparing'!
  1565. = aCollection
  1566. (self class = aCollection class and: [
  1567. self size = aCollection size]) ifFalse: [^false].
  1568. self withIndexDo: [:each :i |
  1569. (aCollection at: i) = each ifFalse: [^false]].
  1570. ^true
  1571. ! !
  1572. !Array methodsFor: 'converting'!
  1573. asJavascript
  1574. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1575. !
  1576. asJSONObject
  1577. ^self collect: [:each | each asJSONObject]
  1578. !
  1579. reversed
  1580. <return self._copy().reverse()>
  1581. ! !
  1582. !Array methodsFor: 'copying'!
  1583. shallowCopy
  1584. | newCollection |
  1585. newCollection := self class new.
  1586. self do: [:each | newCollection add: each].
  1587. ^newCollection
  1588. !
  1589. deepCopy
  1590. | newCollection |
  1591. newCollection := self class new.
  1592. self do: [:each | newCollection add: each deepCopy].
  1593. ^newCollection
  1594. !
  1595. copyFrom: anIndex to: anotherIndex
  1596. | array |
  1597. array := self class new.
  1598. anIndex to: anotherIndex do: [:each |
  1599. array add: (self at: each)].
  1600. ^array
  1601. ! !
  1602. !Array methodsFor: 'enumerating'!
  1603. join: aString
  1604. <return self.join(aString)>
  1605. !
  1606. sort
  1607. ^self basicPerform: 'sort'
  1608. !
  1609. sort: aBlock
  1610. <
  1611. return self.sort(function(a, b) {
  1612. if(aBlock(a,b)) {return -1} else {return 1}
  1613. })
  1614. >
  1615. !
  1616. sorted
  1617. ^self copy sort
  1618. !
  1619. sorted: aBlock
  1620. ^self copy sort: aBlock
  1621. !
  1622. printString
  1623. | str |
  1624. str := '' writeStream.
  1625. str nextPutAll: super printString, ' ('.
  1626. self
  1627. do: [:each | str nextPutAll: each printString]
  1628. separatedBy: [str nextPutAll: ' '].
  1629. str nextPutAll: ')'.
  1630. ^str contents
  1631. ! !
  1632. Object subclass: #RegularExpression
  1633. instanceVariableNames: ''
  1634. category: 'Kernel'!
  1635. !RegularExpression methodsFor: 'evaluating'!
  1636. compile: aString
  1637. <return self.compile(aString)>
  1638. !
  1639. exec: aString
  1640. <return self.exec(aString) || nil>
  1641. !
  1642. test: aString
  1643. <return self.test(aString)>
  1644. ! !
  1645. !RegularExpression class methodsFor: 'instance creation'!
  1646. fromString: aString flag: anotherString
  1647. <return new RegExp(aString, anotherString)>
  1648. !
  1649. fromString: aString
  1650. ^self fromString: aString flag: ''
  1651. ! !
  1652. Object subclass: #Error
  1653. instanceVariableNames: 'messageText'
  1654. category: 'Kernel'!
  1655. !Error methodsFor: 'accessing'!
  1656. messageText
  1657. ^messageText
  1658. !
  1659. messageText: aString
  1660. messageText := aString
  1661. !
  1662. context
  1663. <return self.context>
  1664. ! !
  1665. !Error methodsFor: 'signaling'!
  1666. signal
  1667. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1668. ! !
  1669. !Error class methodsFor: 'instance creation'!
  1670. signal: aString
  1671. ^self new
  1672. messageText: aString;
  1673. signal
  1674. ! !
  1675. Object subclass: #MethodContext
  1676. instanceVariableNames: ''
  1677. category: 'Kernel'!
  1678. !MethodContext methodsFor: 'accessing'!
  1679. receiver
  1680. <return self.receiver>
  1681. !
  1682. selector
  1683. <return smalltalk.convertSelector(self.selector)>
  1684. !
  1685. home
  1686. <return self.homeContext>
  1687. !
  1688. temps
  1689. <return self.temps>
  1690. !
  1691. printString
  1692. ^super printString, '(', self asString, ')'
  1693. !
  1694. asString
  1695. ^self receiver class printString, ' >> ', self selector
  1696. ! !
  1697. Object subclass: #Association
  1698. instanceVariableNames: 'key value'
  1699. category: 'Kernel'!
  1700. !Association methodsFor: 'accessing'!
  1701. key: aKey
  1702. key := aKey
  1703. !
  1704. key
  1705. ^key
  1706. !
  1707. value: aValue
  1708. value := aValue
  1709. !
  1710. value
  1711. ^value
  1712. ! !
  1713. !Association methodsFor: 'comparing'!
  1714. = anAssociation
  1715. ^self class = anAssociation class and: [
  1716. self key = anAssociation key and: [
  1717. self value = anAssociation value]]
  1718. ! !
  1719. !Association class methodsFor: 'instance creation'!
  1720. key: aKey value: aValue
  1721. ^self new
  1722. key: aKey;
  1723. value: aValue;
  1724. yourself
  1725. ! !
  1726. Collection subclass: #Dictionary
  1727. instanceVariableNames: 'keys'
  1728. category: 'Kernel'!
  1729. !Dictionary methodsFor: 'accessing'!
  1730. size
  1731. ^keys size
  1732. !
  1733. associations
  1734. | associations |
  1735. associations := #().
  1736. keys do: [:each |
  1737. associations add: (Association key: each value: (self at: each))].
  1738. ^associations
  1739. !
  1740. keys
  1741. ^keys copy
  1742. !
  1743. values
  1744. ^keys collect: [:each | self at: each]
  1745. !
  1746. at: aKey put: aValue
  1747. (keys includes: aKey) ifFalse: [keys add: aKey].
  1748. ^self basicAt: aKey put: aValue
  1749. !
  1750. at: aKey ifAbsent: aBlock
  1751. ^(self keys includes: aKey)
  1752. ifTrue: [self basicAt: aKey]
  1753. ifFalse: aBlock
  1754. !
  1755. at: aKey ifAbsentPut: aBlock
  1756. ^self at: aKey ifAbsent: [
  1757. self at: aKey put: aBlock value]
  1758. !
  1759. at: aKey ifPresent: aBlock
  1760. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1761. !
  1762. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1763. ^(self basicAt: aKey)
  1764. ifNil: anotherBlock
  1765. ifNotNil: [aBlock value: (self at: aKey)]
  1766. !
  1767. at: aKey
  1768. ^self at: aKey ifAbsent: [self errorNotFound]
  1769. ! !
  1770. !Dictionary methodsFor: 'adding/removing'!
  1771. add: anAssociation
  1772. self at: anAssociation key put: anAssociation value
  1773. !
  1774. addAll: aDictionary
  1775. super addAll: aDictionary associations.
  1776. ^aDictionary
  1777. !
  1778. remove: aKey
  1779. self removeKey: aKey
  1780. !
  1781. removeKey: aKey
  1782. keys remove: aKey
  1783. ! !
  1784. !Dictionary methodsFor: 'comparing'!
  1785. = aDictionary
  1786. self class = aDictionary class ifFalse: [^false].
  1787. self size = aDictionary size ifFalse: [^false].
  1788. ^self associations = aDictionary associations
  1789. ! !
  1790. !Dictionary methodsFor: 'converting'!
  1791. asJSONObject
  1792. | object |
  1793. object := Object new.
  1794. self keysAndValuesDo: [:key :value |
  1795. object basicAt: key put: value asJSONObject].
  1796. ^object
  1797. ! !
  1798. !Dictionary methodsFor: 'copying'!
  1799. shallowCopy
  1800. | copy |
  1801. copy := self class new.
  1802. self associationsDo: [:each |
  1803. copy at: each key put: each value].
  1804. ^copy
  1805. !
  1806. , aCollection
  1807. self shouldNotImplement
  1808. !
  1809. copyFrom: anIndex to: anotherIndex
  1810. self shouldNotImplement
  1811. ! !
  1812. !Dictionary methodsFor: 'enumerating'!
  1813. associationsDo: aBlock
  1814. self associations do: aBlock
  1815. !
  1816. keysAndValuesDo: aBlock
  1817. self associationsDo: [:each |
  1818. aBlock value: each key value: each value]
  1819. !
  1820. do: aBlock
  1821. self values do: aBlock
  1822. !
  1823. select: aBlock
  1824. | newDict |
  1825. newDict := self class new.
  1826. self keysAndValuesDo: [:key :value |
  1827. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1828. ^newDict
  1829. !
  1830. collect: aBlock
  1831. | newDict |
  1832. newDict := self class new.
  1833. self keysAndValuesDo: [:key :value |
  1834. newDict at: key put: (aBlock value: value)].
  1835. ^newDict
  1836. !
  1837. detect: aBlock ifNone: anotherBlock
  1838. ^self values detect: aBlock ifNone: anotherBlock
  1839. !
  1840. includes: anObject
  1841. ^self values includes: anObject
  1842. ! !
  1843. !Dictionary methodsFor: 'initialization'!
  1844. initialize
  1845. super initialize.
  1846. keys := #()
  1847. ! !
  1848. !Dictionary methodsFor: 'printing'!
  1849. printString
  1850. ^ String streamContents: [:aStream|
  1851. aStream
  1852. nextPutAll: super printString;
  1853. nextPutAll: '('.
  1854. self associations
  1855. do: [:anAssociation|
  1856. aStream
  1857. nextPutAll: anAssociation key printString;
  1858. nextPutAll: ' -> ';
  1859. nextPutAll: anAssociation value printString]
  1860. separatedBy: [aStream nextPutAll: ' , '].
  1861. aStream nextPutAll: ')'.
  1862. ]
  1863. ! !
  1864. !Dictionary class methodsFor: 'instance creation'!
  1865. fromPairs: aCollection
  1866. | dict |
  1867. dict := self new.
  1868. aCollection do: [:each | dict add: each].
  1869. ^dict
  1870. ! !
  1871. Object subclass: #ClassBuilder
  1872. instanceVariableNames: ''
  1873. category: 'Kernel'!
  1874. !ClassBuilder methodsFor: 'class creation'!
  1875. superclass: aClass subclass: aString
  1876. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  1877. !
  1878. class: aClass instanceVariableNames: aString
  1879. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1880. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1881. self setupClass: aClass
  1882. !
  1883. superclass: aClass subclass: aString instanceVariableNames: aString2 module: aString3
  1884. | newClass |
  1885. newClass := self addSubclassOf: aClass
  1886. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1887. module: (aString3 ifNil: ['unclassified']).
  1888. self setupClass: newClass
  1889. !
  1890. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  1891. | newClass |
  1892. newClass := self addSubclassOf: aClass
  1893. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1894. package: (aString3 ifNil: ['unclassified']).
  1895. self setupClass: newClass
  1896. ! !
  1897. !ClassBuilder methodsFor: 'private'!
  1898. instanceVariableNamesFor: aString
  1899. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1900. !
  1901. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1902. <smalltalk.addClass(aString, aClass, aCollection);
  1903. return smalltalk[aString]>
  1904. !
  1905. setupClass: aClass
  1906. <smalltalk.init(aClass);>
  1907. !
  1908. addSubclassOf: aClass named: aString instanceVariableNames: aCollection module: moduleName
  1909. <smalltalk.addClass(aString, aClass, aCollection, moduleName);
  1910. return smalltalk[aString]>
  1911. !
  1912. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  1913. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  1914. return smalltalk[aString]>
  1915. ! !
  1916. Object subclass: #ClassCategoryReader
  1917. instanceVariableNames: 'class category chunkParser'
  1918. category: 'Kernel'!
  1919. !ClassCategoryReader methodsFor: 'accessing'!
  1920. class: aClass category: aString
  1921. class := aClass.
  1922. category := aString
  1923. ! !
  1924. !ClassCategoryReader methodsFor: 'fileIn'!
  1925. scanFrom: aChunkParser
  1926. | chunk |
  1927. [chunk := aChunkParser nextChunk.
  1928. chunk isEmpty] whileFalse: [
  1929. self compileMethod: chunk]
  1930. ! !
  1931. !ClassCategoryReader methodsFor: 'initialization'!
  1932. initialize
  1933. super initialize.
  1934. chunkParser := ChunkParser new.
  1935. ! !
  1936. !ClassCategoryReader methodsFor: 'private'!
  1937. compileMethod: aString
  1938. | method |
  1939. method := Compiler new load: aString forClass: class.
  1940. method category: category.
  1941. class addCompiledMethod: method
  1942. ! !
  1943. Object subclass: #Stream
  1944. instanceVariableNames: 'collection position streamSize'
  1945. category: 'Kernel'!
  1946. !Stream methodsFor: 'accessing'!
  1947. collection
  1948. ^collection
  1949. !
  1950. setCollection: aCollection
  1951. collection := aCollection
  1952. !
  1953. position
  1954. ^position ifNil: [position := 0]
  1955. !
  1956. position: anInteger
  1957. position := anInteger
  1958. !
  1959. streamSize
  1960. ^streamSize
  1961. !
  1962. setStreamSize: anInteger
  1963. streamSize := anInteger
  1964. !
  1965. contents
  1966. ^self collection
  1967. copyFrom: 1
  1968. to: self streamSize
  1969. !
  1970. size
  1971. ^self streamSize
  1972. ! !
  1973. !Stream methodsFor: 'actions'!
  1974. reset
  1975. self position: 0
  1976. !
  1977. close
  1978. !
  1979. flush
  1980. !
  1981. resetContents
  1982. self reset.
  1983. self setStreamSize: 0
  1984. ! !
  1985. !Stream methodsFor: 'enumerating'!
  1986. do: aBlock
  1987. [self atEnd] whileFalse: [aBlock value: self next]
  1988. ! !
  1989. !Stream methodsFor: 'positioning'!
  1990. setToEnd
  1991. self position: self size
  1992. !
  1993. skip: anInteger
  1994. self position: ((self position + anInteger) min: self size max: 0)
  1995. ! !
  1996. !Stream methodsFor: 'reading'!
  1997. next
  1998. self position: self position + 1.
  1999. ^collection at: self position
  2000. !
  2001. next: anInteger
  2002. | tempCollection |
  2003. tempCollection := self collection class new.
  2004. anInteger timesRepeat: [
  2005. self atEnd ifFalse: [
  2006. tempCollection add: self next]].
  2007. ^tempCollection
  2008. !
  2009. peek
  2010. ^self atEnd ifFalse: [
  2011. self collection at: self position + 1]
  2012. ! !
  2013. !Stream methodsFor: 'testing'!
  2014. atEnd
  2015. ^self position = self size
  2016. !
  2017. atStart
  2018. ^self position = 0
  2019. !
  2020. isEmpty
  2021. ^self size = 0
  2022. ! !
  2023. !Stream methodsFor: 'writing'!
  2024. nextPut: anObject
  2025. self position: self position + 1.
  2026. self collection at: self position put: anObject.
  2027. self setStreamSize: (self streamSize max: self position)
  2028. !
  2029. nextPutAll: aCollection
  2030. aCollection do: [:each |
  2031. self nextPut: each]
  2032. ! !
  2033. !Stream class methodsFor: 'instance creation'!
  2034. on: aCollection
  2035. ^self new
  2036. setCollection: aCollection;
  2037. setStreamSize: aCollection size;
  2038. yourself
  2039. ! !
  2040. Stream subclass: #StringStream
  2041. instanceVariableNames: ''
  2042. category: 'Kernel'!
  2043. !StringStream methodsFor: 'reading'!
  2044. next: anInteger
  2045. | tempCollection |
  2046. tempCollection := self collection class new.
  2047. anInteger timesRepeat: [
  2048. self atEnd ifFalse: [
  2049. tempCollection := tempCollection, self next]].
  2050. ^tempCollection
  2051. ! !
  2052. !StringStream methodsFor: 'writing'!
  2053. nextPut: aString
  2054. self nextPutAll: aString
  2055. !
  2056. nextPutAll: aString
  2057. self setCollection:
  2058. (self collection copyFrom: 1 to: self position),
  2059. aString,
  2060. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  2061. self position: self position + aString size.
  2062. self setStreamSize: (self streamSize max: self position)
  2063. !
  2064. cr
  2065. ^self nextPutAll: String cr
  2066. !
  2067. crlf
  2068. ^self nextPutAll: String crlf
  2069. !
  2070. lf
  2071. ^self nextPutAll: String lf
  2072. !
  2073. space
  2074. self nextPut: ' '
  2075. ! !
  2076. Object subclass: #ClassCommentReader
  2077. instanceVariableNames: 'class chunkParser'
  2078. category: 'Kernel'!
  2079. !ClassCommentReader methodsFor: 'accessing'!
  2080. class: aClass
  2081. class := aClass
  2082. ! !
  2083. !ClassCommentReader methodsFor: 'fileIn'!
  2084. scanFrom: aChunkParser
  2085. | chunk |
  2086. chunk := aChunkParser nextChunk.
  2087. chunk isEmpty ifFalse: [
  2088. self setComment: chunk].
  2089. ! !
  2090. !ClassCommentReader methodsFor: 'initialization'!
  2091. initialize
  2092. super initialize.
  2093. chunkParser := ChunkParser new.
  2094. ! !
  2095. !ClassCommentReader methodsFor: 'private'!
  2096. setComment: aString
  2097. class comment: aString
  2098. ! !
  2099. Object subclass: #Random
  2100. instanceVariableNames: ''
  2101. category: 'Kernel'!
  2102. !Random methodsFor: 'accessing'!
  2103. next
  2104. <return Math.random()>
  2105. !
  2106. next: anInteger
  2107. ^(1 to: anInteger) collect: [:each | self next]
  2108. ! !
  2109. Object subclass: #Point
  2110. instanceVariableNames: 'x y'
  2111. category: 'Kernel'!
  2112. !Point methodsFor: 'accessing'!
  2113. x
  2114. ^x
  2115. !
  2116. y
  2117. ^y
  2118. !
  2119. y: aNumber
  2120. y := aNumber
  2121. !
  2122. x: aNumber
  2123. x := aNumber
  2124. ! !
  2125. !Point methodsFor: 'arithmetic'!
  2126. * aPoint
  2127. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2128. !
  2129. + aPoint
  2130. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2131. !
  2132. - aPoint
  2133. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2134. !
  2135. / aPoint
  2136. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2137. !
  2138. = aPoint
  2139. ^aPoint class = self class and: [
  2140. (aPoint x = self x) & (aPoint y = self y)]
  2141. ! !
  2142. !Point methodsFor: 'converting'!
  2143. asPoint
  2144. ^self
  2145. ! !
  2146. !Point class methodsFor: 'instance creation'!
  2147. x: aNumber y: anotherNumber
  2148. ^self new
  2149. x: aNumber;
  2150. y: anotherNumber;
  2151. yourself
  2152. ! !
  2153. Object subclass: #Message
  2154. instanceVariableNames: 'selector arguments'
  2155. category: 'Kernel'!
  2156. !Message methodsFor: 'accessing'!
  2157. selector
  2158. ^selector
  2159. !
  2160. selector: aString
  2161. selector := aString
  2162. !
  2163. arguments: anArray
  2164. arguments := anArray
  2165. !
  2166. arguments
  2167. ^arguments
  2168. ! !
  2169. !Message methodsFor: 'printing'!
  2170. printString
  2171. ^ String streamContents: [:aStream|
  2172. aStream
  2173. nextPutAll: super printString;
  2174. nextPutAll: '(';
  2175. nextPutAll: selector;
  2176. nextPutAll: ')' ]
  2177. ! !
  2178. !Message class methodsFor: 'instance creation'!
  2179. selector: aString arguments: anArray
  2180. ^self new
  2181. selector: aString;
  2182. arguments: anArray;
  2183. yourself
  2184. ! !
  2185. Error subclass: #MessageNotUnderstood
  2186. instanceVariableNames: 'message receiver'
  2187. category: 'Kernel'!
  2188. !MessageNotUnderstood methodsFor: 'accessing'!
  2189. message
  2190. ^message
  2191. !
  2192. message: aMessage
  2193. message := aMessage
  2194. !
  2195. receiver
  2196. ^receiver
  2197. !
  2198. receiver: anObject
  2199. receiver := anObject
  2200. !
  2201. messageText
  2202. ^self receiver asString, ' does not understand #', self message selector
  2203. ! !
  2204. Object subclass: #ErrorHandler
  2205. instanceVariableNames: ''
  2206. category: 'Kernel'!
  2207. !ErrorHandler methodsFor: 'error handling'!
  2208. handleError: anError
  2209. anError context ifNotNil: [self logErrorContext: anError context].
  2210. self logError: anError
  2211. ! !
  2212. !ErrorHandler methodsFor: 'private'!
  2213. logContext: aContext
  2214. aContext home ifNotNil: [
  2215. self logContext: aContext home].
  2216. self log: aContext receiver asString, '>>', aContext selector
  2217. !
  2218. logErrorContext: aContext
  2219. aContext ifNotNil: [
  2220. aContext home ifNotNil: [
  2221. self logContext: aContext home]]
  2222. !
  2223. logError: anError
  2224. self log: anError messageText
  2225. !
  2226. log: aString
  2227. console log: aString
  2228. ! !
  2229. ErrorHandler class instanceVariableNames: 'current'!
  2230. !ErrorHandler class methodsFor: 'accessing'!
  2231. current
  2232. ^current ifNil: [current := self new]
  2233. !
  2234. setCurrent: anHandler
  2235. current := anHandler
  2236. ! !
  2237. !ErrorHandler class methodsFor: 'initialization'!
  2238. initialize
  2239. self register
  2240. !
  2241. register
  2242. ErrorHandler setCurrent: self new
  2243. ! !
  2244. Object subclass: #JSObjectProxy
  2245. instanceVariableNames: 'jsObject'
  2246. category: 'Kernel'!
  2247. !JSObjectProxy methodsFor: 'accessing'!
  2248. jsObject: aJSObject
  2249. jsObject := aJSObject
  2250. !
  2251. jsObject
  2252. ^jsObject
  2253. !
  2254. at: aString
  2255. <return self['@jsObject'][aString]>
  2256. !
  2257. at: aString put: anObject
  2258. <self['@jsObject'][aString] = anObject>
  2259. ! !
  2260. !JSObjectProxy methodsFor: 'proxy'!
  2261. printString
  2262. ^self jsObject toString
  2263. !
  2264. inspectOn: anInspector
  2265. | variables |
  2266. variables := Dictionary new.
  2267. variables at: '#self' put: self jsObject.
  2268. anInspector setLabel: self printString.
  2269. <for(var i in self['@jsObject']) {
  2270. variables._at_put_(i, self['@jsObject'][i]);
  2271. }>.
  2272. anInspector setVariables: variables
  2273. !
  2274. doesNotUnderstand: aMessage
  2275. | obj selector jsSelector arguments |
  2276. obj := self jsObject.
  2277. selector := aMessage selector.
  2278. jsSelector := selector asJavaScriptSelector.
  2279. arguments := aMessage arguments.
  2280. <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
  2281. super doesNotUnderstand: aMessage
  2282. ! !
  2283. !JSObjectProxy class methodsFor: 'instance creation'!
  2284. on: aJSObject
  2285. ^self new
  2286. jsObject: aJSObject;
  2287. yourself
  2288. ! !
  2289. Collection subclass: #Set
  2290. instanceVariableNames: 'elements'
  2291. category: 'Kernel'!
  2292. !Set methodsFor: 'accessing'!
  2293. size
  2294. ^elements size
  2295. ! !
  2296. !Set methodsFor: 'adding/removing'!
  2297. add: anObject
  2298. <
  2299. var found;
  2300. for(var i in self['@elements']) {
  2301. if(anObject == self['@elements'][i]) {
  2302. found = true;
  2303. break;
  2304. }
  2305. }
  2306. if(!!found) {self['@elements'].push(anObject)}
  2307. >
  2308. !
  2309. remove: anObject
  2310. elements remove: anObject
  2311. ! !
  2312. !Set methodsFor: 'comparing'!
  2313. = aCollection
  2314. ^self class = aCollection class and: [
  2315. elements = aCollection asArray]
  2316. ! !
  2317. !Set methodsFor: 'converting'!
  2318. asArray
  2319. ^elements copy
  2320. ! !
  2321. !Set methodsFor: 'enumerating'!
  2322. detect: aBlock ifNone: anotherBlock
  2323. ^elements detect: aBlock ifNone: anotherBlock
  2324. !
  2325. do: aBlock
  2326. elements do: aBlock
  2327. ! !
  2328. !Set methodsFor: 'initialization'!
  2329. initialize
  2330. super initialize.
  2331. elements := #()
  2332. ! !
  2333. !Set methodsFor: 'testing'!
  2334. includes: anObject
  2335. ^elements includes: anObject
  2336. ! !