Kernel.st 51 KB

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