Kernel.st 44 KB

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