Kernel.st 50 KB

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