Kernel-Objects.st 21 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. Smalltalk current createPackage: 'Kernel-Objects' properties: #{}!
  2. nil subclass: #Object
  3. instanceVariableNames: ''
  4. category: 'Kernel-Objects'!
  5. !Object methodsFor: 'accessing'!
  6. yourself
  7. ^self
  8. !
  9. class
  10. <return self.klass>
  11. !
  12. size
  13. self error: 'Object not indexable'
  14. !
  15. instVarAt: aString
  16. <return self['@'+aString]>
  17. !
  18. instVarAt: aString put: anObject
  19. <self['@' + aString] = anObject>
  20. !
  21. basicAt: aString
  22. <return self[aString]>
  23. !
  24. basicAt: aString put: anObject
  25. <return self[aString] = anObject>
  26. !
  27. basicDelete: aString
  28. <delete self[aString]; return aString>
  29. ! !
  30. !Object methodsFor: 'comparing'!
  31. = anObject
  32. ^self == anObject
  33. !
  34. ~= anObject
  35. ^(self = anObject) = false
  36. !
  37. == anObject
  38. <return self === anObject>
  39. !
  40. ~~ anObject
  41. ^(self == anObject) = false
  42. ! !
  43. !Object methodsFor: 'converting'!
  44. -> anObject
  45. ^Association key: self value: anObject
  46. !
  47. asString
  48. ^self printString
  49. !
  50. asJavascript
  51. ^self asString
  52. !
  53. asJSON
  54. ^JSON parse: self asJSONString
  55. !
  56. asJSONString
  57. ^JSON stringify: self
  58. ! !
  59. !Object methodsFor: 'copying'!
  60. copy
  61. ^self shallowCopy postCopy
  62. !
  63. shallowCopy
  64. <
  65. var copy = self.klass._new();
  66. for(var i in self) {
  67. if(/^@.+/.test(i)) {
  68. copy[i] = self[i];
  69. }
  70. }
  71. return copy;
  72. >
  73. !
  74. deepCopy
  75. <
  76. var copy = self.klass._new();
  77. for(var i in self) {
  78. if(/^@.+/.test(i)) {
  79. copy[i] = self[i]._deepCopy();
  80. }
  81. }
  82. return copy;
  83. >
  84. !
  85. postCopy
  86. ! !
  87. !Object methodsFor: 'error handling'!
  88. error: aString
  89. Error signal: aString
  90. !
  91. subclassResponsibility
  92. self error: 'This method is a responsibility of a subclass'
  93. !
  94. shouldNotImplement
  95. self error: 'This method should not be implemented in ', self class name
  96. !
  97. try: aBlock catch: anotherBlock
  98. <try{aBlock()} catch(e) {anotherBlock(e)}>
  99. !
  100. doesNotUnderstand: aMessage
  101. MessageNotUnderstood new
  102. receiver: self;
  103. message: aMessage;
  104. signal
  105. !
  106. halt
  107. self error: 'Halt encountered'
  108. !
  109. deprecatedAPI
  110. "Just a simple way to deprecate methods.
  111. #deprecatedAPI is in the 'error handling' protocol even if it doesn't throw an error,
  112. but it could in the future."
  113. console warn: thisContext home asString, ' is deprecated!! (in ', thisContext home home asString, ')'
  114. ! !
  115. !Object methodsFor: 'initialization'!
  116. initialize
  117. ! !
  118. !Object methodsFor: 'message handling'!
  119. perform: aSymbol
  120. ^self perform: aSymbol withArguments: #()
  121. !
  122. perform: aSymbol withArguments: aCollection
  123. ^self basicPerform: aSymbol asSelector withArguments: aCollection
  124. !
  125. basicPerform: aSymbol
  126. ^self basicPerform: aSymbol withArguments: #()
  127. !
  128. basicPerform: aSymbol withArguments: aCollection
  129. <return self[aSymbol].apply(self, aCollection);>
  130. ! !
  131. !Object methodsFor: 'printing'!
  132. printString
  133. ^'a ', self class name
  134. !
  135. printNl
  136. <console.log(self)>
  137. !
  138. log: aString block: aBlock
  139. | result |
  140. console log: aString, ' time: ', (Date millisecondsToRun: [result := aBlock value]) printString.
  141. ^result
  142. !
  143. storeString
  144. "Answer a String representation of the receiver from which the receiver
  145. can be reconstructed."
  146. ^ String streamContents: [:s | self storeOn: s]
  147. !
  148. storeOn: aStream
  149. aStream nextPutAll: self printString
  150. ! !
  151. !Object methodsFor: 'testing'!
  152. isKindOf: aClass
  153. ^(self isMemberOf: aClass)
  154. ifTrue: [true]
  155. ifFalse: [self class inheritsFrom: aClass]
  156. !
  157. isMemberOf: aClass
  158. ^self class = aClass
  159. !
  160. ifNil: aBlock
  161. "inlined in the Compiler"
  162. ^self
  163. !
  164. ifNil: aBlock ifNotNil: anotherBlock
  165. "inlined in the Compiler"
  166. ^anotherBlock value
  167. !
  168. ifNotNil: aBlock
  169. "inlined in the Compiler"
  170. ^aBlock value
  171. !
  172. ifNotNil: aBlock ifNil: anotherBlock
  173. "inlined in the Compiler"
  174. ^aBlock value
  175. !
  176. isNil
  177. ^false
  178. !
  179. notNil
  180. ^self isNil not
  181. !
  182. isClass
  183. ^false
  184. !
  185. isMetaclass
  186. ^false
  187. !
  188. isNumber
  189. ^false
  190. !
  191. isString
  192. ^false
  193. !
  194. isParseFailure
  195. ^false
  196. ! !
  197. !Object class methodsFor: 'initialization'!
  198. initialize
  199. "no op"
  200. ! !
  201. Object subclass: #Smalltalk
  202. instanceVariableNames: ''
  203. category: 'Kernel-Objects'!
  204. !Smalltalk methodsFor: 'accessing'!
  205. classes
  206. <return self.classes()>
  207. !
  208. at: aString
  209. <return self[aString]>
  210. !
  211. basicParse: aString
  212. <return smalltalk.parser.parse(aString)>
  213. !
  214. parse: aString
  215. | result |
  216. self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
  217. ^result
  218. !
  219. parseError: anException parsing: aString
  220. | row col message lines badLine code |
  221. <row = anException.line;
  222. col = anException.column;
  223. message = anException.message;>.
  224. lines := aString lines.
  225. badLine := lines at: row.
  226. badLine := (badLine copyFrom: 1 to: col - 1), ' ===>', (badLine copyFrom: col to: badLine size).
  227. lines at: row put: badLine.
  228. code := String streamContents: [:s |
  229. lines withIndexDo: [:l :i |
  230. s nextPutAll: i asString, ': ', l, String lf]].
  231. ^ Error new messageText: ('Parse error on line ' , row , ' column ' , col , ' : ' , message , ' Below is code with line numbers and ===> marker inserted:' , String lf, code)
  232. !
  233. reservedWords
  234. "JavaScript reserved words"
  235. <return self.reservedWords>
  236. !
  237. readJSObject: anObject
  238. <return self.readJSObject(anObject)>
  239. ! !
  240. !Smalltalk methodsFor: 'classes'!
  241. removeClass: aClass
  242. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  243. aClass methodDictionary values do: [:each |
  244. aClass removeCompiledMethod: each].
  245. aClass class methodDictionary values do: [:each |
  246. aClass class removeCompiledMethod: each].
  247. self basicDelete: aClass name
  248. ! !
  249. !Smalltalk methodsFor: 'packages'!
  250. packages
  251. "Return all Package instances in the system."
  252. <return self.packages.all()>
  253. !
  254. packageAt: packageName
  255. <return self.packages[packageName]>
  256. !
  257. packageAt: packageName ifAbsent: aBlock
  258. ^(self packageAt: packageName) ifNil: aBlock
  259. !
  260. removePackage: packageName
  261. "Removes a package and all its classes."
  262. | pkg |
  263. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  264. pkg classes do: [:each |
  265. self removeClass: each].
  266. self deletePackage: packageName
  267. !
  268. renamePackage: packageName to: newName
  269. "Rename a package."
  270. | pkg |
  271. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  272. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  273. <smalltalk.packages[newName] = smalltalk.packages[packageName]>.
  274. pkg name: newName.
  275. self deletePackage: packageName.
  276. ! !
  277. !Smalltalk methodsFor: 'private'!
  278. createPackage: packageName
  279. "Create and bind a new package with given name and return it."
  280. <return smalltalk.addPackage(packageName, nil)>
  281. !
  282. deletePackage: packageName
  283. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  284. To remove a package, use #removePackage instead."
  285. <delete smalltalk.packages[packageName]>
  286. !
  287. createPackage: packageName properties: aDict
  288. "Create and bind a new package with given name and return it."
  289. | object |
  290. <object = {};>.
  291. aDict keysAndValuesDo: [:key :value |
  292. <object[key] = value>.
  293. ].
  294. <return smalltalk.addPackage(packageName, object)>
  295. ! !
  296. Smalltalk class instanceVariableNames: 'current'!
  297. !Smalltalk class methodsFor: 'accessing'!
  298. current
  299. <return smalltalk>
  300. ! !
  301. Object subclass: #Package
  302. instanceVariableNames: 'commitPathJs commitPathSt'
  303. category: 'Kernel-Objects'!
  304. !Package commentStamp!
  305. 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.
  306. 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.
  307. Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
  308. Smalltalk current packageAt: 'Kernel'
  309. ...but you can also use:
  310. Package named: 'Kernel'
  311. 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
  312. 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
  313. String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.!
  314. !Package methodsFor: 'accessing'!
  315. name
  316. <return self.pkgName>
  317. !
  318. name: aString
  319. <self.pkgName = aString>
  320. !
  321. dependencies
  322. ^self propertyAt: 'dependencies' ifAbsent: [#()]
  323. !
  324. dependencies: anArray
  325. ^self propertyAt: 'dependencies' put: anArray
  326. !
  327. properties
  328. ^Smalltalk current readJSObject: (self basicAt: 'properties')
  329. !
  330. properties: aDict
  331. "We store it as a javascript object."
  332. | object |
  333. <object = {};>.
  334. aDict keysAndValuesDo: [:key :value |
  335. <object[key] = value>.
  336. ].
  337. <return self.properties = object>
  338. !
  339. commitPathJs
  340. ^ commitPathJs ifNil: [self class defaultCommitPathJs]
  341. !
  342. commitPathJs: aString
  343. commitPathJs := aString
  344. !
  345. commitPathSt
  346. ^ commitPathSt ifNil: [self class defaultCommitPathSt]
  347. !
  348. commitPathSt: aString
  349. commitPathSt := aString
  350. ! !
  351. !Package methodsFor: 'classes'!
  352. classes
  353. "We need to do a reverse scan."
  354. ^Smalltalk current classes select: [:c | c package == self]
  355. ! !
  356. !Package methodsFor: 'printing'!
  357. printString
  358. ^self name
  359. ! !
  360. !Package methodsFor: 'private'!
  361. propertiesAsJSON
  362. <return JSON.stringify(self.properties)>
  363. !
  364. jsProperties
  365. <return self.properties>
  366. !
  367. jsProperties: aJSObject
  368. <return self.properties = aJSObject>
  369. ! !
  370. !Package methodsFor: 'properties'!
  371. propertyAt: key
  372. <return self.properties[key]>
  373. !
  374. propertyAt: key put: value
  375. <return self.properties[key] = value>
  376. !
  377. propertyAt: key ifAbsent: block
  378. ^(self propertyAt: key) ifNil: [block value]
  379. ! !
  380. Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
  381. !Package class methodsFor: 'commit paths'!
  382. defaultCommitPathJs
  383. ^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']
  384. !
  385. defaultCommitPathJs: aString
  386. defaultCommitPathJs := aString
  387. !
  388. defaultCommitPathSt
  389. ^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']
  390. !
  391. defaultCommitPathSt: aString
  392. defaultCommitPathSt := aString
  393. !
  394. resetCommitPaths
  395. defaultCommitPathJs := nil.
  396. defaultCommitPathSt := nil.
  397. ! !
  398. !Package class methodsFor: 'not yet classified'!
  399. named: aPackageName
  400. ^Smalltalk current packageAt: aPackageName
  401. !
  402. named: aPackageName ifAbsent: aBlock
  403. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  404. ! !
  405. Object subclass: #Number
  406. instanceVariableNames: ''
  407. category: 'Kernel-Objects'!
  408. !Number methodsFor: ''!
  409. ! !
  410. !Number methodsFor: 'arithmetic'!
  411. + aNumber
  412. "Inlined in the Compiler"
  413. <return self + aNumber>
  414. !
  415. - aNumber
  416. "Inlined in the Compiler"
  417. <return self - aNumber>
  418. !
  419. * aNumber
  420. "Inlined in the Compiler"
  421. <return self * aNumber>
  422. !
  423. / aNumber
  424. "Inlined in the Compiler"
  425. <return self / aNumber>
  426. !
  427. max: aNumber
  428. <return Math.max(self, aNumber);>
  429. !
  430. min: aNumber
  431. <return Math.min(self, aNumber);>
  432. !
  433. negated
  434. ^0 - self
  435. !
  436. \\ aNumber
  437. <return self % aNumber>
  438. !
  439. sqrt
  440. <return Math.sqrt(self)>
  441. !
  442. squared
  443. ^self * self
  444. ! !
  445. !Number methodsFor: 'comparing'!
  446. = aNumber
  447. aNumber class = self class ifFalse: [^false].
  448. <return Number(self) == aNumber>
  449. !
  450. > aNumber
  451. "Inlined in the Compiler"
  452. <return self >> aNumber>
  453. !
  454. < aNumber
  455. "Inlined in the Compiler"
  456. <return self < aNumber>
  457. !
  458. >= aNumber
  459. "Inlined in the Compiler"
  460. <return self >>= aNumber>
  461. !
  462. <= aNumber
  463. "Inlined in the Compiler"
  464. <return self <= aNumber>
  465. !
  466. == aNumber
  467. aNumber class = self class ifFalse: [^false].
  468. <return Number(self) === Number(aNumber)>
  469. ! !
  470. !Number methodsFor: 'converting'!
  471. rounded
  472. <return Math.round(self);>
  473. !
  474. truncated
  475. |result|
  476. self >= 0
  477. ifTrue: [<result = Math.floor(self);>]
  478. ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
  479. ^ result
  480. !
  481. to: aNumber
  482. | array first last count |
  483. first := self truncated.
  484. last := aNumber truncated + 1.
  485. count := 1.
  486. array := Array new.
  487. (last - first) timesRepeat: [
  488. array at: count put: first.
  489. count := count + 1.
  490. first := first + 1].
  491. ^array
  492. !
  493. asString
  494. ^self printString
  495. !
  496. asJavascript
  497. ^'(', self printString, ')'
  498. !
  499. atRandom
  500. ^(Random new next * self) truncated + 1
  501. !
  502. @ aNumber
  503. ^Point x: self y: aNumber
  504. !
  505. asPoint
  506. ^Point x: self y: self
  507. !
  508. to: stop by: step
  509. | array value pos |
  510. value := self.
  511. array := Array new.
  512. pos := 1.
  513. step = 0 ifTrue: [self error: 'step must be non-zero'].
  514. step < 0
  515. ifTrue: [[ value >= stop ] whileTrue: [
  516. array at: pos put: value.
  517. pos := pos + 1.
  518. value := value + step]]
  519. ifFalse: [[ value <= stop ] whileTrue: [
  520. array at: pos put: value.
  521. pos := pos + 1.
  522. value := value + step]].
  523. ^array
  524. ! !
  525. !Number methodsFor: 'copying'!
  526. deepCopy
  527. ^self copy
  528. !
  529. copy
  530. ^self
  531. ! !
  532. !Number methodsFor: 'enumerating'!
  533. timesRepeat: aBlock
  534. | integer count |
  535. integer := self truncated.
  536. count := 1.
  537. [count > self] whileFalse: [
  538. aBlock value.
  539. count := count + 1]
  540. !
  541. to: stop do: aBlock
  542. "Evaluate aBlock for each number from self to aNumber."
  543. | nextValue |
  544. nextValue := self.
  545. [nextValue <= stop]
  546. whileTrue:
  547. [aBlock value: nextValue.
  548. nextValue := nextValue + 1]
  549. !
  550. to: stop by: step do: aBlock
  551. | value |
  552. value := self.
  553. step = 0 ifTrue: [self error: 'step must be non-zero'].
  554. step < 0
  555. ifTrue: [[ value >= stop ] whileTrue: [
  556. aBlock value: value.
  557. value := value + step]]
  558. ifFalse: [[ value <= stop ] whileTrue: [
  559. aBlock value: value.
  560. value := value + step]]
  561. ! !
  562. !Number methodsFor: 'printing'!
  563. printString
  564. <return String(self)>
  565. !
  566. printShowingDecimalPlaces: placesDesired
  567. <return self.toFixed(placesDesired)>
  568. ! !
  569. !Number methodsFor: 'testing'!
  570. isNumber
  571. ^true
  572. !
  573. even
  574. ^ 0 = (self \\ 2)
  575. !
  576. odd
  577. ^ self even not
  578. ! !
  579. !Number methodsFor: 'timeouts/intervals'!
  580. clearInterval
  581. <clearInterval(Number(self))>
  582. !
  583. clearTimeout
  584. <clearTimeout(Number(self))>
  585. ! !
  586. !Number class methodsFor: 'instance creation'!
  587. pi
  588. <return Math.PI>
  589. ! !
  590. Object subclass: #Boolean
  591. instanceVariableNames: ''
  592. category: 'Kernel-Objects'!
  593. !Boolean methodsFor: 'comparing'!
  594. = aBoolean
  595. aBoolean class = self class ifFalse: [^false].
  596. <return Boolean(self == true) == aBoolean>
  597. !
  598. == aBoolean
  599. aBoolean class = self class ifFalse: [^false].
  600. <return Boolean(self == true) === Boolean(aBoolean == true)>
  601. ! !
  602. !Boolean methodsFor: 'controlling'!
  603. ifTrue: aBlock
  604. "inlined in the Compiler"
  605. ^self ifTrue: aBlock ifFalse: []
  606. !
  607. ifFalse: aBlock
  608. "inlined in the Compiler"
  609. ^self ifTrue: [] ifFalse: aBlock
  610. !
  611. ifFalse: aBlock ifTrue: anotherBlock
  612. "inlined in the Compiler"
  613. ^self ifTrue: anotherBlock ifFalse: aBlock
  614. !
  615. ifTrue: aBlock ifFalse: anotherBlock
  616. "inlined in the Compiler"
  617. <
  618. if(self == true) {
  619. return aBlock();
  620. } else {
  621. return anotherBlock();
  622. }
  623. >
  624. !
  625. and: aBlock
  626. ^self = true
  627. ifTrue: aBlock
  628. ifFalse: [false]
  629. !
  630. or: aBlock
  631. ^self = true
  632. ifTrue: [true]
  633. ifFalse: aBlock
  634. !
  635. not
  636. ^self = false
  637. !
  638. & aBoolean
  639. <
  640. if(self == true) {
  641. return aBoolean;
  642. } else {
  643. return false;
  644. }
  645. >
  646. !
  647. | aBoolean
  648. <
  649. if(self == true) {
  650. return true;
  651. } else {
  652. return aBoolean;
  653. }
  654. >
  655. ! !
  656. !Boolean methodsFor: 'copying'!
  657. shallowCopy
  658. ^self
  659. !
  660. deepCopy
  661. ^self
  662. ! !
  663. !Boolean methodsFor: 'printing'!
  664. printString
  665. <return self.toString()>
  666. ! !
  667. Object subclass: #Date
  668. instanceVariableNames: ''
  669. category: 'Kernel-Objects'!
  670. !Date commentStamp!
  671. The Date class is used to work with dates and times.!
  672. !Date methodsFor: 'accessing'!
  673. year
  674. <return self.getFullYear()>
  675. !
  676. month
  677. <return self.getMonth() + 1>
  678. !
  679. month: aNumber
  680. <self.setMonth(aNumber - 1)>
  681. !
  682. day
  683. ^self dayOfWeek
  684. !
  685. dayOfWeek
  686. <return self.getDay() + 1>
  687. !
  688. dayOfWeek: aNumber
  689. <return self.setDay(aNumber - 1)>
  690. !
  691. day: aNumber
  692. self day: aNumber
  693. !
  694. year: aNumber
  695. <self.setFullYear(aNumber)>
  696. !
  697. dayOfMonth
  698. <return self.getDate()>
  699. !
  700. dayOfMonth: aNumber
  701. <self.setDate(aNumber)>
  702. !
  703. time
  704. <return self.getTime()>
  705. !
  706. time: aNumber
  707. <self.setTime(aNumber)>
  708. !
  709. hours: aNumber
  710. <self.setHours(aNumber)>
  711. !
  712. minutes: aNumber
  713. <self.setMinutes(aNumber)>
  714. !
  715. seconds: aNumber
  716. <self.setSeconds(aNumber)>
  717. !
  718. milliseconds: aNumber
  719. <self.setMilliseconds(aNumber)>
  720. !
  721. hours
  722. <return self.getHours()>
  723. !
  724. minutes
  725. <return self.getMinutes()>
  726. !
  727. seconds
  728. <return self.getSeconds()>
  729. !
  730. milliseconds
  731. <return self.getMilliseconds()>
  732. ! !
  733. !Date methodsFor: 'arithmetic'!
  734. - aDate
  735. <return self - aDate>
  736. !
  737. + aDate
  738. <return self + aDate>
  739. ! !
  740. !Date methodsFor: 'comparing'!
  741. < aDate
  742. <return self < aDate>
  743. !
  744. > aDate
  745. <return self >> aDate>
  746. !
  747. <= aDate
  748. <return self <= aDate>
  749. !
  750. >= aDate
  751. <return self >>= aDate>
  752. ! !
  753. !Date methodsFor: 'converting'!
  754. asString
  755. <return self.toString()>
  756. !
  757. asMilliseconds
  758. ^self time
  759. !
  760. asDateString
  761. <return self.toDateString()>
  762. !
  763. asTimeString
  764. <return self.toTimeString()>
  765. !
  766. asLocaleString
  767. <return self.toLocaleString()>
  768. !
  769. asNumber
  770. ^self asMilliseconds
  771. ! !
  772. !Date methodsFor: 'printing'!
  773. printString
  774. ^self asString
  775. ! !
  776. !Date class methodsFor: 'instance creation'!
  777. new: anObject
  778. <return new Date(anObject)>
  779. !
  780. fromString: aString
  781. "Example: Date fromString('2011/04/15 00:00:00')"
  782. ^self new: aString
  783. !
  784. fromSeconds: aNumber
  785. ^self fromMilliseconds: aNumber * 1000
  786. !
  787. fromMilliseconds: aNumber
  788. ^self new: aNumber
  789. !
  790. today
  791. ^self new
  792. !
  793. now
  794. ^self today
  795. !
  796. millisecondsToRun: aBlock
  797. | t |
  798. t := Date now.
  799. aBlock value.
  800. ^Date now - t
  801. ! !
  802. Object subclass: #UndefinedObject
  803. instanceVariableNames: ''
  804. category: 'Kernel-Objects'!
  805. !UndefinedObject methodsFor: 'class creation'!
  806. subclass: aString instanceVariableNames: anotherString
  807. ^self subclass: aString instanceVariableNames: anotherString package: nil
  808. !
  809. subclass: aString instanceVariableNames: aString2 category: aString3
  810. "Kept for compatibility."
  811. self deprecatedAPI.
  812. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  813. !
  814. subclass: aString instanceVariableNames: aString2 package: aString3
  815. ^ClassBuilder new
  816. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  817. ! !
  818. !UndefinedObject methodsFor: 'copying'!
  819. shallowCopy
  820. ^self
  821. !
  822. deepCopy
  823. ^self
  824. ! !
  825. !UndefinedObject methodsFor: 'printing'!
  826. printString
  827. ^'nil'
  828. ! !
  829. !UndefinedObject methodsFor: 'testing'!
  830. ifNil: aBlock
  831. "inlined in the Compiler"
  832. ^self ifNil: aBlock ifNotNil: []
  833. !
  834. ifNotNil: aBlock
  835. "inlined in the Compiler"
  836. ^self
  837. !
  838. ifNil: aBlock ifNotNil: anotherBlock
  839. "inlined in the Compiler"
  840. ^aBlock value
  841. !
  842. ifNotNil: aBlock ifNil: anotherBlock
  843. "inlined in the Compiler"
  844. ^anotherBlock value
  845. !
  846. isNil
  847. ^true
  848. !
  849. notNil
  850. ^false
  851. ! !
  852. !UndefinedObject class methodsFor: 'instance creation'!
  853. new
  854. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  855. ! !
  856. Object subclass: #Random
  857. instanceVariableNames: ''
  858. category: 'Kernel-Objects'!
  859. !Random methodsFor: 'accessing'!
  860. next
  861. <return Math.random()>
  862. !
  863. next: anInteger
  864. ^(1 to: anInteger) collect: [:each | self next]
  865. ! !
  866. Object subclass: #Point
  867. instanceVariableNames: 'x y'
  868. category: 'Kernel-Objects'!
  869. !Point methodsFor: 'accessing'!
  870. x
  871. ^x
  872. !
  873. y
  874. ^y
  875. !
  876. y: aNumber
  877. y := aNumber
  878. !
  879. x: aNumber
  880. x := aNumber
  881. ! !
  882. !Point methodsFor: 'arithmetic'!
  883. * aPoint
  884. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  885. !
  886. + aPoint
  887. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  888. !
  889. - aPoint
  890. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  891. !
  892. / aPoint
  893. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  894. !
  895. = aPoint
  896. ^aPoint class = self class and: [
  897. (aPoint x = self x) & (aPoint y = self y)]
  898. ! !
  899. !Point methodsFor: 'converting'!
  900. asPoint
  901. ^self
  902. ! !
  903. !Point class methodsFor: 'instance creation'!
  904. x: aNumber y: anotherNumber
  905. ^self new
  906. x: aNumber;
  907. y: anotherNumber;
  908. yourself
  909. ! !
  910. Object subclass: #JSObjectProxy
  911. instanceVariableNames: 'jsObject'
  912. category: 'Kernel-Objects'!
  913. !JSObjectProxy methodsFor: 'accessing'!
  914. jsObject: aJSObject
  915. jsObject := aJSObject
  916. !
  917. jsObject
  918. ^jsObject
  919. !
  920. at: aString
  921. <return self['@jsObject'][aString]>
  922. !
  923. at: aString put: anObject
  924. <self['@jsObject'][aString] = anObject>
  925. ! !
  926. !JSObjectProxy methodsFor: 'proxy'!
  927. printString
  928. ^self jsObject toString
  929. !
  930. inspectOn: anInspector
  931. | variables |
  932. variables := Dictionary new.
  933. variables at: '#self' put: self jsObject.
  934. anInspector setLabel: self printString.
  935. <for(var i in self['@jsObject']) {
  936. variables._at_put_(i, self['@jsObject'][i]);
  937. }>.
  938. anInspector setVariables: variables
  939. !
  940. doesNotUnderstand: aMessage
  941. | obj selector jsSelector arguments |
  942. obj := self jsObject.
  943. selector := aMessage selector.
  944. jsSelector := selector asJavaScriptSelector.
  945. arguments := aMessage arguments.
  946. <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
  947. super doesNotUnderstand: aMessage
  948. ! !
  949. !JSObjectProxy class methodsFor: 'instance creation'!
  950. on: aJSObject
  951. ^self new
  952. jsObject: aJSObject;
  953. yourself
  954. ! !