Kernel-Objects.st 21 KB

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