2
0

Kernel-Objects.st 32 KB

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