Kernel.st 41 KB

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