1
0

Kernel-Objects.st 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  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. Answer 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. ifNil: [ super doesNotUnderstand: aMessage ]
  587. ifNotNil: [ :jsSelector |
  588. self
  589. forwardMessage: jsSelector
  590. withArguments: aMessage arguments ]
  591. !
  592. forwardMessage: aString withArguments: anArray
  593. <
  594. return smalltalk.send(self._jsObject(), aString, anArray);
  595. >
  596. !
  597. inspectOn: anInspector
  598. | variables |
  599. variables := Dictionary new.
  600. variables at: '#self' put: self jsObject.
  601. anInspector setLabel: self printString.
  602. self addObjectVariablesTo: variables.
  603. anInspector setVariables: variables
  604. ! !
  605. !JSObjectProxy class methodsFor: 'instance creation'!
  606. on: aJSObject
  607. ^self new
  608. jsObject: aJSObject;
  609. yourself
  610. ! !
  611. Object subclass: #Number
  612. instanceVariableNames: ''
  613. package: 'Kernel-Objects'!
  614. !Number commentStamp!
  615. Number holds the most general methods for dealing with numbers.
  616. Number is directly mapped to JavaScript Number.
  617. Most arithmetic methods like `#+` `#/` `#-` `#max:` are directly inlined into javascript.
  618. ##Enumerating
  619. A Number can be used to evaluate a Block a fixed number of times:
  620. 5 timesRepeat: [Transcript show: 'This will be printed 5 times'; cr].
  621. 1 to: 5 do: [:aNumber| Transcript show: aNumber asString; cr].
  622. 1 to: 10 by: 2 do: [:aNumber| Transcript show: aNumber asString; cr].!
  623. !Number methodsFor: 'accessing'!
  624. identityHash
  625. ^self asString, 'n'
  626. ! !
  627. !Number methodsFor: 'arithmetic'!
  628. * aNumber
  629. "Inlined in the Compiler"
  630. <return self * aNumber>
  631. !
  632. + aNumber
  633. "Inlined in the Compiler"
  634. <return self + aNumber>
  635. !
  636. - aNumber
  637. "Inlined in the Compiler"
  638. <return self - aNumber>
  639. !
  640. / aNumber
  641. "Inlined in the Compiler"
  642. <return self / aNumber>
  643. !
  644. \\ aNumber
  645. <return self % aNumber>
  646. !
  647. abs
  648. <return Math.abs(self);>
  649. !
  650. max: aNumber
  651. <return Math.max(self, aNumber);>
  652. !
  653. min: aNumber
  654. <return Math.min(self, aNumber);>
  655. !
  656. negated
  657. ^0 - self
  658. !
  659. sqrt
  660. <return Math.sqrt(self)>
  661. !
  662. squared
  663. ^self * self
  664. ! !
  665. !Number methodsFor: 'comparing'!
  666. < aNumber
  667. "Inlined in the Compiler"
  668. <return self < aNumber>
  669. !
  670. <= aNumber
  671. "Inlined in the Compiler"
  672. <return self <= aNumber>
  673. !
  674. = aNumber
  675. <
  676. if(!! aNumber._isNumber || !! aNumber._isNumber()) {
  677. return false;
  678. }
  679. return Number(self) == aNumber
  680. >
  681. !
  682. > aNumber
  683. "Inlined in the Compiler"
  684. <return self >> aNumber>
  685. !
  686. >= aNumber
  687. "Inlined in the Compiler"
  688. <return self >>= aNumber>
  689. ! !
  690. !Number methodsFor: 'converting'!
  691. & aNumber
  692. <return self & aNumber>
  693. !
  694. @ aNumber
  695. ^Point x: self y: aNumber
  696. !
  697. asJSON
  698. ^self
  699. !
  700. asJavascript
  701. ^'(', self printString, ')'
  702. !
  703. asPoint
  704. ^Point x: self y: self
  705. !
  706. asString
  707. < return String(self) >
  708. !
  709. atRandom
  710. ^(Random new next * self) truncated + 1
  711. !
  712. rounded
  713. <return Math.round(self);>
  714. !
  715. to: aNumber
  716. | array first last count |
  717. first := self truncated.
  718. last := aNumber truncated + 1.
  719. count := 1.
  720. array := Array new.
  721. (last - first) timesRepeat: [
  722. array at: count put: first.
  723. count := count + 1.
  724. first := first + 1].
  725. ^array
  726. !
  727. to: stop by: step
  728. | array value pos |
  729. value := self.
  730. array := Array new.
  731. pos := 1.
  732. step = 0 ifTrue: [self error: 'step must be non-zero'].
  733. step < 0
  734. ifTrue: [[ value >= stop ] whileTrue: [
  735. array at: pos put: value.
  736. pos := pos + 1.
  737. value := value + step]]
  738. ifFalse: [[ value <= stop ] whileTrue: [
  739. array at: pos put: value.
  740. pos := pos + 1.
  741. value := value + step]].
  742. ^array
  743. !
  744. truncated
  745. <
  746. if(self >>= 0) {
  747. return Math.floor(self);
  748. } else {
  749. return Math.floor(self * (-1)) * (-1);
  750. };
  751. >
  752. !
  753. | aNumber
  754. <return self | aNumber>
  755. ! !
  756. !Number methodsFor: 'copying'!
  757. copy
  758. ^self
  759. !
  760. deepCopy
  761. ^self copy
  762. ! !
  763. !Number methodsFor: 'enumerating'!
  764. timesRepeat: aBlock
  765. | count |
  766. count := 1.
  767. [count > self] whileFalse: [
  768. aBlock value.
  769. count := count + 1]
  770. !
  771. to: stop by: step do: aBlock
  772. | value |
  773. value := self.
  774. step = 0 ifTrue: [self error: 'step must be non-zero'].
  775. step < 0
  776. ifTrue: [[ value >= stop ] whileTrue: [
  777. aBlock value: value.
  778. value := value + step]]
  779. ifFalse: [[ value <= stop ] whileTrue: [
  780. aBlock value: value.
  781. value := value + step]]
  782. !
  783. to: stop do: aBlock
  784. "Evaluate aBlock for each number from self to aNumber."
  785. | nextValue |
  786. nextValue := self.
  787. [nextValue <= stop]
  788. whileTrue:
  789. [aBlock value: nextValue.
  790. nextValue := nextValue + 1]
  791. ! !
  792. !Number methodsFor: 'printing'!
  793. printOn: aStream
  794. aStream nextPutAll: self asString
  795. !
  796. printShowingDecimalPlaces: placesDesired
  797. <return self.toFixed(placesDesired)>
  798. ! !
  799. !Number methodsFor: 'testing'!
  800. IsImmutable
  801. ^ true
  802. !
  803. even
  804. ^ 0 = (self \\ 2)
  805. !
  806. isNumber
  807. ^true
  808. !
  809. isZero
  810. ^self = 0
  811. !
  812. negative
  813. "Answer whether the receiver is mathematically negative."
  814. ^ self < 0
  815. !
  816. odd
  817. ^ self even not
  818. !
  819. positive
  820. "Answer whether the receiver is positive or equal to 0. (ST-80 protocol)."
  821. ^ self >= 0
  822. ! !
  823. !Number class methodsFor: 'instance creation'!
  824. pi
  825. <return Math.PI>
  826. ! !
  827. Object subclass: #Organizer
  828. instanceVariableNames: ''
  829. package: 'Kernel-Objects'!
  830. !Organizer methodsFor: 'accessing'!
  831. addElement: anObject
  832. <self.elements.addElement(anObject)>
  833. !
  834. elements
  835. ^ (self basicAt: 'elements') copy
  836. !
  837. removeElement: anObject
  838. <self.elements.removeElement(anObject)>
  839. ! !
  840. Organizer subclass: #ClassOrganizer
  841. instanceVariableNames: ''
  842. package: 'Kernel-Objects'!
  843. !ClassOrganizer methodsFor: 'accessing'!
  844. addElement: aString
  845. super addElement: aString.
  846. SystemAnnouncer current announce: (ProtocolAdded new
  847. protocol: aString;
  848. theClass: self theClass;
  849. yourself)
  850. !
  851. removeElement: aString
  852. super removeElement: aString.
  853. SystemAnnouncer current announce: (ProtocolRemoved new
  854. protocol: aString;
  855. theClass: self theClass;
  856. yourself)
  857. !
  858. theClass
  859. < return self.theClass >
  860. ! !
  861. Organizer subclass: #PackageOrganizer
  862. instanceVariableNames: ''
  863. package: 'Kernel-Objects'!
  864. Object subclass: #Package
  865. instanceVariableNames: 'commitPathJs commitPathSt'
  866. package: 'Kernel-Objects'!
  867. !Package commentStamp!
  868. 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.
  869. 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.
  870. Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
  871. Smalltalk current packageAt: 'Kernel'
  872. ...but you can also use:
  873. Package named: 'Kernel'
  874. 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
  875. 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
  876. String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.
  877. You can fetch a package from the server:
  878. Package fetch: 'Additional-Examples'!
  879. !Package methodsFor: 'accessing'!
  880. commitPathJs
  881. ^ commitPathJs ifNil: [self class defaultCommitPathJs]
  882. !
  883. commitPathJs: aString
  884. commitPathJs := aString
  885. !
  886. commitPathSt
  887. ^ commitPathSt ifNil: [self class defaultCommitPathSt]
  888. !
  889. commitPathSt: aString
  890. commitPathSt := aString
  891. !
  892. name
  893. <return self.pkgName>
  894. !
  895. name: aString
  896. <self.pkgName = aString>
  897. !
  898. organization
  899. ^ self basicAt: 'organization'
  900. ! !
  901. !Package methodsFor: 'classes'!
  902. classes
  903. ^ self organization elements
  904. !
  905. setupClasses
  906. self classes
  907. do: [ :each | ClassBuilder new setupClass: each ];
  908. do: [ :each | each initialize ]
  909. !
  910. sortedClasses
  911. "Answer all classes in the receiver, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)."
  912. ^self class sortedClasses: self classes
  913. ! !
  914. !Package methodsFor: 'printing'!
  915. printOn: aStream
  916. super printOn: aStream.
  917. aStream
  918. nextPutAll: ' (';
  919. nextPutAll: self name;
  920. nextPutAll: ')'
  921. ! !
  922. !Package methodsFor: 'testing'!
  923. isPackage
  924. ^ true
  925. ! !
  926. Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
  927. !Package class methodsFor: 'accessing'!
  928. named: aPackageName
  929. ^Smalltalk current packageAt: aPackageName
  930. !
  931. named: aPackageName ifAbsent: aBlock
  932. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  933. ! !
  934. !Package class methodsFor: 'commit paths'!
  935. commitPathsFromLoader
  936. <
  937. var commitPath = typeof amber !!== 'undefined' && amber.commitPath;
  938. if (!!commitPath) return;
  939. if (commitPath.js) self._defaultCommitPathJs_(commitPath.js);
  940. if (commitPath.st) self._defaultCommitPathSt_(commitPath.st);
  941. >
  942. !
  943. defaultCommitPathJs
  944. ^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']
  945. !
  946. defaultCommitPathJs: aString
  947. defaultCommitPathJs := aString
  948. !
  949. defaultCommitPathSt
  950. ^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']
  951. !
  952. defaultCommitPathSt: aString
  953. defaultCommitPathSt := aString
  954. !
  955. resetCommitPaths
  956. defaultCommitPathJs := nil.
  957. defaultCommitPathSt := nil.
  958. ! !
  959. !Package class methodsFor: 'initialization'!
  960. initialize
  961. super initialize.
  962. self commitPathsFromLoader
  963. ! !
  964. !Package class methodsFor: 'loading-storing'!
  965. load: aPackageName
  966. self load: aPackageName prefix: self defaultCommitPathJs, '/'
  967. !
  968. load: aPackageName prefix: aPrefix
  969. jQuery
  970. getScript: (aPrefix , aPackageName , '.js')
  971. onSuccess: [
  972. (Package named: aPackageName) setupClasses ]
  973. ! !
  974. !Package class methodsFor: 'sorting'!
  975. sortedClasses: classes
  976. "Answer classes, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)"
  977. | children others nodes expandedClasses |
  978. children := #().
  979. others := #().
  980. classes do: [:each |
  981. (classes includes: each superclass)
  982. ifFalse: [children add: each]
  983. ifTrue: [others add: each]].
  984. nodes := children collect: [:each |
  985. ClassSorterNode on: each classes: others level: 0].
  986. nodes := nodes sorted: [:a :b | a theClass name <= b theClass name ].
  987. expandedClasses := Array new.
  988. nodes do: [:aNode |
  989. aNode traverseClassesWith: expandedClasses].
  990. ^expandedClasses
  991. ! !
  992. Object subclass: #Point
  993. instanceVariableNames: 'x y'
  994. package: 'Kernel-Objects'!
  995. !Point commentStamp!
  996. A `Point` represents an x-y pair of numbers usually designating a geometric coordinate.
  997. Points are traditionally created using the binary `#@` message to a number:
  998. 100@120
  999. Points can then be arithmetically manipulated:
  1000. 100@100 + (10@10)
  1001. ...or for example:
  1002. (100@100) * 2
  1003. **NOTE:** Creating a Point with a negative y-value will need a space after `@` in order to avoid a parsing error:
  1004. 100@ -100 "but 100@-100 would not parse"
  1005. Amber does not have much behavior in this class out-of-the-box.!
  1006. !Point methodsFor: 'accessing'!
  1007. x
  1008. ^x
  1009. !
  1010. x: aNumber
  1011. x := aNumber
  1012. !
  1013. y
  1014. ^y
  1015. !
  1016. y: aNumber
  1017. y := aNumber
  1018. ! !
  1019. !Point methodsFor: 'arithmetic'!
  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. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  1031. !
  1032. = aPoint
  1033. ^aPoint class = self class and: [
  1034. (aPoint x = self x) & (aPoint y = self y)]
  1035. ! !
  1036. !Point methodsFor: 'converting'!
  1037. asPoint
  1038. ^self
  1039. ! !
  1040. !Point methodsFor: 'printing'!
  1041. printOn: aStream
  1042. "Print receiver in classic x@y notation."
  1043. x printOn: aStream.
  1044. aStream nextPutAll: '@'.
  1045. (y notNil and: [y negative]) ifTrue: [
  1046. "Avoid ambiguous @- construct"
  1047. aStream space ].
  1048. y printOn: aStream
  1049. ! !
  1050. !Point methodsFor: 'transforming'!
  1051. translateBy: delta
  1052. "Answer a Point translated by delta (an instance of Point)."
  1053. ^(delta x + x) @ (delta y + y)
  1054. ! !
  1055. !Point class methodsFor: 'instance creation'!
  1056. x: aNumber y: anotherNumber
  1057. ^self new
  1058. x: aNumber;
  1059. y: anotherNumber;
  1060. yourself
  1061. ! !
  1062. Object subclass: #Random
  1063. instanceVariableNames: ''
  1064. package: 'Kernel-Objects'!
  1065. !Random commentStamp!
  1066. `Random` is a random number generator and is implemented as a trivial wrapper around javascript `Math.random()` and is used like this:
  1067. Random new next
  1068. 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`
  1069. 10 atRandom
  1070. ...and if you want a random number in a specific interval this also works:
  1071. (3 to: 7) atRandom
  1072. ...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:
  1073. 5 atRandom + 2
  1074. Since `#atRandom` is implemented in `SequencableCollection` you can easy pick an element at random:
  1075. #('a' 'b' 'c') atRandom
  1076. ...or perhaps a letter from a `String`:
  1077. 'abc' atRandom
  1078. Since Amber does not have Characters this will return a `String` of length 1 like for example `'b'`.!
  1079. !Random methodsFor: 'accessing'!
  1080. next
  1081. <return Math.random()>
  1082. !
  1083. next: anInteger
  1084. ^(1 to: anInteger) collect: [:each | self next]
  1085. ! !
  1086. Object subclass: #Smalltalk
  1087. instanceVariableNames: ''
  1088. package: 'Kernel-Objects'!
  1089. !Smalltalk commentStamp!
  1090. Smalltalk has only one instance, accessed with `Smalltalk current`.
  1091. It represents the global JavaScript variable `smalltalk` declared in `js/boot.js`.
  1092. The `smalltalk` object holds all class and packages defined in the system.
  1093. ## Classes
  1094. Classes can be accessed using the following methods:
  1095. - `#classes` answers the full list of Smalltalk classes in the system
  1096. - `#at:` answers a specific class of `nil`
  1097. ## Packages
  1098. Packages can be accessed using the following methods:
  1099. - `#packages` answers the full list of packages
  1100. - `#packageAt:` answers a specific class of `nil`
  1101. __note:__ classes and packages are accessed using strings, not symbols
  1102. ## Parsing
  1103. The `#parse:` method is used to parse Smalltalk source code.
  1104. It requires the `Compiler` package and the `js/parser.js` parser file in order to work!
  1105. !Smalltalk methodsFor: 'accessing'!
  1106. at: aString
  1107. <return self[aString]>
  1108. !
  1109. parse: aString
  1110. | result |
  1111. self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
  1112. ^result
  1113. !
  1114. readJSObject: anObject
  1115. <return self.readJSObject(anObject)>
  1116. !
  1117. reservedWords
  1118. "JavaScript reserved words"
  1119. <return self.reservedWords>
  1120. !
  1121. version
  1122. "Answer the version string of Amber"
  1123. ^ '0.10'
  1124. ! !
  1125. !Smalltalk methodsFor: 'classes'!
  1126. classes
  1127. <return self.classes()>
  1128. !
  1129. deleteClass: aClass
  1130. "Deletes a class by deleting its binding only. Use #removeClass instead"
  1131. <self.removeClass(aClass)>
  1132. !
  1133. removeClass: aClass
  1134. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  1135. self deleteClass: aClass.
  1136. SystemAnnouncer current
  1137. announce: (ClassRemoved new
  1138. theClass: aClass;
  1139. yourself)
  1140. ! !
  1141. !Smalltalk methodsFor: 'error handling'!
  1142. asSmalltalkException: anObject
  1143. "A JavaScript exception may be thrown.
  1144. We then need to convert it back to a Smalltalk object"
  1145. ^ ((self isSmalltalkObject: anObject) and: [ anObject isKindOf: Error ])
  1146. ifTrue: [ anObject ]
  1147. ifFalse: [ JavaScriptException on: anObject ]
  1148. !
  1149. parseError: anException parsing: aString
  1150. ^ ParseError new messageText: 'Parse error on line ', (anException basicAt: 'line') ,' column ' , (anException basicAt: 'column') ,' : Unexpected character ', (anException basicAt: 'found')
  1151. ! !
  1152. !Smalltalk methodsFor: 'packages'!
  1153. createPackage: packageName
  1154. "Create and bind a new package with given name and return it."
  1155. <return smalltalk.addPackage(packageName)>
  1156. !
  1157. deletePackage: packageName
  1158. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  1159. To remove a package, use #removePackage instead."
  1160. <delete smalltalk.packages[packageName]>
  1161. !
  1162. packageAt: packageName
  1163. <return self.packages[packageName]>
  1164. !
  1165. packageAt: packageName ifAbsent: aBlock
  1166. ^(self packageAt: packageName) ifNil: aBlock
  1167. !
  1168. packages
  1169. "Return all Package instances in the system."
  1170. <return self.packages.all()>
  1171. !
  1172. pseudoVariableNames
  1173. ^ #('self' 'super' 'nil' 'true' 'false' 'thisContext')
  1174. !
  1175. removePackage: packageName
  1176. "Removes a package and all its classes."
  1177. | pkg |
  1178. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1179. pkg classes do: [:each |
  1180. self removeClass: each].
  1181. self deletePackage: packageName
  1182. !
  1183. renamePackage: packageName to: newName
  1184. "Rename a package."
  1185. | pkg |
  1186. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1187. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  1188. (self basicAt: 'packages') at: newName put: pkg.
  1189. pkg name: newName.
  1190. self deletePackage: packageName.
  1191. ! !
  1192. !Smalltalk methodsFor: 'private'!
  1193. basicParse: aString
  1194. <return smalltalk.parser.parse(aString)>
  1195. !
  1196. createPackage: packageName properties: aDict
  1197. "Needed to import .st files: they begin with this call."
  1198. self deprecatedAPI.
  1199. aDict isEmpty ifFalse: [ self error: 'createPackage:properties: called with nonempty properties' ].
  1200. ^ self createPackage: packageName
  1201. ! !
  1202. !Smalltalk methodsFor: 'testing'!
  1203. isSmalltalkObject: anObject
  1204. "Consider anObject a Smalltalk object if it has a 'klass' property.
  1205. Note that this may be unaccurate"
  1206. <return typeof anObject.klass !!== 'undefined'>
  1207. ! !
  1208. Smalltalk class instanceVariableNames: 'current'!
  1209. !Smalltalk class methodsFor: 'accessing'!
  1210. current
  1211. <return smalltalk>
  1212. ! !
  1213. Object subclass: #Timeout
  1214. instanceVariableNames: 'rawTimeout'
  1215. package: 'Kernel-Objects'!
  1216. !Timeout commentStamp!
  1217. I am wrapping the returns from set{Timeout,Interval}.
  1218. Number suffices in browsers, but node.js returns an object.!
  1219. !Timeout methodsFor: 'accessing'!
  1220. rawTimeout: anObject
  1221. rawTimeout := anObject
  1222. ! !
  1223. !Timeout methodsFor: 'timeout/interval'!
  1224. clearInterval
  1225. <
  1226. var interval = self["@rawTimeout"];
  1227. clearInterval(interval);
  1228. >
  1229. !
  1230. clearTimeout
  1231. <
  1232. var timeout = self["@rawTimeout"];
  1233. clearTimeout(timeout);
  1234. >
  1235. ! !
  1236. !Timeout class methodsFor: 'instance creation'!
  1237. on: anObject
  1238. ^self new rawTimeout: anObject; yourself
  1239. ! !
  1240. Object subclass: #UndefinedObject
  1241. instanceVariableNames: ''
  1242. package: 'Kernel-Objects'!
  1243. !UndefinedObject commentStamp!
  1244. 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.
  1245. `nil` is the Smalltalk representation of the `undefined` JavaScript object.!
  1246. !UndefinedObject methodsFor: 'class creation'!
  1247. subclass: aString instanceVariableNames: anotherString
  1248. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1249. !
  1250. subclass: aString instanceVariableNames: aString2 category: aString3
  1251. "Kept for compatibility."
  1252. self deprecatedAPI.
  1253. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1254. !
  1255. subclass: aString instanceVariableNames: aString2 package: aString3
  1256. ^ClassBuilder new
  1257. superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
  1258. ! !
  1259. !UndefinedObject methodsFor: 'converting'!
  1260. asJSON
  1261. ^null
  1262. ! !
  1263. !UndefinedObject methodsFor: 'copying'!
  1264. deepCopy
  1265. ^self
  1266. !
  1267. shallowCopy
  1268. ^self
  1269. ! !
  1270. !UndefinedObject methodsFor: 'printing'!
  1271. printOn: aStream
  1272. aStream nextPutAll: 'nil'
  1273. ! !
  1274. !UndefinedObject methodsFor: 'testing'!
  1275. ifNil: aBlock
  1276. "inlined in the Compiler"
  1277. ^self ifNil: aBlock ifNotNil: []
  1278. !
  1279. ifNil: aBlock ifNotNil: anotherBlock
  1280. "inlined in the Compiler"
  1281. ^aBlock value
  1282. !
  1283. ifNotNil: aBlock
  1284. "inlined in the Compiler"
  1285. ^self
  1286. !
  1287. ifNotNil: aBlock ifNil: anotherBlock
  1288. "inlined in the Compiler"
  1289. ^anotherBlock value
  1290. !
  1291. isImmutable
  1292. ^ true
  1293. !
  1294. isNil
  1295. ^true
  1296. !
  1297. notNil
  1298. ^false
  1299. ! !
  1300. !UndefinedObject class methodsFor: 'instance creation'!
  1301. new
  1302. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1303. ! !
  1304. !String methodsFor: '*Kernel-Objects'!
  1305. asJavaScriptSelector
  1306. "Return first keyword of the selector, without trailing colon."
  1307. ^self replace: '^([a-zA-Z0-9]*).*$' with: '$1'
  1308. ! !