Kernel.st 44 KB

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