Kernel-Objects.st 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748
  1. Smalltalk current createPackage: 'Kernel-Objects'!
  2. nil subclass: #Object
  3. instanceVariableNames: ''
  4. package: 'Kernel-Objects'!
  5. !Object commentStamp!
  6. *Object is the root of the Smalltalk class system*. All classes in the system are subclasses of Object.
  7. Object provides default behavior common to all normal objects, such as:
  8. - access
  9. - copying
  10. - comparison
  11. - error handling
  12. - message sending
  13. - reflection
  14. Also utility messages that all objects should respond to are defined here.
  15. Object has no instance variable.
  16. ##Access
  17. Instance variables can be accessed with `#instVarAt:` and `#instVarAt:put:`. `Object >> instanceVariableNames` answers a collection of all instance variable names.
  18. Accessing JavaScript properties of an object is done through `#basicAt:`, `#basicAt:put:` and `basicDelete:`.
  19. ##Copying
  20. Copying an object is handled by `#copy` and `#deepCopy`. The first one performs a shallow copy of the receiver, while the second one performs a deep copy.
  21. The hook method `#postCopy` can be overriden in subclasses to copy fields as necessary to complete the full copy. It will be sent by the copy of the receiver.
  22. ##Comparison
  23. Objects understand equality `#=` and identity `#==` comparison.
  24. ##Error handling
  25. - `#halt` is the typical message to use for inserting breakpoints during debugging.
  26. - `#error:` throws a generic error exception
  27. - `#doesNotUnderstand:` handles the fact that there was an attempt to send the given message to the receiver but the receiver does not understand this message.
  28. Overriding this message can be useful to implement proxies for example.!
  29. !Object methodsFor: 'accessing'!
  30. basicAt: aString
  31. <return self[aString]>
  32. !
  33. basicAt: aString put: anObject
  34. <return self[aString] = anObject>
  35. !
  36. basicDelete: aString
  37. <delete self[aString]; return aString>
  38. !
  39. class
  40. <return self.klass>
  41. !
  42. identityHash
  43. <
  44. var hash=self.identityHash;
  45. if (hash) return hash;
  46. hash=smalltalk.nextId();
  47. Object.defineProperty(self, 'identityHash', {value:hash});
  48. return hash;
  49. >
  50. !
  51. instVarAt: aString
  52. < return self['@'+aString] >
  53. !
  54. instVarAt: aString put: anObject
  55. < self['@' + aString] = anObject >
  56. !
  57. size
  58. self error: 'Object not indexable'
  59. !
  60. value
  61. <return self.valueOf()>
  62. !
  63. yourself
  64. ^self
  65. ! !
  66. !Object methodsFor: 'comparing'!
  67. = anObject
  68. ^self == anObject
  69. !
  70. == anObject
  71. ^self identityHash = anObject identityHash
  72. !
  73. ~= anObject
  74. ^(self = anObject) = false
  75. !
  76. ~~ anObject
  77. ^(self == anObject) = false
  78. ! !
  79. !Object methodsFor: 'converting'!
  80. -> anObject
  81. ^Association key: self value: anObject
  82. !
  83. asJSON
  84. | variables |
  85. variables := HashedCollection new.
  86. self class allInstanceVariableNames do: [:each |
  87. variables at: each put: (self instVarAt: each) asJSON].
  88. ^variables
  89. !
  90. asJSONString
  91. ^JSON stringify: self asJSON
  92. !
  93. asJavascript
  94. ^self asString
  95. !
  96. asString
  97. ^self printString
  98. !
  99. test
  100. | a |
  101. a := 1.
  102. self halt
  103. ! !
  104. !Object methodsFor: 'copying'!
  105. copy
  106. ^self shallowCopy postCopy
  107. !
  108. deepCopy
  109. <
  110. var copy = self.klass._new();
  111. for(var i in self) {
  112. if(/^@.+/.test(i)) {
  113. copy[i] = self[i]._deepCopy();
  114. }
  115. }
  116. return copy;
  117. >
  118. !
  119. postCopy
  120. !
  121. shallowCopy
  122. <
  123. var copy = self.klass._new();
  124. for(var i in self) {
  125. if(/^@.+/.test(i)) {
  126. copy[i] = self[i];
  127. }
  128. }
  129. return copy;
  130. >
  131. ! !
  132. !Object methodsFor: 'error handling'!
  133. deprecatedAPI
  134. "Just a simple way to deprecate methods.
  135. #deprecatedAPI is in the 'error handling' protocol even if it doesn't throw an error,
  136. but it could in the future."
  137. console warn: thisContext home asString, ' is deprecated!! (in ', thisContext home home asString, ')'
  138. !
  139. doesNotUnderstand: aMessage
  140. MessageNotUnderstood new
  141. receiver: self;
  142. message: aMessage;
  143. signal
  144. !
  145. error: aString
  146. Error signal: aString
  147. !
  148. halt
  149. self error: 'Halt encountered'
  150. !
  151. shouldNotImplement
  152. self error: 'This method should not be implemented in ', self class name
  153. !
  154. subclassResponsibility
  155. self error: 'This method is a responsibility of a subclass'
  156. !
  157. throw: anObject
  158. < throw anObject >
  159. !
  160. try: aBlock catch: anotherBlock
  161. <try{return aBlock()} catch(e) {return anotherBlock(e)}>
  162. ! !
  163. !Object methodsFor: 'initialization'!
  164. initialize
  165. ! !
  166. !Object methodsFor: 'message handling'!
  167. basicPerform: aString
  168. ^self basicPerform: aString withArguments: #()
  169. !
  170. basicPerform: aString withArguments: aCollection
  171. <return self[aString].apply(self, aCollection);>
  172. !
  173. perform: aString
  174. ^self perform: aString withArguments: #()
  175. !
  176. perform: aString withArguments: aCollection
  177. <return smalltalk.send(self, aString._asSelector(), aCollection)>
  178. ! !
  179. !Object methodsFor: 'printing'!
  180. printOn: aStream
  181. "Append to the aStream, a string representing the receiver."
  182. aStream nextPutAll: (self class name first isVowel
  183. ifTrue: [ 'an ' ]
  184. ifFalse: [ 'a ' ]).
  185. aStream nextPutAll: self class name
  186. !
  187. printString
  188. "Answer a String representation of the receiver."
  189. ^ String streamContents: [ :stream | self printOn: stream ]
  190. ! !
  191. !Object methodsFor: 'streaming'!
  192. putOn: aStream
  193. aStream nextPut: self
  194. ! !
  195. !Object methodsFor: 'testing'!
  196. ifNil: aBlock
  197. "inlined in the Compiler"
  198. ^self
  199. !
  200. ifNil: aBlock ifNotNil: anotherBlock
  201. "inlined in the Compiler"
  202. ^anotherBlock value: self
  203. !
  204. ifNotNil: aBlock
  205. "inlined in the Compiler"
  206. ^aBlock value: self
  207. !
  208. ifNotNil: aBlock ifNil: anotherBlock
  209. "inlined in the Compiler"
  210. ^aBlock value: self
  211. !
  212. isBoolean
  213. ^ false
  214. !
  215. isClass
  216. ^false
  217. !
  218. isCompiledMethod
  219. ^ false
  220. !
  221. isImmutable
  222. ^ false
  223. !
  224. isKindOf: aClass
  225. ^(self isMemberOf: aClass)
  226. ifTrue: [true]
  227. ifFalse: [self class inheritsFrom: aClass]
  228. !
  229. isMemberOf: aClass
  230. ^self class = aClass
  231. !
  232. isMetaclass
  233. ^false
  234. !
  235. isNil
  236. ^false
  237. !
  238. isNumber
  239. ^false
  240. !
  241. isPackage
  242. ^ false
  243. !
  244. isParseFailure
  245. ^false
  246. !
  247. isString
  248. ^false
  249. !
  250. isSymbol
  251. ^false
  252. !
  253. notNil
  254. ^self isNil not
  255. !
  256. respondsTo: aSelector
  257. ^self class canUnderstand: aSelector
  258. ! !
  259. !Object class methodsFor: 'initialization'!
  260. initialize
  261. "no op"
  262. ! !
  263. Object subclass: #Boolean
  264. instanceVariableNames: ''
  265. package: 'Kernel-Objects'!
  266. !Boolean commentStamp!
  267. Boolean wraps the JavaScript `Boolean()` constructor. The `true` and `false` objects are the JavaScript boolean objects.
  268. Boolean defines the protocol for logic testing operations and conditional control structures for the logical values.
  269. Boolean instances are weither `true` or `false`.!
  270. !Boolean methodsFor: 'comparing'!
  271. = aBoolean
  272. <
  273. if(!! aBoolean._isBoolean || !! aBoolean._isBoolean()) {
  274. return false;
  275. }
  276. return Boolean(self == true) == aBoolean
  277. >
  278. !
  279. == aBoolean
  280. ^self = aBoolean
  281. ! !
  282. !Boolean methodsFor: 'controlling'!
  283. & aBoolean
  284. <
  285. if(self == true) {
  286. return aBoolean;
  287. } else {
  288. return false;
  289. }
  290. >
  291. !
  292. and: aBlock
  293. ^self = true
  294. ifTrue: aBlock
  295. ifFalse: [false]
  296. !
  297. ifFalse: aBlock
  298. "inlined in the Compiler"
  299. ^self ifTrue: [] ifFalse: aBlock
  300. !
  301. ifFalse: aBlock ifTrue: anotherBlock
  302. "inlined in the Compiler"
  303. ^self ifTrue: anotherBlock ifFalse: aBlock
  304. !
  305. ifTrue: aBlock
  306. "inlined in the Compiler"
  307. ^self ifTrue: aBlock ifFalse: []
  308. !
  309. ifTrue: aBlock ifFalse: anotherBlock
  310. "inlined in the Compiler"
  311. <
  312. if(self == true) {
  313. return aBlock();
  314. } else {
  315. return anotherBlock();
  316. }
  317. >
  318. !
  319. not
  320. ^self = false
  321. !
  322. or: aBlock
  323. ^self = true
  324. ifTrue: [true]
  325. ifFalse: aBlock
  326. !
  327. | aBoolean
  328. <
  329. if(self == true) {
  330. return true;
  331. } else {
  332. return aBoolean;
  333. }
  334. >
  335. ! !
  336. !Boolean methodsFor: 'converting'!
  337. asJSON
  338. ^self
  339. !
  340. asString
  341. < return self.toString() >
  342. ! !
  343. !Boolean methodsFor: 'copying'!
  344. deepCopy
  345. ^self
  346. !
  347. shallowCopy
  348. ^self
  349. ! !
  350. !Boolean methodsFor: 'printing'!
  351. printOn: aStream
  352. aStream nextPutAll: self asString
  353. ! !
  354. !Boolean methodsFor: 'testing'!
  355. isBoolean
  356. ^ true
  357. !
  358. isImmutable
  359. ^ true
  360. ! !
  361. Object subclass: #Date
  362. instanceVariableNames: ''
  363. package: 'Kernel-Objects'!
  364. !Date commentStamp!
  365. The Date class is used to work with dates and times. Therefore `Date today` and `Date now` are both valid in
  366. Amber and answer the same date object.
  367. Date wraps the `Date()` JavaScript constructor, and Smalltalk date objects are JavaScript date objects.!
  368. !Date methodsFor: 'accessing'!
  369. day
  370. ^self dayOfWeek
  371. !
  372. day: aNumber
  373. self dayOfWeek: aNumber
  374. !
  375. dayOfMonth
  376. <return self.getDate()>
  377. !
  378. dayOfMonth: aNumber
  379. <self.setDate(aNumber)>
  380. !
  381. dayOfWeek
  382. <return self.getDay() + 1>
  383. !
  384. dayOfWeek: aNumber
  385. <return self.setDay(aNumber - 1)>
  386. !
  387. hours
  388. <return self.getHours()>
  389. !
  390. hours: aNumber
  391. <self.setHours(aNumber)>
  392. !
  393. milliseconds
  394. <return self.getMilliseconds()>
  395. !
  396. milliseconds: aNumber
  397. <self.setMilliseconds(aNumber)>
  398. !
  399. minutes
  400. <return self.getMinutes()>
  401. !
  402. minutes: aNumber
  403. <self.setMinutes(aNumber)>
  404. !
  405. month
  406. <return self.getMonth() + 1>
  407. !
  408. month: aNumber
  409. <self.setMonth(aNumber - 1)>
  410. !
  411. seconds
  412. <return self.getSeconds()>
  413. !
  414. seconds: aNumber
  415. <self.setSeconds(aNumber)>
  416. !
  417. time
  418. <return self.getTime()>
  419. !
  420. time: aNumber
  421. <self.setTime(aNumber)>
  422. !
  423. year
  424. <return self.getFullYear()>
  425. !
  426. year: aNumber
  427. <self.setFullYear(aNumber)>
  428. ! !
  429. !Date methodsFor: 'arithmetic'!
  430. + aDate
  431. <return self + aDate>
  432. !
  433. - aDate
  434. <return self - aDate>
  435. ! !
  436. !Date methodsFor: 'comparing'!
  437. < aDate
  438. <return self < aDate>
  439. !
  440. <= aDate
  441. <return self <= aDate>
  442. !
  443. > aDate
  444. <return self >> aDate>
  445. !
  446. >= aDate
  447. <return self >>= aDate>
  448. ! !
  449. !Date methodsFor: 'converting'!
  450. asDateString
  451. <return self.toDateString()>
  452. !
  453. asLocaleString
  454. <return self.toLocaleString()>
  455. !
  456. asMilliseconds
  457. ^self time
  458. !
  459. asNumber
  460. ^self asMilliseconds
  461. !
  462. asString
  463. <return self.toString()>
  464. !
  465. asTimeString
  466. <return self.toTimeString()>
  467. ! !
  468. !Date methodsFor: 'printing'!
  469. printOn: aStream
  470. aStream nextPutAll: self asString
  471. ! !
  472. !Date class methodsFor: 'instance creation'!
  473. fromMilliseconds: aNumber
  474. ^self new: aNumber
  475. !
  476. fromSeconds: aNumber
  477. ^self fromMilliseconds: aNumber * 1000
  478. !
  479. fromString: aString
  480. "Example: Date fromString('2011/04/15 00:00:00')"
  481. ^self new: aString
  482. !
  483. millisecondsToRun: aBlock
  484. | t |
  485. t := Date now.
  486. aBlock value.
  487. ^Date now - t
  488. !
  489. new: anObject
  490. <return new Date(anObject)>
  491. !
  492. now
  493. ^self today
  494. !
  495. today
  496. ^self new
  497. ! !
  498. Object subclass: #JSObjectProxy
  499. instanceVariableNames: 'jsObject'
  500. package: 'Kernel-Objects'!
  501. !JSObjectProxy commentStamp!
  502. JSObjectProxy handles sending messages to JavaScript object, therefore accessing JavaScript objects from Amber is transparent.
  503. JSOjbectProxy makes intensive use of `#doesNotUnderstand:`.
  504. ## Examples
  505. JSObjectProxy objects are instanciated by Amber when a Smalltalk message is sent to a JavaScript object.
  506. window alert: 'hello world'.
  507. window inspect.
  508. (window jQuery: 'body') append: 'hello world'
  509. Smalltalk messages sends are converted to JavaScript function calls or object property access _(in this order)_. If n one of them match, a `MessageNotUnderstood` error will be thrown.
  510. ## Message conversion rules
  511. - `someUser name` becomes `someUser.name`
  512. - `someUser name: 'John'` becomes `someUser name = "John"`
  513. - `console log: 'hello world'` becomes `console.log('hello world')`
  514. - `(window jQuery: 'foo') css: 'background' color: 'red'` becomes `window.jQuery('foo').css('background', 'red')`
  515. __Note:__ For keyword-based messages, only the first keyword is kept: `window foo: 1 bar: 2` is equivalent to `window foo: 1 baz: 2`.!
  516. !JSObjectProxy methodsFor: 'accessing'!
  517. at: aString
  518. <return self['@jsObject'][aString]>
  519. !
  520. at: aString ifAbsent: aBlock
  521. "return the aString property or evaluate aBlock if the property is not defined on the object"
  522. <
  523. var obj = self['@jsObject'];
  524. return aString in obj ? obj[aString] : aBlock();
  525. >
  526. !
  527. at: aString ifPresent: aBlock
  528. "return the evaluation of aBlock with the value if the property is defined or return nil"
  529. <
  530. var obj = self['@jsObject'];
  531. return aString in obj ? aBlock(obj[aString]) : nil;
  532. >
  533. !
  534. at: aString ifPresent: aBlock ifAbsent: anotherBlock
  535. "return the evaluation of aBlock with the value if the property is defined
  536. or return value of anotherBlock"
  537. <
  538. var obj = self['@jsObject'];
  539. return aString in obj ? aBlock(obj[aString]) : anotherBlock();
  540. >
  541. !
  542. at: aString put: anObject
  543. <self['@jsObject'][aString] = anObject>
  544. !
  545. jsObject
  546. ^jsObject
  547. !
  548. jsObject: aJSObject
  549. jsObject := aJSObject
  550. !
  551. lookupProperty: aString
  552. "Looks up a property in JS object.
  553. Return the property if it is present, or nil if it is not present."
  554. <return aString in self._jsObject() ? aString : nil>
  555. !
  556. value
  557. "if attribute 'value' exists on the JS object return it,
  558. otherwise return the result of Object>>value."
  559. ^ self
  560. at: 'value'
  561. ifAbsent: [ super value ]
  562. ! !
  563. !JSObjectProxy methodsFor: 'enumerating'!
  564. keysAndValuesDo: aBlock
  565. <
  566. var o = self['@jsObject'];
  567. for(var i in o) {
  568. aBlock(i, o[i]);
  569. }
  570. >
  571. ! !
  572. !JSObjectProxy methodsFor: 'printing'!
  573. printOn: aStream
  574. aStream nextPutAll: self jsObject toString
  575. ! !
  576. !JSObjectProxy methodsFor: 'proxy'!
  577. addObjectVariablesTo: aDictionary
  578. <
  579. for(var i in self['@jsObject']) {
  580. aDictionary._at_put_(i, self['@jsObject'][i]);
  581. }
  582. >
  583. !
  584. doesNotUnderstand: aMessage
  585. ^(self lookupProperty: aMessage selector asJavaScriptSelector)
  586. ifNotNil: [ :jsSelector | self forwardMessage: jsSelector withArguments: aMessage arguments ]
  587. ifNil: [ super doesNotUnderstand: aMessage ]
  588. !
  589. forwardMessage: aString withArguments: anArray
  590. <
  591. return smalltalk.send(self._jsObject(), aString, anArray);
  592. >
  593. !
  594. inspectOn: anInspector
  595. | variables |
  596. variables := Dictionary new.
  597. variables at: '#self' put: self jsObject.
  598. anInspector setLabel: self printString.
  599. self addObjectVariablesTo: variables.
  600. anInspector setVariables: variables
  601. ! !
  602. !JSObjectProxy class methodsFor: 'instance creation'!
  603. on: aJSObject
  604. ^self new
  605. jsObject: aJSObject;
  606. yourself
  607. ! !
  608. Object subclass: #Number
  609. instanceVariableNames: ''
  610. package: 'Kernel-Objects'!
  611. !Number commentStamp!
  612. Number holds the most general methods for dealing with numbers.
  613. Number is directly mapped to JavaScript Number.
  614. Most arithmetic methods like `#+` `#/` `#-` `#max:` are directly inlined into javascript.
  615. ##Enumerating
  616. A Number can be used to evaluate a Block a fixed number of times:
  617. 5 timesRepeat: [Transcript show: 'This will be printed 5 times'; cr].
  618. 1 to: 5 do: [:aNumber| Transcript show: aNumber asString; cr].
  619. 1 to: 10 by: 2 do: [:aNumber| Transcript show: aNumber asString; cr].!
  620. !Number methodsFor: 'accessing'!
  621. identityHash
  622. ^self asString, 'n'
  623. ! !
  624. !Number methodsFor: 'arithmetic'!
  625. * aNumber
  626. "Inlined in the Compiler"
  627. <return self * aNumber>
  628. !
  629. + aNumber
  630. "Inlined in the Compiler"
  631. <return self + aNumber>
  632. !
  633. - aNumber
  634. "Inlined in the Compiler"
  635. <return self - aNumber>
  636. !
  637. / aNumber
  638. "Inlined in the Compiler"
  639. <return self / aNumber>
  640. !
  641. \\ aNumber
  642. <return self % aNumber>
  643. !
  644. abs
  645. <return Math.abs(self);>
  646. !
  647. max: aNumber
  648. <return Math.max(self, aNumber);>
  649. !
  650. min: aNumber
  651. <return Math.min(self, aNumber);>
  652. !
  653. negated
  654. ^0 - self
  655. !
  656. sqrt
  657. <return Math.sqrt(self)>
  658. !
  659. squared
  660. ^self * self
  661. ! !
  662. !Number methodsFor: 'comparing'!
  663. < aNumber
  664. "Inlined in the Compiler"
  665. <return self < aNumber>
  666. !
  667. <= aNumber
  668. "Inlined in the Compiler"
  669. <return self <= aNumber>
  670. !
  671. = aNumber
  672. <
  673. if(!! aNumber._isNumber || !! aNumber._isNumber()) {
  674. return false;
  675. }
  676. return Number(self) == aNumber
  677. >
  678. !
  679. > aNumber
  680. "Inlined in the Compiler"
  681. <return self >> aNumber>
  682. !
  683. >= aNumber
  684. "Inlined in the Compiler"
  685. <return self >>= aNumber>
  686. ! !
  687. !Number methodsFor: 'converting'!
  688. & aNumber
  689. <return self & aNumber>
  690. !
  691. @ aNumber
  692. ^Point x: self y: aNumber
  693. !
  694. asJSON
  695. ^self
  696. !
  697. asJavascript
  698. ^'(', self printString, ')'
  699. !
  700. asPoint
  701. ^Point x: self y: self
  702. !
  703. asString
  704. < return String(self) >
  705. !
  706. atRandom
  707. ^(Random new next * self) truncated + 1
  708. !
  709. rounded
  710. <return Math.round(self);>
  711. !
  712. to: aNumber
  713. | array first last count |
  714. first := self truncated.
  715. last := aNumber truncated + 1.
  716. count := 1.
  717. array := Array new.
  718. (last - first) timesRepeat: [
  719. array at: count put: first.
  720. count := count + 1.
  721. first := first + 1].
  722. ^array
  723. !
  724. to: stop by: step
  725. | array value pos |
  726. value := self.
  727. array := Array new.
  728. pos := 1.
  729. step = 0 ifTrue: [self error: 'step must be non-zero'].
  730. step < 0
  731. ifTrue: [[ value >= stop ] whileTrue: [
  732. array at: pos put: value.
  733. pos := pos + 1.
  734. value := value + step]]
  735. ifFalse: [[ value <= stop ] whileTrue: [
  736. array at: pos put: value.
  737. pos := pos + 1.
  738. value := value + step]].
  739. ^array
  740. !
  741. truncated
  742. <
  743. if(self >>= 0) {
  744. return Math.floor(self);
  745. } else {
  746. return Math.floor(self * (-1)) * (-1);
  747. };
  748. >
  749. !
  750. | aNumber
  751. <return self | aNumber>
  752. ! !
  753. !Number methodsFor: 'copying'!
  754. copy
  755. ^self
  756. !
  757. deepCopy
  758. ^self copy
  759. ! !
  760. !Number methodsFor: 'enumerating'!
  761. timesRepeat: aBlock
  762. | count |
  763. count := 1.
  764. [count > self] whileFalse: [
  765. aBlock value.
  766. count := count + 1]
  767. !
  768. to: stop by: step do: aBlock
  769. | value |
  770. value := self.
  771. step = 0 ifTrue: [self error: 'step must be non-zero'].
  772. step < 0
  773. ifTrue: [[ value >= stop ] whileTrue: [
  774. aBlock value: value.
  775. value := value + step]]
  776. ifFalse: [[ value <= stop ] whileTrue: [
  777. aBlock value: value.
  778. value := value + step]]
  779. !
  780. to: stop do: aBlock
  781. "Evaluate aBlock for each number from self to aNumber."
  782. | nextValue |
  783. nextValue := self.
  784. [nextValue <= stop]
  785. whileTrue:
  786. [aBlock value: nextValue.
  787. nextValue := nextValue + 1]
  788. ! !
  789. !Number methodsFor: 'printing'!
  790. printOn: aStream
  791. aStream nextPutAll: self asString
  792. !
  793. printShowingDecimalPlaces: placesDesired
  794. <return self.toFixed(placesDesired)>
  795. ! !
  796. !Number methodsFor: 'testing'!
  797. IsImmutable
  798. ^ true
  799. !
  800. even
  801. ^ 0 = (self \\ 2)
  802. !
  803. isNumber
  804. ^true
  805. !
  806. isZero
  807. ^self = 0
  808. !
  809. negative
  810. "Answer whether the receiver is mathematically negative."
  811. ^ self < 0
  812. !
  813. odd
  814. ^ self even not
  815. !
  816. positive
  817. "Answer whether the receiver is positive or equal to 0. (ST-80 protocol)."
  818. ^ self >= 0
  819. ! !
  820. !Number class methodsFor: 'instance creation'!
  821. pi
  822. <return Math.PI>
  823. ! !
  824. Object subclass: #Organizer
  825. instanceVariableNames: ''
  826. package: 'Kernel-Objects'!
  827. !Organizer methodsFor: 'accessing'!
  828. addElement: anObject
  829. <self.elements.addElement(anObject)>
  830. !
  831. elements
  832. ^ (self basicAt: 'elements') copy
  833. !
  834. removeElement: anObject
  835. <self.elements.removeElement(anObject)>
  836. ! !
  837. Organizer subclass: #ClassOrganizer
  838. instanceVariableNames: ''
  839. package: 'Kernel-Objects'!
  840. !ClassOrganizer methodsFor: 'accessing'!
  841. addElement: aString
  842. super addElement: aString.
  843. SystemAnnouncer current announce: (ProtocolAdded new
  844. protocol: aString;
  845. theClass: self theClass;
  846. yourself)
  847. !
  848. removeElement: aString
  849. super removeElement: aString.
  850. SystemAnnouncer current announce: (ProtocolRemoved new
  851. protocol: aString;
  852. theClass: self theClass;
  853. yourself)
  854. !
  855. theClass
  856. < return self.theClass >
  857. ! !
  858. Organizer subclass: #PackageOrganizer
  859. instanceVariableNames: ''
  860. package: 'Kernel-Objects'!
  861. Object subclass: #Package
  862. instanceVariableNames: 'commitPathJs commitPathSt'
  863. package: 'Kernel-Objects'!
  864. !Package commentStamp!
  865. A Package is similar to a "class category" typically found in other Smalltalks like Pharo or Squeak. Amber does not have class categories anymore, it had in the beginning but now each class in the system knows which package it belongs to.
  866. A Package has a name, an Array of "requires", a comment and a Dictionary with other optional key value attributes. A Package can also be queried for its classes, but it will then resort to a reverse scan of all classes to find them.
  867. Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
  868. Smalltalk current packageAt: 'Kernel'
  869. ...but you can also use:
  870. Package named: 'Kernel'
  871. A Package differs slightly from a Monticello package which can span multiple class categories using a naming convention based on hyphenation. But just as in Monticello a Package supports "class extensions" so a Package
  872. can define behaviors in foreign classes using a naming convention for method categories where the category starts with an asterisk and then the name of the owning package follows. This can easily be seen in for example class
  873. String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.
  874. You can fetch a package from the server:
  875. Package fetch: 'Additional-Examples'!
  876. !Package methodsFor: 'accessing'!
  877. commitPathJs
  878. ^ commitPathJs ifNil: [self class defaultCommitPathJs]
  879. !
  880. commitPathJs: aString
  881. commitPathJs := aString
  882. !
  883. commitPathSt
  884. ^ commitPathSt ifNil: [self class defaultCommitPathSt]
  885. !
  886. commitPathSt: aString
  887. commitPathSt := aString
  888. !
  889. name
  890. <return self.pkgName>
  891. !
  892. name: aString
  893. <self.pkgName = aString>
  894. !
  895. organization
  896. ^ self basicAt: 'organization'
  897. ! !
  898. !Package methodsFor: 'classes'!
  899. classes
  900. ^ self organization elements
  901. !
  902. setupClasses
  903. self classes
  904. do: [ :each | ClassBuilder new setupClass: each ];
  905. do: [ :each | each initialize ]
  906. !
  907. sortedClasses
  908. "Answer all classes in the receiver, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)."
  909. ^self class sortedClasses: self classes
  910. ! !
  911. !Package methodsFor: 'printing'!
  912. printOn: aStream
  913. super printOn: aStream.
  914. aStream
  915. nextPutAll: ' (';
  916. nextPutAll: self name;
  917. nextPutAll: ')'
  918. ! !
  919. !Package methodsFor: 'testing'!
  920. isPackage
  921. ^ true
  922. ! !
  923. Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
  924. !Package class methodsFor: 'accessing'!
  925. named: aPackageName
  926. ^Smalltalk current packageAt: aPackageName
  927. !
  928. named: aPackageName ifAbsent: aBlock
  929. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  930. ! !
  931. !Package class methodsFor: 'commit paths'!
  932. commitPathsFromLoader
  933. <
  934. var commitPath = typeof amber !!== 'undefined' && amber.commitPath;
  935. if (!!commitPath) return;
  936. if (commitPath.js) self._defaultCommitPathJs_(commitPath.js);
  937. if (commitPath.st) self._defaultCommitPathSt_(commitPath.st);
  938. >
  939. !
  940. defaultCommitPathJs
  941. ^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']
  942. !
  943. defaultCommitPathJs: aString
  944. defaultCommitPathJs := aString
  945. !
  946. defaultCommitPathSt
  947. ^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']
  948. !
  949. defaultCommitPathSt: aString
  950. defaultCommitPathSt := aString
  951. !
  952. resetCommitPaths
  953. defaultCommitPathJs := nil.
  954. defaultCommitPathSt := nil.
  955. ! !
  956. !Package class methodsFor: 'initialization'!
  957. initialize
  958. super initialize.
  959. self commitPathsFromLoader
  960. ! !
  961. !Package class methodsFor: 'loading-storing'!
  962. load: aPackageName
  963. self load: aPackageName prefix: self defaultCommitPathJs, '/'
  964. !
  965. load: aPackageName prefix: aPrefix
  966. jQuery
  967. getScript: (aPrefix , aPackageName , '.js')
  968. onSuccess: [
  969. (Package named: aPackageName) setupClasses ]
  970. ! !
  971. !Package class methodsFor: 'sorting'!
  972. sortedClasses: classes
  973. "Answer classes, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)"
  974. | children others nodes expandedClasses |
  975. children := #().
  976. others := #().
  977. classes do: [:each |
  978. (classes includes: each superclass)
  979. ifFalse: [children add: each]
  980. ifTrue: [others add: each]].
  981. nodes := children collect: [:each |
  982. ClassSorterNode on: each classes: others level: 0].
  983. nodes := nodes sorted: [:a :b | a theClass name <= b theClass name ].
  984. expandedClasses := Array new.
  985. nodes do: [:aNode |
  986. aNode traverseClassesWith: expandedClasses].
  987. ^expandedClasses
  988. ! !
  989. Object subclass: #Point
  990. instanceVariableNames: 'x y'
  991. package: 'Kernel-Objects'!
  992. !Point commentStamp!
  993. A `Point` represents an x-y pair of numbers usually designating a geometric coordinate.
  994. Points are traditionally created using the binary `#@` message to a number:
  995. 100@120
  996. Points can then be arithmetically manipulated:
  997. 100@100 + (10@10)
  998. ...or for example:
  999. (100@100) * 2
  1000. **NOTE:** Creating a Point with a negative y-value will need a space after `@` in order to avoid a parsing error:
  1001. 100@ -100 "but 100@-100 would not parse"
  1002. Amber does not have much behavior in this class out-of-the-box.!
  1003. !Point methodsFor: 'accessing'!
  1004. x
  1005. ^x
  1006. !
  1007. x: aNumber
  1008. x := aNumber
  1009. !
  1010. y
  1011. ^y
  1012. !
  1013. y: aNumber
  1014. y := aNumber
  1015. ! !
  1016. !Point methodsFor: 'arithmetic'!
  1017. * aPoint
  1018. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  1019. !
  1020. + aPoint
  1021. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  1022. !
  1023. - aPoint
  1024. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  1025. !
  1026. / aPoint
  1027. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  1028. !
  1029. = aPoint
  1030. ^aPoint class = self class and: [
  1031. (aPoint x = self x) & (aPoint y = self y)]
  1032. ! !
  1033. !Point methodsFor: 'converting'!
  1034. asPoint
  1035. ^self
  1036. ! !
  1037. !Point methodsFor: 'printing'!
  1038. printOn: aStream
  1039. "Print receiver in classic x@y notation."
  1040. x printOn: aStream.
  1041. aStream nextPutAll: '@'.
  1042. (y notNil and: [y negative]) ifTrue: [
  1043. "Avoid ambiguous @- construct"
  1044. aStream space ].
  1045. y printOn: aStream
  1046. ! !
  1047. !Point methodsFor: 'transforming'!
  1048. translateBy: delta
  1049. "Answer a Point translated by delta (an instance of Point)."
  1050. ^(delta x + x) @ (delta y + y)
  1051. ! !
  1052. !Point class methodsFor: 'instance creation'!
  1053. x: aNumber y: anotherNumber
  1054. ^self new
  1055. x: aNumber;
  1056. y: anotherNumber;
  1057. yourself
  1058. ! !
  1059. Object subclass: #Random
  1060. instanceVariableNames: ''
  1061. package: 'Kernel-Objects'!
  1062. !Random commentStamp!
  1063. `Random` is a random number generator and is implemented as a trivial wrapper around javascript `Math.random()` and is used like this:
  1064. Random new next
  1065. This will return a float x where x < 1 and x > 0. If you want a random integer from 1 to 10 you can use `#atRandom`
  1066. 10 atRandom
  1067. ...and if you want a random number in a specific interval this also works:
  1068. (3 to: 7) atRandom
  1069. ...but be aware that `#to:` does not create an Interval as in other Smalltalk implementations but in fact an `Array` of numbers, so it's better to use:
  1070. 5 atRandom + 2
  1071. Since `#atRandom` is implemented in `SequencableCollection` you can easy pick an element at random:
  1072. #('a' 'b' 'c') atRandom
  1073. ...or perhaps a letter from a `String`:
  1074. 'abc' atRandom
  1075. Since Amber does not have Characters this will return a `String` of length 1 like for example `'b'`.!
  1076. !Random methodsFor: 'accessing'!
  1077. next
  1078. <return Math.random()>
  1079. !
  1080. next: anInteger
  1081. ^(1 to: anInteger) collect: [:each | self next]
  1082. ! !
  1083. Object subclass: #Smalltalk
  1084. instanceVariableNames: ''
  1085. package: 'Kernel-Objects'!
  1086. !Smalltalk commentStamp!
  1087. Smalltalk has only one instance, accessed with `Smalltalk current`.
  1088. It represents the global JavaScript variable `smalltalk` declared in `js/boot.js`.
  1089. The `smalltalk` object holds all class and packages defined in the system.
  1090. ## Classes
  1091. Classes can be accessed using the following methods:
  1092. - `#classes` answers the full list of Smalltalk classes in the system
  1093. - `#at:` answers a specific class of `nil`
  1094. ## Packages
  1095. Packages can be accessed using the following methods:
  1096. - `#packages` answers the full list of packages
  1097. - `#packageAt:` answers a specific class of `nil`
  1098. __note:__ classes and packages are accessed using strings, not symbols
  1099. ## Parsing
  1100. The `#parse:` method is used to parse Smalltalk source code.
  1101. It requires the `Compiler` package and the `js/parser.js` parser file in order to work!
  1102. !Smalltalk methodsFor: 'accessing'!
  1103. at: aString
  1104. <return self[aString]>
  1105. !
  1106. parse: aString
  1107. | result |
  1108. self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
  1109. ^result
  1110. !
  1111. readJSObject: anObject
  1112. <return self.readJSObject(anObject)>
  1113. !
  1114. reservedWords
  1115. "JavaScript reserved words"
  1116. <return self.reservedWords>
  1117. !
  1118. version
  1119. "Answer the version string of Amber"
  1120. ^ '0.10'
  1121. ! !
  1122. !Smalltalk methodsFor: 'classes'!
  1123. classes
  1124. <return self.classes()>
  1125. !
  1126. deleteClass: aClass
  1127. "Deletes a class by deleting its binding only. Use #removeClass instead"
  1128. <self.removeClass(aClass)>
  1129. !
  1130. removeClass: aClass
  1131. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  1132. self deleteClass: aClass.
  1133. SystemAnnouncer current
  1134. announce: (ClassRemoved new
  1135. theClass: aClass;
  1136. yourself)
  1137. ! !
  1138. !Smalltalk methodsFor: 'error handling'!
  1139. asSmalltalkException: anObject
  1140. "A JavaScript exception may be thrown.
  1141. We then need to convert it back to a Smalltalk object"
  1142. ^ ((self isSmalltalkObject: anObject) and: [ anObject isKindOf: Error ])
  1143. ifTrue: [ anObject ]
  1144. ifFalse: [ JavaScriptException on: anObject ]
  1145. !
  1146. parseError: anException parsing: aString
  1147. ^ ParseError new messageText: 'Parse error on line ', (anException basicAt: 'line') ,' column ' , (anException basicAt: 'column') ,' : Unexpected character ', (anException basicAt: 'found')
  1148. ! !
  1149. !Smalltalk methodsFor: 'packages'!
  1150. createPackage: packageName
  1151. "Create and bind a new package with given name and return it."
  1152. <return smalltalk.addPackage(packageName)>
  1153. !
  1154. deletePackage: packageName
  1155. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  1156. To remove a package, use #removePackage instead."
  1157. <delete smalltalk.packages[packageName]>
  1158. !
  1159. packageAt: packageName
  1160. <return self.packages[packageName]>
  1161. !
  1162. packageAt: packageName ifAbsent: aBlock
  1163. ^(self packageAt: packageName) ifNil: aBlock
  1164. !
  1165. packages
  1166. "Return all Package instances in the system."
  1167. <return self.packages.all()>
  1168. !
  1169. pseudoVariableNames
  1170. ^ #('self' 'super' 'nil' 'true' 'false' 'thisContext')
  1171. !
  1172. removePackage: packageName
  1173. "Removes a package and all its classes."
  1174. | pkg |
  1175. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1176. pkg classes do: [:each |
  1177. self removeClass: each].
  1178. self deletePackage: packageName
  1179. !
  1180. renamePackage: packageName to: newName
  1181. "Rename a package."
  1182. | pkg |
  1183. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1184. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  1185. (self basicAt: 'packages') at: newName put: pkg.
  1186. pkg name: newName.
  1187. self deletePackage: packageName.
  1188. ! !
  1189. !Smalltalk methodsFor: 'private'!
  1190. basicParse: aString
  1191. <return smalltalk.parser.parse(aString)>
  1192. !
  1193. createPackage: packageName properties: aDict
  1194. "Needed to import .st files: they begin with this call."
  1195. self deprecatedAPI.
  1196. aDict isEmpty ifFalse: [ self error: 'createPackage:properties: called with nonempty properties' ].
  1197. ^ self createPackage: packageName
  1198. ! !
  1199. !Smalltalk methodsFor: 'testing'!
  1200. isSmalltalkObject: anObject
  1201. "Consider anObject a Smalltalk object if it has a 'klass' property.
  1202. Note that this may be unaccurate"
  1203. <return typeof anObject.klass !!== 'undefined'>
  1204. ! !
  1205. Smalltalk class instanceVariableNames: 'current'!
  1206. !Smalltalk class methodsFor: 'accessing'!
  1207. current
  1208. <return smalltalk>
  1209. ! !
  1210. Object subclass: #Timeout
  1211. instanceVariableNames: 'rawTimeout'
  1212. package: 'Kernel-Objects'!
  1213. !Timeout commentStamp!
  1214. I am wrapping the returns from set{Timeout,Interval}.
  1215. Number suffices in browsers, but node.js returns an object.!
  1216. !Timeout methodsFor: 'accessing'!
  1217. rawTimeout: anObject
  1218. rawTimeout := anObject
  1219. ! !
  1220. !Timeout methodsFor: 'timeout/interval'!
  1221. clearInterval
  1222. <
  1223. var interval = self["@rawTimeout"];
  1224. clearInterval(interval);
  1225. >
  1226. !
  1227. clearTimeout
  1228. <
  1229. var timeout = self["@rawTimeout"];
  1230. clearTimeout(timeout);
  1231. >
  1232. ! !
  1233. !Timeout class methodsFor: 'instance creation'!
  1234. on: anObject
  1235. ^self new rawTimeout: anObject; yourself
  1236. ! !
  1237. Object subclass: #UndefinedObject
  1238. instanceVariableNames: ''
  1239. package: 'Kernel-Objects'!
  1240. !UndefinedObject commentStamp!
  1241. UndefinedObject describes the behavior of its sole instance, `nil`. `nil` represents a prior value for variables that have not been initialized, or for results which are meaningless.
  1242. `nil` is the Smalltalk representation of the `undefined` JavaScript object.!
  1243. !UndefinedObject methodsFor: 'class creation'!
  1244. subclass: aString instanceVariableNames: anotherString
  1245. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1246. !
  1247. subclass: aString instanceVariableNames: aString2 category: aString3
  1248. "Kept for compatibility."
  1249. self deprecatedAPI.
  1250. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1251. !
  1252. subclass: aString instanceVariableNames: aString2 package: aString3
  1253. ^ClassBuilder new
  1254. superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
  1255. ! !
  1256. !UndefinedObject methodsFor: 'converting'!
  1257. asJSON
  1258. ^null
  1259. ! !
  1260. !UndefinedObject methodsFor: 'copying'!
  1261. deepCopy
  1262. ^self
  1263. !
  1264. shallowCopy
  1265. ^self
  1266. ! !
  1267. !UndefinedObject methodsFor: 'printing'!
  1268. printOn: aStream
  1269. aStream nextPutAll: 'nil'
  1270. ! !
  1271. !UndefinedObject methodsFor: 'testing'!
  1272. ifNil: aBlock
  1273. "inlined in the Compiler"
  1274. ^self ifNil: aBlock ifNotNil: []
  1275. !
  1276. ifNil: aBlock ifNotNil: anotherBlock
  1277. "inlined in the Compiler"
  1278. ^aBlock value
  1279. !
  1280. ifNotNil: aBlock
  1281. "inlined in the Compiler"
  1282. ^self
  1283. !
  1284. ifNotNil: aBlock ifNil: anotherBlock
  1285. "inlined in the Compiler"
  1286. ^anotherBlock value
  1287. !
  1288. isImmutable
  1289. ^ true
  1290. !
  1291. isNil
  1292. ^true
  1293. !
  1294. notNil
  1295. ^false
  1296. ! !
  1297. !UndefinedObject class methodsFor: 'instance creation'!
  1298. new
  1299. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1300. ! !
  1301. !String methodsFor: '*Kernel-Objects'!
  1302. asJavaScriptSelector
  1303. "Return first keyword of the selector, without trailing colon."
  1304. ^self replace: '^([a-zA-Z0-9]*).*$' with: '$1'
  1305. ! !