Kernel-Methods.st 5.9 KB

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