Kernel-Objects.st 33 KB

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