Kernel.st 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171
  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. !Number methodsFor: 'comparing'!
  582. = aNumber
  583. aNumber class = self class ifFalse: [^false].
  584. <return Number(self) == aNumber>
  585. !
  586. > aNumber
  587. "Inlined in the Compiler"
  588. <return self >> aNumber>
  589. !
  590. < aNumber
  591. "Inlined in the Compiler"
  592. <return self < aNumber>
  593. !
  594. >= aNumber
  595. "Inlined in the Compiler"
  596. <return self >>= aNumber>
  597. !
  598. <= aNumber
  599. "Inlined in the Compiler"
  600. <return self <= aNumber>
  601. !
  602. == aNumber
  603. aNumber class = self class ifFalse: [^false].
  604. <return Number(self) === Number(aNumber)>
  605. ! !
  606. !Number methodsFor: 'converting'!
  607. rounded
  608. <return Math.round(self);>
  609. !
  610. truncated
  611. |result|
  612. self >= 0
  613. ifTrue: [<result = Math.floor(self);>]
  614. ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
  615. ^ result
  616. !
  617. to: aNumber
  618. | array first last count |
  619. first := self truncated.
  620. last := aNumber truncated + 1.
  621. count := 1.
  622. array := Array new.
  623. (last - first) timesRepeat: [
  624. array at: count put: first.
  625. count := count + 1.
  626. first := first + 1].
  627. ^array
  628. !
  629. asString
  630. ^self printString
  631. !
  632. asJavascript
  633. ^'(', self printString, ')'
  634. !
  635. atRandom
  636. ^(Random new next * self) truncated + 1
  637. !
  638. @ aNumber
  639. ^Point x: self y: aNumber
  640. !
  641. asPoint
  642. ^Point x: self y: self
  643. !
  644. asJSONObject
  645. ^self
  646. !
  647. to: stop by: step
  648. | array value pos |
  649. value := self.
  650. array := Array new.
  651. pos := 1.
  652. step = 0 ifTrue: [self error: 'step must be non-zero'].
  653. step < 0
  654. ifTrue: [[ value >= stop ] whileTrue: [
  655. array at: pos put: value.
  656. pos := pos + 1.
  657. value := value + step]]
  658. ifFalse: [[ value <= stop ] whileTrue: [
  659. array at: pos put: value.
  660. pos := pos + 1.
  661. value := value + step]].
  662. ^array
  663. !
  664. to: stop by: step do: aBlock
  665. | value |
  666. value := self.
  667. step = 0 ifTrue: [self error: 'step must be non-zero'].
  668. step < 0
  669. ifTrue: [[ value >= stop ] whileTrue: [
  670. aBlock value: value.
  671. value := value + step]]
  672. ifFalse: [[ value <= stop ] whileTrue: [
  673. aBlock value: value.
  674. value := value + step]]
  675. ! !
  676. !Number methodsFor: 'copying'!
  677. deepCopy
  678. ^self copy
  679. !
  680. copy
  681. ^self
  682. ! !
  683. !Number methodsFor: 'enumerating'!
  684. timesRepeat: aBlock
  685. | integer count |
  686. integer := self truncated.
  687. count := 1.
  688. [count > self] whileFalse: [
  689. aBlock value.
  690. count := count + 1]
  691. !
  692. to: stop do: aBlock
  693. "Evaluate aBlock for each number from self to aNumber."
  694. | nextValue |
  695. nextValue := self.
  696. [nextValue <= stop]
  697. whileTrue:
  698. [aBlock value: nextValue.
  699. nextValue := nextValue + 1]
  700. ! !
  701. !Number methodsFor: 'printing'!
  702. printString
  703. <return String(self)>
  704. !
  705. printShowingDecimalPlaces: placesDesired
  706. <return self.toFixed(placesDesired)>
  707. ! !
  708. !Number methodsFor: 'testing'!
  709. isNumber
  710. ^true
  711. !
  712. even
  713. ^ 0 = (self \\ 2)
  714. !
  715. odd
  716. ^ self even not
  717. ! !
  718. !Number methodsFor: 'timeouts/intervals'!
  719. clearInterval
  720. <clearInterval(Number(self))>
  721. !
  722. clearTimeout
  723. <clearTimeout(Number(self))>
  724. ! !
  725. !Number class methodsFor: 'instance creation'!
  726. pi
  727. <return Math.PI>
  728. ! !
  729. Object subclass: #BlockClosure
  730. instanceVariableNames: ''
  731. category: 'Kernel'!
  732. !BlockClosure methodsFor: 'accessing'!
  733. compiledSource
  734. <return self.toString()>
  735. ! !
  736. !BlockClosure methodsFor: 'controlling'!
  737. whileTrue: aBlock
  738. "inlined in the Compiler"
  739. <while(self()) {aBlock()}>
  740. !
  741. whileFalse: aBlock
  742. "inlined in the Compiler"
  743. <while(!!self()) {aBlock()}>
  744. !
  745. whileFalse
  746. "inlined in the Compiler"
  747. self whileFalse: []
  748. !
  749. whileTrue
  750. "inlined in the Compiler"
  751. self whileTrue: []
  752. ! !
  753. !BlockClosure methodsFor: 'error handling'!
  754. on: anErrorClass do: aBlock
  755. self try: self catch: [:error |
  756. (error isKindOf: anErrorClass)
  757. ifTrue: [aBlock value: error]
  758. ifFalse: [error signal]]
  759. ! !
  760. !BlockClosure methodsFor: 'evaluating'!
  761. value
  762. "inlined in the Compiler"
  763. <return self();>
  764. !
  765. value: anArg
  766. "inlined in the Compiler"
  767. <return self(anArg);>
  768. !
  769. value: firstArg value: secondArg
  770. "inlined in the Compiler"
  771. <return self(firstArg, secondArg);>
  772. !
  773. value: firstArg value: secondArg value: thirdArg
  774. "inlined in the Compiler"
  775. <return self(firstArg, secondArg, thirdArg);>
  776. !
  777. valueWithPossibleArguments: aCollection
  778. <return self.apply(null, aCollection);>
  779. !
  780. new
  781. "Use the receiver as a JS constructor.
  782. *Do not* use this method to instanciate Smalltalk objects!!"
  783. <return new self()>
  784. !
  785. applyTo: anObject arguments: aCollection
  786. <return self.apply(anObject, aCollection)>
  787. !
  788. timeToRun
  789. "Answer the number of milliseconds taken to execute this block."
  790. ^ Date millisecondsToRun: self
  791. ! !
  792. !BlockClosure methodsFor: 'timeout/interval'!
  793. valueWithTimeout: aNumber
  794. <return setTimeout(self, aNumber)>
  795. !
  796. valueWithInterval: aNumber
  797. <return setInterval(self, aNumber)>
  798. ! !
  799. Object subclass: #Boolean
  800. instanceVariableNames: ''
  801. category: 'Kernel'!
  802. !Boolean methodsFor: 'comparing'!
  803. = aBoolean
  804. aBoolean class = self class ifFalse: [^false].
  805. <return Boolean(self == true) == aBoolean>
  806. !
  807. == aBoolean
  808. aBoolean class = self class ifFalse: [^false].
  809. <return Boolean(self == true) === Boolean(aBoolean == true)>
  810. ! !
  811. !Boolean methodsFor: 'controlling'!
  812. ifTrue: aBlock
  813. "inlined in the Compiler"
  814. ^self ifTrue: aBlock ifFalse: []
  815. !
  816. ifFalse: aBlock
  817. "inlined in the Compiler"
  818. ^self ifTrue: [] ifFalse: aBlock
  819. !
  820. ifFalse: aBlock ifTrue: anotherBlock
  821. "inlined in the Compiler"
  822. ^self ifTrue: anotherBlock ifFalse: aBlock
  823. !
  824. ifTrue: aBlock ifFalse: anotherBlock
  825. "inlined in the Compiler"
  826. <
  827. if(self == true) {
  828. return aBlock();
  829. } else {
  830. return anotherBlock();
  831. }
  832. >
  833. !
  834. and: aBlock
  835. ^self = true
  836. ifTrue: aBlock
  837. ifFalse: [false]
  838. !
  839. or: aBlock
  840. ^self = true
  841. ifTrue: [true]
  842. ifFalse: aBlock
  843. !
  844. not
  845. ^self = false
  846. !
  847. & aBoolean
  848. <
  849. if(self == true) {
  850. return aBoolean;
  851. } else {
  852. return false;
  853. }
  854. >
  855. !
  856. | aBoolean
  857. <
  858. if(self == true) {
  859. return true;
  860. } else {
  861. return aBoolean;
  862. }
  863. >
  864. ! !
  865. !Boolean methodsFor: 'converting'!
  866. asJSONObject
  867. ^self
  868. ! !
  869. !Boolean methodsFor: 'copying'!
  870. shallowCopy
  871. ^self
  872. !
  873. deepCopy
  874. ^self
  875. ! !
  876. !Boolean methodsFor: 'printing'!
  877. printString
  878. <return self.toString()>
  879. ! !
  880. Object subclass: #Date
  881. instanceVariableNames: ''
  882. category: 'Kernel'!
  883. !Date commentStamp!
  884. The Date class is used to work with dates and times.!
  885. !Date methodsFor: 'accessing'!
  886. year
  887. <return self.getFullYear()>
  888. !
  889. month
  890. <return self.getMonth() + 1>
  891. !
  892. month: aNumber
  893. <self.setMonth(aNumber - 1)>
  894. !
  895. day
  896. ^self dayOfWeek
  897. !
  898. dayOfWeek
  899. <return self.getDay() + 1>
  900. !
  901. dayOfWeek: aNumber
  902. <return self.setDay(aNumber - 1)>
  903. !
  904. day: aNumber
  905. self day: aNumber
  906. !
  907. year: aNumber
  908. <self.setFullYear(aNumber)>
  909. !
  910. dayOfMonth
  911. <return self.getDate()>
  912. !
  913. dayOfMonth: aNumber
  914. <self.setDate(aNumber)>
  915. !
  916. time
  917. <return self.getTime()>
  918. !
  919. time: aNumber
  920. <self.setTime(aNumber)>
  921. !
  922. hours: aNumber
  923. <self.setHours(aNumber)>
  924. !
  925. minutes: aNumber
  926. <self.setMinutes(aNumber)>
  927. !
  928. seconds: aNumber
  929. <self.setSeconds(aNumber)>
  930. !
  931. milliseconds: aNumber
  932. <self.setMilliseconds(aNumber)>
  933. !
  934. hours
  935. <return self.getHours()>
  936. !
  937. minutes
  938. <return self.getMinutes()>
  939. !
  940. seconds
  941. <return self.getSeconds()>
  942. !
  943. milliseconds
  944. <return self.getMilliseconds()>
  945. ! !
  946. !Date methodsFor: 'arithmetic'!
  947. - aDate
  948. <return self - aDate>
  949. !
  950. + aDate
  951. <return self + aDate>
  952. ! !
  953. !Date methodsFor: 'comparing'!
  954. < aDate
  955. <return self < aDate>
  956. !
  957. > aDate
  958. <return self >> aDate>
  959. !
  960. <= aDate
  961. <return self <= aDate>
  962. !
  963. >= aDate
  964. <return self >>= aDate>
  965. ! !
  966. !Date methodsFor: 'converting'!
  967. asString
  968. <return self.toString()>
  969. !
  970. asMilliseconds
  971. ^self time
  972. !
  973. asDateString
  974. <return self.toDateString()>
  975. !
  976. asTimeString
  977. <return self.toTimeString()>
  978. !
  979. asLocaleString
  980. <return self.toLocaleString()>
  981. !
  982. asNumber
  983. ^self asMilliseconds
  984. !
  985. asJSONObject
  986. ^self
  987. ! !
  988. !Date methodsFor: 'printing'!
  989. printString
  990. ^self asString
  991. ! !
  992. !Date class methodsFor: 'instance creation'!
  993. new: anObject
  994. <return new Date(anObject)>
  995. !
  996. fromString: aString
  997. "Example: Date fromString('2011/04/15 00:00:00')"
  998. ^self new: aString
  999. !
  1000. fromSeconds: aNumber
  1001. ^self fromMilliseconds: aNumber * 1000
  1002. !
  1003. fromMilliseconds: aNumber
  1004. ^self new: aNumber
  1005. !
  1006. today
  1007. ^self new
  1008. !
  1009. now
  1010. ^self today
  1011. !
  1012. millisecondsToRun: aBlock
  1013. | t |
  1014. t := Date now.
  1015. aBlock value.
  1016. ^Date now - t
  1017. ! !
  1018. Object subclass: #UndefinedObject
  1019. instanceVariableNames: ''
  1020. category: 'Kernel'!
  1021. !UndefinedObject methodsFor: 'class creation'!
  1022. subclass: aString instanceVariableNames: anotherString
  1023. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1024. !
  1025. subclass: aString instanceVariableNames: aString2 category: aString3
  1026. "Kept for compatibility."
  1027. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1028. !
  1029. subclass: aString instanceVariableNames: aString2 package: aString3
  1030. ^ClassBuilder new
  1031. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  1032. ! !
  1033. !UndefinedObject methodsFor: 'copying'!
  1034. shallowCopy
  1035. ^self
  1036. !
  1037. deepCopy
  1038. ^self
  1039. ! !
  1040. !UndefinedObject methodsFor: 'printing'!
  1041. printString
  1042. ^'nil'
  1043. ! !
  1044. !UndefinedObject methodsFor: 'testing'!
  1045. ifNil: aBlock
  1046. "inlined in the Compiler"
  1047. ^self ifNil: aBlock ifNotNil: []
  1048. !
  1049. ifNotNil: aBlock
  1050. "inlined in the Compiler"
  1051. ^self
  1052. !
  1053. ifNil: aBlock ifNotNil: anotherBlock
  1054. "inlined in the Compiler"
  1055. ^aBlock value
  1056. !
  1057. ifNotNil: aBlock ifNil: anotherBlock
  1058. "inlined in the Compiler"
  1059. ^anotherBlock value
  1060. !
  1061. isNil
  1062. ^true
  1063. !
  1064. notNil
  1065. ^false
  1066. ! !
  1067. !UndefinedObject class methodsFor: 'instance creation'!
  1068. new
  1069. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1070. ! !
  1071. Object subclass: #Collection
  1072. instanceVariableNames: ''
  1073. category: 'Kernel'!
  1074. !Collection methodsFor: 'accessing'!
  1075. size
  1076. self subclassResponsibility
  1077. !
  1078. readStream
  1079. ^self stream
  1080. !
  1081. writeStream
  1082. ^self stream
  1083. !
  1084. stream
  1085. ^self streamClass on: self
  1086. !
  1087. streamClass
  1088. ^self class streamClass
  1089. ! !
  1090. !Collection methodsFor: 'adding/removing'!
  1091. add: anObject
  1092. self subclassResponsibility
  1093. !
  1094. addAll: aCollection
  1095. aCollection do: [:each |
  1096. self add: each].
  1097. ^aCollection
  1098. !
  1099. remove: anObject
  1100. self subclassResponsibility
  1101. ! !
  1102. !Collection methodsFor: 'converting'!
  1103. asArray
  1104. | array index |
  1105. array := Array new.
  1106. index := 0.
  1107. self do: [:each |
  1108. index := index + 1.
  1109. array at: index put: each].
  1110. ^array
  1111. !
  1112. asSet
  1113. ^Set withAll: self
  1114. ! !
  1115. !Collection methodsFor: 'copying'!
  1116. , aCollection
  1117. ^self copy
  1118. addAll: aCollection;
  1119. yourself
  1120. !
  1121. copyWith: anObject
  1122. ^self copy add: anObject; yourself
  1123. !
  1124. copyWithAll: aCollection
  1125. ^self copy addAll: aCollection; yourself
  1126. !
  1127. copyWithoutAll: aCollection
  1128. "Answer a copy of the receiver that does not contain any elements
  1129. equal to those in aCollection."
  1130. ^ self reject: [:each | aCollection includes: each]
  1131. ! !
  1132. !Collection methodsFor: 'enumerating'!
  1133. do: aBlock
  1134. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  1135. !
  1136. collect: aBlock
  1137. | newCollection |
  1138. newCollection := self class new.
  1139. self do: [:each |
  1140. newCollection add: (aBlock value: each)].
  1141. ^newCollection
  1142. !
  1143. detect: aBlock
  1144. ^self detect: aBlock ifNone: [self errorNotFound]
  1145. !
  1146. detect: aBlock ifNone: anotherBlock
  1147. <
  1148. for(var i = 0; i < self.length; i++)
  1149. if(aBlock(self[i]))
  1150. return self[i];
  1151. return anotherBlock();
  1152. >
  1153. !
  1154. do: aBlock separatedBy: anotherBlock
  1155. | first |
  1156. first := true.
  1157. self do: [:each |
  1158. first
  1159. ifTrue: [first := false]
  1160. ifFalse: [anotherBlock value].
  1161. aBlock value: each]
  1162. !
  1163. inject: anObject into: aBlock
  1164. | result |
  1165. result := anObject.
  1166. self do: [:each |
  1167. result := aBlock value: result value: each].
  1168. ^result
  1169. !
  1170. reject: aBlock
  1171. ^self select: [:each | (aBlock value: each) = false]
  1172. !
  1173. select: aBlock
  1174. | stream |
  1175. stream := self class new writeStream.
  1176. self do: [:each |
  1177. (aBlock value: each) ifTrue: [
  1178. stream nextPut: each]].
  1179. ^stream contents
  1180. ! !
  1181. !Collection methodsFor: 'error handling'!
  1182. errorNotFound
  1183. self error: 'Object is not in the collection'
  1184. ! !
  1185. !Collection methodsFor: 'testing'!
  1186. includes: anObject
  1187. <
  1188. var i = self.length;
  1189. while (i--) {
  1190. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1191. }
  1192. return false
  1193. >
  1194. !
  1195. notEmpty
  1196. ^self isEmpty not
  1197. !
  1198. isEmpty
  1199. ^self size = 0
  1200. !
  1201. ifNotEmpty: aBlock
  1202. self notEmpty ifTrue: aBlock.
  1203. !
  1204. ifEmpty: aBlock
  1205. self isEmpty ifTrue: aBlock.
  1206. ! !
  1207. !Collection class methodsFor: 'accessing'!
  1208. streamClass
  1209. ^Stream
  1210. ! !
  1211. !Collection class methodsFor: 'instance creation'!
  1212. with: anObject
  1213. ^self new
  1214. add: anObject;
  1215. yourself
  1216. !
  1217. with: anObject with: anotherObject
  1218. ^self new
  1219. add: anObject;
  1220. add: anotherObject;
  1221. yourself
  1222. !
  1223. with: firstObject with: secondObject with: thirdObject
  1224. ^self new
  1225. add: firstObject;
  1226. add: secondObject;
  1227. add: thirdObject;
  1228. yourself
  1229. !
  1230. withAll: aCollection
  1231. ^self new
  1232. addAll: aCollection;
  1233. yourself
  1234. ! !
  1235. Collection subclass: #SequenceableCollection
  1236. instanceVariableNames: ''
  1237. category: 'Kernel'!
  1238. !SequenceableCollection methodsFor: 'accessing'!
  1239. at: anIndex
  1240. ^self at: anIndex ifAbsent: [
  1241. self errorNotFound]
  1242. !
  1243. at: anIndex ifAbsent: aBlock
  1244. self subclassResponsibility
  1245. !
  1246. at: anIndex put: anObject
  1247. self subclassResponsibility
  1248. !
  1249. first
  1250. ^self at: 1
  1251. !
  1252. fourth
  1253. ^self at: 4
  1254. !
  1255. last
  1256. ^self at: self size
  1257. !
  1258. second
  1259. ^self at: 2
  1260. !
  1261. third
  1262. ^self at: 3
  1263. !
  1264. allButFirst
  1265. ^self copyFrom: 2 to: self size
  1266. !
  1267. allButLast
  1268. ^self copyFrom: 1 to: self size - 1
  1269. !
  1270. indexOf: anObject
  1271. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1272. !
  1273. indexOf: anObject ifAbsent: aBlock
  1274. <
  1275. for(var i=0;i<self.length;i++){
  1276. if(self[i].__eq(anObject)) {return i+1}
  1277. }
  1278. return aBlock();
  1279. >
  1280. !
  1281. indexOf: anObject startingAt: start ifAbsent: aBlock
  1282. <
  1283. for(var i=start-1;i<self.length;i++){
  1284. if(self[i].__eq(anObject)) {return i+1}
  1285. }
  1286. return aBlock();
  1287. >
  1288. !
  1289. indexOf: anObject startingAt: start
  1290. "Answer the index of the first occurence of anElement after start
  1291. within the receiver. If the receiver does not contain anElement,
  1292. answer 0."
  1293. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1294. ! !
  1295. !SequenceableCollection methodsFor: 'adding'!
  1296. removeLast
  1297. self remove: self last
  1298. !
  1299. addLast: anObject
  1300. self add: anObject
  1301. ! !
  1302. !SequenceableCollection methodsFor: 'converting'!
  1303. reversed
  1304. self subclassResponsibility
  1305. ! !
  1306. !SequenceableCollection methodsFor: 'copying'!
  1307. copyFrom: anIndex to: anotherIndex
  1308. self subclassResponsibility
  1309. ! !
  1310. !SequenceableCollection methodsFor: 'enumerating'!
  1311. withIndexDo: aBlock
  1312. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1313. ! !
  1314. SequenceableCollection subclass: #String
  1315. instanceVariableNames: ''
  1316. category: 'Kernel'!
  1317. !String methodsFor: 'accessing'!
  1318. size
  1319. <return self.length>
  1320. !
  1321. at: anIndex
  1322. <return self[anIndex - 1]>
  1323. !
  1324. at: anIndex put: anObject
  1325. self errorReadOnly
  1326. !
  1327. at: anIndex ifAbsent: aBlock
  1328. (self at: anIndex) ifNil: [aBlock]
  1329. !
  1330. escaped
  1331. <return escape(self)>
  1332. !
  1333. unescaped
  1334. <return unescape(self)>
  1335. !
  1336. asciiValue
  1337. <return self.charCodeAt(0);>
  1338. ! !
  1339. !String methodsFor: 'adding'!
  1340. add: anObject
  1341. self errorReadOnly
  1342. !
  1343. remove: anObject
  1344. self errorReadOnly
  1345. ! !
  1346. !String methodsFor: 'comparing'!
  1347. = aString
  1348. aString class = self class ifFalse: [^false].
  1349. <return String(self) == aString>
  1350. !
  1351. > aString
  1352. <return String(self) >> aString>
  1353. !
  1354. < aString
  1355. <return String(self) < aString>
  1356. !
  1357. >= aString
  1358. <return String(self) >>= aString>
  1359. !
  1360. <= aString
  1361. <return String(self) <= aString>
  1362. !
  1363. == aString
  1364. aString class = self class ifFalse: [^false].
  1365. <return String(self) === String(aString)>
  1366. ! !
  1367. !String methodsFor: 'converting'!
  1368. asSelector
  1369. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1370. | selector |
  1371. selector := '_', self.
  1372. selector := selector replace: ':' with: '_'.
  1373. selector := selector replace: '[+]' with: '_plus'.
  1374. selector := selector replace: '-' with: '_minus'.
  1375. selector := selector replace: '[*]' with: '_star'.
  1376. selector := selector replace: '[/]' with: '_slash'.
  1377. selector := selector replace: '>' with: '_gt'.
  1378. selector := selector replace: '<' with: '_lt'.
  1379. selector := selector replace: '=' with: '_eq'.
  1380. selector := selector replace: ',' with: '_comma'.
  1381. selector := selector replace: '[@]' with: '_at'.
  1382. ^selector
  1383. !
  1384. asJavascript
  1385. <
  1386. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1387. return "unescape(\"" + escape(self) + "\")";
  1388. else
  1389. return "\"" + self + "\"";
  1390. >
  1391. !
  1392. tokenize: aString
  1393. <return self.split(aString)>
  1394. !
  1395. asString
  1396. ^self
  1397. !
  1398. asNumber
  1399. <return Number(self)>
  1400. !
  1401. asJSONObject
  1402. ^self
  1403. !
  1404. asLowercase
  1405. <return self.toLowerCase()>
  1406. !
  1407. asUppercase
  1408. <return self.toUpperCase()>
  1409. !
  1410. reversed
  1411. <return self.split("").reverse().join("")>
  1412. !
  1413. asJavaScriptSelector
  1414. ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
  1415. ! !
  1416. !String methodsFor: 'copying'!
  1417. , aString
  1418. <return self + aString>
  1419. !
  1420. copyFrom: anIndex to: anotherIndex
  1421. <return self.substring(anIndex - 1, anotherIndex)>
  1422. !
  1423. shallowCopy
  1424. ^self class fromString: self
  1425. !
  1426. deepCopy
  1427. ^self shallowCopy
  1428. ! !
  1429. !String methodsFor: 'error handling'!
  1430. errorReadOnly
  1431. self error: 'Object is read-only'
  1432. ! !
  1433. !String methodsFor: 'printing'!
  1434. printString
  1435. ^'''', self, ''''
  1436. !
  1437. printNl
  1438. <console.log(self)>
  1439. ! !
  1440. !String methodsFor: 'regular expressions'!
  1441. replace: aString with: anotherString
  1442. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1443. !
  1444. replaceRegexp: aRegexp with: aString
  1445. <return self.replace(aRegexp, aString)>
  1446. !
  1447. match: aRegexp
  1448. <return self.search(aRegexp) !!= -1>
  1449. !
  1450. trimLeft: separators
  1451. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1452. !
  1453. trimRight: separators
  1454. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1455. !
  1456. trimLeft
  1457. ^self trimLeft: '\s'
  1458. !
  1459. trimRight
  1460. ^self trimRight: '\s'
  1461. !
  1462. trimBoth
  1463. ^self trimBoth: '\s'
  1464. !
  1465. trimBoth: separators
  1466. ^(self trimLeft: separators) trimRight: separators
  1467. ! !
  1468. !String methodsFor: 'split join'!
  1469. join: aCollection
  1470. ^ String
  1471. streamContents: [:stream | aCollection
  1472. do: [:each | stream nextPutAll: each asString]
  1473. separatedBy: [stream nextPutAll: self]]
  1474. !
  1475. lineIndicesDo: aBlock
  1476. "execute aBlock with 3 arguments for each line:
  1477. - start index of line
  1478. - end index of line without line delimiter
  1479. - end index of line including line delimiter(s) CR, LF or CRLF"
  1480. | cr lf start sz nextLF nextCR |
  1481. start := 1.
  1482. sz := self size.
  1483. cr := String cr.
  1484. nextCR := self indexOf: cr startingAt: 1.
  1485. lf := String lf.
  1486. nextLF := self indexOf: lf startingAt: 1.
  1487. [ start <= sz ] whileTrue: [
  1488. (nextLF = 0 and: [ nextCR = 0 ])
  1489. ifTrue: [ "No more CR, nor LF, the string is over"
  1490. aBlock value: start value: sz value: sz.
  1491. ^self ].
  1492. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1493. ifTrue: [ "Found a LF"
  1494. aBlock value: start value: nextLF - 1 value: nextLF.
  1495. start := 1 + nextLF.
  1496. nextLF := self indexOf: lf startingAt: start ]
  1497. ifFalse: [ 1 + nextCR = nextLF
  1498. ifTrue: [ "Found a CR-LF pair"
  1499. aBlock value: start value: nextCR - 1 value: nextLF.
  1500. start := 1 + nextLF.
  1501. nextCR := self indexOf: cr startingAt: start.
  1502. nextLF := self indexOf: lf startingAt: start ]
  1503. ifFalse: [ "Found a CR"
  1504. aBlock value: start value: nextCR - 1 value: nextCR.
  1505. start := 1 + nextCR.
  1506. nextCR := self indexOf: cr startingAt: start ]]]
  1507. !
  1508. linesDo: aBlock
  1509. "Execute aBlock with each line in this string. The terminating line
  1510. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1511. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1512. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1513. !
  1514. lines
  1515. "Answer an array of lines composing this receiver without the line ending delimiters."
  1516. | lines |
  1517. lines := Array new.
  1518. self linesDo: [:aLine | lines add: aLine].
  1519. ^lines
  1520. !
  1521. lineNumber: anIndex
  1522. "Answer a string containing the characters in the given line number."
  1523. | lineCount |
  1524. lineCount := 0.
  1525. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1526. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1527. ^nil
  1528. ! !
  1529. !String methodsFor: 'testing'!
  1530. isString
  1531. ^true
  1532. !
  1533. includesSubString: subString
  1534. < return self.indexOf(subString) !!= -1 >
  1535. ! !
  1536. !String class methodsFor: 'accessing'!
  1537. streamClass
  1538. ^StringStream
  1539. !
  1540. cr
  1541. <return '\r'>
  1542. !
  1543. lf
  1544. <return '\n'>
  1545. !
  1546. space
  1547. <return ' '>
  1548. !
  1549. tab
  1550. <return '\t'>
  1551. !
  1552. crlf
  1553. <return '\r\n'>
  1554. ! !
  1555. !String class methodsFor: 'instance creation'!
  1556. fromString: aString
  1557. <return new self.fn(aString)>
  1558. !
  1559. streamContents: blockWithArg
  1560. |stream|
  1561. stream := (self streamClass on: String new).
  1562. blockWithArg value: stream.
  1563. ^ stream contents
  1564. !
  1565. value: aUTFCharCode
  1566. <return String.fromCharCode(aUTFCharCode);>
  1567. ! !
  1568. SequenceableCollection subclass: #Array
  1569. instanceVariableNames: ''
  1570. category: 'Kernel'!
  1571. !Array methodsFor: 'accessing'!
  1572. size
  1573. <return self.length>
  1574. !
  1575. at: anIndex put: anObject
  1576. <return self[anIndex - 1] = anObject>
  1577. !
  1578. at: anIndex ifAbsent: aBlock
  1579. <
  1580. var value = self[anIndex - 1];
  1581. if(value === undefined) {
  1582. return aBlock();
  1583. } else {
  1584. return value;
  1585. }
  1586. >
  1587. ! !
  1588. !Array methodsFor: 'adding/removing'!
  1589. add: anObject
  1590. <self.push(anObject); return anObject;>
  1591. !
  1592. remove: anObject
  1593. <
  1594. for(var i=0;i<self.length;i++) {
  1595. if(self[i] == anObject) {
  1596. self.splice(i,1);
  1597. break;
  1598. }
  1599. }
  1600. >
  1601. !
  1602. removeFrom: aNumber to: anotherNumber
  1603. <self.splice(aNumber - 1,anotherNumber - 1)>
  1604. ! !
  1605. !Array methodsFor: 'comparing'!
  1606. = aCollection
  1607. (self class = aCollection class and: [
  1608. self size = aCollection size]) ifFalse: [^false].
  1609. self withIndexDo: [:each :i |
  1610. (aCollection at: i) = each ifFalse: [^false]].
  1611. ^true
  1612. ! !
  1613. !Array methodsFor: 'converting'!
  1614. asJavascript
  1615. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1616. !
  1617. asJSONObject
  1618. ^self collect: [:each | each asJSONObject]
  1619. !
  1620. reversed
  1621. <return self._copy().reverse()>
  1622. ! !
  1623. !Array methodsFor: 'copying'!
  1624. shallowCopy
  1625. | newCollection |
  1626. newCollection := self class new.
  1627. self do: [:each | newCollection add: each].
  1628. ^newCollection
  1629. !
  1630. deepCopy
  1631. | newCollection |
  1632. newCollection := self class new.
  1633. self do: [:each | newCollection add: each deepCopy].
  1634. ^newCollection
  1635. !
  1636. copyFrom: anIndex to: anotherIndex
  1637. | array |
  1638. array := self class new.
  1639. anIndex to: anotherIndex do: [:each |
  1640. array add: (self at: each)].
  1641. ^array
  1642. ! !
  1643. !Array methodsFor: 'enumerating'!
  1644. join: aString
  1645. <return self.join(aString)>
  1646. !
  1647. sort
  1648. ^self basicPerform: 'sort'
  1649. !
  1650. sort: aBlock
  1651. <
  1652. return self.sort(function(a, b) {
  1653. if(aBlock(a,b)) {return -1} else {return 1}
  1654. })
  1655. >
  1656. !
  1657. sorted
  1658. ^self copy sort
  1659. !
  1660. sorted: aBlock
  1661. ^self copy sort: aBlock
  1662. !
  1663. printString
  1664. | str |
  1665. str := '' writeStream.
  1666. str nextPutAll: super printString, ' ('.
  1667. self
  1668. do: [:each | str nextPutAll: each printString]
  1669. separatedBy: [str nextPutAll: ' '].
  1670. str nextPutAll: ')'.
  1671. ^str contents
  1672. ! !
  1673. Object subclass: #RegularExpression
  1674. instanceVariableNames: ''
  1675. category: 'Kernel'!
  1676. !RegularExpression methodsFor: 'evaluating'!
  1677. compile: aString
  1678. <return self.compile(aString)>
  1679. !
  1680. exec: aString
  1681. <return self.exec(aString) || nil>
  1682. !
  1683. test: aString
  1684. <return self.test(aString)>
  1685. ! !
  1686. !RegularExpression class methodsFor: 'instance creation'!
  1687. fromString: aString flag: anotherString
  1688. <return new RegExp(aString, anotherString)>
  1689. !
  1690. fromString: aString
  1691. ^self fromString: aString flag: ''
  1692. ! !
  1693. Object subclass: #Error
  1694. instanceVariableNames: 'messageText'
  1695. category: 'Kernel'!
  1696. !Error methodsFor: 'accessing'!
  1697. messageText
  1698. ^messageText
  1699. !
  1700. messageText: aString
  1701. messageText := aString
  1702. !
  1703. context
  1704. <return self.context>
  1705. ! !
  1706. !Error methodsFor: 'signaling'!
  1707. signal
  1708. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1709. ! !
  1710. !Error class methodsFor: 'instance creation'!
  1711. signal: aString
  1712. ^self new
  1713. messageText: aString;
  1714. signal
  1715. ! !
  1716. Object subclass: #MethodContext
  1717. instanceVariableNames: ''
  1718. category: 'Kernel'!
  1719. !MethodContext methodsFor: 'accessing'!
  1720. receiver
  1721. <return self.receiver>
  1722. !
  1723. selector
  1724. <return smalltalk.convertSelector(self.selector)>
  1725. !
  1726. home
  1727. <return self.homeContext>
  1728. !
  1729. temps
  1730. <return self.temps>
  1731. !
  1732. printString
  1733. ^super printString, '(', self asString, ')'
  1734. !
  1735. asString
  1736. ^self receiver class printString, ' >> ', self selector
  1737. ! !
  1738. Object subclass: #Association
  1739. instanceVariableNames: 'key value'
  1740. category: 'Kernel'!
  1741. !Association methodsFor: 'accessing'!
  1742. key: aKey
  1743. key := aKey
  1744. !
  1745. key
  1746. ^key
  1747. !
  1748. value: aValue
  1749. value := aValue
  1750. !
  1751. value
  1752. ^value
  1753. ! !
  1754. !Association methodsFor: 'comparing'!
  1755. = anAssociation
  1756. ^self class = anAssociation class and: [
  1757. self key = anAssociation key and: [
  1758. self value = anAssociation value]]
  1759. ! !
  1760. !Association class methodsFor: 'instance creation'!
  1761. key: aKey value: aValue
  1762. ^self new
  1763. key: aKey;
  1764. value: aValue;
  1765. yourself
  1766. ! !
  1767. Collection subclass: #Dictionary
  1768. instanceVariableNames: 'keys'
  1769. category: 'Kernel'!
  1770. !Dictionary methodsFor: 'accessing'!
  1771. size
  1772. ^keys size
  1773. !
  1774. associations
  1775. | associations |
  1776. associations := #().
  1777. keys do: [:each |
  1778. associations add: (Association key: each value: (self at: each))].
  1779. ^associations
  1780. !
  1781. keys
  1782. ^keys copy
  1783. !
  1784. values
  1785. ^keys collect: [:each | self at: each]
  1786. !
  1787. at: aKey put: aValue
  1788. (keys includes: aKey) ifFalse: [keys add: aKey].
  1789. ^self basicAt: aKey put: aValue
  1790. !
  1791. at: aKey ifAbsent: aBlock
  1792. ^(self keys includes: aKey)
  1793. ifTrue: [self basicAt: aKey]
  1794. ifFalse: aBlock
  1795. !
  1796. at: aKey ifAbsentPut: aBlock
  1797. ^self at: aKey ifAbsent: [
  1798. self at: aKey put: aBlock value]
  1799. !
  1800. at: aKey ifPresent: aBlock
  1801. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1802. !
  1803. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1804. ^(self basicAt: aKey)
  1805. ifNil: anotherBlock
  1806. ifNotNil: [aBlock value: (self at: aKey)]
  1807. !
  1808. at: aKey
  1809. ^self at: aKey ifAbsent: [self errorNotFound]
  1810. ! !
  1811. !Dictionary methodsFor: 'adding/removing'!
  1812. add: anAssociation
  1813. self at: anAssociation key put: anAssociation value
  1814. !
  1815. addAll: aDictionary
  1816. super addAll: aDictionary associations.
  1817. ^aDictionary
  1818. !
  1819. remove: aKey
  1820. self removeKey: aKey
  1821. !
  1822. removeKey: aKey
  1823. keys remove: aKey
  1824. ! !
  1825. !Dictionary methodsFor: 'comparing'!
  1826. = aDictionary
  1827. self class = aDictionary class ifFalse: [^false].
  1828. self size = aDictionary size ifFalse: [^false].
  1829. ^self associations = aDictionary associations
  1830. ! !
  1831. !Dictionary methodsFor: 'converting'!
  1832. asJSONObject
  1833. | object |
  1834. object := Object new.
  1835. self keysAndValuesDo: [:key :value |
  1836. object basicAt: key put: value asJSONObject].
  1837. ^object
  1838. ! !
  1839. !Dictionary methodsFor: 'copying'!
  1840. shallowCopy
  1841. | copy |
  1842. copy := self class new.
  1843. self associationsDo: [:each |
  1844. copy at: each key put: each value].
  1845. ^copy
  1846. !
  1847. , aCollection
  1848. self shouldNotImplement
  1849. !
  1850. copyFrom: anIndex to: anotherIndex
  1851. self shouldNotImplement
  1852. ! !
  1853. !Dictionary methodsFor: 'enumerating'!
  1854. associationsDo: aBlock
  1855. self associations do: aBlock
  1856. !
  1857. keysAndValuesDo: aBlock
  1858. self associationsDo: [:each |
  1859. aBlock value: each key value: each value]
  1860. !
  1861. do: aBlock
  1862. self values do: aBlock
  1863. !
  1864. select: aBlock
  1865. | newDict |
  1866. newDict := self class new.
  1867. self keysAndValuesDo: [:key :value |
  1868. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1869. ^newDict
  1870. !
  1871. collect: aBlock
  1872. | newDict |
  1873. newDict := self class new.
  1874. self keysAndValuesDo: [:key :value |
  1875. newDict at: key put: (aBlock value: value)].
  1876. ^newDict
  1877. !
  1878. detect: aBlock ifNone: anotherBlock
  1879. ^self values detect: aBlock ifNone: anotherBlock
  1880. !
  1881. includes: anObject
  1882. ^self values includes: anObject
  1883. ! !
  1884. !Dictionary methodsFor: 'initialization'!
  1885. initialize
  1886. super initialize.
  1887. keys := #()
  1888. ! !
  1889. !Dictionary methodsFor: 'printing'!
  1890. printString
  1891. ^ String streamContents: [:aStream|
  1892. aStream
  1893. nextPutAll: super printString;
  1894. nextPutAll: '('.
  1895. self associations
  1896. do: [:anAssociation|
  1897. aStream
  1898. nextPutAll: anAssociation key printString;
  1899. nextPutAll: ' -> ';
  1900. nextPutAll: anAssociation value printString]
  1901. separatedBy: [aStream nextPutAll: ' , '].
  1902. aStream nextPutAll: ')'.
  1903. ]
  1904. ! !
  1905. !Dictionary class methodsFor: 'instance creation'!
  1906. fromPairs: aCollection
  1907. | dict |
  1908. dict := self new.
  1909. aCollection do: [:each | dict add: each].
  1910. ^dict
  1911. ! !
  1912. Object subclass: #ClassBuilder
  1913. instanceVariableNames: ''
  1914. category: 'Kernel'!
  1915. !ClassBuilder methodsFor: 'class creation'!
  1916. superclass: aClass subclass: aString
  1917. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  1918. !
  1919. class: aClass instanceVariableNames: aString
  1920. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1921. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1922. self setupClass: aClass
  1923. !
  1924. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  1925. | newClass |
  1926. newClass := self addSubclassOf: aClass
  1927. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1928. package: (aString3 ifNil: ['unclassified']).
  1929. self setupClass: newClass.
  1930. ^newClass
  1931. ! !
  1932. !ClassBuilder methodsFor: 'private'!
  1933. instanceVariableNamesFor: aString
  1934. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1935. !
  1936. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1937. <smalltalk.addClass(aString, aClass, aCollection);
  1938. return smalltalk[aString]>
  1939. !
  1940. setupClass: aClass
  1941. <smalltalk.init(aClass);>
  1942. !
  1943. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  1944. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  1945. return smalltalk[aString]>
  1946. ! !
  1947. Object subclass: #ClassCategoryReader
  1948. instanceVariableNames: 'class category chunkParser'
  1949. category: 'Kernel'!
  1950. !ClassCategoryReader methodsFor: 'accessing'!
  1951. class: aClass category: aString
  1952. class := aClass.
  1953. category := aString
  1954. ! !
  1955. !ClassCategoryReader methodsFor: 'fileIn'!
  1956. scanFrom: aChunkParser
  1957. | chunk |
  1958. [chunk := aChunkParser nextChunk.
  1959. chunk isEmpty] whileFalse: [
  1960. self compileMethod: chunk]
  1961. ! !
  1962. !ClassCategoryReader methodsFor: 'initialization'!
  1963. initialize
  1964. super initialize.
  1965. chunkParser := ChunkParser new.
  1966. ! !
  1967. !ClassCategoryReader methodsFor: 'private'!
  1968. compileMethod: aString
  1969. | method |
  1970. method := Compiler new load: aString forClass: class.
  1971. method category: category.
  1972. class addCompiledMethod: method
  1973. ! !
  1974. Object subclass: #Stream
  1975. instanceVariableNames: 'collection position streamSize'
  1976. category: 'Kernel'!
  1977. !Stream methodsFor: 'accessing'!
  1978. collection
  1979. ^collection
  1980. !
  1981. setCollection: aCollection
  1982. collection := aCollection
  1983. !
  1984. position
  1985. ^position ifNil: [position := 0]
  1986. !
  1987. position: anInteger
  1988. position := anInteger
  1989. !
  1990. streamSize
  1991. ^streamSize
  1992. !
  1993. setStreamSize: anInteger
  1994. streamSize := anInteger
  1995. !
  1996. contents
  1997. ^self collection
  1998. copyFrom: 1
  1999. to: self streamSize
  2000. !
  2001. size
  2002. ^self streamSize
  2003. ! !
  2004. !Stream methodsFor: 'actions'!
  2005. reset
  2006. self position: 0
  2007. !
  2008. close
  2009. !
  2010. flush
  2011. !
  2012. resetContents
  2013. self reset.
  2014. self setStreamSize: 0
  2015. ! !
  2016. !Stream methodsFor: 'enumerating'!
  2017. do: aBlock
  2018. [self atEnd] whileFalse: [aBlock value: self next]
  2019. ! !
  2020. !Stream methodsFor: 'positioning'!
  2021. setToEnd
  2022. self position: self size
  2023. !
  2024. skip: anInteger
  2025. self position: ((self position + anInteger) min: self size max: 0)
  2026. ! !
  2027. !Stream methodsFor: 'reading'!
  2028. next
  2029. self position: self position + 1.
  2030. ^collection at: self position
  2031. !
  2032. next: anInteger
  2033. | tempCollection |
  2034. tempCollection := self collection class new.
  2035. anInteger timesRepeat: [
  2036. self atEnd ifFalse: [
  2037. tempCollection add: self next]].
  2038. ^tempCollection
  2039. !
  2040. peek
  2041. ^self atEnd ifFalse: [
  2042. self collection at: self position + 1]
  2043. ! !
  2044. !Stream methodsFor: 'testing'!
  2045. atEnd
  2046. ^self position = self size
  2047. !
  2048. atStart
  2049. ^self position = 0
  2050. !
  2051. isEmpty
  2052. ^self size = 0
  2053. ! !
  2054. !Stream methodsFor: 'writing'!
  2055. nextPut: anObject
  2056. self position: self position + 1.
  2057. self collection at: self position put: anObject.
  2058. self setStreamSize: (self streamSize max: self position)
  2059. !
  2060. nextPutAll: aCollection
  2061. aCollection do: [:each |
  2062. self nextPut: each]
  2063. ! !
  2064. !Stream class methodsFor: 'instance creation'!
  2065. on: aCollection
  2066. ^self new
  2067. setCollection: aCollection;
  2068. setStreamSize: aCollection size;
  2069. yourself
  2070. ! !
  2071. Stream subclass: #StringStream
  2072. instanceVariableNames: ''
  2073. category: 'Kernel'!
  2074. !StringStream methodsFor: 'reading'!
  2075. next: anInteger
  2076. | tempCollection |
  2077. tempCollection := self collection class new.
  2078. anInteger timesRepeat: [
  2079. self atEnd ifFalse: [
  2080. tempCollection := tempCollection, self next]].
  2081. ^tempCollection
  2082. ! !
  2083. !StringStream methodsFor: 'writing'!
  2084. nextPut: aString
  2085. self nextPutAll: aString
  2086. !
  2087. nextPutAll: aString
  2088. self setCollection:
  2089. (self collection copyFrom: 1 to: self position),
  2090. aString,
  2091. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  2092. self position: self position + aString size.
  2093. self setStreamSize: (self streamSize max: self position)
  2094. !
  2095. cr
  2096. ^self nextPutAll: String cr
  2097. !
  2098. crlf
  2099. ^self nextPutAll: String crlf
  2100. !
  2101. lf
  2102. ^self nextPutAll: String lf
  2103. !
  2104. space
  2105. self nextPut: ' '
  2106. ! !
  2107. Object subclass: #ClassCommentReader
  2108. instanceVariableNames: 'class chunkParser'
  2109. category: 'Kernel'!
  2110. !ClassCommentReader methodsFor: 'accessing'!
  2111. class: aClass
  2112. class := aClass
  2113. ! !
  2114. !ClassCommentReader methodsFor: 'fileIn'!
  2115. scanFrom: aChunkParser
  2116. | chunk |
  2117. chunk := aChunkParser nextChunk.
  2118. chunk isEmpty ifFalse: [
  2119. self setComment: chunk].
  2120. ! !
  2121. !ClassCommentReader methodsFor: 'initialization'!
  2122. initialize
  2123. super initialize.
  2124. chunkParser := ChunkParser new.
  2125. ! !
  2126. !ClassCommentReader methodsFor: 'private'!
  2127. setComment: aString
  2128. class comment: aString
  2129. ! !
  2130. Object subclass: #Random
  2131. instanceVariableNames: ''
  2132. category: 'Kernel'!
  2133. !Random methodsFor: 'accessing'!
  2134. next
  2135. <return Math.random()>
  2136. !
  2137. next: anInteger
  2138. ^(1 to: anInteger) collect: [:each | self next]
  2139. ! !
  2140. Object subclass: #Point
  2141. instanceVariableNames: 'x y'
  2142. category: 'Kernel'!
  2143. !Point methodsFor: 'accessing'!
  2144. x
  2145. ^x
  2146. !
  2147. y
  2148. ^y
  2149. !
  2150. y: aNumber
  2151. y := aNumber
  2152. !
  2153. x: aNumber
  2154. x := aNumber
  2155. ! !
  2156. !Point methodsFor: 'arithmetic'!
  2157. * aPoint
  2158. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2159. !
  2160. + aPoint
  2161. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2162. !
  2163. - aPoint
  2164. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2165. !
  2166. / aPoint
  2167. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2168. !
  2169. = aPoint
  2170. ^aPoint class = self class and: [
  2171. (aPoint x = self x) & (aPoint y = self y)]
  2172. ! !
  2173. !Point methodsFor: 'converting'!
  2174. asPoint
  2175. ^self
  2176. ! !
  2177. !Point class methodsFor: 'instance creation'!
  2178. x: aNumber y: anotherNumber
  2179. ^self new
  2180. x: aNumber;
  2181. y: anotherNumber;
  2182. yourself
  2183. ! !
  2184. Object subclass: #Message
  2185. instanceVariableNames: 'selector arguments'
  2186. category: 'Kernel'!
  2187. !Message methodsFor: 'accessing'!
  2188. selector
  2189. ^selector
  2190. !
  2191. selector: aString
  2192. selector := aString
  2193. !
  2194. arguments: anArray
  2195. arguments := anArray
  2196. !
  2197. arguments
  2198. ^arguments
  2199. ! !
  2200. !Message methodsFor: 'printing'!
  2201. printString
  2202. ^ String streamContents: [:aStream|
  2203. aStream
  2204. nextPutAll: super printString;
  2205. nextPutAll: '(';
  2206. nextPutAll: selector;
  2207. nextPutAll: ')' ]
  2208. ! !
  2209. !Message class methodsFor: 'instance creation'!
  2210. selector: aString arguments: anArray
  2211. ^self new
  2212. selector: aString;
  2213. arguments: anArray;
  2214. yourself
  2215. ! !
  2216. Error subclass: #MessageNotUnderstood
  2217. instanceVariableNames: 'message receiver'
  2218. category: 'Kernel'!
  2219. !MessageNotUnderstood methodsFor: 'accessing'!
  2220. message
  2221. ^message
  2222. !
  2223. message: aMessage
  2224. message := aMessage
  2225. !
  2226. receiver
  2227. ^receiver
  2228. !
  2229. receiver: anObject
  2230. receiver := anObject
  2231. !
  2232. messageText
  2233. ^self receiver asString, ' does not understand #', self message selector
  2234. ! !
  2235. Object subclass: #ErrorHandler
  2236. instanceVariableNames: ''
  2237. category: 'Kernel'!
  2238. !ErrorHandler methodsFor: 'error handling'!
  2239. handleError: anError
  2240. anError context ifNotNil: [self logErrorContext: anError context].
  2241. self logError: anError
  2242. ! !
  2243. !ErrorHandler methodsFor: 'private'!
  2244. logContext: aContext
  2245. aContext home ifNotNil: [
  2246. self logContext: aContext home].
  2247. self log: aContext receiver asString, '>>', aContext selector
  2248. !
  2249. logErrorContext: aContext
  2250. aContext ifNotNil: [
  2251. aContext home ifNotNil: [
  2252. self logContext: aContext home]]
  2253. !
  2254. logError: anError
  2255. self log: anError messageText
  2256. !
  2257. log: aString
  2258. console log: aString
  2259. ! !
  2260. ErrorHandler class instanceVariableNames: 'current'!
  2261. !ErrorHandler class methodsFor: 'accessing'!
  2262. current
  2263. ^current ifNil: [current := self new]
  2264. !
  2265. setCurrent: anHandler
  2266. current := anHandler
  2267. ! !
  2268. !ErrorHandler class methodsFor: 'initialization'!
  2269. initialize
  2270. self register
  2271. !
  2272. register
  2273. ErrorHandler setCurrent: self new
  2274. ! !
  2275. Object subclass: #JSObjectProxy
  2276. instanceVariableNames: 'jsObject'
  2277. category: 'Kernel'!
  2278. !JSObjectProxy methodsFor: 'accessing'!
  2279. jsObject: aJSObject
  2280. jsObject := aJSObject
  2281. !
  2282. jsObject
  2283. ^jsObject
  2284. !
  2285. at: aString
  2286. <return self['@jsObject'][aString]>
  2287. !
  2288. at: aString put: anObject
  2289. <self['@jsObject'][aString] = anObject>
  2290. ! !
  2291. !JSObjectProxy methodsFor: 'proxy'!
  2292. printString
  2293. ^self jsObject toString
  2294. !
  2295. inspectOn: anInspector
  2296. | variables |
  2297. variables := Dictionary new.
  2298. variables at: '#self' put: self jsObject.
  2299. anInspector setLabel: self printString.
  2300. <for(var i in self['@jsObject']) {
  2301. variables._at_put_(i, self['@jsObject'][i]);
  2302. }>.
  2303. anInspector setVariables: variables
  2304. !
  2305. doesNotUnderstand: aMessage
  2306. | obj selector jsSelector arguments |
  2307. obj := self jsObject.
  2308. selector := aMessage selector.
  2309. jsSelector := selector asJavaScriptSelector.
  2310. arguments := aMessage arguments.
  2311. <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
  2312. super doesNotUnderstand: aMessage
  2313. ! !
  2314. !JSObjectProxy class methodsFor: 'instance creation'!
  2315. on: aJSObject
  2316. ^self new
  2317. jsObject: aJSObject;
  2318. yourself
  2319. ! !
  2320. Collection subclass: #Set
  2321. instanceVariableNames: 'elements'
  2322. category: 'Kernel'!
  2323. !Set methodsFor: 'accessing'!
  2324. size
  2325. ^elements size
  2326. ! !
  2327. !Set methodsFor: 'adding/removing'!
  2328. add: anObject
  2329. <
  2330. var found;
  2331. for(var i in self['@elements']) {
  2332. if(anObject == self['@elements'][i]) {
  2333. found = true;
  2334. break;
  2335. }
  2336. }
  2337. if(!!found) {self['@elements'].push(anObject)}
  2338. >
  2339. !
  2340. remove: anObject
  2341. elements remove: anObject
  2342. ! !
  2343. !Set methodsFor: 'comparing'!
  2344. = aCollection
  2345. ^self class = aCollection class and: [
  2346. elements = aCollection asArray]
  2347. ! !
  2348. !Set methodsFor: 'converting'!
  2349. asArray
  2350. ^elements copy
  2351. ! !
  2352. !Set methodsFor: 'enumerating'!
  2353. detect: aBlock ifNone: anotherBlock
  2354. ^elements detect: aBlock ifNone: anotherBlock
  2355. !
  2356. do: aBlock
  2357. elements do: aBlock
  2358. ! !
  2359. !Set methodsFor: 'initialization'!
  2360. initialize
  2361. super initialize.
  2362. elements := #()
  2363. ! !
  2364. !Set methodsFor: 'testing'!
  2365. includes: anObject
  2366. ^elements includes: anObject
  2367. ! !
  2368. Object subclass: #Transcript
  2369. instanceVariableNames: 'textarea'
  2370. category: 'Kernel'!
  2371. Transcript class instanceVariableNames: 'current'!
  2372. !Transcript class methodsFor: 'instance creation'!
  2373. open
  2374. self current open
  2375. !
  2376. new
  2377. self shouldNotImplement
  2378. !
  2379. current
  2380. ^current
  2381. !
  2382. register: aTranscript
  2383. current := aTranscript
  2384. ! !
  2385. !Transcript class methodsFor: 'printing'!
  2386. show: anObject
  2387. self current show: anObject
  2388. !
  2389. cr
  2390. self current show: String cr
  2391. !
  2392. clear
  2393. self current clear
  2394. ! !
  2395. Object subclass: #ConsoleTranscript
  2396. instanceVariableNames: 'textarea'
  2397. category: 'Kernel'!
  2398. !ConsoleTranscript methodsFor: 'actions'!
  2399. open
  2400. ! !
  2401. !ConsoleTranscript methodsFor: 'printing'!
  2402. clear
  2403. "no op"
  2404. !
  2405. cr
  2406. "no op"
  2407. !
  2408. show: anObject
  2409. <console.log(String(anObject._asString()))>
  2410. ! !
  2411. !ConsoleTranscript class methodsFor: 'initialization'!
  2412. initialize
  2413. Transcript register: self new
  2414. ! !