Kernel.st 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032
  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. !Smalltalk methodsFor: 'classes'!
  226. removeClass: aClass
  227. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  228. aClass methodDictionary values do: [:each |
  229. aClass removeCompiledMethod: each].
  230. aClass class methodDictionary values do: [:each |
  231. aClass class removeCompiledMethod: each].
  232. self basicDelete: aClass name
  233. ! !
  234. !Smalltalk methodsFor: 'packages'!
  235. packages
  236. "Return all Package instances in the system."
  237. <return self.packages.all()>
  238. !
  239. packageAt: packageName
  240. <return self.packages[packageName]>
  241. !
  242. packageAt: packageName ifAbsent: aBlock
  243. ^(self packageAt: packageName) ifNil: aBlock
  244. !
  245. removePackage: packageName
  246. "Removes a package and all its classes."
  247. | package |
  248. package := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  249. package classes do: [:each |
  250. self removeClass: each].
  251. self deletePackage: packageName
  252. !
  253. renamePackage: packageName to: newName
  254. "Rename a package."
  255. | package |
  256. package := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  257. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  258. <smalltalk.packages[newName] = smalltalk.packages[packageName]>.
  259. package name: newName.
  260. self deletePackage: packageName.
  261. ! !
  262. !Smalltalk methodsFor: 'private'!
  263. createPackage: packageName
  264. "Create and bind a new package with given name and return it."
  265. <return smalltalk.addPackage(packageName)>
  266. !
  267. deletePackage: packageName
  268. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  269. To remove a package, use #removePackage instead."
  270. <delete smalltalk.packages[packageName]>
  271. ! !
  272. Smalltalk class instanceVariableNames: 'current'!
  273. !Smalltalk class methodsFor: 'accessing'!
  274. current
  275. <return smalltalk>
  276. ! !
  277. Object subclass: #Package
  278. instanceVariableNames: ''
  279. category: 'Kernel'!
  280. !Package commentStamp!
  281. A Package is similar to a "class category" typically found in other Smalltalks like Pharo or Squeak. Jtalk does not have class categories anymore, it had in the beginning but now each class in the system knows which package it belongs to.
  282. 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.
  283. Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
  284. Smalltalk current packageAt: 'Kernel'
  285. ...but you can also use:
  286. Package named: 'Kernel'
  287. 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
  288. 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
  289. String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.!
  290. !Package methodsFor: 'accessing'!
  291. name
  292. <return self.pkgName || nil>
  293. !
  294. requires
  295. <return self.requires || nil>
  296. !
  297. name: aString
  298. <return self.pkgName = aString>
  299. ! !
  300. !Package methodsFor: 'classes'!
  301. classes
  302. "We need to do a reverse scan."
  303. ^Smalltalk current classes select: [:c | c package == self]
  304. ! !
  305. !Package methodsFor: 'printing'!
  306. printString
  307. ^self name
  308. ! !
  309. !Package class methodsFor: 'not yet classified'!
  310. named: aPackageName
  311. ^Smalltalk current packageAt: aPackageName
  312. !
  313. named: aPackageName ifAbsent: aBlock
  314. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  315. ! !
  316. Object subclass: #Behavior
  317. instanceVariableNames: ''
  318. category: 'Kernel'!
  319. !Behavior methodsFor: 'accessing'!
  320. name
  321. <return self.className || nil>
  322. !
  323. superclass
  324. <return self.superclass || nil>
  325. !
  326. subclasses
  327. <return smalltalk.subclasses(self)>
  328. !
  329. allSubclasses
  330. | result |
  331. result := self subclasses.
  332. self subclasses do: [:each |
  333. result addAll: each allSubclasses].
  334. ^result
  335. !
  336. withAllSubclasses
  337. ^(Array with: self) addAll: self allSubclasses; yourself
  338. !
  339. prototype
  340. <return self.fn.prototype>
  341. !
  342. methodDictionary
  343. <var dict = smalltalk.Dictionary._new();
  344. var methods = self.fn.prototype.methods;
  345. for(var i in methods) {
  346. if(methods[i].selector) {
  347. dict._at_put_(methods[i].selector, methods[i]);
  348. }
  349. };
  350. return dict>
  351. !
  352. methodsFor: aString
  353. ^ClassCategoryReader new
  354. class: self category: aString;
  355. yourself
  356. !
  357. addCompiledMethod: aMethod
  358. <smalltalk.addMethod(aMethod.selector._asSelector(), aMethod, self)>
  359. !
  360. instanceVariableNames
  361. <return self.iVarNames>
  362. !
  363. comment
  364. ^(self basicAt: 'comment') ifNil: ['']
  365. !
  366. comment: aString
  367. self basicAt: 'comment' put: aString
  368. !
  369. commentStamp
  370. ^ClassCommentReader new
  371. class: self;
  372. yourself
  373. !
  374. removeCompiledMethod: aMethod
  375. <delete self.fn.prototype[aMethod.selector._asSelector()];
  376. delete self.fn.prototype.methods[aMethod.selector];
  377. smalltalk.init(self);>
  378. !
  379. protocols
  380. | protocols |
  381. protocols := Array new.
  382. self methodDictionary do: [:each |
  383. (protocols includes: each category) ifFalse: [
  384. protocols add: each category]].
  385. ^protocols sort
  386. !
  387. protocolsDo: aBlock
  388. "Execute aBlock for each method category with
  389. its collection of methods in the sort order of category name."
  390. | methodsByCategory |
  391. methodsByCategory := Dictionary new.
  392. self methodDictionary values do: [:m |
  393. (methodsByCategory at: m category ifAbsentPut: [Array new])
  394. add: m].
  395. self protocols do: [:category |
  396. aBlock value: category value: (methodsByCategory at: category)]
  397. !
  398. allInstanceVariableNames
  399. | result |
  400. result := self instanceVariableNames copy.
  401. self superclass ifNotNil: [
  402. result addAll: self superclass allInstanceVariableNames].
  403. ^result
  404. !
  405. methodAt: aString
  406. <return smalltalk.methods(self)[aString]>
  407. !
  408. methodsFor: aString stamp: aStamp
  409. "Added for compatibility, right now ignores stamp."
  410. ^self methodsFor: aString
  411. !
  412. commentStamp: aStamp prior: prior
  413. ^self commentStamp
  414. ! !
  415. !Behavior methodsFor: 'compiling'!
  416. compile: aString
  417. self compile: aString category: ''
  418. !
  419. compile: aString category: anotherString
  420. | method |
  421. method := Compiler new load: aString forClass: self.
  422. method category: anotherString.
  423. self addCompiledMethod: method
  424. ! !
  425. !Behavior methodsFor: 'instance creation'!
  426. new
  427. ^self basicNew initialize
  428. !
  429. basicNew
  430. <return new self.fn()>
  431. !
  432. inheritsFrom: aClass
  433. ^aClass allSubclasses includes: self
  434. ! !
  435. Behavior subclass: #Class
  436. instanceVariableNames: ''
  437. category: 'Kernel'!
  438. !Class methodsFor: 'accessing'!
  439. category
  440. ^self package ifNil: ['unclassified'] ifNotNil: [self package name]
  441. !
  442. rename: aString
  443. <
  444. smalltalk[aString] = self;
  445. delete smalltalk[self.className];
  446. self.className = aString;
  447. >
  448. !
  449. package
  450. <return self.pkg>
  451. !
  452. package: aPackage
  453. <self.pkg = aPackage>
  454. ! !
  455. !Class methodsFor: 'class creation'!
  456. subclass: aString instanceVariableNames: anotherString
  457. "Kept for compatibility."
  458. ^self subclass: aString instanceVariableNames: anotherString package: nil
  459. !
  460. subclass: aString instanceVariableNames: aString2 category: aString3
  461. "Kept for compatibility."
  462. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  463. !
  464. subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
  465. "Just ignore class variables and pools. Added for compatibility."
  466. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  467. !
  468. subclass: aString instanceVariableNames: aString2 module: aString3
  469. ^ClassBuilder new
  470. superclass: self subclass: aString instanceVariableNames: aString2 module: 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 module: aString3
  983. ^ClassBuilder new
  984. superclass: self subclass: aString instanceVariableNames: aString2 module: aString3
  985. !
  986. subclass: aString instanceVariableNames: aString2 package: aString3
  987. ^ClassBuilder new
  988. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  989. ! !
  990. !UndefinedObject methodsFor: 'copying'!
  991. shallowCopy
  992. ^self
  993. !
  994. deepCopy
  995. ^self
  996. ! !
  997. !UndefinedObject methodsFor: 'printing'!
  998. printString
  999. ^'nil'
  1000. ! !
  1001. !UndefinedObject methodsFor: 'testing'!
  1002. ifNil: aBlock
  1003. "inlined in the Compiler"
  1004. ^self ifNil: aBlock ifNotNil: []
  1005. !
  1006. ifNotNil: aBlock
  1007. "inlined in the Compiler"
  1008. ^self
  1009. !
  1010. ifNil: aBlock ifNotNil: anotherBlock
  1011. "inlined in the Compiler"
  1012. ^aBlock value
  1013. !
  1014. ifNotNil: aBlock ifNil: anotherBlock
  1015. "inlined in the Compiler"
  1016. ^anotherBlock value
  1017. !
  1018. isNil
  1019. ^true
  1020. !
  1021. notNil
  1022. ^false
  1023. ! !
  1024. !UndefinedObject class methodsFor: 'instance creation'!
  1025. new
  1026. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1027. ! !
  1028. Object subclass: #Collection
  1029. instanceVariableNames: ''
  1030. category: 'Kernel'!
  1031. !Collection methodsFor: 'accessing'!
  1032. size
  1033. self subclassResponsibility
  1034. !
  1035. readStream
  1036. ^self stream
  1037. !
  1038. writeStream
  1039. ^self stream
  1040. !
  1041. stream
  1042. ^self streamClass on: self
  1043. !
  1044. streamClass
  1045. ^self class streamClass
  1046. ! !
  1047. !Collection methodsFor: 'adding/removing'!
  1048. add: anObject
  1049. self subclassResponsibility
  1050. !
  1051. addAll: aCollection
  1052. aCollection do: [:each |
  1053. self add: each].
  1054. ^aCollection
  1055. !
  1056. remove: anObject
  1057. self subclassResponsibility
  1058. ! !
  1059. !Collection methodsFor: 'converting'!
  1060. asArray
  1061. | array index |
  1062. array := Array new.
  1063. index := 0.
  1064. self do: [:each |
  1065. index := index + 1.
  1066. array at: index put: each].
  1067. ^array
  1068. !
  1069. asSet
  1070. ^Set withAll: self
  1071. ! !
  1072. !Collection methodsFor: 'copying'!
  1073. , aCollection
  1074. ^self copy
  1075. addAll: aCollection;
  1076. yourself
  1077. !
  1078. copyWith: anObject
  1079. ^self copy add: anObject; yourself
  1080. !
  1081. copyWithAll: aCollection
  1082. ^self copy addAll: aCollection; yourself
  1083. ! !
  1084. !Collection methodsFor: 'enumerating'!
  1085. do: aBlock
  1086. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  1087. !
  1088. collect: aBlock
  1089. | newCollection |
  1090. newCollection := self class new.
  1091. self do: [:each |
  1092. newCollection add: (aBlock value: each)].
  1093. ^newCollection
  1094. !
  1095. detect: aBlock
  1096. ^self detect: aBlock ifNone: [self errorNotFound]
  1097. !
  1098. detect: aBlock ifNone: anotherBlock
  1099. <
  1100. for(var i = 0; i < self.length; i++)
  1101. if(aBlock(self[i]))
  1102. return self[i];
  1103. return anotherBlock();
  1104. >
  1105. !
  1106. do: aBlock separatedBy: anotherBlock
  1107. | first |
  1108. first := true.
  1109. self do: [:each |
  1110. first
  1111. ifTrue: [first := false]
  1112. ifFalse: [anotherBlock value].
  1113. aBlock value: each]
  1114. !
  1115. inject: anObject into: aBlock
  1116. | result |
  1117. result := anObject.
  1118. self do: [:each |
  1119. result := aBlock value: result value: each].
  1120. ^result
  1121. !
  1122. reject: aBlock
  1123. ^self select: [:each | (aBlock value: each) = false]
  1124. !
  1125. select: aBlock
  1126. | stream |
  1127. stream := self class new writeStream.
  1128. self do: [:each |
  1129. (aBlock value: each) ifTrue: [
  1130. stream nextPut: each]].
  1131. ^stream contents
  1132. ! !
  1133. !Collection methodsFor: 'error handling'!
  1134. errorNotFound
  1135. self error: 'Object is not in the collection'
  1136. ! !
  1137. !Collection methodsFor: 'testing'!
  1138. includes: anObject
  1139. <
  1140. var i = self.length;
  1141. while (i--) {
  1142. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1143. }
  1144. return false
  1145. >
  1146. !
  1147. notEmpty
  1148. ^self isEmpty not
  1149. !
  1150. isEmpty
  1151. ^self size = 0
  1152. !
  1153. ifNotEmpty: aBlock
  1154. self notEmpty ifTrue: aBlock.
  1155. !
  1156. ifEmpty: aBlock
  1157. self isEmpty ifTrue: aBlock.
  1158. ! !
  1159. !Collection class methodsFor: 'accessing'!
  1160. streamClass
  1161. ^Stream
  1162. ! !
  1163. !Collection class methodsFor: 'instance creation'!
  1164. with: anObject
  1165. ^self new
  1166. add: anObject;
  1167. yourself
  1168. !
  1169. with: anObject with: anotherObject
  1170. ^self new
  1171. add: anObject;
  1172. add: anotherObject;
  1173. yourself
  1174. !
  1175. with: firstObject with: secondObject with: thirdObject
  1176. ^self new
  1177. add: firstObject;
  1178. add: secondObject;
  1179. add: thirdObject;
  1180. yourself
  1181. !
  1182. withAll: aCollection
  1183. ^self new
  1184. addAll: aCollection;
  1185. yourself
  1186. ! !
  1187. Collection subclass: #SequenceableCollection
  1188. instanceVariableNames: ''
  1189. category: 'Kernel'!
  1190. !SequenceableCollection methodsFor: 'accessing'!
  1191. at: anIndex
  1192. ^self at: anIndex ifAbsent: [
  1193. self errorNotFound]
  1194. !
  1195. at: anIndex ifAbsent: aBlock
  1196. self subclassResponsibility
  1197. !
  1198. at: anIndex put: anObject
  1199. self subclassResponsibility
  1200. !
  1201. first
  1202. ^self at: 1
  1203. !
  1204. fourth
  1205. ^self at: 4
  1206. !
  1207. last
  1208. ^self at: self size
  1209. !
  1210. second
  1211. ^self at: 2
  1212. !
  1213. third
  1214. ^self at: 3
  1215. !
  1216. allButFirst
  1217. ^self copyFrom: 2 to: self size
  1218. !
  1219. allButLast
  1220. ^self copyFrom: 1 to: self size - 1
  1221. !
  1222. indexOf: anObject
  1223. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1224. !
  1225. indexOf: anObject ifAbsent: aBlock
  1226. <
  1227. for(var i=0;i<self.length;i++){
  1228. if(self[i].__eq(anObject)) {return i+1}
  1229. }
  1230. return aBlock();
  1231. >
  1232. !
  1233. indexOf: anObject startingAt: start ifAbsent: aBlock
  1234. <
  1235. for(var i=start-1;i<self.length;i++){
  1236. if(self[i].__eq(anObject)) {return i+1}
  1237. }
  1238. return aBlock();
  1239. >
  1240. !
  1241. indexOf: anObject startingAt: start
  1242. "Answer the index of the first occurence of anElement after start
  1243. within the receiver. If the receiver does not contain anElement,
  1244. answer 0."
  1245. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1246. ! !
  1247. !SequenceableCollection methodsFor: 'adding'!
  1248. removeLast
  1249. self remove: self last
  1250. !
  1251. addLast: anObject
  1252. self add: anObject
  1253. ! !
  1254. !SequenceableCollection methodsFor: 'converting'!
  1255. reversed
  1256. self subclassResponsibility
  1257. ! !
  1258. !SequenceableCollection methodsFor: 'copying'!
  1259. copyFrom: anIndex to: anotherIndex
  1260. self subclassResponsibility
  1261. ! !
  1262. !SequenceableCollection methodsFor: 'enumerating'!
  1263. withIndexDo: aBlock
  1264. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1265. ! !
  1266. SequenceableCollection subclass: #String
  1267. instanceVariableNames: ''
  1268. category: 'Kernel'!
  1269. !String methodsFor: 'accessing'!
  1270. size
  1271. <return self.length>
  1272. !
  1273. at: anIndex
  1274. <return self[anIndex - 1]>
  1275. !
  1276. at: anIndex put: anObject
  1277. self errorReadOnly
  1278. !
  1279. at: anIndex ifAbsent: aBlock
  1280. (self at: anIndex) ifNil: [aBlock]
  1281. !
  1282. escaped
  1283. <return escape(self)>
  1284. !
  1285. unescaped
  1286. <return unescape(self)>
  1287. !
  1288. asciiValue
  1289. <return self.charCodeAt(0);>
  1290. ! !
  1291. !String methodsFor: 'adding'!
  1292. add: anObject
  1293. self errorReadOnly
  1294. !
  1295. remove: anObject
  1296. self errorReadOnly
  1297. ! !
  1298. !String methodsFor: 'comparing'!
  1299. = aString
  1300. aString class = self class ifFalse: [^false].
  1301. <return String(self) == aString>
  1302. !
  1303. > aString
  1304. <return String(self) >> aString>
  1305. !
  1306. < aString
  1307. <return String(self) < aString>
  1308. !
  1309. >= aString
  1310. <return String(self) >>= aString>
  1311. !
  1312. <= aString
  1313. <return String(self) <= aString>
  1314. !
  1315. == aString
  1316. aString class = self class ifFalse: [^false].
  1317. <return String(self) === String(aString)>
  1318. ! !
  1319. !String methodsFor: 'converting'!
  1320. asSelector
  1321. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1322. | selector |
  1323. selector := '_', self.
  1324. selector := selector replace: ':' with: '_'.
  1325. selector := selector replace: '[+]' with: '_plus'.
  1326. selector := selector replace: '-' with: '_minus'.
  1327. selector := selector replace: '[*]' with: '_star'.
  1328. selector := selector replace: '[/]' with: '_slash'.
  1329. selector := selector replace: '>' with: '_gt'.
  1330. selector := selector replace: '<' with: '_lt'.
  1331. selector := selector replace: '=' with: '_eq'.
  1332. selector := selector replace: ',' with: '_comma'.
  1333. selector := selector replace: '[@]' with: '_at'.
  1334. ^selector
  1335. !
  1336. asJavascript
  1337. <
  1338. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1339. return "unescape(\"" + escape(self) + "\")";
  1340. else
  1341. return "\"" + self + "\"";
  1342. >
  1343. !
  1344. tokenize: aString
  1345. <return self.split(aString)>
  1346. !
  1347. asString
  1348. ^self
  1349. !
  1350. asNumber
  1351. <return Number(self)>
  1352. !
  1353. asJSONObject
  1354. ^self
  1355. !
  1356. asLowercase
  1357. <return self.toLowerCase()>
  1358. !
  1359. asUppercase
  1360. <return self.toUpperCase()>
  1361. !
  1362. reversed
  1363. <return self.split("").reverse().join("")>
  1364. ! !
  1365. !String methodsFor: 'copying'!
  1366. , aString
  1367. <return self + aString>
  1368. !
  1369. copyFrom: anIndex to: anotherIndex
  1370. <return self.substring(anIndex - 1, anotherIndex)>
  1371. !
  1372. shallowCopy
  1373. ^self class fromString: self
  1374. !
  1375. deepCopy
  1376. ^self shallowCopy
  1377. ! !
  1378. !String methodsFor: 'error handling'!
  1379. errorReadOnly
  1380. self error: 'Object is read-only'
  1381. ! !
  1382. !String methodsFor: 'printing'!
  1383. printString
  1384. ^'''', self, ''''
  1385. !
  1386. printNl
  1387. <console.log(self)>
  1388. ! !
  1389. !String methodsFor: 'regular expressions'!
  1390. replace: aString with: anotherString
  1391. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1392. !
  1393. replaceRegexp: aRegexp with: aString
  1394. <return self.replace(aRegexp, aString)>
  1395. !
  1396. match: aRegexp
  1397. <return self.search(aRegexp) !!= -1>
  1398. !
  1399. trimLeft: separators
  1400. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1401. !
  1402. trimRight: separators
  1403. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1404. !
  1405. trimLeft
  1406. ^self trimLeft: '\s'
  1407. !
  1408. trimRight
  1409. ^self trimRight: '\s'
  1410. !
  1411. trimBoth
  1412. ^self trimBoth: '\s'
  1413. !
  1414. trimBoth: separators
  1415. ^(self trimLeft: separators) trimRight: separators
  1416. ! !
  1417. !String methodsFor: 'split join'!
  1418. join: aCollection
  1419. ^ String
  1420. streamContents: [:stream | aCollection
  1421. do: [:each | stream nextPutAll: each asString]
  1422. separatedBy: [stream nextPutAll: self]]
  1423. !
  1424. lineIndicesDo: aBlock
  1425. "execute aBlock with 3 arguments for each line:
  1426. - start index of line
  1427. - end index of line without line delimiter
  1428. - end index of line including line delimiter(s) CR, LF or CRLF"
  1429. | cr lf start sz nextLF nextCR |
  1430. start := 1.
  1431. sz := self size.
  1432. cr := String cr.
  1433. nextCR := self indexOf: cr startingAt: 1.
  1434. lf := String lf.
  1435. nextLF := self indexOf: lf startingAt: 1.
  1436. [ start <= sz ] whileTrue: [
  1437. (nextLF = 0 and: [ nextCR = 0 ])
  1438. ifTrue: [ "No more CR, nor LF, the string is over"
  1439. aBlock value: start value: sz value: sz.
  1440. ^self ].
  1441. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1442. ifTrue: [ "Found a LF"
  1443. aBlock value: start value: nextLF - 1 value: nextLF.
  1444. start := 1 + nextLF.
  1445. nextLF := self indexOf: lf startingAt: start ]
  1446. ifFalse: [ 1 + nextCR = nextLF
  1447. ifTrue: [ "Found a CR-LF pair"
  1448. aBlock value: start value: nextCR - 1 value: nextLF.
  1449. start := 1 + nextLF.
  1450. nextCR := self indexOf: cr startingAt: start.
  1451. nextLF := self indexOf: lf startingAt: start ]
  1452. ifFalse: [ "Found a CR"
  1453. aBlock value: start value: nextCR - 1 value: nextCR.
  1454. start := 1 + nextCR.
  1455. nextCR := self indexOf: cr startingAt: start ]]]
  1456. !
  1457. linesDo: aBlock
  1458. "Execute aBlock with each line in this string. The terminating line
  1459. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1460. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1461. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1462. !
  1463. lines
  1464. "Answer an array of lines composing this receiver without the line ending delimiters."
  1465. | lines |
  1466. lines := Array new.
  1467. self linesDo: [:aLine | lines add: aLine].
  1468. ^lines
  1469. !
  1470. lineNumber: anIndex
  1471. "Answer a string containing the characters in the given line number."
  1472. | lineCount |
  1473. lineCount := 0.
  1474. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1475. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1476. ^nil
  1477. ! !
  1478. !String methodsFor: 'testing'!
  1479. isString
  1480. ^true
  1481. !
  1482. includesSubString: subString
  1483. < return self.indexOf(subString) !!= -1 >
  1484. ! !
  1485. !String class methodsFor: 'accessing'!
  1486. streamClass
  1487. ^StringStream
  1488. !
  1489. cr
  1490. <return '\r'>
  1491. !
  1492. lf
  1493. <return '\n'>
  1494. !
  1495. space
  1496. <return ' '>
  1497. !
  1498. tab
  1499. <return '\t'>
  1500. !
  1501. crlf
  1502. <return '\r\n'>
  1503. ! !
  1504. !String class methodsFor: 'instance creation'!
  1505. fromString: aString
  1506. <return new self.fn(aString)>
  1507. !
  1508. streamContents: blockWithArg
  1509. |stream|
  1510. stream := (self streamClass on: String new).
  1511. blockWithArg value: stream.
  1512. ^ stream contents
  1513. !
  1514. value: aUTFCharCode
  1515. <return String.fromCharCode(aUTFCharCode);>
  1516. ! !
  1517. SequenceableCollection subclass: #Array
  1518. instanceVariableNames: ''
  1519. category: 'Kernel'!
  1520. !Array methodsFor: 'accessing'!
  1521. size
  1522. <return self.length>
  1523. !
  1524. at: anIndex put: anObject
  1525. <return self[anIndex - 1] = anObject>
  1526. !
  1527. at: anIndex ifAbsent: aBlock
  1528. <
  1529. var value = self[anIndex - 1];
  1530. if(value === undefined) {
  1531. return aBlock();
  1532. } else {
  1533. return value;
  1534. }
  1535. >
  1536. ! !
  1537. !Array methodsFor: 'adding/removing'!
  1538. add: anObject
  1539. <self.push(anObject); return anObject;>
  1540. !
  1541. remove: anObject
  1542. <
  1543. for(var i=0;i<self.length;i++) {
  1544. if(self[i] == anObject) {
  1545. self.splice(i,1);
  1546. break;
  1547. }
  1548. }
  1549. >
  1550. !
  1551. removeFrom: aNumber to: anotherNumber
  1552. <self.splice(aNumber - 1,anotherNumber - 1)>
  1553. ! !
  1554. !Array methodsFor: 'comparing'!
  1555. = aCollection
  1556. (self class = aCollection class and: [
  1557. self size = aCollection size]) ifFalse: [^false].
  1558. self withIndexDo: [:each :i |
  1559. (aCollection at: i) = each ifFalse: [^false]].
  1560. ^true
  1561. ! !
  1562. !Array methodsFor: 'converting'!
  1563. asJavascript
  1564. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1565. !
  1566. asJSONObject
  1567. ^self collect: [:each | each asJSONObject]
  1568. !
  1569. reversed
  1570. <return self._copy().reverse()>
  1571. ! !
  1572. !Array methodsFor: 'copying'!
  1573. shallowCopy
  1574. | newCollection |
  1575. newCollection := self class new.
  1576. self do: [:each | newCollection add: each].
  1577. ^newCollection
  1578. !
  1579. deepCopy
  1580. | newCollection |
  1581. newCollection := self class new.
  1582. self do: [:each | newCollection add: each deepCopy].
  1583. ^newCollection
  1584. !
  1585. copyFrom: anIndex to: anotherIndex
  1586. | array |
  1587. array := self class new.
  1588. anIndex to: anotherIndex do: [:each |
  1589. array add: (self at: each)].
  1590. ^array
  1591. ! !
  1592. !Array methodsFor: 'enumerating'!
  1593. join: aString
  1594. <return self.join(aString)>
  1595. !
  1596. sort
  1597. ^self basicPerform: 'sort'
  1598. !
  1599. sort: aBlock
  1600. <
  1601. return self.sort(function(a, b) {
  1602. if(aBlock(a,b)) {return -1} else {return 1}
  1603. })
  1604. >
  1605. !
  1606. sorted
  1607. ^self copy sort
  1608. !
  1609. sorted: aBlock
  1610. ^self copy sort: aBlock
  1611. !
  1612. printString
  1613. | str |
  1614. str := '' writeStream.
  1615. str nextPutAll: super printString, ' ('.
  1616. self
  1617. do: [:each | str nextPutAll: each printString]
  1618. separatedBy: [str nextPutAll: ' '].
  1619. str nextPutAll: ')'.
  1620. ^str contents
  1621. ! !
  1622. Object subclass: #RegularExpression
  1623. instanceVariableNames: ''
  1624. category: 'Kernel'!
  1625. !RegularExpression methodsFor: 'evaluating'!
  1626. compile: aString
  1627. <return self.compile(aString)>
  1628. !
  1629. exec: aString
  1630. <return self.exec(aString) || nil>
  1631. !
  1632. test: aString
  1633. <return self.test(aString)>
  1634. ! !
  1635. !RegularExpression class methodsFor: 'instance creation'!
  1636. fromString: aString flag: anotherString
  1637. <return new RegExp(aString, anotherString)>
  1638. !
  1639. fromString: aString
  1640. ^self fromString: aString flag: ''
  1641. ! !
  1642. Object subclass: #Error
  1643. instanceVariableNames: 'messageText'
  1644. category: 'Kernel'!
  1645. !Error methodsFor: 'accessing'!
  1646. messageText
  1647. ^messageText
  1648. !
  1649. messageText: aString
  1650. messageText := aString
  1651. !
  1652. context
  1653. <return self.context>
  1654. ! !
  1655. !Error methodsFor: 'signaling'!
  1656. signal
  1657. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1658. ! !
  1659. !Error class methodsFor: 'instance creation'!
  1660. signal: aString
  1661. ^self new
  1662. messageText: aString;
  1663. signal
  1664. ! !
  1665. Object subclass: #MethodContext
  1666. instanceVariableNames: ''
  1667. category: 'Kernel'!
  1668. !MethodContext methodsFor: 'accessing'!
  1669. receiver
  1670. <return self.receiver>
  1671. !
  1672. selector
  1673. <return smalltalk.convertSelector(self.selector)>
  1674. !
  1675. home
  1676. <return self.homeContext>
  1677. !
  1678. temps
  1679. <return self.temps>
  1680. !
  1681. printString
  1682. ^super printString, '(', self asString, ')'
  1683. !
  1684. asString
  1685. ^self receiver class printString, ' >> ', self selector
  1686. ! !
  1687. Object subclass: #Association
  1688. instanceVariableNames: 'key value'
  1689. category: 'Kernel'!
  1690. !Association methodsFor: 'accessing'!
  1691. key: aKey
  1692. key := aKey
  1693. !
  1694. key
  1695. ^key
  1696. !
  1697. value: aValue
  1698. value := aValue
  1699. !
  1700. value
  1701. ^value
  1702. ! !
  1703. !Association methodsFor: 'comparing'!
  1704. = anAssociation
  1705. ^self class = anAssociation class and: [
  1706. self key = anAssociation key and: [
  1707. self value = anAssociation value]]
  1708. ! !
  1709. !Association class methodsFor: 'instance creation'!
  1710. key: aKey value: aValue
  1711. ^self new
  1712. key: aKey;
  1713. value: aValue;
  1714. yourself
  1715. ! !
  1716. Collection subclass: #Dictionary
  1717. instanceVariableNames: 'keys'
  1718. category: 'Kernel'!
  1719. !Dictionary methodsFor: 'accessing'!
  1720. size
  1721. ^keys size
  1722. !
  1723. associations
  1724. | associations |
  1725. associations := #().
  1726. keys do: [:each |
  1727. associations add: (Association key: each value: (self at: each))].
  1728. ^associations
  1729. !
  1730. keys
  1731. ^keys copy
  1732. !
  1733. values
  1734. ^keys collect: [:each | self at: each]
  1735. !
  1736. at: aKey put: aValue
  1737. (keys includes: aKey) ifFalse: [keys add: aKey].
  1738. ^self basicAt: aKey put: aValue
  1739. !
  1740. at: aKey ifAbsent: aBlock
  1741. ^(self keys includes: aKey)
  1742. ifTrue: [self basicAt: aKey]
  1743. ifFalse: aBlock
  1744. !
  1745. at: aKey ifAbsentPut: aBlock
  1746. ^self at: aKey ifAbsent: [
  1747. self at: aKey put: aBlock value]
  1748. !
  1749. at: aKey ifPresent: aBlock
  1750. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1751. !
  1752. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1753. ^(self basicAt: aKey)
  1754. ifNil: anotherBlock
  1755. ifNotNil: [aBlock value: (self at: aKey)]
  1756. !
  1757. at: aKey
  1758. ^self at: aKey ifAbsent: [self errorNotFound]
  1759. ! !
  1760. !Dictionary methodsFor: 'adding/removing'!
  1761. add: anAssociation
  1762. self at: anAssociation key put: anAssociation value
  1763. !
  1764. addAll: aDictionary
  1765. super addAll: aDictionary associations.
  1766. ^aDictionary
  1767. !
  1768. remove: aKey
  1769. self removeKey: aKey
  1770. !
  1771. removeKey: aKey
  1772. keys remove: aKey
  1773. ! !
  1774. !Dictionary methodsFor: 'comparing'!
  1775. = aDictionary
  1776. self class = aDictionary class ifFalse: [^false].
  1777. self size = aDictionary size ifFalse: [^false].
  1778. ^self associations = aDictionary associations
  1779. ! !
  1780. !Dictionary methodsFor: 'converting'!
  1781. asJSONObject
  1782. | object |
  1783. object := Object new.
  1784. self keysAndValuesDo: [:key :value |
  1785. object basicAt: key put: value asJSONObject].
  1786. ^object
  1787. ! !
  1788. !Dictionary methodsFor: 'copying'!
  1789. shallowCopy
  1790. | copy |
  1791. copy := self class new.
  1792. self associationsDo: [:each |
  1793. copy at: each key put: each value].
  1794. ^copy
  1795. !
  1796. , aCollection
  1797. self shouldNotImplement
  1798. !
  1799. copyFrom: anIndex to: anotherIndex
  1800. self shouldNotImplement
  1801. ! !
  1802. !Dictionary methodsFor: 'enumerating'!
  1803. associationsDo: aBlock
  1804. self associations do: aBlock
  1805. !
  1806. keysAndValuesDo: aBlock
  1807. self associationsDo: [:each |
  1808. aBlock value: each key value: each value]
  1809. !
  1810. do: aBlock
  1811. self values do: aBlock
  1812. !
  1813. select: aBlock
  1814. | newDict |
  1815. newDict := self class new.
  1816. self keysAndValuesDo: [:key :value |
  1817. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1818. ^newDict
  1819. !
  1820. collect: aBlock
  1821. | newDict |
  1822. newDict := self class new.
  1823. self keysAndValuesDo: [:key :value |
  1824. newDict at: key put: (aBlock value: value)].
  1825. ^newDict
  1826. !
  1827. detect: aBlock ifNone: anotherBlock
  1828. ^self values detect: aBlock ifNone: anotherBlock
  1829. !
  1830. includes: anObject
  1831. ^self values includes: anObject
  1832. ! !
  1833. !Dictionary methodsFor: 'initialization'!
  1834. initialize
  1835. super initialize.
  1836. keys := #()
  1837. ! !
  1838. !Dictionary methodsFor: 'printing'!
  1839. printString
  1840. ^ String streamContents: [:aStream|
  1841. aStream
  1842. nextPutAll: super printString;
  1843. nextPutAll: '('.
  1844. self associations
  1845. do: [:anAssociation|
  1846. aStream
  1847. nextPutAll: anAssociation key printString;
  1848. nextPutAll: ' -> ';
  1849. nextPutAll: anAssociation value printString]
  1850. separatedBy: [aStream nextPutAll: ' , '].
  1851. aStream nextPutAll: ')'.
  1852. ]
  1853. ! !
  1854. !Dictionary class methodsFor: 'instance creation'!
  1855. fromPairs: aCollection
  1856. | dict |
  1857. dict := self new.
  1858. aCollection do: [:each | dict add: each].
  1859. ^dict
  1860. ! !
  1861. Object subclass: #ClassBuilder
  1862. instanceVariableNames: ''
  1863. category: 'Kernel'!
  1864. !ClassBuilder methodsFor: 'class creation'!
  1865. superclass: aClass subclass: aString
  1866. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  1867. !
  1868. class: aClass instanceVariableNames: aString
  1869. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1870. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1871. self setupClass: aClass
  1872. !
  1873. superclass: aClass subclass: aString instanceVariableNames: aString2 module: aString3
  1874. | newClass |
  1875. newClass := self addSubclassOf: aClass
  1876. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1877. module: (aString3 ifNil: ['unclassified']).
  1878. self setupClass: newClass
  1879. !
  1880. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  1881. | newClass |
  1882. newClass := self addSubclassOf: aClass
  1883. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1884. package: (aString3 ifNil: ['unclassified']).
  1885. self setupClass: newClass
  1886. ! !
  1887. !ClassBuilder methodsFor: 'private'!
  1888. instanceVariableNamesFor: aString
  1889. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1890. !
  1891. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1892. <smalltalk.addClass(aString, aClass, aCollection);
  1893. return smalltalk[aString]>
  1894. !
  1895. setupClass: aClass
  1896. <smalltalk.init(aClass);>
  1897. !
  1898. addSubclassOf: aClass named: aString instanceVariableNames: aCollection module: moduleName
  1899. <smalltalk.addClass(aString, aClass, aCollection, moduleName);
  1900. return smalltalk[aString]>
  1901. !
  1902. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  1903. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  1904. return smalltalk[aString]>
  1905. ! !
  1906. Object subclass: #ClassCategoryReader
  1907. instanceVariableNames: 'class category chunkParser'
  1908. category: 'Kernel'!
  1909. !ClassCategoryReader methodsFor: 'accessing'!
  1910. class: aClass category: aString
  1911. class := aClass.
  1912. category := aString
  1913. ! !
  1914. !ClassCategoryReader methodsFor: 'fileIn'!
  1915. scanFrom: aChunkParser
  1916. | chunk |
  1917. [chunk := aChunkParser nextChunk.
  1918. chunk isEmpty] whileFalse: [
  1919. self compileMethod: chunk]
  1920. ! !
  1921. !ClassCategoryReader methodsFor: 'initialization'!
  1922. initialize
  1923. super initialize.
  1924. chunkParser := ChunkParser new.
  1925. ! !
  1926. !ClassCategoryReader methodsFor: 'private'!
  1927. compileMethod: aString
  1928. | method |
  1929. method := Compiler new load: aString forClass: class.
  1930. method category: category.
  1931. class addCompiledMethod: method
  1932. ! !
  1933. Object subclass: #Stream
  1934. instanceVariableNames: 'collection position streamSize'
  1935. category: 'Kernel'!
  1936. !Stream methodsFor: 'accessing'!
  1937. collection
  1938. ^collection
  1939. !
  1940. setCollection: aCollection
  1941. collection := aCollection
  1942. !
  1943. position
  1944. ^position ifNil: [position := 0]
  1945. !
  1946. position: anInteger
  1947. position := anInteger
  1948. !
  1949. streamSize
  1950. ^streamSize
  1951. !
  1952. setStreamSize: anInteger
  1953. streamSize := anInteger
  1954. !
  1955. contents
  1956. ^self collection
  1957. copyFrom: 1
  1958. to: self streamSize
  1959. !
  1960. size
  1961. ^self streamSize
  1962. ! !
  1963. !Stream methodsFor: 'actions'!
  1964. reset
  1965. self position: 0
  1966. !
  1967. close
  1968. !
  1969. flush
  1970. !
  1971. resetContents
  1972. self reset.
  1973. self setStreamSize: 0
  1974. ! !
  1975. !Stream methodsFor: 'enumerating'!
  1976. do: aBlock
  1977. [self atEnd] whileFalse: [aBlock value: self next]
  1978. ! !
  1979. !Stream methodsFor: 'positioning'!
  1980. setToEnd
  1981. self position: self size
  1982. !
  1983. skip: anInteger
  1984. self position: ((self position + anInteger) min: self size max: 0)
  1985. ! !
  1986. !Stream methodsFor: 'reading'!
  1987. next
  1988. self position: self position + 1.
  1989. ^collection at: self position
  1990. !
  1991. next: anInteger
  1992. | tempCollection |
  1993. tempCollection := self collection class new.
  1994. anInteger timesRepeat: [
  1995. self atEnd ifFalse: [
  1996. tempCollection add: self next]].
  1997. ^tempCollection
  1998. !
  1999. peek
  2000. ^self atEnd ifFalse: [
  2001. self collection at: self position + 1]
  2002. ! !
  2003. !Stream methodsFor: 'testing'!
  2004. atEnd
  2005. ^self position = self size
  2006. !
  2007. atStart
  2008. ^self position = 0
  2009. !
  2010. isEmpty
  2011. ^self size = 0
  2012. ! !
  2013. !Stream methodsFor: 'writing'!
  2014. nextPut: anObject
  2015. self position: self position + 1.
  2016. self collection at: self position put: anObject.
  2017. self setStreamSize: (self streamSize max: self position)
  2018. !
  2019. nextPutAll: aCollection
  2020. aCollection do: [:each |
  2021. self nextPut: each]
  2022. ! !
  2023. !Stream class methodsFor: 'instance creation'!
  2024. on: aCollection
  2025. ^self new
  2026. setCollection: aCollection;
  2027. setStreamSize: aCollection size;
  2028. yourself
  2029. ! !
  2030. Stream subclass: #StringStream
  2031. instanceVariableNames: ''
  2032. category: 'Kernel'!
  2033. !StringStream methodsFor: 'reading'!
  2034. next: anInteger
  2035. | tempCollection |
  2036. tempCollection := self collection class new.
  2037. anInteger timesRepeat: [
  2038. self atEnd ifFalse: [
  2039. tempCollection := tempCollection, self next]].
  2040. ^tempCollection
  2041. ! !
  2042. !StringStream methodsFor: 'writing'!
  2043. nextPut: aString
  2044. self nextPutAll: aString
  2045. !
  2046. nextPutAll: aString
  2047. self setCollection:
  2048. (self collection copyFrom: 1 to: self position),
  2049. aString,
  2050. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  2051. self position: self position + aString size.
  2052. self setStreamSize: (self streamSize max: self position)
  2053. !
  2054. cr
  2055. ^self nextPutAll: String cr
  2056. !
  2057. crlf
  2058. ^self nextPutAll: String crlf
  2059. !
  2060. lf
  2061. ^self nextPutAll: String lf
  2062. !
  2063. space
  2064. self nextPut: ' '
  2065. ! !
  2066. Object subclass: #ClassCommentReader
  2067. instanceVariableNames: 'class chunkParser'
  2068. category: 'Kernel'!
  2069. !ClassCommentReader methodsFor: 'accessing'!
  2070. class: aClass
  2071. class := aClass
  2072. ! !
  2073. !ClassCommentReader methodsFor: 'fileIn'!
  2074. scanFrom: aChunkParser
  2075. | chunk |
  2076. chunk := aChunkParser nextChunk.
  2077. chunk isEmpty ifFalse: [
  2078. self setComment: chunk].
  2079. ! !
  2080. !ClassCommentReader methodsFor: 'initialization'!
  2081. initialize
  2082. super initialize.
  2083. chunkParser := ChunkParser new.
  2084. ! !
  2085. !ClassCommentReader methodsFor: 'private'!
  2086. setComment: aString
  2087. class comment: aString
  2088. ! !
  2089. Object subclass: #Random
  2090. instanceVariableNames: ''
  2091. category: 'Kernel'!
  2092. !Random methodsFor: 'accessing'!
  2093. next
  2094. <return Math.random()>
  2095. !
  2096. next: anInteger
  2097. ^(1 to: anInteger) collect: [:each | self next]
  2098. ! !
  2099. Object subclass: #Point
  2100. instanceVariableNames: 'x y'
  2101. category: 'Kernel'!
  2102. !Point methodsFor: 'accessing'!
  2103. x
  2104. ^x
  2105. !
  2106. y
  2107. ^y
  2108. !
  2109. y: aNumber
  2110. y := aNumber
  2111. !
  2112. x: aNumber
  2113. x := aNumber
  2114. ! !
  2115. !Point methodsFor: 'arithmetic'!
  2116. * aPoint
  2117. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2118. !
  2119. + aPoint
  2120. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2121. !
  2122. - aPoint
  2123. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2124. !
  2125. / aPoint
  2126. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2127. ! !
  2128. !Point methodsFor: 'converting'!
  2129. asPoint
  2130. ^self
  2131. ! !
  2132. !Point class methodsFor: 'instance creation'!
  2133. x: aNumber y: anotherNumber
  2134. ^self new
  2135. x: aNumber;
  2136. y: anotherNumber;
  2137. yourself
  2138. ! !
  2139. Object subclass: #Message
  2140. instanceVariableNames: 'selector arguments'
  2141. category: 'Kernel'!
  2142. !Message methodsFor: 'accessing'!
  2143. selector
  2144. ^selector
  2145. !
  2146. selector: aString
  2147. selector := aString
  2148. !
  2149. arguments: anArray
  2150. arguments := anArray
  2151. !
  2152. arguments
  2153. ^arguments
  2154. ! !
  2155. !Message class methodsFor: 'instance creation'!
  2156. selector: aString arguments: anArray
  2157. ^self new
  2158. selector: aString;
  2159. arguments: anArray;
  2160. yourself
  2161. ! !
  2162. Error subclass: #MessageNotUnderstood
  2163. instanceVariableNames: 'message receiver'
  2164. category: 'Kernel'!
  2165. !MessageNotUnderstood methodsFor: 'accessing'!
  2166. message
  2167. ^message
  2168. !
  2169. message: aMessage
  2170. message := aMessage
  2171. !
  2172. receiver
  2173. ^receiver
  2174. !
  2175. receiver: anObject
  2176. receiver := anObject
  2177. !
  2178. messageText
  2179. ^self receiver asString, ' does not understand #', self message selector
  2180. ! !
  2181. Object subclass: #ErrorHandler
  2182. instanceVariableNames: ''
  2183. category: 'Kernel'!
  2184. !ErrorHandler methodsFor: 'error handling'!
  2185. handleError: anError
  2186. anError context ifNotNil: [self logErrorContext: anError context].
  2187. self logError: anError
  2188. ! !
  2189. !ErrorHandler methodsFor: 'private'!
  2190. logContext: aContext
  2191. aContext home ifNotNil: [
  2192. self logContext: aContext home].
  2193. self log: aContext receiver asString, '>>', aContext selector
  2194. !
  2195. logErrorContext: aContext
  2196. aContext ifNotNil: [
  2197. aContext home ifNotNil: [
  2198. self logContext: aContext home]]
  2199. !
  2200. logError: anError
  2201. self log: anError messageText
  2202. !
  2203. log: aString
  2204. console log: aString
  2205. ! !
  2206. ErrorHandler class instanceVariableNames: 'current'!
  2207. !ErrorHandler class methodsFor: 'accessing'!
  2208. current
  2209. ^current ifNil: [current := self new]
  2210. !
  2211. setCurrent: anHandler
  2212. current := anHandler
  2213. ! !
  2214. !ErrorHandler class methodsFor: 'initialization'!
  2215. initialize
  2216. self register
  2217. !
  2218. register
  2219. ErrorHandler setCurrent: self new
  2220. ! !
  2221. Object subclass: #JSObjectProxy
  2222. instanceVariableNames: 'jsObject'
  2223. category: 'Kernel'!
  2224. !JSObjectProxy methodsFor: 'accessing'!
  2225. jsObject: aJSObject
  2226. jsObject := aJSObject
  2227. !
  2228. jsObject
  2229. ^jsObject
  2230. ! !
  2231. !JSObjectProxy methodsFor: 'proxy'!
  2232. printString
  2233. ^self jsObject toString
  2234. !
  2235. inspectOn: anInspector
  2236. | variables |
  2237. variables := Dictionary new.
  2238. variables at: '#self' put: self jsObject.
  2239. anInspector setLabel: self printString.
  2240. <for(var i in self['@jsObject']) {
  2241. variables._at_put_(i, self['@jsObject'][i]);
  2242. }>.
  2243. anInspector setVariables: variables
  2244. !
  2245. doesNotUnderstand: aMessage
  2246. | obj selector arguments |
  2247. obj := self jsObject.
  2248. selector := aMessage selector.
  2249. arguments := aMessage arguments.
  2250. <if(obj[selector]) {return smalltalk.send(obj, selector, arguments)}>.
  2251. super doesNotUnderstand: aMessage
  2252. ! !
  2253. !JSObjectProxy class methodsFor: 'instance creation'!
  2254. on: aJSObject
  2255. ^self new
  2256. jsObject: aJSObject;
  2257. yourself
  2258. ! !
  2259. Collection subclass: #Set
  2260. instanceVariableNames: 'elements'
  2261. category: 'Kernel'!
  2262. !Set methodsFor: 'accessing'!
  2263. size
  2264. ^elements size
  2265. ! !
  2266. !Set methodsFor: 'adding/removing'!
  2267. add: anObject
  2268. <
  2269. var found;
  2270. for(var i in self['@elements']) {
  2271. if(anObject == self['@elements'][i]) {
  2272. found = true;
  2273. break;
  2274. }
  2275. }
  2276. if(!!found) {self['@elements'].push(anObject)}
  2277. >
  2278. !
  2279. remove: anObject
  2280. elements remove: anObject
  2281. ! !
  2282. !Set methodsFor: 'comparing'!
  2283. = aCollection
  2284. ^self class = aCollection class and: [
  2285. elements = aCollection asArray]
  2286. ! !
  2287. !Set methodsFor: 'converting'!
  2288. asArray
  2289. ^elements copy
  2290. ! !
  2291. !Set methodsFor: 'enumerating'!
  2292. detect: aBlock ifNone: anotherBlock
  2293. ^elements detect: aBlock ifNone: anotherBlock
  2294. !
  2295. do: aBlock
  2296. elements do: aBlock
  2297. ! !
  2298. !Set methodsFor: 'initialization'!
  2299. initialize
  2300. super initialize.
  2301. elements := #()
  2302. ! !
  2303. !Set methodsFor: 'testing'!
  2304. includes: anObject
  2305. ^elements includes: anObject
  2306. ! !