Kernel.st 47 KB

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