Kernel-Objects.st 21 KB

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