1
0

Kernel-Objects.st 32 KB

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