Kernel-Objects.st 32 KB

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