1
0

Kernel.st 53 KB

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