1
0

Kernel.st 53 KB

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