Kernel.st 50 KB

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