Kernel.st 52 KB

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