Kernel.st 45 KB

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