Kernel-Objects.st 32 KB

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