Kernel.st 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954
  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. !Smalltalk methodsFor: 'packages'!
  234. packages
  235. <return self.packages.all()>
  236. !
  237. packageAt: packageName
  238. <return self.packages[packageName]>
  239. !
  240. packageAt: packageName ifAbsent: aBlock
  241. ^(self packageAt: packageName) ifNil: aBlock
  242. !
  243. createPackage: packageName
  244. <return smalltalk.addPackage(packageName)>
  245. !
  246. deletePackage: packageName
  247. <delete smalltalk.packages[packageName]>
  248. ! !
  249. Smalltalk class instanceVariableNames: 'current'!
  250. !Smalltalk class methodsFor: 'accessing'!
  251. current
  252. <return smalltalk>
  253. ! !
  254. Object subclass: #Package
  255. instanceVariableNames: ''
  256. category: 'Kernel'!
  257. !Package methodsFor: 'accessing'!
  258. name
  259. <return self.pkgName || nil>
  260. !
  261. requires
  262. <return self.requires || nil>
  263. !
  264. name: aString
  265. <return self.pkgName = aString>
  266. ! !
  267. Object subclass: #Behavior
  268. instanceVariableNames: ''
  269. category: 'Kernel'!
  270. !Behavior methodsFor: 'accessing'!
  271. name
  272. <return self.className || nil>
  273. !
  274. superclass
  275. <return self.superclass || nil>
  276. !
  277. subclasses
  278. <return smalltalk.subclasses(self)>
  279. !
  280. allSubclasses
  281. | result |
  282. result := self subclasses.
  283. self subclasses do: [:each |
  284. result addAll: each allSubclasses].
  285. ^result
  286. !
  287. withAllSubclasses
  288. ^(Array with: self) addAll: self allSubclasses; yourself
  289. !
  290. prototype
  291. <return self.fn.prototype>
  292. !
  293. methodDictionary
  294. <var dict = smalltalk.Dictionary._new();
  295. var methods = self.fn.prototype.methods;
  296. for(var i in methods) {
  297. if(methods[i].selector) {
  298. dict._at_put_(methods[i].selector, methods[i]);
  299. }
  300. };
  301. return dict>
  302. !
  303. methodsFor: aString
  304. ^ClassCategoryReader new
  305. class: self category: aString;
  306. yourself
  307. !
  308. addCompiledMethod: aMethod
  309. <smalltalk.addMethod(aMethod.selector._asSelector(), aMethod, self)>
  310. !
  311. instanceVariableNames
  312. <return self.iVarNames>
  313. !
  314. comment
  315. ^(self basicAt: 'comment') ifNil: ['']
  316. !
  317. comment: aString
  318. self basicAt: 'comment' put: aString
  319. !
  320. commentStamp
  321. ^ClassCommentReader new
  322. class: self;
  323. yourself
  324. !
  325. removeCompiledMethod: aMethod
  326. <delete self.fn.prototype[aMethod.selector._asSelector()];
  327. delete self.fn.prototype.methods[aMethod.selector];
  328. smalltalk.init(self);>
  329. !
  330. protocols
  331. | protocols |
  332. protocols := Array new.
  333. self methodDictionary do: [:each |
  334. (protocols includes: each category) ifFalse: [
  335. protocols add: each category]].
  336. ^protocols sort
  337. !
  338. protocolsDo: aBlock
  339. "Execute aBlock for each method category with
  340. its collection of methods in the sort order of category name."
  341. | methodsByCategory |
  342. methodsByCategory := Dictionary new.
  343. self methodDictionary values do: [:m |
  344. (methodsByCategory at: m category ifAbsentPut: [Array new])
  345. add: m].
  346. self protocols do: [:category |
  347. aBlock value: category value: (methodsByCategory at: category)]
  348. !
  349. allInstanceVariableNames
  350. | result |
  351. result := self instanceVariableNames copy.
  352. self superclass ifNotNil: [
  353. result addAll: self superclass allInstanceVariableNames].
  354. ^result
  355. !
  356. methodAt: aString
  357. <return smalltalk.methods(self)[aString]>
  358. !
  359. methodsFor: aString stamp: aStamp
  360. "Added for compatibility, right now ignores stamp."
  361. ^self methodsFor: aString
  362. !
  363. commentStamp: aStamp prior: prior
  364. ^self commentStamp
  365. ! !
  366. !Behavior methodsFor: 'compiling'!
  367. compile: aString
  368. self compile: aString category: ''
  369. !
  370. compile: aString category: anotherString
  371. | method |
  372. method := Compiler new load: aString forClass: self.
  373. method category: anotherString.
  374. self addCompiledMethod: method
  375. ! !
  376. !Behavior methodsFor: 'instance creation'!
  377. new
  378. ^self basicNew initialize
  379. !
  380. basicNew
  381. <return new self.fn()>
  382. !
  383. inheritsFrom: aClass
  384. ^aClass allSubclasses includes: self
  385. ! !
  386. Behavior subclass: #Class
  387. instanceVariableNames: ''
  388. category: 'Kernel'!
  389. !Class methodsFor: 'accessing'!
  390. category
  391. ^self package ifNil: ['unclassified'] ifNotNil: [self package name]
  392. !
  393. rename: aString
  394. <
  395. smalltalk[aString] = self;
  396. delete smalltalk[self.className];
  397. self.className = aString;
  398. >
  399. !
  400. package
  401. <return self.pkg>
  402. !
  403. package: aPackage
  404. <self.pkg = aPackage>
  405. ! !
  406. !Class methodsFor: 'class creation'!
  407. subclass: aString instanceVariableNames: anotherString
  408. "Kept for compatibility."
  409. ^self subclass: aString instanceVariableNames: anotherString package: nil
  410. !
  411. subclass: aString instanceVariableNames: aString2 category: aString3
  412. "Kept for compatibility."
  413. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  414. !
  415. subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
  416. "Just ignore class variables and pools. Added for compatibility."
  417. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  418. !
  419. subclass: aString instanceVariableNames: aString2 module: aString3
  420. ^ClassBuilder new
  421. superclass: self subclass: aString instanceVariableNames: aString2 module: aString3
  422. !
  423. subclass: aString instanceVariableNames: aString2 package: aString3
  424. ^ClassBuilder new
  425. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  426. ! !
  427. !Class methodsFor: 'printing'!
  428. printString
  429. ^self name
  430. ! !
  431. !Class methodsFor: 'testing'!
  432. isClass
  433. ^true
  434. ! !
  435. Behavior subclass: #Metaclass
  436. instanceVariableNames: ''
  437. category: 'Kernel'!
  438. !Metaclass methodsFor: 'accessing'!
  439. instanceClass
  440. <return self.instanceClass>
  441. !
  442. instanceVariableNames: aCollection
  443. ClassBuilder new
  444. class: self instanceVariableNames: aCollection
  445. ! !
  446. !Metaclass methodsFor: 'printing'!
  447. printString
  448. ^self instanceClass name, ' class'
  449. ! !
  450. !Metaclass methodsFor: 'testing'!
  451. isMetaclass
  452. ^true
  453. ! !
  454. Object subclass: #CompiledMethod
  455. instanceVariableNames: ''
  456. category: 'Kernel'!
  457. !CompiledMethod methodsFor: 'accessing'!
  458. source
  459. ^(self basicAt: 'source') ifNil: ['']
  460. !
  461. source: aString
  462. self basicAt: 'source' put: aString
  463. !
  464. category
  465. ^(self basicAt: 'category') ifNil: ['']
  466. !
  467. category: aString
  468. self basicAt: 'category' put: aString
  469. !
  470. selector
  471. ^self basicAt: 'selector'
  472. !
  473. selector: aString
  474. self basicAt: 'selector' put: aString
  475. !
  476. fn
  477. ^self basicAt: 'fn'
  478. !
  479. fn: aBlock
  480. self basicAt: 'fn' put: aBlock
  481. !
  482. messageSends
  483. ^self basicAt: 'messageSends'
  484. !
  485. methodClass
  486. ^self basicAt: 'methodClass'
  487. !
  488. referencedClasses
  489. ^self basicAt: 'referencedClasses'
  490. !
  491. arguments
  492. <return self.args || []>
  493. ! !
  494. Object subclass: #Number
  495. instanceVariableNames: ''
  496. category: 'Kernel'!
  497. !Number methodsFor: 'arithmetic'!
  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. / aNumber
  511. "Inlined in the Compiler"
  512. <return self / aNumber>
  513. !
  514. max: aNumber
  515. <return Math.max(self, aNumber);>
  516. !
  517. min: aNumber
  518. <return Math.min(self, aNumber);>
  519. !
  520. modulo: aNumber
  521. <return self % aNumber>
  522. !
  523. negated
  524. ^0 - self
  525. ! !
  526. !Number methodsFor: 'comparing'!
  527. = aNumber
  528. aNumber class = self class ifFalse: [^false].
  529. <return Number(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. "Inlined in the Compiler"
  545. <return self <= aNumber>
  546. !
  547. == aNumber
  548. aNumber class = self class ifFalse: [^false].
  549. <return Number(self) === Number(aNumber)>
  550. ! !
  551. !Number methodsFor: 'converting'!
  552. rounded
  553. <return Math.round(self);>
  554. !
  555. truncated
  556. <return Math.floor(self);>
  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: #Association
  1635. instanceVariableNames: 'key value'
  1636. category: 'Kernel'!
  1637. !Association methodsFor: 'accessing'!
  1638. key: aKey
  1639. key := aKey
  1640. !
  1641. key
  1642. ^key
  1643. !
  1644. value: aValue
  1645. value := aValue
  1646. !
  1647. value
  1648. ^value
  1649. ! !
  1650. !Association methodsFor: 'comparing'!
  1651. = anAssociation
  1652. ^self class = anAssociation class and: [
  1653. self key = anAssociation key and: [
  1654. self value = anAssociation value]]
  1655. ! !
  1656. !Association class methodsFor: 'instance creation'!
  1657. key: aKey value: aValue
  1658. ^self new
  1659. key: aKey;
  1660. value: aValue;
  1661. yourself
  1662. ! !
  1663. Collection subclass: #Dictionary
  1664. instanceVariableNames: 'keys'
  1665. category: 'Kernel'!
  1666. !Dictionary methodsFor: 'accessing'!
  1667. size
  1668. ^keys size
  1669. !
  1670. associations
  1671. | associations |
  1672. associations := #().
  1673. keys do: [:each |
  1674. associations add: (Association key: each value: (self at: each))].
  1675. ^associations
  1676. !
  1677. keys
  1678. ^keys copy
  1679. !
  1680. values
  1681. ^keys collect: [:each | self at: each]
  1682. !
  1683. at: aKey put: aValue
  1684. (keys includes: aKey) ifFalse: [keys add: aKey].
  1685. ^self basicAt: aKey put: aValue
  1686. !
  1687. at: aKey ifAbsent: aBlock
  1688. ^(self keys includes: aKey)
  1689. ifTrue: [self basicAt: aKey]
  1690. ifFalse: aBlock
  1691. !
  1692. at: aKey ifAbsentPut: aBlock
  1693. ^self at: aKey ifAbsent: [
  1694. self at: aKey put: aBlock value]
  1695. !
  1696. at: aKey ifPresent: aBlock
  1697. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1698. !
  1699. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1700. ^(self basicAt: aKey)
  1701. ifNil: anotherBlock
  1702. ifNotNil: [aBlock value: (self at: aKey)]
  1703. !
  1704. at: aKey
  1705. ^self at: aKey ifAbsent: [self errorNotFound]
  1706. ! !
  1707. !Dictionary methodsFor: 'adding/removing'!
  1708. add: anAssociation
  1709. self at: anAssociation key put: anAssociation value
  1710. !
  1711. addAll: aDictionary
  1712. super addAll: aDictionary associations.
  1713. ^aDictionary
  1714. !
  1715. remove: aKey
  1716. self removeKey: aKey
  1717. !
  1718. removeKey: aKey
  1719. keys remove: aKey
  1720. ! !
  1721. !Dictionary methodsFor: 'comparing'!
  1722. = aDictionary
  1723. self class = aDictionary class ifFalse: [^false].
  1724. self size = aDictionary size ifFalse: [^false].
  1725. ^self associations = aDictionary associations
  1726. ! !
  1727. !Dictionary methodsFor: 'converting'!
  1728. asJSONObject
  1729. | object |
  1730. object := Object new.
  1731. self keysAndValuesDo: [:key :value |
  1732. object basicAt: key put: value asJSONObject].
  1733. ^object
  1734. ! !
  1735. !Dictionary methodsFor: 'copying'!
  1736. shallowCopy
  1737. | copy |
  1738. copy := self class new.
  1739. self associationsDo: [:each |
  1740. copy at: each key put: each value].
  1741. ^copy
  1742. !
  1743. , aCollection
  1744. self shouldNotImplement
  1745. !
  1746. copyFrom: anIndex to: anotherIndex
  1747. self shouldNotImplement
  1748. ! !
  1749. !Dictionary methodsFor: 'enumerating'!
  1750. associationsDo: aBlock
  1751. self associations do: aBlock
  1752. !
  1753. keysAndValuesDo: aBlock
  1754. self associationsDo: [:each |
  1755. aBlock value: each key value: each value]
  1756. !
  1757. do: aBlock
  1758. self values do: aBlock
  1759. !
  1760. select: aBlock
  1761. | newDict |
  1762. newDict := self class new.
  1763. self keysAndValuesDo: [:key :value |
  1764. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1765. ^newDict
  1766. !
  1767. collect: aBlock
  1768. | newDict |
  1769. newDict := self class new.
  1770. self keysAndValuesDo: [:key :value |
  1771. newDict at: key put: (aBlock value: value)].
  1772. ^newDict
  1773. !
  1774. detect: aBlock ifNone: anotherBlock
  1775. ^self values detect: aBlock ifNone: anotherBlock
  1776. !
  1777. includes: anObject
  1778. ^self values includes: anObject
  1779. ! !
  1780. !Dictionary methodsFor: 'initialization'!
  1781. initialize
  1782. super initialize.
  1783. keys := #()
  1784. ! !
  1785. !Dictionary methodsFor: 'printing'!
  1786. printString
  1787. ^ String streamContents: [:aStream|
  1788. aStream
  1789. nextPutAll: super printString;
  1790. nextPutAll: '('.
  1791. self associations
  1792. do: [:anAssociation|
  1793. aStream
  1794. nextPutAll: anAssociation key printString;
  1795. nextPutAll: ' -> ';
  1796. nextPutAll: anAssociation value printString]
  1797. separatedBy: [aStream nextPutAll: ' , '].
  1798. aStream nextPutAll: ')'.
  1799. ]
  1800. ! !
  1801. !Dictionary class methodsFor: 'instance creation'!
  1802. fromPairs: aCollection
  1803. | dict |
  1804. dict := self new.
  1805. aCollection do: [:each | dict add: each].
  1806. ^dict
  1807. ! !
  1808. Object subclass: #ClassBuilder
  1809. instanceVariableNames: ''
  1810. category: 'Kernel'!
  1811. !ClassBuilder methodsFor: 'class creation'!
  1812. superclass: aClass subclass: aString
  1813. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  1814. !
  1815. class: aClass instanceVariableNames: aString
  1816. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1817. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1818. self setupClass: aClass
  1819. !
  1820. superclass: aClass subclass: aString instanceVariableNames: aString2 module: aString3
  1821. | newClass |
  1822. newClass := self addSubclassOf: aClass
  1823. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1824. module: (aString3 ifNil: ['unclassified']).
  1825. self setupClass: newClass
  1826. !
  1827. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  1828. | newClass |
  1829. newClass := self addSubclassOf: aClass
  1830. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1831. package: (aString3 ifNil: ['unclassified']).
  1832. self setupClass: newClass
  1833. ! !
  1834. !ClassBuilder methodsFor: 'private'!
  1835. instanceVariableNamesFor: aString
  1836. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1837. !
  1838. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1839. <smalltalk.addClass(aString, aClass, aCollection);
  1840. return smalltalk[aString]>
  1841. !
  1842. setupClass: aClass
  1843. <smalltalk.init(aClass);>
  1844. !
  1845. addSubclassOf: aClass named: aString instanceVariableNames: aCollection module: moduleName
  1846. <smalltalk.addClass(aString, aClass, aCollection, moduleName);
  1847. return smalltalk[aString]>
  1848. !
  1849. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  1850. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  1851. return smalltalk[aString]>
  1852. ! !
  1853. Object subclass: #ClassCategoryReader
  1854. instanceVariableNames: 'class category chunkParser'
  1855. category: 'Kernel'!
  1856. !ClassCategoryReader methodsFor: 'accessing'!
  1857. class: aClass category: aString
  1858. class := aClass.
  1859. category := aString
  1860. ! !
  1861. !ClassCategoryReader methodsFor: 'fileIn'!
  1862. scanFrom: aChunkParser
  1863. | chunk |
  1864. [chunk := aChunkParser nextChunk.
  1865. chunk isEmpty] whileFalse: [
  1866. self compileMethod: chunk]
  1867. ! !
  1868. !ClassCategoryReader methodsFor: 'initialization'!
  1869. initialize
  1870. super initialize.
  1871. chunkParser := ChunkParser new.
  1872. ! !
  1873. !ClassCategoryReader methodsFor: 'private'!
  1874. compileMethod: aString
  1875. | method |
  1876. method := Compiler new load: aString forClass: class.
  1877. method category: category.
  1878. class addCompiledMethod: method
  1879. ! !
  1880. Object subclass: #Stream
  1881. instanceVariableNames: 'collection position streamSize'
  1882. category: 'Kernel'!
  1883. !Stream methodsFor: 'accessing'!
  1884. collection
  1885. ^collection
  1886. !
  1887. setCollection: aCollection
  1888. collection := aCollection
  1889. !
  1890. position
  1891. ^position ifNil: [position := 0]
  1892. !
  1893. position: anInteger
  1894. position := anInteger
  1895. !
  1896. streamSize
  1897. ^streamSize
  1898. !
  1899. setStreamSize: anInteger
  1900. streamSize := anInteger
  1901. !
  1902. contents
  1903. ^self collection
  1904. copyFrom: 1
  1905. to: self streamSize
  1906. !
  1907. size
  1908. ^self streamSize
  1909. ! !
  1910. !Stream methodsFor: 'actions'!
  1911. reset
  1912. self position: 0
  1913. !
  1914. close
  1915. !
  1916. flush
  1917. !
  1918. resetContents
  1919. self reset.
  1920. self setStreamSize: 0
  1921. ! !
  1922. !Stream methodsFor: 'enumerating'!
  1923. do: aBlock
  1924. [self atEnd] whileFalse: [aBlock value: self next]
  1925. ! !
  1926. !Stream methodsFor: 'positioning'!
  1927. setToEnd
  1928. self position: self size
  1929. !
  1930. skip: anInteger
  1931. self position: ((self position + anInteger) min: self size max: 0)
  1932. ! !
  1933. !Stream methodsFor: 'reading'!
  1934. next
  1935. self position: self position + 1.
  1936. ^collection at: self position
  1937. !
  1938. next: anInteger
  1939. | tempCollection |
  1940. tempCollection := self collection class new.
  1941. anInteger timesRepeat: [
  1942. self atEnd ifFalse: [
  1943. tempCollection add: self next]].
  1944. ^tempCollection
  1945. !
  1946. peek
  1947. ^self atEnd ifFalse: [
  1948. self collection at: self position + 1]
  1949. ! !
  1950. !Stream methodsFor: 'testing'!
  1951. atEnd
  1952. ^self position = self size
  1953. !
  1954. atStart
  1955. ^self position = 0
  1956. !
  1957. isEmpty
  1958. ^self size = 0
  1959. ! !
  1960. !Stream methodsFor: 'writing'!
  1961. nextPut: anObject
  1962. self position: self position + 1.
  1963. self collection at: self position put: anObject.
  1964. self setStreamSize: (self streamSize max: self position)
  1965. !
  1966. nextPutAll: aCollection
  1967. aCollection do: [:each |
  1968. self nextPut: each]
  1969. ! !
  1970. !Stream class methodsFor: 'instance creation'!
  1971. on: aCollection
  1972. ^self new
  1973. setCollection: aCollection;
  1974. setStreamSize: aCollection size;
  1975. yourself
  1976. ! !
  1977. Stream subclass: #StringStream
  1978. instanceVariableNames: ''
  1979. category: 'Kernel'!
  1980. !StringStream methodsFor: 'reading'!
  1981. next: anInteger
  1982. | tempCollection |
  1983. tempCollection := self collection class new.
  1984. anInteger timesRepeat: [
  1985. self atEnd ifFalse: [
  1986. tempCollection := tempCollection, self next]].
  1987. ^tempCollection
  1988. ! !
  1989. !StringStream methodsFor: 'writing'!
  1990. nextPut: aString
  1991. self nextPutAll: aString
  1992. !
  1993. nextPutAll: aString
  1994. self setCollection:
  1995. (self collection copyFrom: 1 to: self position),
  1996. aString,
  1997. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  1998. self position: self position + aString size.
  1999. self setStreamSize: (self streamSize max: self position)
  2000. !
  2001. cr
  2002. ^self nextPutAll: String cr
  2003. !
  2004. crlf
  2005. ^self nextPutAll: String crlf
  2006. !
  2007. lf
  2008. ^self nextPutAll: String lf
  2009. !
  2010. space
  2011. self nextPut: ' '
  2012. ! !
  2013. Object subclass: #ClassCommentReader
  2014. instanceVariableNames: 'class chunkParser'
  2015. category: 'Kernel'!
  2016. !ClassCommentReader methodsFor: 'accessing'!
  2017. class: aClass
  2018. class := aClass
  2019. ! !
  2020. !ClassCommentReader methodsFor: 'fileIn'!
  2021. scanFrom: aChunkParser
  2022. | chunk |
  2023. chunk := aChunkParser nextChunk.
  2024. chunk isEmpty ifFalse: [
  2025. self setComment: chunk].
  2026. ! !
  2027. !ClassCommentReader methodsFor: 'initialization'!
  2028. initialize
  2029. super initialize.
  2030. chunkParser := ChunkParser new.
  2031. ! !
  2032. !ClassCommentReader methodsFor: 'private'!
  2033. setComment: aString
  2034. class comment: aString
  2035. ! !
  2036. Object subclass: #Random
  2037. instanceVariableNames: ''
  2038. category: 'Kernel'!
  2039. !Random methodsFor: 'accessing'!
  2040. next
  2041. <return Math.random()>
  2042. !
  2043. next: anInteger
  2044. ^1 to: anInteger collect: [:each | self next]
  2045. ! !
  2046. Object subclass: #Point
  2047. instanceVariableNames: 'x y'
  2048. category: 'Kernel'!
  2049. !Point methodsFor: 'accessing'!
  2050. x
  2051. ^x
  2052. !
  2053. y
  2054. ^y
  2055. !
  2056. y: aNumber
  2057. y := aNumber
  2058. !
  2059. x: aNumber
  2060. x := aNumber
  2061. ! !
  2062. !Point methodsFor: 'arithmetic'!
  2063. * aPoint
  2064. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2065. !
  2066. + aPoint
  2067. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2068. !
  2069. - aPoint
  2070. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2071. !
  2072. / aPoint
  2073. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2074. ! !
  2075. !Point methodsFor: 'converting'!
  2076. asPoint
  2077. ^self
  2078. ! !
  2079. !Point class methodsFor: 'instance creation'!
  2080. x: aNumber y: anotherNumber
  2081. ^self new
  2082. x: aNumber;
  2083. y: anotherNumber;
  2084. yourself
  2085. ! !
  2086. Object subclass: #Message
  2087. instanceVariableNames: 'selector arguments'
  2088. category: 'Kernel'!
  2089. !Message methodsFor: 'accessing'!
  2090. selector
  2091. ^selector
  2092. !
  2093. selector: aString
  2094. selector := aString
  2095. !
  2096. arguments: anArray
  2097. arguments := anArray
  2098. !
  2099. arguments
  2100. ^arguments
  2101. ! !
  2102. !Message class methodsFor: 'instance creation'!
  2103. selector: aString arguments: anArray
  2104. ^self new
  2105. selector: aString;
  2106. arguments: anArray;
  2107. yourself
  2108. ! !
  2109. Error subclass: #MessageNotUnderstood
  2110. instanceVariableNames: 'message receiver'
  2111. category: 'Kernel'!
  2112. !MessageNotUnderstood methodsFor: 'accessing'!
  2113. message
  2114. ^message
  2115. !
  2116. message: aMessage
  2117. message := aMessage
  2118. !
  2119. receiver
  2120. ^receiver
  2121. !
  2122. receiver: anObject
  2123. receiver := anObject
  2124. !
  2125. messageText
  2126. ^self receiver asString, ' does not understand #', self message selector
  2127. ! !
  2128. Object subclass: #ErrorHandler
  2129. instanceVariableNames: ''
  2130. category: 'Kernel'!
  2131. !ErrorHandler methodsFor: 'error handling'!
  2132. handleError: anError
  2133. anError context ifNotNil: [self logErrorContext: anError context].
  2134. self logError: anError
  2135. ! !
  2136. !ErrorHandler methodsFor: 'private'!
  2137. logContext: aContext
  2138. aContext home ifNotNil: [
  2139. self logContext: aContext home].
  2140. self log: aContext receiver asString, '>>', aContext selector
  2141. !
  2142. logErrorContext: aContext
  2143. aContext ifNotNil: [
  2144. aContext home ifNotNil: [
  2145. self logContext: aContext home]]
  2146. !
  2147. logError: anError
  2148. self log: anError messageText
  2149. !
  2150. log: aString
  2151. console log: aString
  2152. ! !
  2153. ErrorHandler class instanceVariableNames: 'current'!
  2154. !ErrorHandler class methodsFor: 'accessing'!
  2155. current
  2156. ^current ifNil: [current := self new]
  2157. !
  2158. setCurrent: anHandler
  2159. current := anHandler
  2160. ! !
  2161. !ErrorHandler class methodsFor: 'initialization'!
  2162. initialize
  2163. self register
  2164. !
  2165. register
  2166. ErrorHandler setCurrent: self new
  2167. ! !
  2168. Object subclass: #JSObjectProxy
  2169. instanceVariableNames: 'jsObject'
  2170. category: 'Kernel'!
  2171. !JSObjectProxy methodsFor: 'accessing'!
  2172. jsObject: aJSObject
  2173. jsObject := aJSObject
  2174. !
  2175. jsObject
  2176. ^jsObject
  2177. ! !
  2178. !JSObjectProxy methodsFor: 'proxy'!
  2179. printString
  2180. ^self jsObject toString
  2181. !
  2182. inspectOn: anInspector
  2183. | variables |
  2184. variables := Dictionary new.
  2185. variables at: '#self' put: self jsObject.
  2186. anInspector setLabel: self printString.
  2187. <for(var i in self['@jsObject']) {
  2188. variables._at_put_(i, self['@jsObject'][i]);
  2189. }>.
  2190. anInspector setVariables: variables
  2191. !
  2192. doesNotUnderstand: aMessage
  2193. | obj selector arguments |
  2194. obj := self jsObject.
  2195. selector := aMessage selector.
  2196. arguments := aMessage arguments.
  2197. <if(obj[selector]) {return smalltalk.send(obj, selector, arguments)}>.
  2198. super doesNotUnderstand: aMessage
  2199. ! !
  2200. !JSObjectProxy class methodsFor: 'instance creation'!
  2201. on: aJSObject
  2202. ^self new
  2203. jsObject: aJSObject;
  2204. yourself
  2205. ! !
  2206. Collection subclass: #Set
  2207. instanceVariableNames: 'elements'
  2208. category: 'Kernel'!
  2209. !Set methodsFor: 'accessing'!
  2210. size
  2211. ^elements size
  2212. ! !
  2213. !Set methodsFor: 'adding/removing'!
  2214. add: anObject
  2215. <
  2216. var found;
  2217. for(var i in self['@elements']) {
  2218. if(anObject == self['@elements'][i]) {
  2219. found = true;
  2220. break;
  2221. }
  2222. }
  2223. if(!!found) {self['@elements'].push(anObject)}
  2224. >
  2225. !
  2226. remove: anObject
  2227. elements remove: anObject
  2228. ! !
  2229. !Set methodsFor: 'comparing'!
  2230. = aCollection
  2231. ^self class = aCollection class and: [
  2232. elements = aCollection asArray]
  2233. ! !
  2234. !Set methodsFor: 'converting'!
  2235. asArray
  2236. ^elements copy
  2237. ! !
  2238. !Set methodsFor: 'enumerating'!
  2239. detect: aBlock ifNone: anotherBlock
  2240. ^elements detect: aBlock ifNone: anotherBlock
  2241. !
  2242. do: aBlock
  2243. elements do: aBlock
  2244. ! !
  2245. !Set methodsFor: 'initialization'!
  2246. initialize
  2247. super initialize.
  2248. elements := #()
  2249. ! !
  2250. !Set methodsFor: 'testing'!
  2251. includes: anObject
  2252. ^elements includes: anObject
  2253. ! !