2
0

Kernel-Objects.st 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  1. Smalltalk current createPackage: 'Kernel-Objects'!
  2. nil subclass: #Object
  3. instanceVariableNames: ''
  4. package: 'Kernel-Objects'!
  5. !Object commentStamp!
  6. *Object is the root of the Smalltalk class system*. All classes in the system are subclasses of Object.
  7. Object provides default behavior common to all normal objects, such as:
  8. - access
  9. - copying
  10. - comparison
  11. - error handling
  12. - message sending
  13. - reflection
  14. Also utility messages that all objects should respond to are defined here.
  15. Object has no instance variable.
  16. ##Access
  17. Instance variables can be accessed with `#instVarAt:` and `#instVarAt:put:`. `Object >> instanceVariableNames` answers a collection of all instance variable names.
  18. Accessing JavaScript properties of an object is done through `#basicAt:`, `#basicAt:put:` and `basicDelete:`.
  19. ##Copying
  20. Copying an object is handled by `#copy` and `#deepCopy`. The first one performs a shallow copy of the receiver, while the second one performs a deep copy.
  21. The hook method `#postCopy` can be overriden in subclasses to copy fields as necessary to complete the full copy. It will be sent by the copy of the receiver.
  22. ##Comparison
  23. Objects understand equality `#=` and identity `#==` comparison.
  24. ##Error handling
  25. - `#halt` is the typical message to use for inserting breakpoints during debugging.
  26. - `#error:` throws a generic error exception
  27. - `#doesNotUnderstand:` handles the fact that there was an attempt to send the given message to the receiver but the receiver does not understand this message.
  28. Overriding this message can be useful to implement proxies for example.!
  29. !Object methodsFor: 'accessing'!
  30. basicAt: aString
  31. <return self[aString]>
  32. !
  33. basicAt: aString put: anObject
  34. <return self[aString] = anObject>
  35. !
  36. basicDelete: aString
  37. <delete self[aString]; return aString>
  38. !
  39. class
  40. <return self.klass>
  41. !
  42. identityHash
  43. <
  44. var hash=self.identityHash;
  45. if (hash) return hash;
  46. hash=smalltalk.nextId();
  47. Object.defineProperty(self, 'identityHash', {value:hash});
  48. return hash;
  49. >
  50. !
  51. instVarAt: aSymbol
  52. <return self['@'+aSymbol._asString()]>
  53. !
  54. instVarAt: aSymbol put: anObject
  55. <self['@' + aSymbol._asString()] = anObject>
  56. !
  57. size
  58. self error: 'Object not indexable'
  59. !
  60. value
  61. <return self.valueOf()>
  62. !
  63. yourself
  64. ^self
  65. ! !
  66. !Object methodsFor: 'comparing'!
  67. = anObject
  68. ^self == anObject
  69. !
  70. == anObject
  71. ^self identityHash = anObject identityHash
  72. !
  73. ~= anObject
  74. ^(self = anObject) = false
  75. !
  76. ~~ anObject
  77. ^(self == anObject) = false
  78. ! !
  79. !Object methodsFor: 'converting'!
  80. -> anObject
  81. ^Association key: self value: anObject
  82. !
  83. asJSON
  84. | variables |
  85. variables := HashedCollection new.
  86. self class allInstanceVariableNames do: [:each |
  87. variables at: each put: (self instVarAt: each) asJSON].
  88. ^variables
  89. !
  90. asJSONString
  91. ^JSON stringify: self asJSON
  92. !
  93. asJavascript
  94. ^self asString
  95. !
  96. asString
  97. ^self printString
  98. !
  99. test
  100. | a |
  101. a := 1.
  102. self halt
  103. ! !
  104. !Object methodsFor: 'copying'!
  105. copy
  106. ^self shallowCopy postCopy
  107. !
  108. deepCopy
  109. <
  110. var copy = self.klass._new();
  111. for(var i in self) {
  112. if(/^@.+/.test(i)) {
  113. copy[i] = self[i]._deepCopy();
  114. }
  115. }
  116. return copy;
  117. >
  118. !
  119. postCopy
  120. !
  121. shallowCopy
  122. <
  123. var copy = self.klass._new();
  124. for(var i in self) {
  125. if(/^@.+/.test(i)) {
  126. copy[i] = self[i];
  127. }
  128. }
  129. return copy;
  130. >
  131. ! !
  132. !Object methodsFor: 'error handling'!
  133. deprecatedAPI
  134. "Just a simple way to deprecate methods.
  135. #deprecatedAPI is in the 'error handling' protocol even if it doesn't throw an error,
  136. but it could in the future."
  137. console warn: thisContext home asString, ' is deprecated!! (in ', thisContext home home asString, ')'
  138. !
  139. doesNotUnderstand: aMessage
  140. MessageNotUnderstood new
  141. receiver: self;
  142. message: aMessage;
  143. signal
  144. !
  145. error: aString
  146. Error signal: aString
  147. !
  148. halt
  149. self error: 'Halt encountered'
  150. !
  151. shouldNotImplement
  152. self error: 'This method should not be implemented in ', self class name
  153. !
  154. subclassResponsibility
  155. self error: 'This method is a responsibility of a subclass'
  156. !
  157. throw: anObject
  158. < throw anObject >
  159. !
  160. try: aBlock catch: anotherBlock
  161. <try{return aBlock()} catch(e) {return anotherBlock(e)}>
  162. ! !
  163. !Object methodsFor: 'initialization'!
  164. initialize
  165. ! !
  166. !Object methodsFor: 'message handling'!
  167. basicPerform: aSymbol
  168. ^self basicPerform: aSymbol withArguments: #()
  169. !
  170. basicPerform: aSymbol withArguments: aCollection
  171. <return self[aSymbol].apply(self, aCollection);>
  172. !
  173. perform: aSymbol
  174. ^self perform: aSymbol withArguments: #()
  175. !
  176. perform: aSymbol withArguments: aCollection
  177. <return smalltalk.send(self, aSymbol._asSelector(), aCollection)>
  178. ! !
  179. !Object methodsFor: 'printing'!
  180. printOn: aStream
  181. "Append to the aStream, a string representing the receiver."
  182. aStream nextPutAll: (self class name first isVowel
  183. ifTrue: [ 'an ' ]
  184. ifFalse: [ 'a ' ]).
  185. aStream nextPutAll: self class name
  186. !
  187. printString
  188. "Answer a String representation of the receiver."
  189. ^ String streamContents: [ :stream | self printOn: stream ]
  190. ! !
  191. !Object methodsFor: 'streaming'!
  192. putOn: aStream
  193. aStream nextPut: self
  194. ! !
  195. !Object methodsFor: 'testing'!
  196. ifNil: aBlock
  197. "inlined in the Compiler"
  198. ^self
  199. !
  200. ifNil: aBlock ifNotNil: anotherBlock
  201. "inlined in the Compiler"
  202. ^anotherBlock value
  203. !
  204. ifNotNil: aBlock
  205. "inlined in the Compiler"
  206. ^aBlock value
  207. !
  208. ifNotNil: aBlock ifNil: anotherBlock
  209. "inlined in the Compiler"
  210. ^aBlock value
  211. !
  212. isBoolean
  213. ^ false
  214. !
  215. isClass
  216. ^false
  217. !
  218. 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: aSymbol
  512. <return self['@jsObject'][aSymbol._asString()]>
  513. !
  514. at: aSymbol ifAbsent: aBlock
  515. "return the aSymbol property or evaluate aBlock if the property is not defined on the object"
  516. <
  517. var obj = self['@jsObject'],
  518. symbol = aSymbol._asString();
  519. return symbol in obj ? obj[symbol] : aBlock();
  520. >
  521. !
  522. at: aSymbol ifPresent: aBlock
  523. "return the evaluation of aBlock with the value if the property is defined or return nil"
  524. <
  525. var obj = self['@jsObject'],
  526. symbol = aSymbol._asString();
  527. return symbol in obj ? aBlock(obj[symbol]) : nil;
  528. >
  529. !
  530. at: aSymbol ifPresent: aBlock ifAbsent: anotherBlock
  531. "return the evaluation of aBlock with the value if the property is defined
  532. or return value of anotherBlock"
  533. <
  534. var obj = self['@jsObject'],
  535. symbol = aSymbol._asString();
  536. return symbol in obj ? aBlock(obj[symbol]) : anotherBlock();
  537. >
  538. !
  539. at: aSymbol put: anObject
  540. <self['@jsObject'][aSymbol._asString()] = anObject>
  541. !
  542. jsObject
  543. ^jsObject
  544. !
  545. jsObject: aJSObject
  546. jsObject := aJSObject
  547. !
  548. value
  549. "if attribute 'value' exists on the JS object return it,
  550. otherwise return the result of Object>>value."
  551. ^ self at: 'value' ifAbsent: [super value]
  552. ! !
  553. !JSObjectProxy methodsFor: 'enumerating'!
  554. keysAndValuesDo: aBlock
  555. <
  556. var o = self['@jsObject'];
  557. for(var i in o) {
  558. aBlock(i, o[i]);
  559. }
  560. >
  561. ! !
  562. !JSObjectProxy methodsFor: 'printing'!
  563. printOn: aStream
  564. aStream nextPutAll: self jsObject toString
  565. ! !
  566. !JSObjectProxy methodsFor: 'proxy'!
  567. addObjectVariablesTo: aDictionary
  568. <
  569. for(var i in self['@jsObject']) {
  570. aDictionary._at_put_(i, self['@jsObject'][i]);
  571. }
  572. >
  573. !
  574. doesNotUnderstand: aMessage
  575. ^ (self canForwardMessage: aMessage)
  576. ifTrue: [ self forwardMessage: aMessage ]
  577. ifFalse: [ ^ super doesNotUnderstand: aMessage ]
  578. !
  579. forwardMessage: aMessage
  580. <
  581. return smalltalk.send(self._jsObject(), aMessage._selector()._asJavaScriptSelector(), aMessage._arguments());
  582. >
  583. !
  584. inspectOn: anInspector
  585. | variables |
  586. variables := Dictionary new.
  587. variables at: '#self' put: self jsObject.
  588. anInspector setLabel: self printString.
  589. self addObjectVariablesTo: variables.
  590. anInspector setVariables: variables
  591. ! !
  592. !JSObjectProxy methodsFor: 'testing'!
  593. canForwardMessage: aMessage
  594. <
  595. var jsSelector = aMessage._selector()._asJavaScriptSelector();
  596. if(jsSelector in self._jsObject()) {
  597. return true
  598. } else {
  599. return false;
  600. }
  601. >
  602. ! !
  603. !JSObjectProxy class methodsFor: 'instance creation'!
  604. on: aJSObject
  605. ^self new
  606. jsObject: aJSObject;
  607. yourself
  608. ! !
  609. Object subclass: #Number
  610. instanceVariableNames: ''
  611. package: 'Kernel-Objects'!
  612. !Number commentStamp!
  613. Number holds the most general methods for dealing with numbers.
  614. Number is directly mapped to JavaScript Number.
  615. Most arithmetic methods like `#+` `#/` `#-` `#max:` are directly inlined into javascript.
  616. ##Enumerating
  617. A Number can be used to evaluate a Block a fixed number of times:
  618. 5 timesRepeat: [Transcript show: 'This will be printed 5 times'; cr].
  619. 1 to: 5 do: [:aNumber| Transcript show: aNumber asString; cr].
  620. 1 to: 10 by: 2 do: [:aNumber| Transcript show: aNumber asString; cr].!
  621. !Number methodsFor: 'accessing'!
  622. identityHash
  623. ^self asString, 'n'
  624. ! !
  625. !Number methodsFor: 'arithmetic'!
  626. * aNumber
  627. "Inlined in the Compiler"
  628. <return self * aNumber>
  629. !
  630. + aNumber
  631. "Inlined in the Compiler"
  632. <return self + aNumber>
  633. !
  634. - aNumber
  635. "Inlined in the Compiler"
  636. <return self - aNumber>
  637. !
  638. / aNumber
  639. "Inlined in the Compiler"
  640. <return self / aNumber>
  641. !
  642. \\ aNumber
  643. <return self % aNumber>
  644. !
  645. \\ aNumber
  646. <return self % aNumber>
  647. !
  648. abs
  649. <return Math.abs(self);>
  650. !
  651. max: aNumber
  652. <return Math.max(self, aNumber);>
  653. !
  654. min: aNumber
  655. <return Math.min(self, aNumber);>
  656. !
  657. negated
  658. ^0 - self
  659. !
  660. sqrt
  661. <return Math.sqrt(self)>
  662. !
  663. squared
  664. ^self * self
  665. ! !
  666. !Number methodsFor: 'comparing'!
  667. < aNumber
  668. "Inlined in the Compiler"
  669. <return self < aNumber>
  670. !
  671. <= aNumber
  672. "Inlined in the Compiler"
  673. <return self <= aNumber>
  674. !
  675. = aNumber
  676. <
  677. if(!! aNumber._isNumber || !! aNumber._isNumber()) {
  678. return false;
  679. }
  680. return Number(self) == aNumber
  681. >
  682. !
  683. > aNumber
  684. "Inlined in the Compiler"
  685. <return self >> aNumber>
  686. !
  687. >= aNumber
  688. "Inlined in the Compiler"
  689. <return self >>= aNumber>
  690. ! !
  691. !Number methodsFor: 'converting'!
  692. & aNumber
  693. <return self & aNumber>
  694. !
  695. @ aNumber
  696. ^Point x: self y: aNumber
  697. !
  698. asJSON
  699. ^self
  700. !
  701. asJavascript
  702. ^'(', self printString, ')'
  703. !
  704. asPoint
  705. ^Point x: self y: self
  706. !
  707. asString
  708. < return String(self) >
  709. !
  710. atRandom
  711. ^(Random new next * self) truncated + 1
  712. !
  713. rounded
  714. <return Math.round(self);>
  715. !
  716. to: aNumber
  717. | array first last count |
  718. first := self truncated.
  719. last := aNumber truncated + 1.
  720. count := 1.
  721. array := Array new.
  722. (last - first) timesRepeat: [
  723. array at: count put: first.
  724. count := count + 1.
  725. first := first + 1].
  726. ^array
  727. !
  728. to: stop by: step
  729. | array value pos |
  730. value := self.
  731. array := Array new.
  732. pos := 1.
  733. step = 0 ifTrue: [self error: 'step must be non-zero'].
  734. step < 0
  735. ifTrue: [[ value >= stop ] whileTrue: [
  736. array at: pos put: value.
  737. pos := pos + 1.
  738. value := value + step]]
  739. ifFalse: [[ value <= stop ] whileTrue: [
  740. array at: pos put: value.
  741. pos := pos + 1.
  742. value := value + step]].
  743. ^array
  744. !
  745. truncated
  746. <
  747. if(self >>= 0) {
  748. return Math.floor(self);
  749. } else {
  750. return Math.floor(self * (-1)) * (-1);
  751. };
  752. >
  753. !
  754. | aNumber
  755. <return self | aNumber>
  756. ! !
  757. !Number methodsFor: 'copying'!
  758. copy
  759. ^self
  760. !
  761. deepCopy
  762. ^self copy
  763. ! !
  764. !Number methodsFor: 'enumerating'!
  765. timesRepeat: aBlock
  766. | count |
  767. count := 1.
  768. [count > self] whileFalse: [
  769. aBlock value.
  770. count := count + 1]
  771. !
  772. to: stop by: step do: aBlock
  773. | value |
  774. value := self.
  775. step = 0 ifTrue: [self error: 'step must be non-zero'].
  776. step < 0
  777. ifTrue: [[ value >= stop ] whileTrue: [
  778. aBlock value: value.
  779. value := value + step]]
  780. ifFalse: [[ value <= stop ] whileTrue: [
  781. aBlock value: value.
  782. value := value + step]]
  783. !
  784. to: stop do: aBlock
  785. "Evaluate aBlock for each number from self to aNumber."
  786. | nextValue |
  787. nextValue := self.
  788. [nextValue <= stop]
  789. whileTrue:
  790. [aBlock value: nextValue.
  791. nextValue := nextValue + 1]
  792. ! !
  793. !Number methodsFor: 'printing'!
  794. printOn: aStream
  795. aStream nextPutAll: self asString
  796. !
  797. printShowingDecimalPlaces: placesDesired
  798. <return self.toFixed(placesDesired)>
  799. ! !
  800. !Number methodsFor: 'testing'!
  801. IsImmutable
  802. ^ true
  803. !
  804. even
  805. ^ 0 = (self \\ 2)
  806. !
  807. isNumber
  808. ^true
  809. !
  810. isZero
  811. ^self = 0
  812. !
  813. negative
  814. "Answer whether the receiver is mathematically negative."
  815. ^ self < 0
  816. !
  817. odd
  818. ^ self even not
  819. !
  820. positive
  821. "Answer whether the receiver is positive or equal to 0. (ST-80 protocol)."
  822. ^ self >= 0
  823. ! !
  824. !Number class methodsFor: 'instance creation'!
  825. pi
  826. <return Math.PI>
  827. ! !
  828. Object subclass: #Organizer
  829. instanceVariableNames: ''
  830. package: 'Kernel-Objects'!
  831. !Organizer methodsFor: 'accessing'!
  832. addElement: anObject
  833. <self.elements.addElement(anObject)>
  834. !
  835. elements
  836. ^ (self basicAt: 'elements') copy
  837. !
  838. removeElement: anObject
  839. <self.elements.removeElement(anObject)>
  840. ! !
  841. Organizer subclass: #ClassOrganizer
  842. instanceVariableNames: ''
  843. package: 'Kernel-Objects'!
  844. !ClassOrganizer methodsFor: 'accessing'!
  845. addElement: aString
  846. super addElement: aString.
  847. SystemAnnouncer current announce: (ProtocolAdded new
  848. protocol: aString;
  849. theClass: self theClass;
  850. yourself)
  851. !
  852. removeElement: aString
  853. super removeElement: aString.
  854. SystemAnnouncer current announce: (ProtocolRemoved new
  855. protocol: aString;
  856. theClass: self theClass;
  857. yourself)
  858. !
  859. theClass
  860. < return self.theClass >
  861. ! !
  862. Organizer subclass: #PackageOrganizer
  863. instanceVariableNames: ''
  864. package: 'Kernel-Objects'!
  865. Object subclass: #Package
  866. instanceVariableNames: 'commitPathJs commitPathSt'
  867. package: 'Kernel-Objects'!
  868. !Package commentStamp!
  869. 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.
  870. 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.
  871. Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
  872. Smalltalk current packageAt: 'Kernel'
  873. ...but you can also use:
  874. Package named: 'Kernel'
  875. 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
  876. 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
  877. String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.
  878. You can fetch a package from the server:
  879. Package fetch: 'Additional-Examples'!
  880. !Package methodsFor: 'accessing'!
  881. commitPathJs
  882. ^ commitPathJs ifNil: [self class defaultCommitPathJs]
  883. !
  884. commitPathJs: aString
  885. commitPathJs := aString
  886. !
  887. commitPathSt
  888. ^ commitPathSt ifNil: [self class defaultCommitPathSt]
  889. !
  890. commitPathSt: aString
  891. commitPathSt := aString
  892. !
  893. dependencies
  894. ^self propertyAt: 'dependencies' ifAbsent: [#()]
  895. !
  896. dependencies: anArray
  897. ^self propertyAt: 'dependencies' put: anArray
  898. !
  899. name
  900. <return self.pkgName>
  901. !
  902. name: aString
  903. <self.pkgName = aString>
  904. !
  905. organization
  906. ^ self basicAt: 'organization'
  907. !
  908. properties
  909. ^Smalltalk current readJSObject: (self basicAt: 'properties')
  910. ! !
  911. !Package methodsFor: 'classes'!
  912. classes
  913. ^ self organization elements
  914. !
  915. setupClasses
  916. self classes
  917. do: [ :each | ClassBuilder new setupClass: each ];
  918. do: [ :each | each initialize ]
  919. !
  920. sortedClasses
  921. "Answer all classes in the receiver, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)."
  922. ^self class sortedClasses: self classes
  923. ! !
  924. !Package methodsFor: 'printing'!
  925. printOn: aStream
  926. super printOn: aStream.
  927. aStream
  928. nextPutAll: ' (';
  929. nextPutAll: self name;
  930. nextPutAll: ')'
  931. ! !
  932. !Package methodsFor: 'private'!
  933. jsProperties
  934. <return self.properties>
  935. !
  936. jsProperties: aJSObject
  937. <return self.properties = aJSObject>
  938. !
  939. propertiesAsJSON
  940. <return JSON.stringify(self.properties)>
  941. ! !
  942. !Package methodsFor: 'properties'!
  943. propertyAt: key
  944. <return self.properties[key]>
  945. !
  946. propertyAt: key ifAbsent: block
  947. ^(self propertyAt: key) ifNil: [block value]
  948. !
  949. propertyAt: key put: value
  950. <return self.properties[key] = value>
  951. ! !
  952. Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
  953. !Package class methodsFor: 'accessing'!
  954. named: aPackageName
  955. ^Smalltalk current packageAt: aPackageName
  956. !
  957. named: aPackageName ifAbsent: aBlock
  958. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  959. ! !
  960. !Package class methodsFor: 'commit paths'!
  961. commitPathsFromLoader
  962. <
  963. var cp = typeof amber !!== 'undefined' && amber.commitPath;
  964. if (!!cp) return;
  965. if (cp.js) self._defaultCommitPathJs_(cp.js);
  966. if (cp.st) self._defaultCommitPathSt_(cp.st);
  967. >
  968. !
  969. defaultCommitPathJs
  970. ^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']
  971. !
  972. defaultCommitPathJs: aString
  973. defaultCommitPathJs := aString
  974. !
  975. defaultCommitPathSt
  976. ^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']
  977. !
  978. defaultCommitPathSt: aString
  979. defaultCommitPathSt := aString
  980. !
  981. resetCommitPaths
  982. defaultCommitPathJs := nil.
  983. defaultCommitPathSt := nil.
  984. ! !
  985. !Package class methodsFor: 'initialization'!
  986. initialize
  987. super initialize.
  988. self commitPathsFromLoader
  989. ! !
  990. !Package class methodsFor: 'loading-storing'!
  991. fetch: aPackageName
  992. self fetch: aPackageName prefix: self defaultCommitPathJs, '/'
  993. !
  994. fetch: aPackageName prefix: aPrefix
  995. jQuery
  996. getScript: (aPrefix , aPackageName , '.js')
  997. onSuccess: [
  998. (Package named: aPackageName) setupClasses ]
  999. ! !
  1000. !Package class methodsFor: 'sorting'!
  1001. sortedClasses: classes
  1002. "Answer classes, sorted by superclass/subclasses and by class name for common subclasses (Issue #143)"
  1003. | children others nodes expandedClasses |
  1004. children := #().
  1005. others := #().
  1006. classes do: [:each |
  1007. (classes includes: each superclass)
  1008. ifFalse: [children add: each]
  1009. ifTrue: [others add: each]].
  1010. nodes := children collect: [:each |
  1011. ClassSorterNode on: each classes: others level: 0].
  1012. nodes := nodes sorted: [:a :b | a theClass name <= b theClass name ].
  1013. expandedClasses := Array new.
  1014. nodes do: [:aNode |
  1015. aNode traverseClassesWith: expandedClasses].
  1016. ^expandedClasses
  1017. ! !
  1018. Object subclass: #Point
  1019. instanceVariableNames: 'x y'
  1020. package: 'Kernel-Objects'!
  1021. !Point commentStamp!
  1022. A `Point` represents an x-y pair of numbers usually designating a geometric coordinate.
  1023. Points are traditionally created using the binary `#@` message to a number:
  1024. 100@120
  1025. Points can then be arithmetically manipulated:
  1026. 100@100 + (10@10)
  1027. ...or for example:
  1028. (100@100) * 2
  1029. **NOTE:** Creating a Point with a negative y-value will need a space after `@` in order to avoid a parsing error:
  1030. 100@ -100 "but 100@-100 would not parse"
  1031. Amber does not have much behavior in this class out-of-the-box.!
  1032. !Point methodsFor: 'accessing'!
  1033. x
  1034. ^x
  1035. !
  1036. x: aNumber
  1037. x := aNumber
  1038. !
  1039. y
  1040. ^y
  1041. !
  1042. y: aNumber
  1043. y := aNumber
  1044. ! !
  1045. !Point methodsFor: 'arithmetic'!
  1046. * aPoint
  1047. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  1048. !
  1049. + aPoint
  1050. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  1051. !
  1052. - aPoint
  1053. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  1054. !
  1055. / aPoint
  1056. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  1057. !
  1058. = aPoint
  1059. ^aPoint class = self class and: [
  1060. (aPoint x = self x) & (aPoint y = self y)]
  1061. ! !
  1062. !Point methodsFor: 'converting'!
  1063. asPoint
  1064. ^self
  1065. ! !
  1066. !Point methodsFor: 'printing'!
  1067. printOn: aStream
  1068. "Print receiver in classic x@y notation."
  1069. x printOn: aStream.
  1070. aStream nextPutAll: '@'.
  1071. (y notNil and: [y negative]) ifTrue: [
  1072. "Avoid ambiguous @- construct"
  1073. aStream space ].
  1074. y printOn: aStream
  1075. ! !
  1076. !Point methodsFor: 'transforming'!
  1077. translateBy: delta
  1078. "Answer a Point translated by delta (an instance of Point)."
  1079. ^(delta x + x) @ (delta y + y)
  1080. ! !
  1081. !Point class methodsFor: 'instance creation'!
  1082. x: aNumber y: anotherNumber
  1083. ^self new
  1084. x: aNumber;
  1085. y: anotherNumber;
  1086. yourself
  1087. ! !
  1088. Object subclass: #Random
  1089. instanceVariableNames: ''
  1090. package: 'Kernel-Objects'!
  1091. !Random commentStamp!
  1092. `Random` is a random number generator and is implemented as a trivial wrapper around javascript `Math.random()` and is used like this:
  1093. Random new next
  1094. 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`
  1095. 10 atRandom
  1096. ...and if you want a random number in a specific interval this also works:
  1097. (3 to: 7) atRandom
  1098. ...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:
  1099. 5 atRandom + 2
  1100. Since `#atRandom` is implemented in `SequencableCollection` you can easy pick an element at random:
  1101. #('a' 'b' 'c') atRandom
  1102. ...or perhaps a letter from a `String`:
  1103. 'abc' atRandom
  1104. Since Amber does not have Characters this will return a `String` of length 1 like for example `'b'`.!
  1105. !Random methodsFor: 'accessing'!
  1106. next
  1107. <return Math.random()>
  1108. !
  1109. next: anInteger
  1110. ^(1 to: anInteger) collect: [:each | self next]
  1111. ! !
  1112. Object subclass: #Smalltalk
  1113. instanceVariableNames: ''
  1114. package: 'Kernel-Objects'!
  1115. !Smalltalk commentStamp!
  1116. Smalltalk has only one instance, accessed with `Smalltalk current`.
  1117. It represents the global JavaScript variable `smalltalk` declared in `js/boot.js`.
  1118. The `smalltalk` object holds all class and packages defined in the system.
  1119. ## Classes
  1120. Classes can be accessed using the following methods:
  1121. - `#classes` answers the full list of Smalltalk classes in the system
  1122. - `#at:` answers a specific class of `nil`
  1123. ## Packages
  1124. Packages can be accessed using the following methods:
  1125. - `#packages` answers the full list of packages
  1126. - `#packageAt:` answers a specific class of `nil`
  1127. __note:__ classes and packages are accessed using strings, not symbols
  1128. ## Parsing
  1129. The `#parse:` method is used to parse Smalltalk source code.
  1130. It requires the `Compiler` package and the `js/parser.js` parser file in order to work!
  1131. !Smalltalk methodsFor: 'accessing'!
  1132. at: aSymbol
  1133. <return self[aSymbol._asString()]>
  1134. !
  1135. parse: aString
  1136. | result |
  1137. self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
  1138. ^result
  1139. !
  1140. readJSObject: anObject
  1141. <return self.readJSObject(anObject)>
  1142. !
  1143. reservedWords
  1144. "JavaScript reserved words"
  1145. <return self.reservedWords>
  1146. !
  1147. version
  1148. "Answer the version string of Amber"
  1149. ^ '0.10'
  1150. ! !
  1151. !Smalltalk methodsFor: 'classes'!
  1152. classes
  1153. <return self.classes()>
  1154. !
  1155. deleteClass: aClass
  1156. "Deletes a class by deleting its binding only. Use #removeClass instead"
  1157. <self.removeClass(aClass)>
  1158. !
  1159. removeClass: aClass
  1160. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  1161. self deleteClass: aClass.
  1162. SystemAnnouncer current
  1163. announce: (ClassRemoved new
  1164. theClass: aClass;
  1165. yourself)
  1166. ! !
  1167. !Smalltalk methodsFor: 'error handling'!
  1168. asSmalltalkException: anObject
  1169. "A JavaScript exception may be thrown.
  1170. We then need to convert it back to a Smalltalk object"
  1171. ^ ((self isSmalltalkObject: anObject) and: [ anObject isKindOf: Error ])
  1172. ifTrue: [ anObject ]
  1173. ifFalse: [ JavaScriptException on: anObject ]
  1174. !
  1175. parseError: anException parsing: aString
  1176. ^ ParseError new messageText: 'Parse error on line ', (anException basicAt: 'line') ,' column ' , (anException basicAt: 'column') ,' : Unexpected character ', (anException basicAt: 'found')
  1177. ! !
  1178. !Smalltalk methodsFor: 'packages'!
  1179. createPackage: packageName
  1180. "Create and bind a new package with given name and return it."
  1181. <return smalltalk.addPackage(packageName)>
  1182. !
  1183. deletePackage: packageName
  1184. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  1185. To remove a package, use #removePackage instead."
  1186. <delete smalltalk.packages[packageName]>
  1187. !
  1188. packageAt: packageName
  1189. <return self.packages[packageName]>
  1190. !
  1191. packageAt: packageName ifAbsent: aBlock
  1192. ^(self packageAt: packageName) ifNil: aBlock
  1193. !
  1194. packages
  1195. "Return all Package instances in the system."
  1196. <return self.packages.all()>
  1197. !
  1198. pseudoVariableNames
  1199. ^ #('self' 'super' 'nil' 'true' 'false' 'thisContext')
  1200. !
  1201. removePackage: packageName
  1202. "Removes a package and all its classes."
  1203. | pkg |
  1204. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1205. pkg classes do: [:each |
  1206. self removeClass: each].
  1207. self deletePackage: packageName
  1208. !
  1209. renamePackage: packageName to: newName
  1210. "Rename a package."
  1211. | pkg |
  1212. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  1213. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  1214. (self basicAt: 'packages') at: newName put: pkg.
  1215. pkg name: newName.
  1216. self deletePackage: packageName.
  1217. ! !
  1218. !Smalltalk methodsFor: 'private'!
  1219. basicParse: aString
  1220. <return smalltalk.parser.parse(aString)>
  1221. !
  1222. createPackage: packageName properties: aDict
  1223. "Needed to import .st files: they begin with this call."
  1224. self deprecatedAPI.
  1225. aDict isEmpty ifFalse: [ self error: 'createPackage:properties: called with nonempty properties' ].
  1226. ^ self createPackage: packageName
  1227. ! !
  1228. !Smalltalk methodsFor: 'testing'!
  1229. isSmalltalkObject: anObject
  1230. "Consider anObject a Smalltalk object if it has a 'klass' property.
  1231. Note that this may be unaccurate"
  1232. <return typeof anObject.klass !!== 'undefined'>
  1233. ! !
  1234. Smalltalk class instanceVariableNames: 'current'!
  1235. !Smalltalk class methodsFor: 'accessing'!
  1236. current
  1237. <return smalltalk>
  1238. ! !
  1239. Object subclass: #Timeout
  1240. instanceVariableNames: 'rawTimeout'
  1241. package: 'Kernel-Objects'!
  1242. !Timeout commentStamp!
  1243. I am wrapping the returns from set{Timeout,Interval}.
  1244. Number suffices in browsers, but node.js returns an object.!
  1245. !Timeout methodsFor: 'accessing'!
  1246. rawTimeout: anObject
  1247. rawTimeout := anObject
  1248. ! !
  1249. !Timeout methodsFor: 'timeout/interval'!
  1250. clearInterval
  1251. <
  1252. var interval = self["@rawTimeout"];
  1253. clearInterval(interval);
  1254. >
  1255. !
  1256. clearTimeout
  1257. <
  1258. var timeout = self["@rawTimeout"];
  1259. clearTimeout(timeout);
  1260. >
  1261. ! !
  1262. !Timeout class methodsFor: 'instance creation'!
  1263. on: anObject
  1264. ^self new rawTimeout: anObject; yourself
  1265. ! !
  1266. Object subclass: #UndefinedObject
  1267. instanceVariableNames: ''
  1268. package: 'Kernel-Objects'!
  1269. !UndefinedObject commentStamp!
  1270. 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.
  1271. `nil` is the Smalltalk representation of the `undefined` JavaScript object.!
  1272. !UndefinedObject methodsFor: 'class creation'!
  1273. subclass: aString instanceVariableNames: anotherString
  1274. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1275. !
  1276. subclass: aString instanceVariableNames: aString2 category: aString3
  1277. "Kept for compatibility."
  1278. self deprecatedAPI.
  1279. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1280. !
  1281. subclass: aString instanceVariableNames: aString2 package: aString3
  1282. ^ClassBuilder new
  1283. superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
  1284. ! !
  1285. !UndefinedObject methodsFor: 'converting'!
  1286. asJSON
  1287. ^null
  1288. ! !
  1289. !UndefinedObject methodsFor: 'copying'!
  1290. deepCopy
  1291. ^self
  1292. !
  1293. shallowCopy
  1294. ^self
  1295. ! !
  1296. !UndefinedObject methodsFor: 'printing'!
  1297. printOn: aStream
  1298. aStream nextPutAll: 'nil'
  1299. ! !
  1300. !UndefinedObject methodsFor: 'testing'!
  1301. ifNil: aBlock
  1302. "inlined in the Compiler"
  1303. ^self ifNil: aBlock ifNotNil: []
  1304. !
  1305. ifNil: aBlock ifNotNil: anotherBlock
  1306. "inlined in the Compiler"
  1307. ^aBlock value
  1308. !
  1309. ifNotNil: aBlock
  1310. "inlined in the Compiler"
  1311. ^self
  1312. !
  1313. ifNotNil: aBlock ifNil: anotherBlock
  1314. "inlined in the Compiler"
  1315. ^anotherBlock value
  1316. !
  1317. isImmutable
  1318. ^ true
  1319. !
  1320. isNil
  1321. ^true
  1322. !
  1323. notNil
  1324. ^false
  1325. ! !
  1326. !UndefinedObject class methodsFor: 'instance creation'!
  1327. new
  1328. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1329. ! !