Kernel.st 46 KB

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