Kernel.st 47 KB

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