1
0

Kernel.st 48 KB

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