Kernel.st 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052
  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. !Collection methodsFor: 'enumerating'!
  1087. do: aBlock
  1088. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  1089. !
  1090. collect: aBlock
  1091. | newCollection |
  1092. newCollection := self class new.
  1093. self do: [:each |
  1094. newCollection add: (aBlock value: each)].
  1095. ^newCollection
  1096. !
  1097. detect: aBlock
  1098. ^self detect: aBlock ifNone: [self errorNotFound]
  1099. !
  1100. detect: aBlock ifNone: anotherBlock
  1101. <
  1102. for(var i = 0; i < self.length; i++)
  1103. if(aBlock(self[i]))
  1104. return self[i];
  1105. return anotherBlock();
  1106. >
  1107. !
  1108. do: aBlock separatedBy: anotherBlock
  1109. | first |
  1110. first := true.
  1111. self do: [:each |
  1112. first
  1113. ifTrue: [first := false]
  1114. ifFalse: [anotherBlock value].
  1115. aBlock value: each]
  1116. !
  1117. inject: anObject into: aBlock
  1118. | result |
  1119. result := anObject.
  1120. self do: [:each |
  1121. result := aBlock value: result value: each].
  1122. ^result
  1123. !
  1124. reject: aBlock
  1125. ^self select: [:each | (aBlock value: each) = false]
  1126. !
  1127. select: aBlock
  1128. | stream |
  1129. stream := self class new writeStream.
  1130. self do: [:each |
  1131. (aBlock value: each) ifTrue: [
  1132. stream nextPut: each]].
  1133. ^stream contents
  1134. ! !
  1135. !Collection methodsFor: 'error handling'!
  1136. errorNotFound
  1137. self error: 'Object is not in the collection'
  1138. ! !
  1139. !Collection methodsFor: 'testing'!
  1140. includes: anObject
  1141. <
  1142. var i = self.length;
  1143. while (i--) {
  1144. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1145. }
  1146. return false
  1147. >
  1148. !
  1149. notEmpty
  1150. ^self isEmpty not
  1151. !
  1152. isEmpty
  1153. ^self size = 0
  1154. !
  1155. ifNotEmpty: aBlock
  1156. self notEmpty ifTrue: aBlock.
  1157. !
  1158. ifEmpty: aBlock
  1159. self isEmpty ifTrue: aBlock.
  1160. ! !
  1161. !Collection class methodsFor: 'accessing'!
  1162. streamClass
  1163. ^Stream
  1164. ! !
  1165. !Collection class methodsFor: 'instance creation'!
  1166. with: anObject
  1167. ^self new
  1168. add: anObject;
  1169. yourself
  1170. !
  1171. with: anObject with: anotherObject
  1172. ^self new
  1173. add: anObject;
  1174. add: anotherObject;
  1175. yourself
  1176. !
  1177. with: firstObject with: secondObject with: thirdObject
  1178. ^self new
  1179. add: firstObject;
  1180. add: secondObject;
  1181. add: thirdObject;
  1182. yourself
  1183. !
  1184. withAll: aCollection
  1185. ^self new
  1186. addAll: aCollection;
  1187. yourself
  1188. ! !
  1189. Collection subclass: #SequenceableCollection
  1190. instanceVariableNames: ''
  1191. category: 'Kernel'!
  1192. !SequenceableCollection methodsFor: 'accessing'!
  1193. at: anIndex
  1194. ^self at: anIndex ifAbsent: [
  1195. self errorNotFound]
  1196. !
  1197. at: anIndex ifAbsent: aBlock
  1198. self subclassResponsibility
  1199. !
  1200. at: anIndex put: anObject
  1201. self subclassResponsibility
  1202. !
  1203. first
  1204. ^self at: 1
  1205. !
  1206. fourth
  1207. ^self at: 4
  1208. !
  1209. last
  1210. ^self at: self size
  1211. !
  1212. second
  1213. ^self at: 2
  1214. !
  1215. third
  1216. ^self at: 3
  1217. !
  1218. allButFirst
  1219. ^self copyFrom: 2 to: self size
  1220. !
  1221. allButLast
  1222. ^self copyFrom: 1 to: self size - 1
  1223. !
  1224. indexOf: anObject
  1225. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1226. !
  1227. indexOf: anObject ifAbsent: aBlock
  1228. <
  1229. for(var i=0;i<self.length;i++){
  1230. if(self[i].__eq(anObject)) {return i+1}
  1231. }
  1232. return aBlock();
  1233. >
  1234. !
  1235. indexOf: anObject startingAt: start ifAbsent: aBlock
  1236. <
  1237. for(var i=start-1;i<self.length;i++){
  1238. if(self[i].__eq(anObject)) {return i+1}
  1239. }
  1240. return aBlock();
  1241. >
  1242. !
  1243. indexOf: anObject startingAt: start
  1244. "Answer the index of the first occurence of anElement after start
  1245. within the receiver. If the receiver does not contain anElement,
  1246. answer 0."
  1247. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1248. ! !
  1249. !SequenceableCollection methodsFor: 'adding'!
  1250. removeLast
  1251. self remove: self last
  1252. !
  1253. addLast: anObject
  1254. self add: anObject
  1255. ! !
  1256. !SequenceableCollection methodsFor: 'converting'!
  1257. reversed
  1258. self subclassResponsibility
  1259. ! !
  1260. !SequenceableCollection methodsFor: 'copying'!
  1261. copyFrom: anIndex to: anotherIndex
  1262. self subclassResponsibility
  1263. ! !
  1264. !SequenceableCollection methodsFor: 'enumerating'!
  1265. withIndexDo: aBlock
  1266. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1267. ! !
  1268. SequenceableCollection subclass: #String
  1269. instanceVariableNames: ''
  1270. category: 'Kernel'!
  1271. !String methodsFor: 'accessing'!
  1272. size
  1273. <return self.length>
  1274. !
  1275. at: anIndex
  1276. <return self[anIndex - 1]>
  1277. !
  1278. at: anIndex put: anObject
  1279. self errorReadOnly
  1280. !
  1281. at: anIndex ifAbsent: aBlock
  1282. (self at: anIndex) ifNil: [aBlock]
  1283. !
  1284. escaped
  1285. <return escape(self)>
  1286. !
  1287. unescaped
  1288. <return unescape(self)>
  1289. !
  1290. asciiValue
  1291. <return self.charCodeAt(0);>
  1292. ! !
  1293. !String methodsFor: 'adding'!
  1294. add: anObject
  1295. self errorReadOnly
  1296. !
  1297. remove: anObject
  1298. self errorReadOnly
  1299. ! !
  1300. !String methodsFor: 'comparing'!
  1301. = aString
  1302. aString class = self class ifFalse: [^false].
  1303. <return String(self) == aString>
  1304. !
  1305. > aString
  1306. <return String(self) >> aString>
  1307. !
  1308. < aString
  1309. <return String(self) < aString>
  1310. !
  1311. >= aString
  1312. <return String(self) >>= aString>
  1313. !
  1314. <= aString
  1315. <return String(self) <= aString>
  1316. !
  1317. == aString
  1318. aString class = self class ifFalse: [^false].
  1319. <return String(self) === String(aString)>
  1320. ! !
  1321. !String methodsFor: 'converting'!
  1322. asSelector
  1323. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1324. | selector |
  1325. selector := '_', self.
  1326. selector := selector replace: ':' with: '_'.
  1327. selector := selector replace: '[+]' with: '_plus'.
  1328. selector := selector replace: '-' with: '_minus'.
  1329. selector := selector replace: '[*]' with: '_star'.
  1330. selector := selector replace: '[/]' with: '_slash'.
  1331. selector := selector replace: '>' with: '_gt'.
  1332. selector := selector replace: '<' with: '_lt'.
  1333. selector := selector replace: '=' with: '_eq'.
  1334. selector := selector replace: ',' with: '_comma'.
  1335. selector := selector replace: '[@]' with: '_at'.
  1336. ^selector
  1337. !
  1338. asJavascript
  1339. <
  1340. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1341. return "unescape(\"" + escape(self) + "\")";
  1342. else
  1343. return "\"" + self + "\"";
  1344. >
  1345. !
  1346. tokenize: aString
  1347. <return self.split(aString)>
  1348. !
  1349. asString
  1350. ^self
  1351. !
  1352. asNumber
  1353. <return Number(self)>
  1354. !
  1355. asJSONObject
  1356. ^self
  1357. !
  1358. asLowercase
  1359. <return self.toLowerCase()>
  1360. !
  1361. asUppercase
  1362. <return self.toUpperCase()>
  1363. !
  1364. reversed
  1365. <return self.split("").reverse().join("")>
  1366. !
  1367. asJavaScriptSelector
  1368. <return String(self.replace(/^_/, '').replace(/_.*/, ''))>
  1369. ! !
  1370. !String methodsFor: 'copying'!
  1371. , aString
  1372. <return self + aString>
  1373. !
  1374. copyFrom: anIndex to: anotherIndex
  1375. <return self.substring(anIndex - 1, anotherIndex)>
  1376. !
  1377. shallowCopy
  1378. ^self class fromString: self
  1379. !
  1380. deepCopy
  1381. ^self shallowCopy
  1382. ! !
  1383. !String methodsFor: 'error handling'!
  1384. errorReadOnly
  1385. self error: 'Object is read-only'
  1386. ! !
  1387. !String methodsFor: 'printing'!
  1388. printString
  1389. ^'''', self, ''''
  1390. !
  1391. printNl
  1392. <console.log(self)>
  1393. ! !
  1394. !String methodsFor: 'regular expressions'!
  1395. replace: aString with: anotherString
  1396. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1397. !
  1398. replaceRegexp: aRegexp with: aString
  1399. <return self.replace(aRegexp, aString)>
  1400. !
  1401. match: aRegexp
  1402. <return self.search(aRegexp) !!= -1>
  1403. !
  1404. trimLeft: separators
  1405. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1406. !
  1407. trimRight: separators
  1408. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1409. !
  1410. trimLeft
  1411. ^self trimLeft: '\s'
  1412. !
  1413. trimRight
  1414. ^self trimRight: '\s'
  1415. !
  1416. trimBoth
  1417. ^self trimBoth: '\s'
  1418. !
  1419. trimBoth: separators
  1420. ^(self trimLeft: separators) trimRight: separators
  1421. ! !
  1422. !String methodsFor: 'split join'!
  1423. join: aCollection
  1424. ^ String
  1425. streamContents: [:stream | aCollection
  1426. do: [:each | stream nextPutAll: each asString]
  1427. separatedBy: [stream nextPutAll: self]]
  1428. !
  1429. lineIndicesDo: aBlock
  1430. "execute aBlock with 3 arguments for each line:
  1431. - start index of line
  1432. - end index of line without line delimiter
  1433. - end index of line including line delimiter(s) CR, LF or CRLF"
  1434. | cr lf start sz nextLF nextCR |
  1435. start := 1.
  1436. sz := self size.
  1437. cr := String cr.
  1438. nextCR := self indexOf: cr startingAt: 1.
  1439. lf := String lf.
  1440. nextLF := self indexOf: lf startingAt: 1.
  1441. [ start <= sz ] whileTrue: [
  1442. (nextLF = 0 and: [ nextCR = 0 ])
  1443. ifTrue: [ "No more CR, nor LF, the string is over"
  1444. aBlock value: start value: sz value: sz.
  1445. ^self ].
  1446. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1447. ifTrue: [ "Found a LF"
  1448. aBlock value: start value: nextLF - 1 value: nextLF.
  1449. start := 1 + nextLF.
  1450. nextLF := self indexOf: lf startingAt: start ]
  1451. ifFalse: [ 1 + nextCR = nextLF
  1452. ifTrue: [ "Found a CR-LF pair"
  1453. aBlock value: start value: nextCR - 1 value: nextLF.
  1454. start := 1 + nextLF.
  1455. nextCR := self indexOf: cr startingAt: start.
  1456. nextLF := self indexOf: lf startingAt: start ]
  1457. ifFalse: [ "Found a CR"
  1458. aBlock value: start value: nextCR - 1 value: nextCR.
  1459. start := 1 + nextCR.
  1460. nextCR := self indexOf: cr startingAt: start ]]]
  1461. !
  1462. linesDo: aBlock
  1463. "Execute aBlock with each line in this string. The terminating line
  1464. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1465. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1466. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1467. !
  1468. lines
  1469. "Answer an array of lines composing this receiver without the line ending delimiters."
  1470. | lines |
  1471. lines := Array new.
  1472. self linesDo: [:aLine | lines add: aLine].
  1473. ^lines
  1474. !
  1475. lineNumber: anIndex
  1476. "Answer a string containing the characters in the given line number."
  1477. | lineCount |
  1478. lineCount := 0.
  1479. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1480. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1481. ^nil
  1482. ! !
  1483. !String methodsFor: 'testing'!
  1484. isString
  1485. ^true
  1486. !
  1487. includesSubString: subString
  1488. < return self.indexOf(subString) !!= -1 >
  1489. ! !
  1490. !String class methodsFor: 'accessing'!
  1491. streamClass
  1492. ^StringStream
  1493. !
  1494. cr
  1495. <return '\r'>
  1496. !
  1497. lf
  1498. <return '\n'>
  1499. !
  1500. space
  1501. <return ' '>
  1502. !
  1503. tab
  1504. <return '\t'>
  1505. !
  1506. crlf
  1507. <return '\r\n'>
  1508. ! !
  1509. !String class methodsFor: 'instance creation'!
  1510. fromString: aString
  1511. <return new self.fn(aString)>
  1512. !
  1513. streamContents: blockWithArg
  1514. |stream|
  1515. stream := (self streamClass on: String new).
  1516. blockWithArg value: stream.
  1517. ^ stream contents
  1518. !
  1519. value: aUTFCharCode
  1520. <return String.fromCharCode(aUTFCharCode);>
  1521. ! !
  1522. SequenceableCollection subclass: #Array
  1523. instanceVariableNames: ''
  1524. category: 'Kernel'!
  1525. !Array methodsFor: 'accessing'!
  1526. size
  1527. <return self.length>
  1528. !
  1529. at: anIndex put: anObject
  1530. <return self[anIndex - 1] = anObject>
  1531. !
  1532. at: anIndex ifAbsent: aBlock
  1533. <
  1534. var value = self[anIndex - 1];
  1535. if(value === undefined) {
  1536. return aBlock();
  1537. } else {
  1538. return value;
  1539. }
  1540. >
  1541. ! !
  1542. !Array methodsFor: 'adding/removing'!
  1543. add: anObject
  1544. <self.push(anObject); return anObject;>
  1545. !
  1546. remove: anObject
  1547. <
  1548. for(var i=0;i<self.length;i++) {
  1549. if(self[i] == anObject) {
  1550. self.splice(i,1);
  1551. break;
  1552. }
  1553. }
  1554. >
  1555. !
  1556. removeFrom: aNumber to: anotherNumber
  1557. <self.splice(aNumber - 1,anotherNumber - 1)>
  1558. ! !
  1559. !Array methodsFor: 'comparing'!
  1560. = aCollection
  1561. (self class = aCollection class and: [
  1562. self size = aCollection size]) ifFalse: [^false].
  1563. self withIndexDo: [:each :i |
  1564. (aCollection at: i) = each ifFalse: [^false]].
  1565. ^true
  1566. ! !
  1567. !Array methodsFor: 'converting'!
  1568. asJavascript
  1569. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1570. !
  1571. asJSONObject
  1572. ^self collect: [:each | each asJSONObject]
  1573. !
  1574. reversed
  1575. <return self._copy().reverse()>
  1576. ! !
  1577. !Array methodsFor: 'copying'!
  1578. shallowCopy
  1579. | newCollection |
  1580. newCollection := self class new.
  1581. self do: [:each | newCollection add: each].
  1582. ^newCollection
  1583. !
  1584. deepCopy
  1585. | newCollection |
  1586. newCollection := self class new.
  1587. self do: [:each | newCollection add: each deepCopy].
  1588. ^newCollection
  1589. !
  1590. copyFrom: anIndex to: anotherIndex
  1591. | array |
  1592. array := self class new.
  1593. anIndex to: anotherIndex do: [:each |
  1594. array add: (self at: each)].
  1595. ^array
  1596. ! !
  1597. !Array methodsFor: 'enumerating'!
  1598. join: aString
  1599. <return self.join(aString)>
  1600. !
  1601. sort
  1602. ^self basicPerform: 'sort'
  1603. !
  1604. sort: aBlock
  1605. <
  1606. return self.sort(function(a, b) {
  1607. if(aBlock(a,b)) {return -1} else {return 1}
  1608. })
  1609. >
  1610. !
  1611. sorted
  1612. ^self copy sort
  1613. !
  1614. sorted: aBlock
  1615. ^self copy sort: aBlock
  1616. !
  1617. printString
  1618. | str |
  1619. str := '' writeStream.
  1620. str nextPutAll: super printString, ' ('.
  1621. self
  1622. do: [:each | str nextPutAll: each printString]
  1623. separatedBy: [str nextPutAll: ' '].
  1624. str nextPutAll: ')'.
  1625. ^str contents
  1626. ! !
  1627. Object subclass: #RegularExpression
  1628. instanceVariableNames: ''
  1629. category: 'Kernel'!
  1630. !RegularExpression methodsFor: 'evaluating'!
  1631. compile: aString
  1632. <return self.compile(aString)>
  1633. !
  1634. exec: aString
  1635. <return self.exec(aString) || nil>
  1636. !
  1637. test: aString
  1638. <return self.test(aString)>
  1639. ! !
  1640. !RegularExpression class methodsFor: 'instance creation'!
  1641. fromString: aString flag: anotherString
  1642. <return new RegExp(aString, anotherString)>
  1643. !
  1644. fromString: aString
  1645. ^self fromString: aString flag: ''
  1646. ! !
  1647. Object subclass: #Error
  1648. instanceVariableNames: 'messageText'
  1649. category: 'Kernel'!
  1650. !Error methodsFor: 'accessing'!
  1651. messageText
  1652. ^messageText
  1653. !
  1654. messageText: aString
  1655. messageText := aString
  1656. !
  1657. context
  1658. <return self.context>
  1659. ! !
  1660. !Error methodsFor: 'signaling'!
  1661. signal
  1662. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1663. ! !
  1664. !Error class methodsFor: 'instance creation'!
  1665. signal: aString
  1666. ^self new
  1667. messageText: aString;
  1668. signal
  1669. ! !
  1670. Object subclass: #MethodContext
  1671. instanceVariableNames: ''
  1672. category: 'Kernel'!
  1673. !MethodContext methodsFor: 'accessing'!
  1674. receiver
  1675. <return self.receiver>
  1676. !
  1677. selector
  1678. <return smalltalk.convertSelector(self.selector)>
  1679. !
  1680. home
  1681. <return self.homeContext>
  1682. !
  1683. temps
  1684. <return self.temps>
  1685. !
  1686. printString
  1687. ^super printString, '(', self asString, ')'
  1688. !
  1689. asString
  1690. ^self receiver class printString, ' >> ', self selector
  1691. ! !
  1692. Object subclass: #Association
  1693. instanceVariableNames: 'key value'
  1694. category: 'Kernel'!
  1695. !Association methodsFor: 'accessing'!
  1696. key: aKey
  1697. key := aKey
  1698. !
  1699. key
  1700. ^key
  1701. !
  1702. value: aValue
  1703. value := aValue
  1704. !
  1705. value
  1706. ^value
  1707. ! !
  1708. !Association methodsFor: 'comparing'!
  1709. = anAssociation
  1710. ^self class = anAssociation class and: [
  1711. self key = anAssociation key and: [
  1712. self value = anAssociation value]]
  1713. ! !
  1714. !Association class methodsFor: 'instance creation'!
  1715. key: aKey value: aValue
  1716. ^self new
  1717. key: aKey;
  1718. value: aValue;
  1719. yourself
  1720. ! !
  1721. Collection subclass: #Dictionary
  1722. instanceVariableNames: 'keys'
  1723. category: 'Kernel'!
  1724. !Dictionary methodsFor: 'accessing'!
  1725. size
  1726. ^keys size
  1727. !
  1728. associations
  1729. | associations |
  1730. associations := #().
  1731. keys do: [:each |
  1732. associations add: (Association key: each value: (self at: each))].
  1733. ^associations
  1734. !
  1735. keys
  1736. ^keys copy
  1737. !
  1738. values
  1739. ^keys collect: [:each | self at: each]
  1740. !
  1741. at: aKey put: aValue
  1742. (keys includes: aKey) ifFalse: [keys add: aKey].
  1743. ^self basicAt: aKey put: aValue
  1744. !
  1745. at: aKey ifAbsent: aBlock
  1746. ^(self keys includes: aKey)
  1747. ifTrue: [self basicAt: aKey]
  1748. ifFalse: aBlock
  1749. !
  1750. at: aKey ifAbsentPut: aBlock
  1751. ^self at: aKey ifAbsent: [
  1752. self at: aKey put: aBlock value]
  1753. !
  1754. at: aKey ifPresent: aBlock
  1755. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1756. !
  1757. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1758. ^(self basicAt: aKey)
  1759. ifNil: anotherBlock
  1760. ifNotNil: [aBlock value: (self at: aKey)]
  1761. !
  1762. at: aKey
  1763. ^self at: aKey ifAbsent: [self errorNotFound]
  1764. ! !
  1765. !Dictionary methodsFor: 'adding/removing'!
  1766. add: anAssociation
  1767. self at: anAssociation key put: anAssociation value
  1768. !
  1769. addAll: aDictionary
  1770. super addAll: aDictionary associations.
  1771. ^aDictionary
  1772. !
  1773. remove: aKey
  1774. self removeKey: aKey
  1775. !
  1776. removeKey: aKey
  1777. keys remove: aKey
  1778. ! !
  1779. !Dictionary methodsFor: 'comparing'!
  1780. = aDictionary
  1781. self class = aDictionary class ifFalse: [^false].
  1782. self size = aDictionary size ifFalse: [^false].
  1783. ^self associations = aDictionary associations
  1784. ! !
  1785. !Dictionary methodsFor: 'converting'!
  1786. asJSONObject
  1787. | object |
  1788. object := Object new.
  1789. self keysAndValuesDo: [:key :value |
  1790. object basicAt: key put: value asJSONObject].
  1791. ^object
  1792. ! !
  1793. !Dictionary methodsFor: 'copying'!
  1794. shallowCopy
  1795. | copy |
  1796. copy := self class new.
  1797. self associationsDo: [:each |
  1798. copy at: each key put: each value].
  1799. ^copy
  1800. !
  1801. , aCollection
  1802. self shouldNotImplement
  1803. !
  1804. copyFrom: anIndex to: anotherIndex
  1805. self shouldNotImplement
  1806. ! !
  1807. !Dictionary methodsFor: 'enumerating'!
  1808. associationsDo: aBlock
  1809. self associations do: aBlock
  1810. !
  1811. keysAndValuesDo: aBlock
  1812. self associationsDo: [:each |
  1813. aBlock value: each key value: each value]
  1814. !
  1815. do: aBlock
  1816. self values do: aBlock
  1817. !
  1818. select: aBlock
  1819. | newDict |
  1820. newDict := self class new.
  1821. self keysAndValuesDo: [:key :value |
  1822. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1823. ^newDict
  1824. !
  1825. collect: aBlock
  1826. | newDict |
  1827. newDict := self class new.
  1828. self keysAndValuesDo: [:key :value |
  1829. newDict at: key put: (aBlock value: value)].
  1830. ^newDict
  1831. !
  1832. detect: aBlock ifNone: anotherBlock
  1833. ^self values detect: aBlock ifNone: anotherBlock
  1834. !
  1835. includes: anObject
  1836. ^self values includes: anObject
  1837. ! !
  1838. !Dictionary methodsFor: 'initialization'!
  1839. initialize
  1840. super initialize.
  1841. keys := #()
  1842. ! !
  1843. !Dictionary methodsFor: 'printing'!
  1844. printString
  1845. ^ String streamContents: [:aStream|
  1846. aStream
  1847. nextPutAll: super printString;
  1848. nextPutAll: '('.
  1849. self associations
  1850. do: [:anAssociation|
  1851. aStream
  1852. nextPutAll: anAssociation key printString;
  1853. nextPutAll: ' -> ';
  1854. nextPutAll: anAssociation value printString]
  1855. separatedBy: [aStream nextPutAll: ' , '].
  1856. aStream nextPutAll: ')'.
  1857. ]
  1858. ! !
  1859. !Dictionary class methodsFor: 'instance creation'!
  1860. fromPairs: aCollection
  1861. | dict |
  1862. dict := self new.
  1863. aCollection do: [:each | dict add: each].
  1864. ^dict
  1865. ! !
  1866. Object subclass: #ClassBuilder
  1867. instanceVariableNames: ''
  1868. category: 'Kernel'!
  1869. !ClassBuilder methodsFor: 'class creation'!
  1870. superclass: aClass subclass: aString
  1871. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  1872. !
  1873. class: aClass instanceVariableNames: aString
  1874. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1875. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1876. self setupClass: aClass
  1877. !
  1878. superclass: aClass subclass: aString instanceVariableNames: aString2 module: aString3
  1879. | newClass |
  1880. newClass := self addSubclassOf: aClass
  1881. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1882. module: (aString3 ifNil: ['unclassified']).
  1883. self setupClass: newClass
  1884. !
  1885. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  1886. | newClass |
  1887. newClass := self addSubclassOf: aClass
  1888. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1889. package: (aString3 ifNil: ['unclassified']).
  1890. self setupClass: newClass
  1891. ! !
  1892. !ClassBuilder methodsFor: 'private'!
  1893. instanceVariableNamesFor: aString
  1894. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1895. !
  1896. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1897. <smalltalk.addClass(aString, aClass, aCollection);
  1898. return smalltalk[aString]>
  1899. !
  1900. setupClass: aClass
  1901. <smalltalk.init(aClass);>
  1902. !
  1903. addSubclassOf: aClass named: aString instanceVariableNames: aCollection module: moduleName
  1904. <smalltalk.addClass(aString, aClass, aCollection, moduleName);
  1905. return smalltalk[aString]>
  1906. !
  1907. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  1908. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  1909. return smalltalk[aString]>
  1910. ! !
  1911. Object subclass: #ClassCategoryReader
  1912. instanceVariableNames: 'class category chunkParser'
  1913. category: 'Kernel'!
  1914. !ClassCategoryReader methodsFor: 'accessing'!
  1915. class: aClass category: aString
  1916. class := aClass.
  1917. category := aString
  1918. ! !
  1919. !ClassCategoryReader methodsFor: 'fileIn'!
  1920. scanFrom: aChunkParser
  1921. | chunk |
  1922. [chunk := aChunkParser nextChunk.
  1923. chunk isEmpty] whileFalse: [
  1924. self compileMethod: chunk]
  1925. ! !
  1926. !ClassCategoryReader methodsFor: 'initialization'!
  1927. initialize
  1928. super initialize.
  1929. chunkParser := ChunkParser new.
  1930. ! !
  1931. !ClassCategoryReader methodsFor: 'private'!
  1932. compileMethod: aString
  1933. | method |
  1934. method := Compiler new load: aString forClass: class.
  1935. method category: category.
  1936. class addCompiledMethod: method
  1937. ! !
  1938. Object subclass: #Stream
  1939. instanceVariableNames: 'collection position streamSize'
  1940. category: 'Kernel'!
  1941. !Stream methodsFor: 'accessing'!
  1942. collection
  1943. ^collection
  1944. !
  1945. setCollection: aCollection
  1946. collection := aCollection
  1947. !
  1948. position
  1949. ^position ifNil: [position := 0]
  1950. !
  1951. position: anInteger
  1952. position := anInteger
  1953. !
  1954. streamSize
  1955. ^streamSize
  1956. !
  1957. setStreamSize: anInteger
  1958. streamSize := anInteger
  1959. !
  1960. contents
  1961. ^self collection
  1962. copyFrom: 1
  1963. to: self streamSize
  1964. !
  1965. size
  1966. ^self streamSize
  1967. ! !
  1968. !Stream methodsFor: 'actions'!
  1969. reset
  1970. self position: 0
  1971. !
  1972. close
  1973. !
  1974. flush
  1975. !
  1976. resetContents
  1977. self reset.
  1978. self setStreamSize: 0
  1979. ! !
  1980. !Stream methodsFor: 'enumerating'!
  1981. do: aBlock
  1982. [self atEnd] whileFalse: [aBlock value: self next]
  1983. ! !
  1984. !Stream methodsFor: 'positioning'!
  1985. setToEnd
  1986. self position: self size
  1987. !
  1988. skip: anInteger
  1989. self position: ((self position + anInteger) min: self size max: 0)
  1990. ! !
  1991. !Stream methodsFor: 'reading'!
  1992. next
  1993. self position: self position + 1.
  1994. ^collection at: self position
  1995. !
  1996. next: anInteger
  1997. | tempCollection |
  1998. tempCollection := self collection class new.
  1999. anInteger timesRepeat: [
  2000. self atEnd ifFalse: [
  2001. tempCollection add: self next]].
  2002. ^tempCollection
  2003. !
  2004. peek
  2005. ^self atEnd ifFalse: [
  2006. self collection at: self position + 1]
  2007. ! !
  2008. !Stream methodsFor: 'testing'!
  2009. atEnd
  2010. ^self position = self size
  2011. !
  2012. atStart
  2013. ^self position = 0
  2014. !
  2015. isEmpty
  2016. ^self size = 0
  2017. ! !
  2018. !Stream methodsFor: 'writing'!
  2019. nextPut: anObject
  2020. self position: self position + 1.
  2021. self collection at: self position put: anObject.
  2022. self setStreamSize: (self streamSize max: self position)
  2023. !
  2024. nextPutAll: aCollection
  2025. aCollection do: [:each |
  2026. self nextPut: each]
  2027. ! !
  2028. !Stream class methodsFor: 'instance creation'!
  2029. on: aCollection
  2030. ^self new
  2031. setCollection: aCollection;
  2032. setStreamSize: aCollection size;
  2033. yourself
  2034. ! !
  2035. Stream subclass: #StringStream
  2036. instanceVariableNames: ''
  2037. category: 'Kernel'!
  2038. !StringStream methodsFor: 'reading'!
  2039. next: anInteger
  2040. | tempCollection |
  2041. tempCollection := self collection class new.
  2042. anInteger timesRepeat: [
  2043. self atEnd ifFalse: [
  2044. tempCollection := tempCollection, self next]].
  2045. ^tempCollection
  2046. ! !
  2047. !StringStream methodsFor: 'writing'!
  2048. nextPut: aString
  2049. self nextPutAll: aString
  2050. !
  2051. nextPutAll: aString
  2052. self setCollection:
  2053. (self collection copyFrom: 1 to: self position),
  2054. aString,
  2055. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  2056. self position: self position + aString size.
  2057. self setStreamSize: (self streamSize max: self position)
  2058. !
  2059. cr
  2060. ^self nextPutAll: String cr
  2061. !
  2062. crlf
  2063. ^self nextPutAll: String crlf
  2064. !
  2065. lf
  2066. ^self nextPutAll: String lf
  2067. !
  2068. space
  2069. self nextPut: ' '
  2070. ! !
  2071. Object subclass: #ClassCommentReader
  2072. instanceVariableNames: 'class chunkParser'
  2073. category: 'Kernel'!
  2074. !ClassCommentReader methodsFor: 'accessing'!
  2075. class: aClass
  2076. class := aClass
  2077. ! !
  2078. !ClassCommentReader methodsFor: 'fileIn'!
  2079. scanFrom: aChunkParser
  2080. | chunk |
  2081. chunk := aChunkParser nextChunk.
  2082. chunk isEmpty ifFalse: [
  2083. self setComment: chunk].
  2084. ! !
  2085. !ClassCommentReader methodsFor: 'initialization'!
  2086. initialize
  2087. super initialize.
  2088. chunkParser := ChunkParser new.
  2089. ! !
  2090. !ClassCommentReader methodsFor: 'private'!
  2091. setComment: aString
  2092. class comment: aString
  2093. ! !
  2094. Object subclass: #Random
  2095. instanceVariableNames: ''
  2096. category: 'Kernel'!
  2097. !Random methodsFor: 'accessing'!
  2098. next
  2099. <return Math.random()>
  2100. !
  2101. next: anInteger
  2102. ^(1 to: anInteger) collect: [:each | self next]
  2103. ! !
  2104. Object subclass: #Point
  2105. instanceVariableNames: 'x y'
  2106. category: 'Kernel'!
  2107. !Point methodsFor: 'accessing'!
  2108. x
  2109. ^x
  2110. !
  2111. y
  2112. ^y
  2113. !
  2114. y: aNumber
  2115. y := aNumber
  2116. !
  2117. x: aNumber
  2118. x := aNumber
  2119. ! !
  2120. !Point methodsFor: 'arithmetic'!
  2121. * aPoint
  2122. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2123. !
  2124. + aPoint
  2125. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2126. !
  2127. - aPoint
  2128. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2129. !
  2130. / aPoint
  2131. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2132. !
  2133. = aPoint
  2134. ^aPoint class = self class and: [
  2135. (aPoint x = self x) & (aPoint y = self y)]
  2136. ! !
  2137. !Point methodsFor: 'converting'!
  2138. asPoint
  2139. ^self
  2140. ! !
  2141. !Point class methodsFor: 'instance creation'!
  2142. x: aNumber y: anotherNumber
  2143. ^self new
  2144. x: aNumber;
  2145. y: anotherNumber;
  2146. yourself
  2147. ! !
  2148. Object subclass: #Message
  2149. instanceVariableNames: 'selector arguments'
  2150. category: 'Kernel'!
  2151. !Message methodsFor: 'accessing'!
  2152. selector
  2153. ^selector
  2154. !
  2155. selector: aString
  2156. selector := aString
  2157. !
  2158. arguments: anArray
  2159. arguments := anArray
  2160. !
  2161. arguments
  2162. ^arguments
  2163. ! !
  2164. !Message class methodsFor: 'instance creation'!
  2165. selector: aString arguments: anArray
  2166. ^self new
  2167. selector: aString;
  2168. arguments: anArray;
  2169. yourself
  2170. ! !
  2171. Error subclass: #MessageNotUnderstood
  2172. instanceVariableNames: 'message receiver'
  2173. category: 'Kernel'!
  2174. !MessageNotUnderstood methodsFor: 'accessing'!
  2175. message
  2176. ^message
  2177. !
  2178. message: aMessage
  2179. message := aMessage
  2180. !
  2181. receiver
  2182. ^receiver
  2183. !
  2184. receiver: anObject
  2185. receiver := anObject
  2186. !
  2187. messageText
  2188. ^self receiver asString, ' does not understand #', self message selector
  2189. ! !
  2190. Object subclass: #ErrorHandler
  2191. instanceVariableNames: ''
  2192. category: 'Kernel'!
  2193. !ErrorHandler methodsFor: 'error handling'!
  2194. handleError: anError
  2195. anError context ifNotNil: [self logErrorContext: anError context].
  2196. self logError: anError
  2197. ! !
  2198. !ErrorHandler methodsFor: 'private'!
  2199. logContext: aContext
  2200. aContext home ifNotNil: [
  2201. self logContext: aContext home].
  2202. self log: aContext receiver asString, '>>', aContext selector
  2203. !
  2204. logErrorContext: aContext
  2205. aContext ifNotNil: [
  2206. aContext home ifNotNil: [
  2207. self logContext: aContext home]]
  2208. !
  2209. logError: anError
  2210. self log: anError messageText
  2211. !
  2212. log: aString
  2213. console log: aString
  2214. ! !
  2215. ErrorHandler class instanceVariableNames: 'current'!
  2216. !ErrorHandler class methodsFor: 'accessing'!
  2217. current
  2218. ^current ifNil: [current := self new]
  2219. !
  2220. setCurrent: anHandler
  2221. current := anHandler
  2222. ! !
  2223. !ErrorHandler class methodsFor: 'initialization'!
  2224. initialize
  2225. self register
  2226. !
  2227. register
  2228. ErrorHandler setCurrent: self new
  2229. ! !
  2230. Object subclass: #JSObjectProxy
  2231. instanceVariableNames: 'jsObject'
  2232. category: 'Kernel'!
  2233. !JSObjectProxy methodsFor: 'accessing'!
  2234. jsObject: aJSObject
  2235. jsObject := aJSObject
  2236. !
  2237. jsObject
  2238. ^jsObject
  2239. !
  2240. at: aString
  2241. <return self['@jsObject'][aString]>
  2242. !
  2243. at: aString put: anObject
  2244. <self['@jsObject'][aString] = anObject>
  2245. ! !
  2246. !JSObjectProxy methodsFor: 'proxy'!
  2247. printString
  2248. ^self jsObject toString
  2249. !
  2250. inspectOn: anInspector
  2251. | variables |
  2252. variables := Dictionary new.
  2253. variables at: '#self' put: self jsObject.
  2254. anInspector setLabel: self printString.
  2255. <for(var i in self['@jsObject']) {
  2256. variables._at_put_(i, self['@jsObject'][i]);
  2257. }>.
  2258. anInspector setVariables: variables
  2259. !
  2260. doesNotUnderstand: aMessage
  2261. | obj selector jsSelector arguments |
  2262. obj := self jsObject.
  2263. selector := aMessage selector.
  2264. jsSelector := selector asJavaScriptSelector.
  2265. arguments := aMessage arguments.
  2266. <if(obj[jsSelector]) {return smalltalk.send(obj, jsSelector, arguments)}>.
  2267. super doesNotUnderstand: aMessage
  2268. ! !
  2269. !JSObjectProxy class methodsFor: 'instance creation'!
  2270. on: aJSObject
  2271. ^self new
  2272. jsObject: aJSObject;
  2273. yourself
  2274. ! !
  2275. Collection subclass: #Set
  2276. instanceVariableNames: 'elements'
  2277. category: 'Kernel'!
  2278. !Set methodsFor: 'accessing'!
  2279. size
  2280. ^elements size
  2281. ! !
  2282. !Set methodsFor: 'adding/removing'!
  2283. add: anObject
  2284. <
  2285. var found;
  2286. for(var i in self['@elements']) {
  2287. if(anObject == self['@elements'][i]) {
  2288. found = true;
  2289. break;
  2290. }
  2291. }
  2292. if(!!found) {self['@elements'].push(anObject)}
  2293. >
  2294. !
  2295. remove: anObject
  2296. elements remove: anObject
  2297. ! !
  2298. !Set methodsFor: 'comparing'!
  2299. = aCollection
  2300. ^self class = aCollection class and: [
  2301. elements = aCollection asArray]
  2302. ! !
  2303. !Set methodsFor: 'converting'!
  2304. asArray
  2305. ^elements copy
  2306. ! !
  2307. !Set methodsFor: 'enumerating'!
  2308. detect: aBlock ifNone: anotherBlock
  2309. ^elements detect: aBlock ifNone: anotherBlock
  2310. !
  2311. do: aBlock
  2312. elements do: aBlock
  2313. ! !
  2314. !Set methodsFor: 'initialization'!
  2315. initialize
  2316. super initialize.
  2317. elements := #()
  2318. ! !
  2319. !Set methodsFor: 'testing'!
  2320. includes: anObject
  2321. ^elements includes: anObject
  2322. ! !