Kernel.st 46 KB

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