Kernel.st 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819
  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. printShowingDecimalPlaces: placesDesired
  555. <return self.toFixed(placesDesired)>
  556. ! !
  557. !Number methodsFor: 'testing'!
  558. isNumber
  559. ^true
  560. !
  561. even
  562. ^ 0 = (self modulo: 2)
  563. !
  564. odd
  565. ^ self even not
  566. ! !
  567. !Number methodsFor: 'timeouts/intervals'!
  568. clearInterval
  569. <clearInterval(Number(self))>
  570. !
  571. clearTimeout
  572. <clearTimeout(Number(self))>
  573. ! !
  574. !Number class methodsFor: 'instance creation'!
  575. pi
  576. <return Math.PI>
  577. ! !
  578. Object subclass: #BlockClosure
  579. instanceVariableNames: ''
  580. category: 'Kernel'!
  581. !BlockClosure methodsFor: 'accessing'!
  582. compiledSource
  583. <return self.toString()>
  584. ! !
  585. !BlockClosure methodsFor: 'controlling'!
  586. whileTrue: aBlock
  587. "inlined in the Compiler"
  588. <while(self()) {aBlock()}>
  589. !
  590. whileFalse: aBlock
  591. "inlined in the Compiler"
  592. <while(!!self()) {aBlock()}>
  593. !
  594. whileFalse
  595. "inlined in the Compiler"
  596. self whileFalse: []
  597. !
  598. whileTrue
  599. "inlined in the Compiler"
  600. self whileTrue: []
  601. ! !
  602. !BlockClosure methodsFor: 'error handling'!
  603. on: anErrorClass do: aBlock
  604. self try: self catch: [:error |
  605. (error isKindOf: anErrorClass)
  606. ifTrue: [aBlock value: error]
  607. ifFalse: [error signal]]
  608. ! !
  609. !BlockClosure methodsFor: 'evaluating'!
  610. value
  611. "inlined in the Compiler"
  612. <return self();>
  613. !
  614. value: anArg
  615. "inlined in the Compiler"
  616. <return self(anArg);>
  617. !
  618. value: firstArg value: secondArg
  619. "inlined in the Compiler"
  620. <return self(firstArg, secondArg);>
  621. !
  622. value: firstArg value: secondArg value: thirdArg
  623. "inlined in the Compiler"
  624. <return self(firstArg, secondArg, thirdArg);>
  625. !
  626. valueWithPossibleArguments: aCollection
  627. <return self.apply(null, aCollection);>
  628. !
  629. new
  630. "Use the receiver as a JS constructor.
  631. *Do not* use this method to instanciate Smalltalk objects!!"
  632. <return new self()>
  633. !
  634. applyTo: anObject arguments: aCollection
  635. <return self.apply(anObject, aCollection)>
  636. !
  637. timeToRun
  638. "Answer the number of milliseconds taken to execute this block."
  639. ^ Date millisecondsToRun: self
  640. ! !
  641. !BlockClosure methodsFor: 'timeout/interval'!
  642. valueWithTimeout: aNumber
  643. <return setTimeout(self, aNumber)>
  644. !
  645. valueWithInterval: aNumber
  646. <return setInterval(self, aNumber)>
  647. ! !
  648. Object subclass: #Boolean
  649. instanceVariableNames: ''
  650. category: 'Kernel'!
  651. !Boolean methodsFor: 'comparing'!
  652. = aBoolean
  653. <return Boolean(self == true) == aBoolean>
  654. !
  655. asJSONObject
  656. ^self
  657. ! !
  658. !Boolean methodsFor: 'controlling'!
  659. ifTrue: aBlock
  660. "inlined in the Compiler"
  661. ^self ifTrue: aBlock ifFalse: []
  662. !
  663. ifFalse: aBlock
  664. "inlined in the Compiler"
  665. ^self ifTrue: [] ifFalse: aBlock
  666. !
  667. ifFalse: aBlock ifTrue: anotherBlock
  668. "inlined in the Compiler"
  669. ^self ifTrue: anotherBlock ifFalse: aBlock
  670. !
  671. ifTrue: aBlock ifFalse: anotherBlock
  672. "inlined in the Compiler"
  673. <
  674. if(self == true) {
  675. return aBlock();
  676. } else {
  677. return anotherBlock();
  678. }
  679. >
  680. !
  681. and: aBlock
  682. ^self = true
  683. ifTrue: aBlock
  684. ifFalse: [false]
  685. !
  686. or: aBlock
  687. ^self = true
  688. ifTrue: [true]
  689. ifFalse: aBlock
  690. !
  691. not
  692. ^self = false
  693. !
  694. & aBoolean
  695. <
  696. if(self == true) {
  697. return aBoolean;
  698. } else {
  699. return false;
  700. }
  701. >
  702. !
  703. | aBoolean
  704. <
  705. if(self == true) {
  706. return true;
  707. } else {
  708. return aBoolean;
  709. }
  710. >
  711. ! !
  712. !Boolean methodsFor: 'copying'!
  713. shallowCopy
  714. ^self
  715. !
  716. deepCopy
  717. ^self
  718. ! !
  719. !Boolean methodsFor: 'printing'!
  720. printString
  721. <return self.toString()>
  722. ! !
  723. Object subclass: #Date
  724. instanceVariableNames: ''
  725. category: 'Kernel'!
  726. !Date commentStamp!
  727. The Date class is used to work with dates and times.!
  728. !Date methodsFor: 'accessing'!
  729. year
  730. <return self.getFullYear()>
  731. !
  732. month
  733. <return self.getMonth() + 1>
  734. !
  735. month: aNumber
  736. <self.setMonth(aNumber - 1)>
  737. !
  738. day
  739. ^self dayOfWeek
  740. !
  741. dayOfWeek
  742. <return self.getDay() + 1>
  743. !
  744. dayOfWeek: aNumber
  745. <return self.setDay(aNumber - 1)>
  746. !
  747. day: aNumber
  748. self day: aNumber
  749. !
  750. year: aNumber
  751. <self.setFullYear(aNumber)>
  752. !
  753. dayOfMonth
  754. <return self.getDate()>
  755. !
  756. dayOfMonth: aNumber
  757. <self.setDate(aNumber)>
  758. !
  759. time
  760. <return self.getTime()>
  761. !
  762. time: aNumber
  763. <self.setTime(aNumber)>
  764. !
  765. hours: aNumber
  766. <self.setHours(aNumber)>
  767. !
  768. minutes: aNumber
  769. <self.setMinutes(aNumber)>
  770. !
  771. seconds: aNumber
  772. <self.setSeconds(aNumber)>
  773. !
  774. milliseconds: aNumber
  775. <self.setMilliseconds(aNumber)>
  776. !
  777. hours
  778. <return self.getHours()>
  779. !
  780. minutes
  781. <return self.getMinutes()>
  782. !
  783. seconds
  784. <return self.getSeconds()>
  785. !
  786. milliseconds
  787. <return self.getMilliseconds()>
  788. ! !
  789. !Date methodsFor: 'arithmetic'!
  790. - aDate
  791. <return self - aDate>
  792. !
  793. + aDate
  794. <return self + aDate>
  795. ! !
  796. !Date methodsFor: 'comparing'!
  797. < aDate
  798. <return self < aDate>
  799. !
  800. > aDate
  801. <return self >> aDate>
  802. !
  803. <= aDate
  804. <self <= aDate>
  805. !
  806. >= aDate
  807. <self >>= aDate>
  808. ! !
  809. !Date methodsFor: 'converting'!
  810. asString
  811. <return self.toString()>
  812. !
  813. asMilliseconds
  814. ^self time
  815. !
  816. asDateString
  817. <return self.toDateString()>
  818. !
  819. asTimeString
  820. <return self.toTimeString()>
  821. !
  822. asLocaleString
  823. <return self.toLocaleString()>
  824. !
  825. asNumber
  826. ^self asMilliseconds
  827. !
  828. asJSONObject
  829. ^self
  830. ! !
  831. !Date methodsFor: 'printing'!
  832. printString
  833. ^self asString
  834. ! !
  835. !Date class methodsFor: 'instance creation'!
  836. new: anObject
  837. <return new Date(anObject)>
  838. !
  839. fromString: aString
  840. "Example: Date fromString('2011/04/15 00:00:00')"
  841. ^self new: aString
  842. !
  843. fromSeconds: aNumber
  844. ^self fromMilliseconds: aNumber * 1000
  845. !
  846. fromMilliseconds: aNumber
  847. ^self new: aNumber
  848. !
  849. today
  850. ^self new
  851. !
  852. now
  853. ^self today
  854. !
  855. millisecondsToRun: aBlock
  856. | t |
  857. t := Date now.
  858. aBlock value.
  859. ^Date now - t
  860. ! !
  861. Object subclass: #UndefinedObject
  862. instanceVariableNames: ''
  863. category: 'Kernel'!
  864. !UndefinedObject methodsFor: 'class creation'!
  865. subclass: aString instanceVariableNames: anotherString
  866. ^self subclass: aString instanceVariableNames: anotherString category: nil
  867. !
  868. subclass: aString instanceVariableNames: aString2 category: aString3
  869. ^ClassBuilder new
  870. superclass: self subclass: aString instanceVariableNames: aString2 category: aString3
  871. ! !
  872. !UndefinedObject methodsFor: 'copying'!
  873. shallowCopy
  874. ^self
  875. !
  876. deepCopy
  877. ^self
  878. ! !
  879. !UndefinedObject methodsFor: 'printing'!
  880. printString
  881. ^'nil'
  882. ! !
  883. !UndefinedObject methodsFor: 'testing'!
  884. ifNil: aBlock
  885. "inlined in the Compiler"
  886. ^self ifNil: aBlock ifNotNil: []
  887. !
  888. ifNotNil: aBlock
  889. "inlined in the Compiler"
  890. ^self
  891. !
  892. ifNil: aBlock ifNotNil: anotherBlock
  893. "inlined in the Compiler"
  894. ^aBlock value
  895. !
  896. ifNotNil: aBlock ifNil: anotherBlock
  897. "inlined in the Compiler"
  898. ^anotherBlock value
  899. !
  900. isNil
  901. ^true
  902. !
  903. notNil
  904. ^false
  905. ! !
  906. !UndefinedObject class methodsFor: 'instance creation'!
  907. new
  908. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  909. ! !
  910. Object subclass: #Collection
  911. instanceVariableNames: ''
  912. category: 'Kernel'!
  913. !Collection methodsFor: 'accessing'!
  914. size
  915. self subclassResponsibility
  916. !
  917. readStream
  918. ^self stream
  919. !
  920. writeStream
  921. ^self stream
  922. !
  923. stream
  924. ^self streamClass on: self
  925. !
  926. streamClass
  927. ^self class streamClass
  928. ! !
  929. !Collection methodsFor: 'adding/removing'!
  930. add: anObject
  931. self subclassResponsibility
  932. !
  933. addAll: aCollection
  934. aCollection do: [:each |
  935. self add: each].
  936. ^aCollection
  937. !
  938. remove: anObject
  939. self subclassResponsibility
  940. ! !
  941. !Collection methodsFor: 'converting'!
  942. asArray
  943. | array index |
  944. array := Array new.
  945. index := 0.
  946. self do: [:each |
  947. index := index + 1.
  948. array at: index put: each].
  949. ^array
  950. !
  951. asSet
  952. ^Set withAll: self
  953. ! !
  954. !Collection methodsFor: 'copying'!
  955. , aCollection
  956. ^self copy
  957. addAll: aCollection;
  958. yourself
  959. !
  960. copyWith: anObject
  961. ^self copy add: anObject; yourself
  962. !
  963. copyWithAll: aCollection
  964. ^self copy addAll: aCollection; yourself
  965. ! !
  966. !Collection methodsFor: 'enumerating'!
  967. do: aBlock
  968. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  969. !
  970. collect: aBlock
  971. | newCollection |
  972. newCollection := self class new.
  973. self do: [:each |
  974. newCollection add: (aBlock value: each)].
  975. ^newCollection
  976. !
  977. detect: aBlock
  978. ^self detect: aBlock ifNone: [self errorNotFound]
  979. !
  980. detect: aBlock ifNone: anotherBlock
  981. <
  982. for(var i = 0; i < self.length; i++)
  983. if(aBlock(self[i]))
  984. return self[i];
  985. return anotherBlock();
  986. >
  987. !
  988. do: aBlock separatedBy: anotherBlock
  989. | first |
  990. first := true.
  991. self do: [:each |
  992. first
  993. ifTrue: [first := false]
  994. ifFalse: [anotherBlock value].
  995. aBlock value: each]
  996. !
  997. inject: anObject into: aBlock
  998. | result |
  999. result := anObject.
  1000. self do: [:each |
  1001. result := aBlock value: result value: each].
  1002. ^result
  1003. !
  1004. reject: aBlock
  1005. ^self select: [:each | (aBlock value: each) = false]
  1006. !
  1007. select: aBlock
  1008. | stream |
  1009. stream := self class new writeStream.
  1010. self do: [:each |
  1011. (aBlock value: each) ifTrue: [
  1012. stream nextPut: each]].
  1013. ^stream contents
  1014. ! !
  1015. !Collection methodsFor: 'error handling'!
  1016. errorNotFound
  1017. self error: 'Object is not in the collection'
  1018. ! !
  1019. !Collection methodsFor: 'testing'!
  1020. includes: anObject
  1021. <
  1022. var i = self.length;
  1023. while (i--) {
  1024. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1025. }
  1026. return false
  1027. >
  1028. !
  1029. notEmpty
  1030. ^self isEmpty not
  1031. !
  1032. isEmpty
  1033. ^self size = 0
  1034. !
  1035. ifNotEmpty: aBlock
  1036. self notEmpty ifTrue: aBlock.
  1037. !
  1038. ifEmpty: aBlock
  1039. self isEmpty ifTrue: aBlock.
  1040. ! !
  1041. !Collection class methodsFor: 'accessing'!
  1042. streamClass
  1043. ^Stream
  1044. ! !
  1045. !Collection class methodsFor: 'instance creation'!
  1046. with: anObject
  1047. ^self new
  1048. add: anObject;
  1049. yourself
  1050. !
  1051. with: anObject with: anotherObject
  1052. ^self new
  1053. add: anObject;
  1054. add: anotherObject;
  1055. yourself
  1056. !
  1057. with: firstObject with: secondObject with: thirdObject
  1058. ^self new
  1059. add: firstObject;
  1060. add: secondObject;
  1061. add: thirdObject;
  1062. yourself
  1063. !
  1064. withAll: aCollection
  1065. ^self new
  1066. addAll: aCollection;
  1067. yourself
  1068. ! !
  1069. Collection subclass: #SequenceableCollection
  1070. instanceVariableNames: ''
  1071. category: 'Kernel'!
  1072. !SequenceableCollection methodsFor: 'accessing'!
  1073. at: anIndex
  1074. ^self at: anIndex ifAbsent: [
  1075. self errorNotFound]
  1076. !
  1077. at: anIndex ifAbsent: aBlock
  1078. self subclassResponsibility
  1079. !
  1080. at: anIndex put: anObject
  1081. self subclassResponsibility
  1082. !
  1083. first
  1084. ^self at: 1
  1085. !
  1086. fourth
  1087. ^self at: 4
  1088. !
  1089. last
  1090. ^self at: self size
  1091. !
  1092. second
  1093. ^self at: 2
  1094. !
  1095. third
  1096. ^self at: 3
  1097. !
  1098. allButFirst
  1099. ^self copyFrom: 2 to: self size
  1100. !
  1101. allButLast
  1102. ^self copyFrom: 1 to: self size - 1
  1103. !
  1104. indexOf: anObject
  1105. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1106. !
  1107. indexOf: anObject ifAbsent: aBlock
  1108. <
  1109. for(var i=0;i<self.length;i++){
  1110. if(self[i].__eq(anObject)) {return i+1}
  1111. }
  1112. return aBlock();
  1113. >
  1114. !
  1115. indexOf: anObject startingAt: start ifAbsent: aBlock
  1116. <
  1117. for(var i=start-1;i<self.length;i++){
  1118. if(self[i].__eq(anObject)) {return i+1}
  1119. }
  1120. return aBlock();
  1121. >
  1122. !
  1123. indexOf: anObject startingAt: start
  1124. "Answer the index of the first occurence of anElement after start
  1125. within the receiver. If the receiver does not contain anElement,
  1126. answer 0."
  1127. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1128. ! !
  1129. !SequenceableCollection methodsFor: 'adding'!
  1130. removeLast
  1131. self remove: self last
  1132. !
  1133. addLast: anObject
  1134. self add: anObject
  1135. ! !
  1136. !SequenceableCollection methodsFor: 'converting'!
  1137. reversed
  1138. self subclassResponsibility
  1139. ! !
  1140. !SequenceableCollection methodsFor: 'copying'!
  1141. copyFrom: anIndex to: anotherIndex
  1142. self subclassResponsibility
  1143. ! !
  1144. !SequenceableCollection methodsFor: 'enumerating'!
  1145. withIndexDo: aBlock
  1146. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1147. ! !
  1148. SequenceableCollection subclass: #String
  1149. instanceVariableNames: ''
  1150. category: 'Kernel'!
  1151. !String methodsFor: 'accessing'!
  1152. size
  1153. <return self.length>
  1154. !
  1155. at: anIndex
  1156. <return self[anIndex - 1]>
  1157. !
  1158. at: anIndex put: anObject
  1159. self errorReadOnly
  1160. !
  1161. at: anIndex ifAbsent: aBlock
  1162. (self at: anIndex) ifNil: [aBlock]
  1163. !
  1164. escaped
  1165. <return escape(self)>
  1166. !
  1167. unescaped
  1168. <return unescape(self)>
  1169. !
  1170. asciiValue
  1171. <return self.charCodeAt(0);>
  1172. ! !
  1173. !String methodsFor: 'adding'!
  1174. add: anObject
  1175. self errorReadOnly
  1176. !
  1177. remove: anObject
  1178. self errorReadOnly
  1179. ! !
  1180. !String methodsFor: 'comparing'!
  1181. = aString
  1182. <return String(self) == aString>
  1183. !
  1184. > aString
  1185. <return String(self) >> aString>
  1186. !
  1187. < aString
  1188. <return String(self) < aString>
  1189. !
  1190. >= aString
  1191. <return String(self) >>= aString>
  1192. !
  1193. <= aString
  1194. <return String(self) <= aString>
  1195. ! !
  1196. !String methodsFor: 'converting'!
  1197. asSelector
  1198. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1199. | selector |
  1200. selector := '_', self.
  1201. selector := selector replace: ':' with: '_'.
  1202. selector := selector replace: '[+]' with: '_plus'.
  1203. selector := selector replace: '-' with: '_minus'.
  1204. selector := selector replace: '[*]' with: '_star'.
  1205. selector := selector replace: '[/]' with: '_slash'.
  1206. selector := selector replace: '>' with: '_gt'.
  1207. selector := selector replace: '<' with: '_lt'.
  1208. selector := selector replace: '=' with: '_eq'.
  1209. selector := selector replace: ',' with: '_comma'.
  1210. selector := selector replace: '[@]' with: '_at'.
  1211. ^selector
  1212. !
  1213. asJavascript
  1214. <
  1215. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1216. return "unescape(\"" + escape(self) + "\")";
  1217. else
  1218. return "\"" + self + "\"";
  1219. >
  1220. !
  1221. tokenize: aString
  1222. <return self.split(aString)>
  1223. !
  1224. asString
  1225. ^self
  1226. !
  1227. asNumber
  1228. <return Number(self)>
  1229. !
  1230. asJSONObject
  1231. ^self
  1232. !
  1233. asLowercase
  1234. <return self.toLowerCase()>
  1235. !
  1236. asUppercase
  1237. <return self.toUpperCase()>
  1238. !
  1239. reversed
  1240. <return self.split("").reverse().join("")>
  1241. ! !
  1242. !String methodsFor: 'copying'!
  1243. , aString
  1244. <return self + aString>
  1245. !
  1246. copyFrom: anIndex to: anotherIndex
  1247. <return self.substring(anIndex - 1, anotherIndex)>
  1248. !
  1249. shallowCopy
  1250. ^self class fromString: self
  1251. !
  1252. deepCopy
  1253. ^self shallowCopy
  1254. ! !
  1255. !String methodsFor: 'error handling'!
  1256. errorReadOnly
  1257. self error: 'Object is read-only'
  1258. ! !
  1259. !String methodsFor: 'printing'!
  1260. printString
  1261. ^'''', self, ''''
  1262. !
  1263. printNl
  1264. <console.log(self)>
  1265. ! !
  1266. !String methodsFor: 'regular expressions'!
  1267. replace: aString with: anotherString
  1268. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1269. !
  1270. replaceRegexp: aRegexp with: aString
  1271. <return self.replace(aRegexp, aString)>
  1272. !
  1273. match: aRegexp
  1274. <return self.search(aRegexp) !!= -1>
  1275. !
  1276. trimLeft: separators
  1277. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1278. !
  1279. trimRight: separators
  1280. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1281. !
  1282. trimLeft
  1283. ^self trimLeft: '\s'
  1284. !
  1285. trimRight
  1286. ^self trimRight: '\s'
  1287. !
  1288. trimBoth
  1289. ^self trimBoth: '\s'
  1290. !
  1291. trimBoth: separators
  1292. ^(self trimLeft: separators) trimRight: separators
  1293. ! !
  1294. !String methodsFor: 'split join'!
  1295. join: aCollection
  1296. ^ String
  1297. streamContents: [:stream | aCollection
  1298. do: [:each | stream nextPutAll: each asString]
  1299. separatedBy: [stream nextPutAll: self]]
  1300. !
  1301. lineIndicesDo: aBlock
  1302. "execute aBlock with 3 arguments for each line:
  1303. - start index of line
  1304. - end index of line without line delimiter
  1305. - end index of line including line delimiter(s) CR, LF or CRLF"
  1306. | cr lf start sz nextLF nextCR |
  1307. start := 1.
  1308. sz := self size.
  1309. cr := String cr.
  1310. nextCR := self indexOf: cr startingAt: 1.
  1311. lf := String lf.
  1312. nextLF := self indexOf: lf startingAt: 1.
  1313. [ start <= sz ] whileTrue: [
  1314. (nextLF = 0 and: [ nextCR = 0 ])
  1315. ifTrue: [ "No more CR, nor LF, the string is over"
  1316. aBlock value: start value: sz value: sz.
  1317. ^self ].
  1318. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1319. ifTrue: [ "Found a LF"
  1320. aBlock value: start value: nextLF - 1 value: nextLF.
  1321. start := 1 + nextLF.
  1322. nextLF := self indexOf: lf startingAt: start ]
  1323. ifFalse: [ 1 + nextCR = nextLF
  1324. ifTrue: [ "Found a CR-LF pair"
  1325. aBlock value: start value: nextCR - 1 value: nextLF.
  1326. start := 1 + nextLF.
  1327. nextCR := self indexOf: cr startingAt: start.
  1328. nextLF := self indexOf: lf startingAt: start ]
  1329. ifFalse: [ "Found a CR"
  1330. aBlock value: start value: nextCR - 1 value: nextCR.
  1331. start := 1 + nextCR.
  1332. nextCR := self indexOf: cr startingAt: start ]]]
  1333. !
  1334. linesDo: aBlock
  1335. "Execute aBlock with each line in this string. The terminating line
  1336. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1337. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1338. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1339. !
  1340. lines
  1341. "Answer an array of lines composing this receiver without the line ending delimiters."
  1342. | lines |
  1343. lines := Array new.
  1344. self linesDo: [:aLine | lines add: aLine].
  1345. ^lines
  1346. !
  1347. lineNumber: anIndex
  1348. "Answer a string containing the characters in the given line number."
  1349. | lineCount |
  1350. lineCount := 0.
  1351. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1352. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1353. ^nil
  1354. ! !
  1355. !String methodsFor: 'testing'!
  1356. isString
  1357. ^true
  1358. !
  1359. includesSubString: subString
  1360. < return self.indexOf(subString) !!= -1 >
  1361. ! !
  1362. !String class methodsFor: 'accessing'!
  1363. streamClass
  1364. ^StringStream
  1365. !
  1366. cr
  1367. <return '\r'>
  1368. !
  1369. lf
  1370. <return '\n'>
  1371. !
  1372. space
  1373. <return ' '>
  1374. !
  1375. tab
  1376. <return '\t'>
  1377. !
  1378. crlf
  1379. <return '\r\n'>
  1380. ! !
  1381. !String class methodsFor: 'instance creation'!
  1382. fromString: aString
  1383. <return new self.fn(aString)>
  1384. !
  1385. streamContents: blockWithArg
  1386. |stream|
  1387. stream := (self streamClass on: String new).
  1388. blockWithArg value: stream.
  1389. ^ stream contents
  1390. !
  1391. value: aUTFCharCode
  1392. <return String.fromCharCode(aUTFCharCode);>
  1393. ! !
  1394. SequenceableCollection subclass: #Array
  1395. instanceVariableNames: ''
  1396. category: 'Kernel'!
  1397. !Array methodsFor: 'accessing'!
  1398. size
  1399. <return self.length>
  1400. !
  1401. at: anIndex put: anObject
  1402. <return self[anIndex - 1] = anObject>
  1403. !
  1404. at: anIndex ifAbsent: aBlock
  1405. <
  1406. var value = self[anIndex - 1];
  1407. if(value === undefined) {
  1408. return aBlock();
  1409. } else {
  1410. return value;
  1411. }
  1412. >
  1413. ! !
  1414. !Array methodsFor: 'adding/removing'!
  1415. add: anObject
  1416. <self.push(anObject); return anObject;>
  1417. !
  1418. remove: anObject
  1419. <
  1420. for(var i=0;i<self.length;i++) {
  1421. if(self[i] == anObject) {
  1422. self.splice(i,1);
  1423. break;
  1424. }
  1425. }
  1426. >
  1427. !
  1428. removeFrom: aNumber to: anotherNumber
  1429. <self.splice(aNumber - 1,anotherNumber - 1)>
  1430. ! !
  1431. !Array methodsFor: 'converting'!
  1432. asJavascript
  1433. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1434. !
  1435. asJSONObject
  1436. ^self collect: [:each | each asJSONObject]
  1437. !
  1438. reversed
  1439. <return self._copy().reverse()>
  1440. ! !
  1441. !Array methodsFor: 'copying'!
  1442. shallowCopy
  1443. | newCollection |
  1444. newCollection := self class new.
  1445. self do: [:each | newCollection add: each].
  1446. ^newCollection
  1447. !
  1448. deepCopy
  1449. | newCollection |
  1450. newCollection := self class new.
  1451. self do: [:each | newCollection add: each deepCopy].
  1452. ^newCollection
  1453. !
  1454. copyFrom: anIndex to: anotherIndex
  1455. | array |
  1456. array := self class new.
  1457. anIndex to: anotherIndex do: [:each |
  1458. array add: (self at: each)].
  1459. ^array
  1460. ! !
  1461. !Array methodsFor: 'enumerating'!
  1462. join: aString
  1463. <return self.join(aString)>
  1464. !
  1465. sort
  1466. ^self basicPerform: 'sort'
  1467. !
  1468. sort: aBlock
  1469. <
  1470. return self.sort(function(a, b) {
  1471. if(aBlock(a,b)) {return -1} else {return 1}
  1472. })
  1473. >
  1474. !
  1475. sorted
  1476. ^self copy sort
  1477. !
  1478. sorted: aBlock
  1479. ^self copy sort: aBlock
  1480. !
  1481. printString
  1482. | str |
  1483. str := '' writeStream.
  1484. str nextPutAll: super printString, ' ('.
  1485. self
  1486. do: [:each | str nextPutAll: each printString]
  1487. separatedBy: [str nextPutAll: ' '].
  1488. str nextPutAll: ')'.
  1489. ^str contents
  1490. ! !
  1491. Object subclass: #RegularExpression
  1492. instanceVariableNames: ''
  1493. category: 'Kernel'!
  1494. !RegularExpression methodsFor: 'evaluating'!
  1495. compile: aString
  1496. <return self.compile(aString)>
  1497. !
  1498. exec: aString
  1499. <return self.exec(aString) || nil>
  1500. !
  1501. test: aString
  1502. <return self.test(aString)>
  1503. ! !
  1504. !RegularExpression class methodsFor: 'instance creation'!
  1505. fromString: aString flag: anotherString
  1506. <return new RegExp(aString, anotherString)>
  1507. !
  1508. fromString: aString
  1509. ^self fromString: aString flag: ''
  1510. ! !
  1511. Object subclass: #Error
  1512. instanceVariableNames: 'messageText'
  1513. category: 'Kernel'!
  1514. !Error methodsFor: 'accessing'!
  1515. messageText
  1516. ^messageText
  1517. !
  1518. messageText: aString
  1519. messageText := aString
  1520. !
  1521. context
  1522. <return self.context>
  1523. ! !
  1524. !Error methodsFor: 'signaling'!
  1525. signal
  1526. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1527. ! !
  1528. !Error class methodsFor: 'instance creation'!
  1529. signal: aString
  1530. ^self new
  1531. messageText: aString;
  1532. signal
  1533. ! !
  1534. Object subclass: #MethodContext
  1535. instanceVariableNames: ''
  1536. category: 'Kernel'!
  1537. !MethodContext methodsFor: 'accessing'!
  1538. receiver
  1539. <return self.receiver>
  1540. !
  1541. selector
  1542. <return smalltalk.convertSelector(self.selector)>
  1543. !
  1544. home
  1545. <return self.homeContext>
  1546. !
  1547. temps
  1548. <return self.temps>
  1549. !
  1550. printString
  1551. ^super printString, '(', self asString, ')'
  1552. !
  1553. asString
  1554. ^self receiver class printString, ' >> ', self selector
  1555. ! !
  1556. Object subclass: #Association
  1557. instanceVariableNames: 'key value'
  1558. category: 'Kernel'!
  1559. !Association methodsFor: 'accessing'!
  1560. key: aKey
  1561. key := aKey
  1562. !
  1563. key
  1564. ^key
  1565. !
  1566. value: aValue
  1567. value := aValue
  1568. !
  1569. value
  1570. ^value
  1571. ! !
  1572. !Association methodsFor: 'comparing'!
  1573. = anAssociation
  1574. ^self class = anAssociation class and: [
  1575. self key = anAssociation key and: [
  1576. self value = anAssociation value]]
  1577. ! !
  1578. !Association class methodsFor: 'instance creation'!
  1579. key: aKey value: aValue
  1580. ^self new
  1581. key: aKey;
  1582. value: aValue;
  1583. yourself
  1584. ! !
  1585. Collection subclass: #Dictionary
  1586. instanceVariableNames: 'keys'
  1587. category: 'Kernel'!
  1588. !Dictionary methodsFor: 'accessing'!
  1589. size
  1590. ^keys size
  1591. !
  1592. associations
  1593. | associations |
  1594. associations := #().
  1595. keys do: [:each |
  1596. associations add: (Association key: each value: (self at: each))].
  1597. ^associations
  1598. !
  1599. keys
  1600. ^keys copy
  1601. !
  1602. values
  1603. ^keys collect: [:each | self at: each]
  1604. !
  1605. at: aKey put: aValue
  1606. (keys includes: aKey) ifFalse: [keys add: aKey].
  1607. ^self basicAt: aKey put: aValue
  1608. !
  1609. at: aKey ifAbsent: aBlock
  1610. ^(self keys includes: aKey)
  1611. ifTrue: [self basicAt: aKey]
  1612. ifFalse: aBlock
  1613. !
  1614. at: aKey ifAbsentPut: aBlock
  1615. ^self at: aKey ifAbsent: [
  1616. self at: aKey put: aBlock value]
  1617. !
  1618. at: aKey ifPresent: aBlock
  1619. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1620. !
  1621. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1622. ^(self basicAt: aKey)
  1623. ifNil: anotherBlock
  1624. ifNotNil: [aBlock value: (self at: aKey)]
  1625. !
  1626. at: aKey
  1627. ^self at: aKey ifAbsent: [self errorNotFound]
  1628. ! !
  1629. !Dictionary methodsFor: 'adding/removing'!
  1630. add: anAssociation
  1631. self at: anAssociation key put: anAssociation value
  1632. !
  1633. addAll: aDictionary
  1634. super addAll: aDictionary associations.
  1635. ^aDictionary
  1636. !
  1637. remove: aKey
  1638. self removeKey: aKey
  1639. !
  1640. removeKey: aKey
  1641. keys remove: aKey
  1642. ! !
  1643. !Dictionary methodsFor: 'comparing'!
  1644. = aDictionary
  1645. self class = aDictionary class ifFalse: [^false].
  1646. self associationsDo: [:assoc |
  1647. (aDictionary at: assoc key ifAbsent: [^false]) = assoc value
  1648. ifFalse: [^false]].
  1649. ^true
  1650. ! !
  1651. !Dictionary methodsFor: 'converting'!
  1652. asJSONObject
  1653. | object |
  1654. object := Object new.
  1655. self keysAndValuesDo: [:key :value |
  1656. object basicAt: key put: value asJSONObject].
  1657. ^object
  1658. ! !
  1659. !Dictionary methodsFor: 'copying'!
  1660. shallowCopy
  1661. | copy |
  1662. copy := self class new.
  1663. self associationsDo: [:each |
  1664. copy at: each key put: each value].
  1665. ^copy
  1666. !
  1667. , aCollection
  1668. self shouldNotImplement
  1669. !
  1670. copyFrom: anIndex to: anotherIndex
  1671. self shouldNotImplement
  1672. ! !
  1673. !Dictionary methodsFor: 'enumerating'!
  1674. associationsDo: aBlock
  1675. self associations do: aBlock
  1676. !
  1677. keysAndValuesDo: aBlock
  1678. self associationsDo: [:each |
  1679. aBlock value: each key value: each value]
  1680. !
  1681. do: aBlock
  1682. self values do: aBlock
  1683. !
  1684. select: aBlock
  1685. | newDict |
  1686. newDict := self class new.
  1687. self keysAndValuesDo: [:key :value |
  1688. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1689. ^newDict
  1690. !
  1691. collect: aBlock
  1692. | newDict |
  1693. newDict := self class new.
  1694. self keysAndValuesDo: [:key :value |
  1695. newDict at: key put: (aBlock value: value)].
  1696. ^newDict
  1697. !
  1698. detect: aBlock ifNone: anotherBlock
  1699. ^self values detect: aBlock ifNone: anotherBlock
  1700. !
  1701. includes: anObject
  1702. ^self values includes: anObject
  1703. ! !
  1704. !Dictionary methodsFor: 'initialization'!
  1705. initialize
  1706. super initialize.
  1707. keys := #()
  1708. ! !
  1709. !Dictionary methodsFor: 'printing'!
  1710. printString
  1711. ^ String streamContents: [:aStream|
  1712. aStream
  1713. nextPutAll: super printString;
  1714. nextPutAll: '('.
  1715. self associations
  1716. do: [:anAssociation|
  1717. aStream
  1718. nextPutAll: anAssociation key printString;
  1719. nextPutAll: ' -> ';
  1720. nextPutAll: anAssociation value printString]
  1721. separatedBy: [aStream nextPutAll: ' , '].
  1722. aStream nextPutAll: ')'.
  1723. ]
  1724. ! !
  1725. !Dictionary class methodsFor: 'instance creation'!
  1726. fromPairs: aCollection
  1727. | dict |
  1728. dict := self new.
  1729. aCollection do: [:each | dict add: each].
  1730. ^dict
  1731. ! !
  1732. Object subclass: #ClassBuilder
  1733. instanceVariableNames: ''
  1734. category: 'Kernel'!
  1735. !ClassBuilder methodsFor: 'class creation'!
  1736. superclass: aClass subclass: aString
  1737. self superclass: aClass subclass: aString instanceVariableNames: '' category: nil
  1738. !
  1739. superclass: aClass subclass: aString instanceVariableNames: aString2 category: aString3
  1740. | newClass |
  1741. newClass := self addSubclassOf: aClass named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2).
  1742. self setupClass: newClass.
  1743. newClass category: (aString3 ifNil: ['unclassified'])
  1744. !
  1745. class: aClass instanceVariableNames: aString
  1746. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1747. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1748. self setupClass: aClass
  1749. ! !
  1750. !ClassBuilder methodsFor: 'private'!
  1751. instanceVariableNamesFor: aString
  1752. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1753. !
  1754. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1755. <smalltalk.addClass(aString, aClass, aCollection);
  1756. return smalltalk[aString]>
  1757. !
  1758. setupClass: aClass
  1759. <smalltalk.init(aClass);>
  1760. ! !
  1761. Object subclass: #ClassCategoryReader
  1762. instanceVariableNames: 'class category chunkParser'
  1763. category: 'Kernel'!
  1764. !ClassCategoryReader methodsFor: 'accessing'!
  1765. class: aClass category: aString
  1766. class := aClass.
  1767. category := aString
  1768. ! !
  1769. !ClassCategoryReader methodsFor: 'fileIn'!
  1770. scanFrom: aChunkParser
  1771. | chunk |
  1772. [chunk := aChunkParser nextChunk.
  1773. chunk isEmpty] whileFalse: [
  1774. self compileMethod: chunk]
  1775. ! !
  1776. !ClassCategoryReader methodsFor: 'initialization'!
  1777. initialize
  1778. super initialize.
  1779. chunkParser := ChunkParser new.
  1780. ! !
  1781. !ClassCategoryReader methodsFor: 'private'!
  1782. compileMethod: aString
  1783. | method |
  1784. method := Compiler new load: aString forClass: class.
  1785. method category: category.
  1786. class addCompiledMethod: method
  1787. ! !
  1788. Object subclass: #Stream
  1789. instanceVariableNames: 'collection position streamSize'
  1790. category: 'Kernel'!
  1791. !Stream methodsFor: 'accessing'!
  1792. collection
  1793. ^collection
  1794. !
  1795. setCollection: aCollection
  1796. collection := aCollection
  1797. !
  1798. position
  1799. ^position ifNil: [position := 0]
  1800. !
  1801. position: anInteger
  1802. position := anInteger
  1803. !
  1804. streamSize
  1805. ^streamSize
  1806. !
  1807. setStreamSize: anInteger
  1808. streamSize := anInteger
  1809. !
  1810. contents
  1811. ^self collection
  1812. copyFrom: 1
  1813. to: self streamSize
  1814. !
  1815. size
  1816. ^self streamSize
  1817. ! !
  1818. !Stream methodsFor: 'actions'!
  1819. reset
  1820. self position: 0
  1821. !
  1822. close
  1823. !
  1824. flush
  1825. !
  1826. resetContents
  1827. self reset.
  1828. self setStreamSize: 0
  1829. ! !
  1830. !Stream methodsFor: 'enumerating'!
  1831. do: aBlock
  1832. [self atEnd] whileFalse: [aBlock value: self next]
  1833. ! !
  1834. !Stream methodsFor: 'positioning'!
  1835. setToEnd
  1836. self position: self size
  1837. !
  1838. skip: anInteger
  1839. self position: ((self position + anInteger) min: self size max: 0)
  1840. ! !
  1841. !Stream methodsFor: 'reading'!
  1842. next
  1843. self position: self position + 1.
  1844. ^collection at: self position
  1845. !
  1846. next: anInteger
  1847. | tempCollection |
  1848. tempCollection := self collection class new.
  1849. anInteger timesRepeat: [
  1850. self atEnd ifFalse: [
  1851. tempCollection add: self next]].
  1852. ^tempCollection
  1853. !
  1854. peek
  1855. ^self atEnd ifFalse: [
  1856. self collection at: self position + 1]
  1857. ! !
  1858. !Stream methodsFor: 'testing'!
  1859. atEnd
  1860. ^self position = self size
  1861. !
  1862. atStart
  1863. ^self position = 0
  1864. !
  1865. isEmpty
  1866. ^self size = 0
  1867. ! !
  1868. !Stream methodsFor: 'writing'!
  1869. nextPut: anObject
  1870. self position: self position + 1.
  1871. self collection at: self position put: anObject.
  1872. self setStreamSize: (self streamSize max: self position)
  1873. !
  1874. nextPutAll: aCollection
  1875. aCollection do: [:each |
  1876. self nextPut: each]
  1877. ! !
  1878. !Stream class methodsFor: 'instance creation'!
  1879. on: aCollection
  1880. ^self new
  1881. setCollection: aCollection;
  1882. setStreamSize: aCollection size;
  1883. yourself
  1884. ! !
  1885. Stream subclass: #StringStream
  1886. instanceVariableNames: ''
  1887. category: 'Kernel'!
  1888. !StringStream methodsFor: 'reading'!
  1889. next: anInteger
  1890. | tempCollection |
  1891. tempCollection := self collection class new.
  1892. anInteger timesRepeat: [
  1893. self atEnd ifFalse: [
  1894. tempCollection := tempCollection, self next]].
  1895. ^tempCollection
  1896. ! !
  1897. !StringStream methodsFor: 'writing'!
  1898. nextPut: aString
  1899. self nextPutAll: aString
  1900. !
  1901. nextPutAll: aString
  1902. self setCollection:
  1903. (self collection copyFrom: 1 to: self position),
  1904. aString,
  1905. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  1906. self position: self position + aString size.
  1907. self setStreamSize: (self streamSize max: self position)
  1908. !
  1909. cr
  1910. ^self nextPutAll: String cr
  1911. !
  1912. crlf
  1913. ^self nextPutAll: String crlf
  1914. !
  1915. lf
  1916. ^self nextPutAll: String lf
  1917. !
  1918. space
  1919. self nextPut: ' '
  1920. ! !
  1921. Object subclass: #ClassCommentReader
  1922. instanceVariableNames: 'class chunkParser'
  1923. category: 'Kernel'!
  1924. !ClassCommentReader methodsFor: 'accessing'!
  1925. class: aClass
  1926. class := aClass
  1927. ! !
  1928. !ClassCommentReader methodsFor: 'fileIn'!
  1929. scanFrom: aChunkParser
  1930. | chunk |
  1931. chunk := aChunkParser nextChunk.
  1932. chunk isEmpty ifFalse: [
  1933. self setComment: chunk].
  1934. ! !
  1935. !ClassCommentReader methodsFor: 'initialization'!
  1936. initialize
  1937. super initialize.
  1938. chunkParser := ChunkParser new.
  1939. ! !
  1940. !ClassCommentReader methodsFor: 'private'!
  1941. setComment: aString
  1942. class comment: aString
  1943. ! !
  1944. Object subclass: #Random
  1945. instanceVariableNames: ''
  1946. category: 'Kernel'!
  1947. !Random methodsFor: 'accessing'!
  1948. next
  1949. <return Math.random()>
  1950. !
  1951. next: anInteger
  1952. ^1 to: anInteger collect: [:each | self next]
  1953. ! !
  1954. Object subclass: #Point
  1955. instanceVariableNames: 'x y'
  1956. category: 'Kernel'!
  1957. !Point methodsFor: 'accessing'!
  1958. x
  1959. ^x
  1960. !
  1961. y
  1962. ^y
  1963. !
  1964. y: aNumber
  1965. y := aNumber
  1966. !
  1967. x: aNumber
  1968. x := aNumber
  1969. ! !
  1970. !Point methodsFor: 'arithmetic'!
  1971. * aPoint
  1972. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  1973. !
  1974. + aPoint
  1975. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  1976. !
  1977. - aPoint
  1978. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  1979. !
  1980. / aPoint
  1981. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  1982. ! !
  1983. !Point methodsFor: 'converting'!
  1984. asPoint
  1985. ^self
  1986. ! !
  1987. !Point class methodsFor: 'instance creation'!
  1988. x: aNumber y: anotherNumber
  1989. ^self new
  1990. x: aNumber;
  1991. y: anotherNumber;
  1992. yourself
  1993. ! !
  1994. Object subclass: #Message
  1995. instanceVariableNames: 'selector arguments'
  1996. category: 'Kernel'!
  1997. !Message methodsFor: 'accessing'!
  1998. selector
  1999. ^selector
  2000. !
  2001. selector: aString
  2002. selector := aString
  2003. !
  2004. arguments: anArray
  2005. arguments := anArray
  2006. !
  2007. arguments
  2008. ^arguments
  2009. ! !
  2010. !Message class methodsFor: 'instance creation'!
  2011. selector: aString arguments: anArray
  2012. ^self new
  2013. selector: aString;
  2014. arguments: anArray;
  2015. yourself
  2016. ! !
  2017. Error subclass: #MessageNotUnderstood
  2018. instanceVariableNames: 'message receiver'
  2019. category: 'Kernel'!
  2020. !MessageNotUnderstood methodsFor: 'accessing'!
  2021. message
  2022. ^message
  2023. !
  2024. message: aMessage
  2025. message := aMessage
  2026. !
  2027. receiver
  2028. ^receiver
  2029. !
  2030. receiver: anObject
  2031. receiver := anObject
  2032. !
  2033. messageText
  2034. ^self receiver asString, ' does not understand #', self message selector
  2035. ! !
  2036. Object subclass: #ErrorHandler
  2037. instanceVariableNames: ''
  2038. category: 'Kernel'!
  2039. !ErrorHandler methodsFor: 'error handling'!
  2040. handleError: anError
  2041. anError context ifNotNil: [self logErrorContext: anError context].
  2042. self logError: anError
  2043. ! !
  2044. !ErrorHandler methodsFor: 'private'!
  2045. logContext: aContext
  2046. aContext home ifNotNil: [
  2047. self logContext: aContext home].
  2048. self log: aContext receiver asString, '>>', aContext selector
  2049. !
  2050. logErrorContext: aContext
  2051. aContext ifNotNil: [
  2052. aContext home ifNotNil: [
  2053. self logContext: aContext home]]
  2054. !
  2055. logError: anError
  2056. self log: anError messageText
  2057. !
  2058. log: aString
  2059. console log: aString
  2060. ! !
  2061. ErrorHandler class instanceVariableNames: 'current'!
  2062. !ErrorHandler class methodsFor: 'accessing'!
  2063. current
  2064. ^current
  2065. !
  2066. setCurrent: anHandler
  2067. current := anHandler
  2068. ! !
  2069. !ErrorHandler class methodsFor: 'initialization'!
  2070. initialize
  2071. self register
  2072. !
  2073. register
  2074. ErrorHandler setCurrent: self new
  2075. ! !
  2076. Object subclass: #JSObjectProxy
  2077. instanceVariableNames: 'jsObject'
  2078. category: 'Kernel'!
  2079. !JSObjectProxy methodsFor: 'accessing'!
  2080. jsObject: aJSObject
  2081. jsObject := aJSObject
  2082. !
  2083. jsObject
  2084. ^jsObject
  2085. ! !
  2086. !JSObjectProxy methodsFor: 'proxy'!
  2087. printString
  2088. ^self jsObject toString
  2089. !
  2090. inspectOn: anInspector
  2091. | variables |
  2092. variables := Dictionary new.
  2093. variables at: '#self' put: self jsObject.
  2094. anInspector setLabel: self printString.
  2095. <for(var i in self['@jsObject']) {
  2096. variables._at_put_(i, self['@jsObject'][i]);
  2097. }>.
  2098. anInspector setVariables: variables
  2099. ! !
  2100. !JSObjectProxy class methodsFor: 'instance creation'!
  2101. on: aJSObject
  2102. ^self new
  2103. jsObject: aJSObject;
  2104. yourself
  2105. ! !
  2106. Collection subclass: #Set
  2107. instanceVariableNames: 'elements'
  2108. category: 'Kernel'!
  2109. !Set methodsFor: 'accessing'!
  2110. size
  2111. ^elements size
  2112. ! !
  2113. !Set methodsFor: 'adding/removing'!
  2114. add: anObject
  2115. <
  2116. var found;
  2117. for(var i in self['@elements']) {
  2118. if(anObject == self['@elements'][i]) {
  2119. found = true;
  2120. break;
  2121. }
  2122. }
  2123. if(!!found) {self['@elements'].push(anObject)}
  2124. >
  2125. !
  2126. remove: anObject
  2127. elements remove: anObject
  2128. ! !
  2129. !Set methodsFor: 'converting'!
  2130. asArray
  2131. ^elements copy
  2132. ! !
  2133. !Set methodsFor: 'enumerating'!
  2134. detect: aBlock ifNone: anotherBlock
  2135. ^elements detect: aBlock ifNone: anotherBlock
  2136. !
  2137. do: aBlock
  2138. elements do: aBlock
  2139. ! !
  2140. !Set methodsFor: 'initialization'!
  2141. initialize
  2142. super initialize.
  2143. elements := #()
  2144. ! !
  2145. !Set methodsFor: 'testing'!
  2146. includes: anObject
  2147. ^elements includes: anObject
  2148. ! !