Kernel-Objects.st 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  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
  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. isImmutable
  219. ^ false
  220. !
  221. isKindOf: aClass
  222. ^(self isMemberOf: aClass)
  223. ifTrue: [true]
  224. ifFalse: [self class inheritsFrom: aClass]
  225. !
  226. isMemberOf: aClass
  227. ^self class = aClass
  228. !
  229. isMetaclass
  230. ^false
  231. !
  232. isNil
  233. ^false
  234. !
  235. isNumber
  236. ^false
  237. !
  238. isParseFailure
  239. ^false
  240. !
  241. isString
  242. ^false
  243. !
  244. isSymbol
  245. ^false
  246. !
  247. notNil
  248. ^self isNil not
  249. !
  250. respondsTo: aSelector
  251. ^self class canUnderstand: aSelector
  252. ! !
  253. !Object class methodsFor: 'initialization'!
  254. initialize
  255. "no op"
  256. ! !
  257. Object subclass: #Boolean
  258. instanceVariableNames: ''
  259. package: 'Kernel-Objects'!
  260. !Boolean commentStamp!
  261. Boolean wraps the JavaScript `Boolean()` constructor. The `true` and `false` objects are the JavaScript boolean objects.
  262. Boolean defines the protocol for logic testing operations and conditional control structures for the logical values.
  263. Boolean instances are weither `true` or `false`.!
  264. !Boolean methodsFor: 'comparing'!
  265. = aBoolean
  266. <
  267. if(!! aBoolean._isBoolean || !! aBoolean._isBoolean()) {
  268. return false;
  269. }
  270. return Boolean(self == true) == aBoolean
  271. >
  272. !
  273. == aBoolean
  274. ^self = aBoolean
  275. ! !
  276. !Boolean methodsFor: 'controlling'!
  277. & aBoolean
  278. <
  279. if(self == true) {
  280. return aBoolean;
  281. } else {
  282. return false;
  283. }
  284. >
  285. !
  286. and: aBlock
  287. ^self = true
  288. ifTrue: aBlock
  289. ifFalse: [false]
  290. !
  291. ifFalse: aBlock
  292. "inlined in the Compiler"
  293. ^self ifTrue: [] ifFalse: aBlock
  294. !
  295. ifFalse: aBlock ifTrue: anotherBlock
  296. "inlined in the Compiler"
  297. ^self ifTrue: anotherBlock ifFalse: aBlock
  298. !
  299. ifTrue: aBlock
  300. "inlined in the Compiler"
  301. ^self ifTrue: aBlock ifFalse: []
  302. !
  303. ifTrue: aBlock ifFalse: anotherBlock
  304. "inlined in the Compiler"
  305. <
  306. if(self == true) {
  307. return aBlock();
  308. } else {
  309. return anotherBlock();
  310. }
  311. >
  312. !
  313. not
  314. ^self = false
  315. !
  316. or: aBlock
  317. ^self = true
  318. ifTrue: [true]
  319. ifFalse: aBlock
  320. !
  321. | aBoolean
  322. <
  323. if(self == true) {
  324. return true;
  325. } else {
  326. return aBoolean;
  327. }
  328. >
  329. ! !
  330. !Boolean methodsFor: 'converting'!
  331. asJSON
  332. ^self
  333. !
  334. asString
  335. < return self.toString() >
  336. ! !
  337. !Boolean methodsFor: 'copying'!
  338. deepCopy
  339. ^self
  340. !
  341. shallowCopy
  342. ^self
  343. ! !
  344. !Boolean methodsFor: 'printing'!
  345. printOn: aStream
  346. aStream nextPutAll: self asString
  347. ! !
  348. !Boolean methodsFor: 'testing'!
  349. isBoolean
  350. ^ true
  351. !
  352. isImmutable
  353. ^ true
  354. ! !
  355. Object subclass: #Date
  356. instanceVariableNames: ''
  357. package: 'Kernel-Objects'!
  358. !Date commentStamp!
  359. The Date class is used to work with dates and times. Therefore `Date today` and `Date now` are both valid in
  360. Amber and answer the same date object.
  361. Date wraps the `Date()` JavaScript constructor, and Smalltalk date objects are JavaScript date objects.!
  362. !Date methodsFor: 'accessing'!
  363. day
  364. ^self dayOfWeek
  365. !
  366. day: aNumber
  367. self dayOfWeek: aNumber
  368. !
  369. dayOfMonth
  370. <return self.getDate()>
  371. !
  372. dayOfMonth: aNumber
  373. <self.setDate(aNumber)>
  374. !
  375. dayOfWeek
  376. <return self.getDay() + 1>
  377. !
  378. dayOfWeek: aNumber
  379. <return self.setDay(aNumber - 1)>
  380. !
  381. hours
  382. <return self.getHours()>
  383. !
  384. hours: aNumber
  385. <self.setHours(aNumber)>
  386. !
  387. milliseconds
  388. <return self.getMilliseconds()>
  389. !
  390. milliseconds: aNumber
  391. <self.setMilliseconds(aNumber)>
  392. !
  393. minutes
  394. <return self.getMinutes()>
  395. !
  396. minutes: aNumber
  397. <self.setMinutes(aNumber)>
  398. !
  399. month
  400. <return self.getMonth() + 1>
  401. !
  402. month: aNumber
  403. <self.setMonth(aNumber - 1)>
  404. !
  405. seconds
  406. <return self.getSeconds()>
  407. !
  408. seconds: aNumber
  409. <self.setSeconds(aNumber)>
  410. !
  411. time
  412. <return self.getTime()>
  413. !
  414. time: aNumber
  415. <self.setTime(aNumber)>
  416. !
  417. year
  418. <return self.getFullYear()>
  419. !
  420. year: aNumber
  421. <self.setFullYear(aNumber)>
  422. ! !
  423. !Date methodsFor: 'arithmetic'!
  424. + aDate
  425. <return self + aDate>
  426. !
  427. - aDate
  428. <return self - aDate>
  429. ! !
  430. !Date methodsFor: 'comparing'!
  431. < aDate
  432. <return self < aDate>
  433. !
  434. <= aDate
  435. <return self <= aDate>
  436. !
  437. > aDate
  438. <return self >> aDate>
  439. !
  440. >= aDate
  441. <return self >>= aDate>
  442. ! !
  443. !Date methodsFor: 'converting'!
  444. asDateString
  445. <return self.toDateString()>
  446. !
  447. asLocaleString
  448. <return self.toLocaleString()>
  449. !
  450. asMilliseconds
  451. ^self time
  452. !
  453. asNumber
  454. ^self asMilliseconds
  455. !
  456. asString
  457. <return self.toString()>
  458. !
  459. asTimeString
  460. <return self.toTimeString()>
  461. ! !
  462. !Date methodsFor: 'printing'!
  463. printOn: aStream
  464. aStream nextPutAll: self asString
  465. ! !
  466. !Date class methodsFor: 'instance creation'!
  467. fromMilliseconds: aNumber
  468. ^self new: aNumber
  469. !
  470. fromSeconds: aNumber
  471. ^self fromMilliseconds: aNumber * 1000
  472. !
  473. fromString: aString
  474. "Example: Date fromString('2011/04/15 00:00:00')"
  475. ^self new: aString
  476. !
  477. millisecondsToRun: aBlock
  478. | t |
  479. t := Date now.
  480. aBlock value.
  481. ^Date now - t
  482. !
  483. new: anObject
  484. <return new Date(anObject)>
  485. !
  486. now
  487. ^self today
  488. !
  489. today
  490. ^self new
  491. ! !
  492. Object subclass: #JSObjectProxy
  493. instanceVariableNames: 'jsObject'
  494. package: 'Kernel-Objects'!
  495. !JSObjectProxy commentStamp!
  496. JSObjectProxy handles sending messages to JavaScript object, therefore accessing JavaScript objects from Amber is transparent.
  497. JSOjbectProxy makes intensive use of `#doesNotUnderstand:`.
  498. ## Examples
  499. JSObjectProxy objects are instanciated by Amber when a Smalltalk message is sent to a JavaScript object.
  500. window alert: 'hello world'.
  501. window inspect.
  502. (window jQuery: 'body') append: 'hello world'
  503. 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.
  504. ## Message conversion rules
  505. - `someUser name` becomes `someUser.name`
  506. - `someUser name: 'John'` becomes `someUser name = "John"`
  507. - `console log: 'hello world'` becomes `console.log('hello world')`
  508. - `(window jQuery: 'foo') css: 'background' color: 'red'` becomes `window.jQuery('foo').css('background', 'red')`
  509. __Note:__ For keyword-based messages, only the first keyword is kept: `window foo: 1 bar: 2` is equivalent to `window foo: 1 baz: 2`.!
  510. !JSObjectProxy methodsFor: 'accessing'!
  511. at: aString
  512. <return self['@jsObject'][aString]>
  513. !
  514. at: aString ifAbsent: aBlock
  515. "return the aString property or evaluate aBlock if the property is not defined on the object"
  516. <
  517. var obj = self['@jsObject'];
  518. return aString in obj ? obj[aString] : aBlock();
  519. >
  520. !
  521. at: aString ifPresent: aBlock
  522. "return the evaluation of aBlock with the value if the property is defined or return nil"
  523. <
  524. var obj = self['@jsObject'];
  525. return aString in obj ? aBlock(obj[aString]) : nil;
  526. >
  527. !
  528. at: aString ifPresent: aBlock ifAbsent: anotherBlock
  529. "return the evaluation of aBlock with the value if the property is defined
  530. or return value of anotherBlock"
  531. <
  532. var obj = self['@jsObject'];
  533. return aString in obj ? aBlock(obj[aString]) : anotherBlock();
  534. >
  535. !
  536. at: aString put: anObject
  537. <self['@jsObject'][aString] = anObject>
  538. !
  539. jsObject
  540. ^jsObject
  541. !
  542. jsObject: aJSObject
  543. jsObject := aJSObject
  544. !
  545. value
  546. "if attribute 'value' exists on the JS object return it,
  547. otherwise return the result of Object>>value."
  548. ^ self
  549. at: 'value'
  550. ifAbsent: [ super value ]
  551. ! !
  552. !JSObjectProxy methodsFor: 'enumerating'!
  553. keysAndValuesDo: aBlock
  554. <
  555. var o = self['@jsObject'];
  556. for(var i in o) {
  557. aBlock(i, o[i]);
  558. }
  559. >
  560. ! !
  561. !JSObjectProxy methodsFor: 'printing'!
  562. printOn: aStream
  563. aStream nextPutAll: self jsObject toString
  564. ! !
  565. !JSObjectProxy methodsFor: 'proxy'!
  566. addObjectVariablesTo: aDictionary
  567. <
  568. for(var i in self['@jsObject']) {
  569. aDictionary._at_put_(i, self['@jsObject'][i]);
  570. }
  571. >
  572. !
  573. doesNotUnderstand: aMessage
  574. ^ (self canForwardMessage: aMessage)
  575. ifTrue: [ self forwardMessage: aMessage ]
  576. ifFalse: [ ^ super doesNotUnderstand: aMessage ]
  577. !
  578. forwardMessage: aMessage
  579. <
  580. return smalltalk.send(self._jsObject(), aMessage._selector()._asJavaScriptSelector(), aMessage._arguments());
  581. >
  582. !
  583. inspectOn: anInspector
  584. | variables |
  585. variables := Dictionary new.
  586. variables at: '#self' put: self jsObject.
  587. anInspector setLabel: self printString.
  588. self addObjectVariablesTo: variables.
  589. anInspector setVariables: variables
  590. ! !
  591. !JSObjectProxy methodsFor: 'testing'!
  592. canForwardMessage: aMessage
  593. <
  594. var jsSelector = aMessage._selector()._asJavaScriptSelector();
  595. if(jsSelector in self._jsObject()) {
  596. return true
  597. } else {
  598. return false;
  599. }
  600. >
  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. dependencies
  890. ^self propertyAt: 'dependencies' ifAbsent: [#()]
  891. !
  892. dependencies: anArray
  893. ^self propertyAt: 'dependencies' put: anArray
  894. !
  895. name
  896. <return self.pkgName>
  897. !
  898. name: aString
  899. <self.pkgName = aString>
  900. !
  901. organization
  902. ^ self basicAt: 'organization'
  903. !
  904. properties
  905. ^Smalltalk current readJSObject: (self basicAt: 'properties')
  906. ! !
  907. !Package methodsFor: 'classes'!
  908. classes
  909. ^ self organization elements
  910. !
  911. setupClasses
  912. self classes
  913. do: [ :each | ClassBuilder new setupClass: each ];
  914. do: [ :each | each initialize ]
  915. !
  916. sortedClasses
  917. "Answer all classes in the receiver, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)."
  918. ^self class sortedClasses: self classes
  919. ! !
  920. !Package methodsFor: 'printing'!
  921. printOn: aStream
  922. super printOn: aStream.
  923. aStream
  924. nextPutAll: ' (';
  925. nextPutAll: self name;
  926. nextPutAll: ')'
  927. ! !
  928. !Package methodsFor: 'private'!
  929. jsProperties
  930. <return self.properties>
  931. !
  932. jsProperties: aJSObject
  933. <return self.properties = aJSObject>
  934. !
  935. propertiesAsJSON
  936. <return JSON.stringify(self.properties)>
  937. ! !
  938. !Package methodsFor: 'properties'!
  939. propertyAt: key
  940. <return self.properties[key]>
  941. !
  942. propertyAt: key ifAbsent: block
  943. ^(self propertyAt: key) ifNil: [block value]
  944. !
  945. propertyAt: key put: value
  946. <return self.properties[key] = value>
  947. ! !
  948. Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
  949. !Package class methodsFor: 'accessing'!
  950. named: aPackageName
  951. ^Smalltalk current packageAt: aPackageName
  952. !
  953. named: aPackageName ifAbsent: aBlock
  954. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  955. ! !
  956. !Package class methodsFor: 'commit paths'!
  957. commitPathsFromLoader
  958. <
  959. var cp = typeof amber !!== 'undefined' && amber.commitPath;
  960. if (!!cp) return;
  961. if (cp.js) self._defaultCommitPathJs_(cp.js);
  962. if (cp.st) self._defaultCommitPathSt_(cp.st);
  963. >
  964. !
  965. defaultCommitPathJs
  966. ^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']
  967. !
  968. defaultCommitPathJs: aString
  969. defaultCommitPathJs := aString
  970. !
  971. defaultCommitPathSt
  972. ^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']
  973. !
  974. defaultCommitPathSt: aString
  975. defaultCommitPathSt := aString
  976. !
  977. resetCommitPaths
  978. defaultCommitPathJs := nil.
  979. defaultCommitPathSt := nil.
  980. ! !
  981. !Package class methodsFor: 'initialization'!
  982. initialize
  983. super initialize.
  984. self commitPathsFromLoader
  985. ! !
  986. !Package class methodsFor: 'loading-storing'!
  987. fetch: aPackageName
  988. self fetch: aPackageName prefix: self defaultCommitPathJs, '/'
  989. !
  990. fetch: aPackageName prefix: aPrefix
  991. jQuery
  992. getScript: (aPrefix , aPackageName , '.js')
  993. onSuccess: [
  994. (Package named: aPackageName) setupClasses ]
  995. ! !
  996. !Package class methodsFor: 'sorting'!
  997. sortedClasses: classes
  998. "Answer classes, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)"
  999. | children others nodes expandedClasses |
  1000. children := #().
  1001. others := #().
  1002. classes do: [:each |
  1003. (classes includes: each superclass)
  1004. ifFalse: [children add: each]
  1005. ifTrue: [others add: each]].
  1006. nodes := children collect: [:each |
  1007. ClassSorterNode on: each classes: others level: 0].
  1008. nodes := nodes sorted: [:a :b | a theClass name <= b theClass name ].
  1009. expandedClasses := Array new.
  1010. nodes do: [:aNode |
  1011. aNode traverseClassesWith: expandedClasses].
  1012. ^expandedClasses
  1013. ! !
  1014. Object subclass: #Point
  1015. instanceVariableNames: 'x y'
  1016. package: 'Kernel-Objects'!
  1017. !Point commentStamp!
  1018. A `Point` represents an x-y pair of numbers usually designating a geometric coordinate.
  1019. Points are traditionally created using the binary `#@` message to a number:
  1020. 100@120
  1021. Points can then be arithmetically manipulated:
  1022. 100@100 + (10@10)
  1023. ...or for example:
  1024. (100@100) * 2
  1025. **NOTE:** Creating a Point with a negative y-value will need a space after `@` in order to avoid a parsing error:
  1026. 100@ -100 "but 100@-100 would not parse"
  1027. Amber does not have much behavior in this class out-of-the-box.!
  1028. !Point methodsFor: 'accessing'!
  1029. x
  1030. ^x
  1031. !
  1032. x: aNumber
  1033. x := aNumber
  1034. !
  1035. y
  1036. ^y
  1037. !
  1038. y: aNumber
  1039. y := aNumber
  1040. ! !
  1041. !Point methodsFor: 'arithmetic'!
  1042. * aPoint
  1043. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  1044. !
  1045. + aPoint
  1046. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  1047. !
  1048. - aPoint
  1049. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  1050. !
  1051. / aPoint
  1052. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  1053. !
  1054. = aPoint
  1055. ^aPoint class = self class and: [
  1056. (aPoint x = self x) & (aPoint y = self y)]
  1057. ! !
  1058. !Point methodsFor: 'converting'!
  1059. asPoint
  1060. ^self
  1061. ! !
  1062. !Point methodsFor: 'printing'!
  1063. printOn: aStream
  1064. "Print receiver in classic x@y notation."
  1065. x printOn: aStream.
  1066. aStream nextPutAll: '@'.
  1067. (y notNil and: [y negative]) ifTrue: [
  1068. "Avoid ambiguous @- construct"
  1069. aStream space ].
  1070. y printOn: aStream
  1071. ! !
  1072. !Point methodsFor: 'transforming'!
  1073. translateBy: delta
  1074. "Answer a Point translated by delta (an instance of Point)."
  1075. ^(delta x + x) @ (delta y + y)
  1076. ! !
  1077. !Point class methodsFor: 'instance creation'!
  1078. x: aNumber y: anotherNumber
  1079. ^self new
  1080. x: aNumber;
  1081. y: anotherNumber;
  1082. yourself
  1083. ! !
  1084. Object subclass: #Random
  1085. instanceVariableNames: ''
  1086. package: 'Kernel-Objects'!
  1087. !Random commentStamp!
  1088. `Random` is a random number generator and is implemented as a trivial wrapper around javascript `Math.random()` and is used like this:
  1089. Random new next
  1090. 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`
  1091. 10 atRandom
  1092. ...and if you want a random number in a specific interval this also works:
  1093. (3 to: 7) atRandom
  1094. ...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:
  1095. 5 atRandom + 2
  1096. Since `#atRandom` is implemented in `SequencableCollection` you can easy pick an element at random:
  1097. #('a' 'b' 'c') atRandom
  1098. ...or perhaps a letter from a `String`:
  1099. 'abc' atRandom
  1100. Since Amber does not have Characters this will return a `String` of length 1 like for example `'b'`.!
  1101. !Random methodsFor: 'accessing'!
  1102. next
  1103. <return Math.random()>
  1104. !
  1105. next: anInteger
  1106. ^(1 to: anInteger) collect: [:each | self next]
  1107. ! !
  1108. Object subclass: #Smalltalk
  1109. instanceVariableNames: ''
  1110. package: 'Kernel-Objects'!
  1111. !Smalltalk commentStamp!
  1112. Smalltalk has only one instance, accessed with `Smalltalk current`.
  1113. It represents the global JavaScript variable `smalltalk` declared in `js/boot.js`.
  1114. The `smalltalk` object holds all class and packages defined in the system.
  1115. ## Classes
  1116. Classes can be accessed using the following methods:
  1117. - `#classes` answers the full list of Smalltalk classes in the system
  1118. - `#at:` answers a specific class of `nil`
  1119. ## Packages
  1120. Packages can be accessed using the following methods:
  1121. - `#packages` answers the full list of packages
  1122. - `#packageAt:` answers a specific class of `nil`
  1123. __note:__ classes and packages are accessed using strings, not symbols
  1124. ## Parsing
  1125. The `#parse:` method is used to parse Smalltalk source code.
  1126. It requires the `Compiler` package and the `js/parser.js` parser file in order to work!
  1127. !Smalltalk methodsFor: 'accessing'!
  1128. at: aString
  1129. <return self[aString]>
  1130. !
  1131. parse: aString
  1132. | result |
  1133. self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
  1134. ^result
  1135. !
  1136. readJSObject: anObject
  1137. <return self.readJSObject(anObject)>
  1138. !
  1139. reservedWords
  1140. "JavaScript reserved words"
  1141. <return self.reservedWords>
  1142. !
  1143. version
  1144. "Answer the version string of Amber"
  1145. ^ '0.10'
  1146. ! !
  1147. !Smalltalk methodsFor: 'classes'!
  1148. classes
  1149. <return self.classes()>
  1150. !
  1151. deleteClass: aClass
  1152. "Deletes a class by deleting its binding only. Use #removeClass instead"
  1153. <self.removeClass(aClass)>
  1154. !
  1155. removeClass: aClass
  1156. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  1157. self deleteClass: aClass.
  1158. SystemAnnouncer current
  1159. announce: (ClassRemoved new
  1160. theClass: aClass;
  1161. yourself)
  1162. ! !
  1163. !Smalltalk methodsFor: 'error handling'!
  1164. asSmalltalkException: anObject
  1165. "A JavaScript exception may be thrown.
  1166. We then need to convert it back to a Smalltalk object"
  1167. ^ ((self isSmalltalkObject: anObject) and: [ anObject isKindOf: Error ])
  1168. ifTrue: [ anObject ]
  1169. ifFalse: [ JavaScriptException on: anObject ]
  1170. !
  1171. parseError: anException parsing: aString
  1172. ^ ParseError new messageText: 'Parse error on line ', (anException basicAt: 'line') ,' column ' , (anException basicAt: 'column') ,' : Unexpected character ', (anException basicAt: 'found')
  1173. ! !
  1174. !Smalltalk methodsFor: 'packages'!
  1175. createPackage: packageName
  1176. "Create and bind a new package with given name and return it."
  1177. <return smalltalk.addPackage(packageName)>
  1178. !
  1179. deletePackage: packageName
  1180. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  1181. To remove a package, use #removePackage instead."
  1182. <delete smalltalk.packages[packageName]>
  1183. !
  1184. packageAt: packageName
  1185. <return self.packages[packageName]>
  1186. !
  1187. packageAt: packageName ifAbsent: aBlock
  1188. ^(self packageAt: packageName) ifNil: aBlock
  1189. !
  1190. packages
  1191. "Return all Package instances in the system."
  1192. <return self.packages.all()>
  1193. !
  1194. pseudoVariableNames
  1195. ^ #('self' 'super' 'nil' 'true' 'false' 'thisContext')
  1196. !
  1197. removePackage: packageName
  1198. "Removes a package and all its classes."
  1199. | pkg |
  1200. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1201. pkg classes do: [:each |
  1202. self removeClass: each].
  1203. self deletePackage: packageName
  1204. !
  1205. renamePackage: packageName to: newName
  1206. "Rename a package."
  1207. | pkg |
  1208. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1209. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  1210. (self basicAt: 'packages') at: newName put: pkg.
  1211. pkg name: newName.
  1212. self deletePackage: packageName.
  1213. ! !
  1214. !Smalltalk methodsFor: 'private'!
  1215. basicParse: aString
  1216. <return smalltalk.parser.parse(aString)>
  1217. !
  1218. createPackage: packageName properties: aDict
  1219. "Needed to import .st files: they begin with this call."
  1220. self deprecatedAPI.
  1221. aDict isEmpty ifFalse: [ self error: 'createPackage:properties: called with nonempty properties' ].
  1222. ^ self createPackage: packageName
  1223. ! !
  1224. !Smalltalk methodsFor: 'testing'!
  1225. isSmalltalkObject: anObject
  1226. "Consider anObject a Smalltalk object if it has a 'klass' property.
  1227. Note that this may be unaccurate"
  1228. <return typeof anObject.klass !!== 'undefined'>
  1229. ! !
  1230. Smalltalk class instanceVariableNames: 'current'!
  1231. !Smalltalk class methodsFor: 'accessing'!
  1232. current
  1233. <return smalltalk>
  1234. ! !
  1235. Object subclass: #Timeout
  1236. instanceVariableNames: 'rawTimeout'
  1237. package: 'Kernel-Objects'!
  1238. !Timeout commentStamp!
  1239. I am wrapping the returns from set{Timeout,Interval}.
  1240. Number suffices in browsers, but node.js returns an object.!
  1241. !Timeout methodsFor: 'accessing'!
  1242. rawTimeout: anObject
  1243. rawTimeout := anObject
  1244. ! !
  1245. !Timeout methodsFor: 'timeout/interval'!
  1246. clearInterval
  1247. <
  1248. var interval = self["@rawTimeout"];
  1249. clearInterval(interval);
  1250. >
  1251. !
  1252. clearTimeout
  1253. <
  1254. var timeout = self["@rawTimeout"];
  1255. clearTimeout(timeout);
  1256. >
  1257. ! !
  1258. !Timeout class methodsFor: 'instance creation'!
  1259. on: anObject
  1260. ^self new rawTimeout: anObject; yourself
  1261. ! !
  1262. Object subclass: #UndefinedObject
  1263. instanceVariableNames: ''
  1264. package: 'Kernel-Objects'!
  1265. !UndefinedObject commentStamp!
  1266. 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.
  1267. `nil` is the Smalltalk representation of the `undefined` JavaScript object.!
  1268. !UndefinedObject methodsFor: 'class creation'!
  1269. subclass: aString instanceVariableNames: anotherString
  1270. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1271. !
  1272. subclass: aString instanceVariableNames: aString2 category: aString3
  1273. "Kept for compatibility."
  1274. self deprecatedAPI.
  1275. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1276. !
  1277. subclass: aString instanceVariableNames: aString2 package: aString3
  1278. ^ClassBuilder new
  1279. superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
  1280. ! !
  1281. !UndefinedObject methodsFor: 'converting'!
  1282. asJSON
  1283. ^null
  1284. ! !
  1285. !UndefinedObject methodsFor: 'copying'!
  1286. deepCopy
  1287. ^self
  1288. !
  1289. shallowCopy
  1290. ^self
  1291. ! !
  1292. !UndefinedObject methodsFor: 'printing'!
  1293. printOn: aStream
  1294. aStream nextPutAll: 'nil'
  1295. ! !
  1296. !UndefinedObject methodsFor: 'testing'!
  1297. ifNil: aBlock
  1298. "inlined in the Compiler"
  1299. ^self ifNil: aBlock ifNotNil: []
  1300. !
  1301. ifNil: aBlock ifNotNil: anotherBlock
  1302. "inlined in the Compiler"
  1303. ^aBlock value
  1304. !
  1305. ifNotNil: aBlock
  1306. "inlined in the Compiler"
  1307. ^self
  1308. !
  1309. ifNotNil: aBlock ifNil: anotherBlock
  1310. "inlined in the Compiler"
  1311. ^anotherBlock value
  1312. !
  1313. isImmutable
  1314. ^ true
  1315. !
  1316. isNil
  1317. ^true
  1318. !
  1319. notNil
  1320. ^false
  1321. ! !
  1322. !UndefinedObject class methodsFor: 'instance creation'!
  1323. new
  1324. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1325. ! !