Kernel-Objects.st 20 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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: ''
  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. <return 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. !Package methodsFor: 'classes'!
  340. classes
  341. "We need to do a reverse scan."
  342. ^Smalltalk current classes select: [:c | c package == self]
  343. ! !
  344. !Package methodsFor: 'printing'!
  345. printString
  346. ^self name
  347. ! !
  348. !Package methodsFor: 'private'!
  349. propertiesAsJSON
  350. <return JSON.stringify(self.properties)>
  351. !
  352. jsProperties
  353. <return self.properties>
  354. !
  355. jsProperties: aJSObject
  356. <return self.properties = aJSObject>
  357. ! !
  358. !Package methodsFor: 'properties'!
  359. propertyAt: key
  360. <return self.properties[key]>
  361. !
  362. propertyAt: key put: value
  363. <return self.properties[key] = value>
  364. !
  365. propertyAt: key ifAbsent: block
  366. ^(self propertyAt: key) ifNil: [block value]
  367. ! !
  368. !Package class methodsFor: 'not yet classified'!
  369. named: aPackageName
  370. ^Smalltalk current packageAt: aPackageName
  371. !
  372. named: aPackageName ifAbsent: aBlock
  373. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  374. ! !
  375. Object subclass: #Number
  376. instanceVariableNames: ''
  377. category: 'Kernel-Objects'!
  378. !Number methodsFor: ''!
  379. ! !
  380. !Number methodsFor: 'arithmetic'!
  381. + aNumber
  382. "Inlined in the Compiler"
  383. <return self + aNumber>
  384. !
  385. - aNumber
  386. "Inlined in the Compiler"
  387. <return self - aNumber>
  388. !
  389. * aNumber
  390. "Inlined in the Compiler"
  391. <return self * aNumber>
  392. !
  393. / aNumber
  394. "Inlined in the Compiler"
  395. <return self / aNumber>
  396. !
  397. max: aNumber
  398. <return Math.max(self, aNumber);>
  399. !
  400. min: aNumber
  401. <return Math.min(self, aNumber);>
  402. !
  403. negated
  404. ^0 - self
  405. !
  406. \\ aNumber
  407. <return self % aNumber>
  408. !
  409. sqrt
  410. <return Math.sqrt(self)>
  411. !
  412. squared
  413. ^self * self
  414. ! !
  415. !Number methodsFor: 'comparing'!
  416. = aNumber
  417. aNumber class = self class ifFalse: [^false].
  418. <return Number(self) == aNumber>
  419. !
  420. > aNumber
  421. "Inlined in the Compiler"
  422. <return self >> aNumber>
  423. !
  424. < aNumber
  425. "Inlined in the Compiler"
  426. <return self < aNumber>
  427. !
  428. >= aNumber
  429. "Inlined in the Compiler"
  430. <return self >>= aNumber>
  431. !
  432. <= aNumber
  433. "Inlined in the Compiler"
  434. <return self <= aNumber>
  435. !
  436. == aNumber
  437. aNumber class = self class ifFalse: [^false].
  438. <return Number(self) === Number(aNumber)>
  439. ! !
  440. !Number methodsFor: 'converting'!
  441. rounded
  442. <return Math.round(self);>
  443. !
  444. truncated
  445. |result|
  446. self >= 0
  447. ifTrue: [<result = Math.floor(self);>]
  448. ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
  449. ^ result
  450. !
  451. to: aNumber
  452. | array first last count |
  453. first := self truncated.
  454. last := aNumber truncated + 1.
  455. count := 1.
  456. array := Array new.
  457. (last - first) timesRepeat: [
  458. array at: count put: first.
  459. count := count + 1.
  460. first := first + 1].
  461. ^array
  462. !
  463. asString
  464. ^self printString
  465. !
  466. asJavascript
  467. ^'(', self printString, ')'
  468. !
  469. atRandom
  470. ^(Random new next * self) truncated + 1
  471. !
  472. @ aNumber
  473. ^Point x: self y: aNumber
  474. !
  475. asPoint
  476. ^Point x: self y: self
  477. !
  478. to: stop by: step
  479. | array value pos |
  480. value := self.
  481. array := Array new.
  482. pos := 1.
  483. step = 0 ifTrue: [self error: 'step must be non-zero'].
  484. step < 0
  485. ifTrue: [[ value >= stop ] whileTrue: [
  486. array at: pos put: value.
  487. pos := pos + 1.
  488. value := value + step]]
  489. ifFalse: [[ value <= stop ] whileTrue: [
  490. array at: pos put: value.
  491. pos := pos + 1.
  492. value := value + step]].
  493. ^array
  494. ! !
  495. !Number methodsFor: 'copying'!
  496. deepCopy
  497. ^self copy
  498. !
  499. copy
  500. ^self
  501. ! !
  502. !Number methodsFor: 'enumerating'!
  503. timesRepeat: aBlock
  504. | integer count |
  505. integer := self truncated.
  506. count := 1.
  507. [count > self] whileFalse: [
  508. aBlock value.
  509. count := count + 1]
  510. !
  511. to: stop do: aBlock
  512. "Evaluate aBlock for each number from self to aNumber."
  513. | nextValue |
  514. nextValue := self.
  515. [nextValue <= stop]
  516. whileTrue:
  517. [aBlock value: nextValue.
  518. nextValue := nextValue + 1]
  519. !
  520. to: stop by: step do: aBlock
  521. | value |
  522. value := self.
  523. step = 0 ifTrue: [self error: 'step must be non-zero'].
  524. step < 0
  525. ifTrue: [[ value >= stop ] whileTrue: [
  526. aBlock value: value.
  527. value := value + step]]
  528. ifFalse: [[ value <= stop ] whileTrue: [
  529. aBlock value: value.
  530. value := value + step]]
  531. ! !
  532. !Number methodsFor: 'printing'!
  533. printString
  534. <return String(self)>
  535. !
  536. printShowingDecimalPlaces: placesDesired
  537. <return self.toFixed(placesDesired)>
  538. ! !
  539. !Number methodsFor: 'testing'!
  540. isNumber
  541. ^true
  542. !
  543. even
  544. ^ 0 = (self \\ 2)
  545. !
  546. odd
  547. ^ self even not
  548. ! !
  549. !Number methodsFor: 'timeouts/intervals'!
  550. clearInterval
  551. <clearInterval(Number(self))>
  552. !
  553. clearTimeout
  554. <clearTimeout(Number(self))>
  555. ! !
  556. !Number class methodsFor: 'instance creation'!
  557. pi
  558. <return Math.PI>
  559. ! !
  560. Object subclass: #Boolean
  561. instanceVariableNames: ''
  562. category: 'Kernel-Objects'!
  563. !Boolean methodsFor: 'comparing'!
  564. = aBoolean
  565. aBoolean class = self class ifFalse: [^false].
  566. <return Boolean(self == true) == aBoolean>
  567. !
  568. == aBoolean
  569. aBoolean class = self class ifFalse: [^false].
  570. <return Boolean(self == true) === Boolean(aBoolean == true)>
  571. ! !
  572. !Boolean methodsFor: 'controlling'!
  573. ifTrue: aBlock
  574. "inlined in the Compiler"
  575. ^self ifTrue: aBlock ifFalse: []
  576. !
  577. ifFalse: aBlock
  578. "inlined in the Compiler"
  579. ^self ifTrue: [] ifFalse: aBlock
  580. !
  581. ifFalse: aBlock ifTrue: anotherBlock
  582. "inlined in the Compiler"
  583. ^self ifTrue: anotherBlock ifFalse: aBlock
  584. !
  585. ifTrue: aBlock ifFalse: anotherBlock
  586. "inlined in the Compiler"
  587. <
  588. if(self == true) {
  589. return aBlock();
  590. } else {
  591. return anotherBlock();
  592. }
  593. >
  594. !
  595. and: aBlock
  596. ^self = true
  597. ifTrue: aBlock
  598. ifFalse: [false]
  599. !
  600. or: aBlock
  601. ^self = true
  602. ifTrue: [true]
  603. ifFalse: aBlock
  604. !
  605. not
  606. ^self = false
  607. !
  608. & aBoolean
  609. <
  610. if(self == true) {
  611. return aBoolean;
  612. } else {
  613. return false;
  614. }
  615. >
  616. !
  617. | aBoolean
  618. <
  619. if(self == true) {
  620. return true;
  621. } else {
  622. return aBoolean;
  623. }
  624. >
  625. ! !
  626. !Boolean methodsFor: 'copying'!
  627. shallowCopy
  628. ^self
  629. !
  630. deepCopy
  631. ^self
  632. ! !
  633. !Boolean methodsFor: 'printing'!
  634. printString
  635. <return self.toString()>
  636. ! !
  637. Object subclass: #Date
  638. instanceVariableNames: ''
  639. category: 'Kernel-Objects'!
  640. !Date commentStamp!
  641. The Date class is used to work with dates and times.!
  642. !Date methodsFor: 'accessing'!
  643. year
  644. <return self.getFullYear()>
  645. !
  646. month
  647. <return self.getMonth() + 1>
  648. !
  649. month: aNumber
  650. <self.setMonth(aNumber - 1)>
  651. !
  652. day
  653. ^self dayOfWeek
  654. !
  655. dayOfWeek
  656. <return self.getDay() + 1>
  657. !
  658. dayOfWeek: aNumber
  659. <return self.setDay(aNumber - 1)>
  660. !
  661. day: aNumber
  662. self day: aNumber
  663. !
  664. year: aNumber
  665. <self.setFullYear(aNumber)>
  666. !
  667. dayOfMonth
  668. <return self.getDate()>
  669. !
  670. dayOfMonth: aNumber
  671. <self.setDate(aNumber)>
  672. !
  673. time
  674. <return self.getTime()>
  675. !
  676. time: aNumber
  677. <self.setTime(aNumber)>
  678. !
  679. hours: aNumber
  680. <self.setHours(aNumber)>
  681. !
  682. minutes: aNumber
  683. <self.setMinutes(aNumber)>
  684. !
  685. seconds: aNumber
  686. <self.setSeconds(aNumber)>
  687. !
  688. milliseconds: aNumber
  689. <self.setMilliseconds(aNumber)>
  690. !
  691. hours
  692. <return self.getHours()>
  693. !
  694. minutes
  695. <return self.getMinutes()>
  696. !
  697. seconds
  698. <return self.getSeconds()>
  699. !
  700. milliseconds
  701. <return self.getMilliseconds()>
  702. ! !
  703. !Date methodsFor: 'arithmetic'!
  704. - aDate
  705. <return self - aDate>
  706. !
  707. + aDate
  708. <return self + aDate>
  709. ! !
  710. !Date methodsFor: 'comparing'!
  711. < aDate
  712. <return self < aDate>
  713. !
  714. > aDate
  715. <return self >> aDate>
  716. !
  717. <= aDate
  718. <return self <= aDate>
  719. !
  720. >= aDate
  721. <return self >>= aDate>
  722. ! !
  723. !Date methodsFor: 'converting'!
  724. asString
  725. <return self.toString()>
  726. !
  727. asMilliseconds
  728. ^self time
  729. !
  730. asDateString
  731. <return self.toDateString()>
  732. !
  733. asTimeString
  734. <return self.toTimeString()>
  735. !
  736. asLocaleString
  737. <return self.toLocaleString()>
  738. !
  739. asNumber
  740. ^self asMilliseconds
  741. ! !
  742. !Date methodsFor: 'printing'!
  743. printString
  744. ^self asString
  745. ! !
  746. !Date class methodsFor: 'instance creation'!
  747. new: anObject
  748. <return new Date(anObject)>
  749. !
  750. fromString: aString
  751. "Example: Date fromString('2011/04/15 00:00:00')"
  752. ^self new: aString
  753. !
  754. fromSeconds: aNumber
  755. ^self fromMilliseconds: aNumber * 1000
  756. !
  757. fromMilliseconds: aNumber
  758. ^self new: aNumber
  759. !
  760. today
  761. ^self new
  762. !
  763. now
  764. ^self today
  765. !
  766. millisecondsToRun: aBlock
  767. | t |
  768. t := Date now.
  769. aBlock value.
  770. ^Date now - t
  771. ! !
  772. Object subclass: #UndefinedObject
  773. instanceVariableNames: ''
  774. category: 'Kernel-Objects'!
  775. !UndefinedObject methodsFor: 'class creation'!
  776. subclass: aString instanceVariableNames: anotherString
  777. ^self subclass: aString instanceVariableNames: anotherString package: nil
  778. !
  779. subclass: aString instanceVariableNames: aString2 category: aString3
  780. "Kept for compatibility."
  781. self deprecatedAPI.
  782. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  783. !
  784. subclass: aString instanceVariableNames: aString2 package: aString3
  785. ^ClassBuilder new
  786. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  787. ! !
  788. !UndefinedObject methodsFor: 'copying'!
  789. shallowCopy
  790. ^self
  791. !
  792. deepCopy
  793. ^self
  794. ! !
  795. !UndefinedObject methodsFor: 'printing'!
  796. printString
  797. ^'nil'
  798. ! !
  799. !UndefinedObject methodsFor: 'testing'!
  800. ifNil: aBlock
  801. "inlined in the Compiler"
  802. ^self ifNil: aBlock ifNotNil: []
  803. !
  804. ifNotNil: aBlock
  805. "inlined in the Compiler"
  806. ^self
  807. !
  808. ifNil: aBlock ifNotNil: anotherBlock
  809. "inlined in the Compiler"
  810. ^aBlock value
  811. !
  812. ifNotNil: aBlock ifNil: anotherBlock
  813. "inlined in the Compiler"
  814. ^anotherBlock value
  815. !
  816. isNil
  817. ^true
  818. !
  819. notNil
  820. ^false
  821. ! !
  822. !UndefinedObject class methodsFor: 'instance creation'!
  823. new
  824. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  825. ! !
  826. Object subclass: #Random
  827. instanceVariableNames: ''
  828. category: 'Kernel-Objects'!
  829. !Random methodsFor: 'accessing'!
  830. next
  831. <return Math.random()>
  832. !
  833. next: anInteger
  834. ^(1 to: anInteger) collect: [:each | self next]
  835. ! !
  836. Object subclass: #Point
  837. instanceVariableNames: 'x y'
  838. category: 'Kernel-Objects'!
  839. !Point methodsFor: 'accessing'!
  840. x
  841. ^x
  842. !
  843. y
  844. ^y
  845. !
  846. y: aNumber
  847. y := aNumber
  848. !
  849. x: aNumber
  850. x := aNumber
  851. ! !
  852. !Point methodsFor: 'arithmetic'!
  853. * aPoint
  854. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  855. !
  856. + aPoint
  857. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  858. !
  859. - aPoint
  860. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  861. !
  862. / aPoint
  863. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  864. !
  865. = aPoint
  866. ^aPoint class = self class and: [
  867. (aPoint x = self x) & (aPoint y = self y)]
  868. ! !
  869. !Point methodsFor: 'converting'!
  870. asPoint
  871. ^self
  872. ! !
  873. !Point class methodsFor: 'instance creation'!
  874. x: aNumber y: anotherNumber
  875. ^self new
  876. x: aNumber;
  877. y: anotherNumber;
  878. yourself
  879. ! !
  880. Object subclass: #JSObjectProxy
  881. instanceVariableNames: 'jsObject'
  882. category: 'Kernel-Objects'!
  883. !JSObjectProxy methodsFor: 'accessing'!
  884. jsObject: aJSObject
  885. jsObject := aJSObject
  886. !
  887. jsObject
  888. ^jsObject
  889. !
  890. at: aString
  891. <return self['@jsObject'][aString]>
  892. !
  893. at: aString put: anObject
  894. <self['@jsObject'][aString] = anObject>
  895. ! !
  896. !JSObjectProxy methodsFor: 'proxy'!
  897. printString
  898. ^self jsObject toString
  899. !
  900. inspectOn: anInspector
  901. | variables |
  902. variables := Dictionary new.
  903. variables at: '#self' put: self jsObject.
  904. anInspector setLabel: self printString.
  905. <for(var i in self['@jsObject']) {
  906. variables._at_put_(i, self['@jsObject'][i]);
  907. }>.
  908. anInspector setVariables: variables
  909. !
  910. doesNotUnderstand: aMessage
  911. | obj selector jsSelector arguments |
  912. obj := self jsObject.
  913. selector := aMessage selector.
  914. jsSelector := selector asJavaScriptSelector.
  915. arguments := aMessage arguments.
  916. <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
  917. super doesNotUnderstand: aMessage
  918. ! !
  919. !JSObjectProxy class methodsFor: 'instance creation'!
  920. on: aJSObject
  921. ^self new
  922. jsObject: aJSObject;
  923. yourself
  924. ! !