1
0

Kernel-Objects.st 22 KB

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