Kernel-Methods.st 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. Smalltalk current createPackage: 'Kernel-Methods' properties: #{}!
  2. Object subclass: #CompiledMethod
  3. instanceVariableNames: ''
  4. category: 'Kernel-Methods'!
  5. !CompiledMethod methodsFor: 'accessing'!
  6. source
  7. ^(self basicAt: 'source') ifNil: ['']
  8. !
  9. source: aString
  10. self basicAt: 'source' put: aString
  11. !
  12. category
  13. ^(self basicAt: 'category') ifNil: ['']
  14. !
  15. category: aString
  16. self basicAt: 'category' put: aString
  17. !
  18. selector
  19. ^self basicAt: 'selector'
  20. !
  21. selector: aString
  22. self basicAt: 'selector' put: aString
  23. !
  24. fn
  25. ^self basicAt: 'fn'
  26. !
  27. fn: aBlock
  28. self basicAt: 'fn' put: aBlock
  29. !
  30. messageSends
  31. ^self basicAt: 'messageSends'
  32. !
  33. methodClass
  34. ^self basicAt: 'methodClass'
  35. !
  36. referencedClasses
  37. ^self basicAt: 'referencedClasses'
  38. !
  39. arguments
  40. <return self.args || []>
  41. ! !
  42. Object subclass: #BlockClosure
  43. instanceVariableNames: ''
  44. category: 'Kernel-Methods'!
  45. !BlockClosure commentStamp!
  46. A BlockClosure is a lexical closure.
  47. The JavaScript representation is a function.
  48. A BlockClosure is evaluated with the #value* methods in the 'evaluating' protocol.!
  49. !BlockClosure methodsFor: 'accessing'!
  50. compiledSource
  51. <return self.toString()>
  52. !
  53. numArgs
  54. <return self.length>
  55. ! !
  56. !BlockClosure methodsFor: 'controlling'!
  57. whileTrue: aBlock
  58. "inlined in the Compiler"
  59. <while(self()) {aBlock()}>
  60. !
  61. whileFalse: aBlock
  62. "inlined in the Compiler"
  63. <while(!!self()) {aBlock()}>
  64. !
  65. whileFalse
  66. "inlined in the Compiler"
  67. self whileFalse: []
  68. !
  69. whileTrue
  70. "inlined in the Compiler"
  71. self whileTrue: []
  72. ! !
  73. !BlockClosure methodsFor: 'error handling'!
  74. on: anErrorClass do: aBlock
  75. ^self try: self catch: [:error |
  76. (error isKindOf: anErrorClass)
  77. ifTrue: [aBlock value: error]
  78. ifFalse: [error signal]]
  79. ! !
  80. !BlockClosure methodsFor: 'evaluating'!
  81. value
  82. "inlined in the Compiler"
  83. <return self();>
  84. !
  85. value: anArg
  86. "inlined in the Compiler"
  87. <return self(anArg);>
  88. !
  89. value: firstArg value: secondArg
  90. "inlined in the Compiler"
  91. <return self(firstArg, secondArg);>
  92. !
  93. value: firstArg value: secondArg value: thirdArg
  94. "inlined in the Compiler"
  95. <return self(firstArg, secondArg, thirdArg);>
  96. !
  97. valueWithPossibleArguments: aCollection
  98. <return self.apply(null, aCollection);>
  99. !
  100. new
  101. "Use the receiver as a JS constructor.
  102. *Do not* use this method to instanciate Smalltalk objects!!"
  103. <return new self()>
  104. !
  105. applyTo: anObject arguments: aCollection
  106. <return self.apply(anObject, aCollection)>
  107. !
  108. timeToRun
  109. "Answer the number of milliseconds taken to execute this block."
  110. ^ Date millisecondsToRun: self
  111. !
  112. ensure: aBlock
  113. | success |
  114. success := false.
  115. ^[self value. success := true. aBlock value]
  116. on: Error
  117. do: [:ex |
  118. success ifFalse: [aBlock value].
  119. ex signal]
  120. !
  121. newValue: anObject
  122. "Use the receiver as a JS constructor.
  123. *Do not* use this method to instanciate Smalltalk objects!!"
  124. <return new self(anObject)>
  125. !
  126. newValue: anObject value: anObject2
  127. "Use the receiver as a JS constructor.
  128. *Do not* use this method to instanciate Smalltalk objects!!"
  129. <return new self(anObject, anObject2)>
  130. !
  131. newValue: anObject value: anObject2 value: anObject3
  132. "Use the receiver as a JS constructor.
  133. *Do not* use this method to instanciate Smalltalk objects!!"
  134. <return new self(anObject, anObject2)>
  135. ! !
  136. !BlockClosure methodsFor: 'timeout/interval'!
  137. valueWithTimeout: aNumber
  138. <return setTimeout(self, aNumber)>
  139. !
  140. valueWithInterval: aNumber
  141. <return setInterval(self, aNumber)>
  142. ! !
  143. Object subclass: #MethodContext
  144. instanceVariableNames: ''
  145. category: 'Kernel-Methods'!
  146. !MethodContext commentStamp!
  147. MethodContext hold all the dynamic state associated with the execution of either a method activation resulting from a message send. That is used to build the call stack while debugging.
  148. MethodContext instances are JavaScript SmalltalkMethodContext objects defined in boot.js
  149. Current limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block.!
  150. !MethodContext methodsFor: 'accessing'!
  151. receiver
  152. <return self.receiver>
  153. !
  154. selector
  155. <return smalltalk.convertSelector(self.selector)>
  156. !
  157. home
  158. <return self.homeContext>
  159. !
  160. temps
  161. <return self.temps>
  162. !
  163. printString
  164. ^super printString, '(', self asString, ')'
  165. !
  166. asString
  167. ^self receiver class printString, ' >> ', self selector
  168. ! !
  169. Object subclass: #Message
  170. instanceVariableNames: 'selector arguments'
  171. category: 'Kernel-Methods'!
  172. !Message commentStamp!
  173. Generally, the system does not use instances of Message for efficiency reasons.
  174. However, when a message is not understood by its receiver, the interpreter will make up an instance of it in order to capture the information involved in an actual message transmission.
  175. This instance is sent it as an argument with the message doesNotUnderstand: to the receiver.
  176. See boot.js, messageNotUnderstood and its counterpart Object>>doesNotUnderstand:!
  177. !Message methodsFor: 'accessing'!
  178. selector
  179. ^selector
  180. !
  181. selector: aString
  182. selector := aString
  183. !
  184. arguments: anArray
  185. arguments := anArray
  186. !
  187. arguments
  188. ^arguments
  189. ! !
  190. !Message methodsFor: 'printing'!
  191. printString
  192. ^ String streamContents: [:aStream|
  193. aStream
  194. nextPutAll: super printString;
  195. nextPutAll: '(';
  196. nextPutAll: selector;
  197. nextPutAll: ')' ]
  198. ! !
  199. !Message class methodsFor: 'instance creation'!
  200. selector: aString arguments: anArray
  201. ^self new
  202. selector: aString;
  203. arguments: anArray;
  204. yourself
  205. ! !