1
0

Kernel-Methods.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. define("amber_core/Kernel-Methods", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st, globals){
  2. smalltalk.addPackage('Kernel-Methods');
  3. smalltalk.packages["Kernel-Methods"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('BlockClosure', globals.Object, [], 'Kernel-Methods');
  5. globals.BlockClosure.comment="I represent a lexical closure.\x0aI am is directly mapped to JavaScript Function.\x0a\x0a## API\x0a\x0a1. Evaluation\x0a\x0a My instances get evaluated with the `#value*` methods in the 'evaluating' protocol.\x0a\x0a Example: ` [ :x | x + 1 ] value: 3 \x22Answers 4\x22 `\x0a\x0a2. Control structures\x0a\x0a Blocks are used (together with `Boolean`) for control structures (methods in the `controlling` protocol).\x0a\x0a Example: `aBlock whileTrue: [ ... ]`\x0a\x0a3. Error handling\x0a\x0a I provide the `#on:do:` method for handling exceptions.\x0a\x0a Example: ` aBlock on: MessageNotUnderstood do: [ :ex | ... ] `";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "applyTo:arguments:",
  9. protocol: 'evaluating',
  10. fn: function (anObject,aCollection){
  11. var self=this;
  12. return self.apply(anObject, aCollection);
  13. return self},
  14. args: ["anObject", "aCollection"],
  15. source: "applyTo: anObject arguments: aCollection\x0a\x09<return self.apply(anObject, aCollection)>",
  16. messageSends: [],
  17. referencedClasses: []
  18. }),
  19. globals.BlockClosure);
  20. smalltalk.addMethod(
  21. smalltalk.method({
  22. selector: "asCompiledMethod:",
  23. protocol: 'converting',
  24. fn: function (aString){
  25. var self=this;
  26. return smalltalk.method({selector:aString, fn:self});;
  27. return self},
  28. args: ["aString"],
  29. source: "asCompiledMethod: aString\x0a\x09<return smalltalk.method({selector:aString, fn:self});>",
  30. messageSends: [],
  31. referencedClasses: []
  32. }),
  33. globals.BlockClosure);
  34. smalltalk.addMethod(
  35. smalltalk.method({
  36. selector: "compiledSource",
  37. protocol: 'accessing',
  38. fn: function (){
  39. var self=this;
  40. return self.toString();
  41. return self},
  42. args: [],
  43. source: "compiledSource\x0a\x09<return self.toString()>",
  44. messageSends: [],
  45. referencedClasses: []
  46. }),
  47. globals.BlockClosure);
  48. smalltalk.addMethod(
  49. smalltalk.method({
  50. selector: "currySelf",
  51. protocol: 'converting',
  52. fn: function (){
  53. var self=this;
  54. return function () {
  55. var args = [ this ];
  56. args.push.apply(args, arguments);
  57. return self.apply(null, args);
  58. }
  59. ;
  60. return self},
  61. args: [],
  62. source: "currySelf\x0a\x09\x22Transforms [ :selfarg :x :y | stcode ] block\x0a\x09which represents JS function (selfarg, x, y, ...) {jscode}\x0a\x09into function (x, y, ...) {jscode} that takes selfarg from 'this'.\x0a\x09IOW, it is usable as JS method and first arg takes the receiver.\x22\x0a\x09\x0a\x09<\x0a\x09\x09return function () {\x0a\x09\x09\x09var args = [ this ];\x0a\x09\x09\x09args.push.apply(args, arguments);\x0a\x09\x09\x09return self.apply(null, args);\x0a\x09\x09}\x0a\x09>",
  63. messageSends: [],
  64. referencedClasses: []
  65. }),
  66. globals.BlockClosure);
  67. smalltalk.addMethod(
  68. smalltalk.method({
  69. selector: "ensure:",
  70. protocol: 'evaluating',
  71. fn: function (aBlock){
  72. var self=this;
  73. try{return self._value()}finally{aBlock._value()};
  74. return self},
  75. args: ["aBlock"],
  76. source: "ensure: aBlock\x0a\x09<try{return self._value()}finally{aBlock._value()}>",
  77. messageSends: [],
  78. referencedClasses: []
  79. }),
  80. globals.BlockClosure);
  81. smalltalk.addMethod(
  82. smalltalk.method({
  83. selector: "fork",
  84. protocol: 'timeout/interval',
  85. fn: function (){
  86. var self=this;
  87. function $ForkPool(){return globals.ForkPool||(typeof ForkPool=="undefined"?nil:ForkPool)}
  88. return smalltalk.withContext(function($ctx1) {
  89. _st(_st($ForkPool())._default())._fork_(self);
  90. return self}, function($ctx1) {$ctx1.fill(self,"fork",{},globals.BlockClosure)})},
  91. args: [],
  92. source: "fork\x0a\x09ForkPool default fork: self",
  93. messageSends: ["fork:", "default"],
  94. referencedClasses: ["ForkPool"]
  95. }),
  96. globals.BlockClosure);
  97. smalltalk.addMethod(
  98. smalltalk.method({
  99. selector: "new",
  100. protocol: 'evaluating',
  101. fn: function (){
  102. var self=this;
  103. return new self();
  104. return self},
  105. args: [],
  106. source: "new\x0a\x09\x22Use the receiver as a JS constructor.\x0a\x09*Do not* use this method to instanciate Smalltalk objects!\x22\x0a\x09<return new self()>",
  107. messageSends: [],
  108. referencedClasses: []
  109. }),
  110. globals.BlockClosure);
  111. smalltalk.addMethod(
  112. smalltalk.method({
  113. selector: "newValue:",
  114. protocol: 'evaluating',
  115. fn: function (anObject){
  116. var self=this;
  117. return smalltalk.withContext(function($ctx1) {
  118. var $1;
  119. $1=self._newWithValues_([anObject]);
  120. return $1;
  121. }, function($ctx1) {$ctx1.fill(self,"newValue:",{anObject:anObject},globals.BlockClosure)})},
  122. args: ["anObject"],
  123. source: "newValue: anObject\x0a\x09^ self newWithValues: { anObject }",
  124. messageSends: ["newWithValues:"],
  125. referencedClasses: []
  126. }),
  127. globals.BlockClosure);
  128. smalltalk.addMethod(
  129. smalltalk.method({
  130. selector: "newValue:value:",
  131. protocol: 'evaluating',
  132. fn: function (anObject,anObject2){
  133. var self=this;
  134. return smalltalk.withContext(function($ctx1) {
  135. var $1;
  136. $1=self._newWithValues_([anObject,anObject2]);
  137. return $1;
  138. }, function($ctx1) {$ctx1.fill(self,"newValue:value:",{anObject:anObject,anObject2:anObject2},globals.BlockClosure)})},
  139. args: ["anObject", "anObject2"],
  140. source: "newValue: anObject value: anObject2\x0a\x09^ self newWithValues: { anObject. anObject2 }.",
  141. messageSends: ["newWithValues:"],
  142. referencedClasses: []
  143. }),
  144. globals.BlockClosure);
  145. smalltalk.addMethod(
  146. smalltalk.method({
  147. selector: "newValue:value:value:",
  148. protocol: 'evaluating',
  149. fn: function (anObject,anObject2,anObject3){
  150. var self=this;
  151. return smalltalk.withContext(function($ctx1) {
  152. var $1;
  153. $1=self._newWithValues_([anObject,anObject2,anObject3]);
  154. return $1;
  155. }, function($ctx1) {$ctx1.fill(self,"newValue:value:value:",{anObject:anObject,anObject2:anObject2,anObject3:anObject3},globals.BlockClosure)})},
  156. args: ["anObject", "anObject2", "anObject3"],
  157. source: "newValue: anObject value: anObject2 value: anObject3\x0a\x09^ self newWithValues: { anObject. anObject2. anObject3 }.",
  158. messageSends: ["newWithValues:"],
  159. referencedClasses: []
  160. }),
  161. globals.BlockClosure);
  162. smalltalk.addMethod(
  163. smalltalk.method({
  164. selector: "newWithValues:",
  165. protocol: 'evaluating',
  166. fn: function (aCollection){
  167. var self=this;
  168. var constructor = function() {};
  169. constructor.prototype = self.prototype;
  170. var object = new constructor;
  171. var result = self.apply(object, aCollection);
  172. return typeof result === "object" ? result : object;
  173. ;
  174. return self},
  175. args: ["aCollection"],
  176. source: "newWithValues: aCollection\x0a\x09\x22Use the receiver as a JavaScript constructor with a variable number of arguments.\x0a\x09Answer the object created using the operator `new`.\x0a\x0a\x09This algorithm was inspired by http://stackoverflow.com/a/6069331.\x0a\x0a\x09Here's a general breakdown of what's going on:\x0a\x091) Create a new, empty constructor function.\x0a\x092) Set it's prototype to the receiver's prototype. Because the receiver is a `BlockClosure`, it is also a JavaScript function.\x0a\x093) Instantiate a new object using the constructor function just created. \x0a\x09\x09This forces the interpreter to set the internal [[prototype]] property to what was set on the function before. \x0a \x09\x09This has to be done, as we have no access to the [[prototype]] property externally.\x0a\x094) Apply `self` to the object I just instantiated.\x22\x0a\x0a\x09<\x0a\x09\x09var constructor = function() {};\x0a\x09\x09constructor.prototype = self.prototype;\x0a\x09\x09var object = new constructor;\x0a\x09\x09var result = self.apply(object, aCollection);\x0a\x09\x09return typeof result === \x22object\x22 ? result : object;\x0a\x09>",
  177. messageSends: [],
  178. referencedClasses: []
  179. }),
  180. globals.BlockClosure);
  181. smalltalk.addMethod(
  182. smalltalk.method({
  183. selector: "numArgs",
  184. protocol: 'accessing',
  185. fn: function (){
  186. var self=this;
  187. return self.length;
  188. return self},
  189. args: [],
  190. source: "numArgs\x0a\x09<return self.length>",
  191. messageSends: [],
  192. referencedClasses: []
  193. }),
  194. globals.BlockClosure);
  195. smalltalk.addMethod(
  196. smalltalk.method({
  197. selector: "on:do:",
  198. protocol: 'error handling',
  199. fn: function (anErrorClass,aBlock){
  200. var self=this;
  201. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  202. return smalltalk.withContext(function($ctx1) {
  203. var $2,$1;
  204. $1=self._try_catch_(self,(function(error){
  205. var smalltalkError;
  206. return smalltalk.withContext(function($ctx2) {
  207. smalltalkError=_st($Smalltalk())._asSmalltalkException_(error);
  208. smalltalkError;
  209. $2=_st(smalltalkError)._isKindOf_(anErrorClass);
  210. if(smalltalk.assert($2)){
  211. return _st(aBlock)._value_(smalltalkError);
  212. } else {
  213. return _st(smalltalkError)._resignal();
  214. };
  215. }, function($ctx2) {$ctx2.fillBlock({error:error,smalltalkError:smalltalkError},$ctx1,1)})}));
  216. return $1;
  217. }, function($ctx1) {$ctx1.fill(self,"on:do:",{anErrorClass:anErrorClass,aBlock:aBlock},globals.BlockClosure)})},
  218. args: ["anErrorClass", "aBlock"],
  219. source: "on: anErrorClass do: aBlock\x0a\x09\x22All exceptions thrown in the Smalltalk stack are cought.\x0a\x09Convert all JS exceptions to JavaScriptException instances.\x22\x0a\x09\x0a\x09^ self try: self catch: [ :error | | smalltalkError |\x0a\x09\x09smalltalkError := Smalltalk asSmalltalkException: error.\x0a\x09\x09(smalltalkError isKindOf: anErrorClass)\x0a\x09\x09ifTrue: [ aBlock value: smalltalkError ]\x0a\x09\x09ifFalse: [ smalltalkError resignal ] ]",
  220. messageSends: ["try:catch:", "asSmalltalkException:", "ifTrue:ifFalse:", "isKindOf:", "value:", "resignal"],
  221. referencedClasses: ["Smalltalk"]
  222. }),
  223. globals.BlockClosure);
  224. smalltalk.addMethod(
  225. smalltalk.method({
  226. selector: "receiver",
  227. protocol: 'accessing',
  228. fn: function (){
  229. var self=this;
  230. return nil;
  231. },
  232. args: [],
  233. source: "receiver\x0a\x09^ nil",
  234. messageSends: [],
  235. referencedClasses: []
  236. }),
  237. globals.BlockClosure);
  238. smalltalk.addMethod(
  239. smalltalk.method({
  240. selector: "timeToRun",
  241. protocol: 'evaluating',
  242. fn: function (){
  243. var self=this;
  244. function $Date(){return globals.Date||(typeof Date=="undefined"?nil:Date)}
  245. return smalltalk.withContext(function($ctx1) {
  246. var $1;
  247. $1=_st($Date())._millisecondsToRun_(self);
  248. return $1;
  249. }, function($ctx1) {$ctx1.fill(self,"timeToRun",{},globals.BlockClosure)})},
  250. args: [],
  251. source: "timeToRun\x0a\x09\x22Answer the number of milliseconds taken to execute this block.\x22\x0a\x0a\x09^ Date millisecondsToRun: self",
  252. messageSends: ["millisecondsToRun:"],
  253. referencedClasses: ["Date"]
  254. }),
  255. globals.BlockClosure);
  256. smalltalk.addMethod(
  257. smalltalk.method({
  258. selector: "value",
  259. protocol: 'evaluating',
  260. fn: function (){
  261. var self=this;
  262. return self();;
  263. return self},
  264. args: [],
  265. source: "value\x0a\x09<return self();>",
  266. messageSends: [],
  267. referencedClasses: []
  268. }),
  269. globals.BlockClosure);
  270. smalltalk.addMethod(
  271. smalltalk.method({
  272. selector: "value:",
  273. protocol: 'evaluating',
  274. fn: function (anArg){
  275. var self=this;
  276. return self(anArg);;
  277. return self},
  278. args: ["anArg"],
  279. source: "value: anArg\x0a\x09<return self(anArg);>",
  280. messageSends: [],
  281. referencedClasses: []
  282. }),
  283. globals.BlockClosure);
  284. smalltalk.addMethod(
  285. smalltalk.method({
  286. selector: "value:value:",
  287. protocol: 'evaluating',
  288. fn: function (firstArg,secondArg){
  289. var self=this;
  290. return self(firstArg, secondArg);;
  291. return self},
  292. args: ["firstArg", "secondArg"],
  293. source: "value: firstArg value: secondArg\x0a\x09<return self(firstArg, secondArg);>",
  294. messageSends: [],
  295. referencedClasses: []
  296. }),
  297. globals.BlockClosure);
  298. smalltalk.addMethod(
  299. smalltalk.method({
  300. selector: "value:value:value:",
  301. protocol: 'evaluating',
  302. fn: function (firstArg,secondArg,thirdArg){
  303. var self=this;
  304. return self(firstArg, secondArg, thirdArg);;
  305. return self},
  306. args: ["firstArg", "secondArg", "thirdArg"],
  307. source: "value: firstArg value: secondArg value: thirdArg\x0a\x09<return self(firstArg, secondArg, thirdArg);>",
  308. messageSends: [],
  309. referencedClasses: []
  310. }),
  311. globals.BlockClosure);
  312. smalltalk.addMethod(
  313. smalltalk.method({
  314. selector: "valueWithInterval:",
  315. protocol: 'timeout/interval',
  316. fn: function (aNumber){
  317. var self=this;
  318. var interval = setInterval(self, aNumber);
  319. return globals.Timeout._on_(interval);
  320. ;
  321. return self},
  322. args: ["aNumber"],
  323. source: "valueWithInterval: aNumber\x0a\x09<\x0a\x09\x09var interval = setInterval(self, aNumber);\x0a\x09\x09return globals.Timeout._on_(interval);\x0a\x09>",
  324. messageSends: [],
  325. referencedClasses: []
  326. }),
  327. globals.BlockClosure);
  328. smalltalk.addMethod(
  329. smalltalk.method({
  330. selector: "valueWithPossibleArguments:",
  331. protocol: 'evaluating',
  332. fn: function (aCollection){
  333. var self=this;
  334. return self.apply(null, aCollection);;
  335. return self},
  336. args: ["aCollection"],
  337. source: "valueWithPossibleArguments: aCollection\x0a\x09<return self.apply(null, aCollection);>",
  338. messageSends: [],
  339. referencedClasses: []
  340. }),
  341. globals.BlockClosure);
  342. smalltalk.addMethod(
  343. smalltalk.method({
  344. selector: "valueWithTimeout:",
  345. protocol: 'timeout/interval',
  346. fn: function (aNumber){
  347. var self=this;
  348. var timeout = setTimeout(self, aNumber);
  349. return globals.Timeout._on_(timeout);
  350. ;
  351. return self},
  352. args: ["aNumber"],
  353. source: "valueWithTimeout: aNumber\x0a\x09<\x0a\x09\x09var timeout = setTimeout(self, aNumber);\x0a\x09\x09return globals.Timeout._on_(timeout);\x0a\x09>",
  354. messageSends: [],
  355. referencedClasses: []
  356. }),
  357. globals.BlockClosure);
  358. smalltalk.addMethod(
  359. smalltalk.method({
  360. selector: "whileFalse",
  361. protocol: 'controlling',
  362. fn: function (){
  363. var self=this;
  364. return smalltalk.withContext(function($ctx1) {
  365. self._whileFalse_((function(){
  366. return smalltalk.withContext(function($ctx2) {
  367. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  368. return self}, function($ctx1) {$ctx1.fill(self,"whileFalse",{},globals.BlockClosure)})},
  369. args: [],
  370. source: "whileFalse\x0a\x09self whileFalse: []",
  371. messageSends: ["whileFalse:"],
  372. referencedClasses: []
  373. }),
  374. globals.BlockClosure);
  375. smalltalk.addMethod(
  376. smalltalk.method({
  377. selector: "whileFalse:",
  378. protocol: 'controlling',
  379. fn: function (aBlock){
  380. var self=this;
  381. while(!smalltalk.assert(self._value())) {aBlock._value()};
  382. return self},
  383. args: ["aBlock"],
  384. source: "whileFalse: aBlock\x0a\x09<while(!smalltalk.assert(self._value())) {aBlock._value()}>",
  385. messageSends: [],
  386. referencedClasses: []
  387. }),
  388. globals.BlockClosure);
  389. smalltalk.addMethod(
  390. smalltalk.method({
  391. selector: "whileTrue",
  392. protocol: 'controlling',
  393. fn: function (){
  394. var self=this;
  395. return smalltalk.withContext(function($ctx1) {
  396. self._whileTrue_((function(){
  397. return smalltalk.withContext(function($ctx2) {
  398. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  399. return self}, function($ctx1) {$ctx1.fill(self,"whileTrue",{},globals.BlockClosure)})},
  400. args: [],
  401. source: "whileTrue\x0a\x09self whileTrue: []",
  402. messageSends: ["whileTrue:"],
  403. referencedClasses: []
  404. }),
  405. globals.BlockClosure);
  406. smalltalk.addMethod(
  407. smalltalk.method({
  408. selector: "whileTrue:",
  409. protocol: 'controlling',
  410. fn: function (aBlock){
  411. var self=this;
  412. while(smalltalk.assert(self._value())) {aBlock._value()};
  413. return self},
  414. args: ["aBlock"],
  415. source: "whileTrue: aBlock\x0a\x09<while(smalltalk.assert(self._value())) {aBlock._value()}>",
  416. messageSends: [],
  417. referencedClasses: []
  418. }),
  419. globals.BlockClosure);
  420. smalltalk.addClass('CompiledMethod', globals.Object, [], 'Kernel-Methods');
  421. globals.CompiledMethod.comment="I represent a class method of the system. I hold the source and compiled code of a class method.\x0a\x0a## API\x0aMy instances can be accessed using `Behavior >> #methodAt:`\x0a\x0a Object methodAt: 'asString'\x0a\x0aSource code access:\x0a\x0a\x09(String methodAt: 'lines') source\x0a\x0aReferenced classes:\x0a\x0a\x09(String methodAt: 'lines') referencedClasses\x0a\x0aMessages sent from an instance:\x0a\x09\x0a\x09(String methodAt: 'lines') messageSends";
  422. smalltalk.addMethod(
  423. smalltalk.method({
  424. selector: "arguments",
  425. protocol: 'accessing',
  426. fn: function (){
  427. var self=this;
  428. return self.args || [];
  429. return self},
  430. args: [],
  431. source: "arguments\x0a\x09<return self.args || []>",
  432. messageSends: [],
  433. referencedClasses: []
  434. }),
  435. globals.CompiledMethod);
  436. smalltalk.addMethod(
  437. smalltalk.method({
  438. selector: "category",
  439. protocol: 'accessing',
  440. fn: function (){
  441. var self=this;
  442. return smalltalk.withContext(function($ctx1) {
  443. var $1;
  444. $1=self._protocol();
  445. return $1;
  446. }, function($ctx1) {$ctx1.fill(self,"category",{},globals.CompiledMethod)})},
  447. args: [],
  448. source: "category\x0a\x09^ self protocol",
  449. messageSends: ["protocol"],
  450. referencedClasses: []
  451. }),
  452. globals.CompiledMethod);
  453. smalltalk.addMethod(
  454. smalltalk.method({
  455. selector: "defaultProtocol",
  456. protocol: 'defaults',
  457. fn: function (){
  458. var self=this;
  459. return "as yet unclassified";
  460. },
  461. args: [],
  462. source: "defaultProtocol\x0a\x09^ 'as yet unclassified'",
  463. messageSends: [],
  464. referencedClasses: []
  465. }),
  466. globals.CompiledMethod);
  467. smalltalk.addMethod(
  468. smalltalk.method({
  469. selector: "fn",
  470. protocol: 'accessing',
  471. fn: function (){
  472. var self=this;
  473. return smalltalk.withContext(function($ctx1) {
  474. var $1;
  475. $1=self._basicAt_("fn");
  476. return $1;
  477. }, function($ctx1) {$ctx1.fill(self,"fn",{},globals.CompiledMethod)})},
  478. args: [],
  479. source: "fn\x0a\x09^ self basicAt: 'fn'",
  480. messageSends: ["basicAt:"],
  481. referencedClasses: []
  482. }),
  483. globals.CompiledMethod);
  484. smalltalk.addMethod(
  485. smalltalk.method({
  486. selector: "fn:",
  487. protocol: 'accessing',
  488. fn: function (aBlock){
  489. var self=this;
  490. return smalltalk.withContext(function($ctx1) {
  491. self._basicAt_put_("fn",aBlock);
  492. return self}, function($ctx1) {$ctx1.fill(self,"fn:",{aBlock:aBlock},globals.CompiledMethod)})},
  493. args: ["aBlock"],
  494. source: "fn: aBlock\x0a\x09self basicAt: 'fn' put: aBlock",
  495. messageSends: ["basicAt:put:"],
  496. referencedClasses: []
  497. }),
  498. globals.CompiledMethod);
  499. smalltalk.addMethod(
  500. smalltalk.method({
  501. selector: "isCompiledMethod",
  502. protocol: 'testing',
  503. fn: function (){
  504. var self=this;
  505. return true;
  506. },
  507. args: [],
  508. source: "isCompiledMethod\x0a\x09^ true",
  509. messageSends: [],
  510. referencedClasses: []
  511. }),
  512. globals.CompiledMethod);
  513. smalltalk.addMethod(
  514. smalltalk.method({
  515. selector: "isOverridden",
  516. protocol: 'testing',
  517. fn: function (){
  518. var self=this;
  519. var selector;
  520. return smalltalk.withContext(function($ctx1) {
  521. var $1;
  522. var $early={};
  523. try {
  524. selector=self._selector();
  525. _st(self._methodClass())._allSubclassesDo_((function(each){
  526. return smalltalk.withContext(function($ctx2) {
  527. $1=_st(each)._includesSelector_(selector);
  528. if(smalltalk.assert($1)){
  529. throw $early=[true];
  530. };
  531. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  532. return false;
  533. }
  534. catch(e) {if(e===$early)return e[0]; throw e}
  535. }, function($ctx1) {$ctx1.fill(self,"isOverridden",{selector:selector},globals.CompiledMethod)})},
  536. args: [],
  537. source: "isOverridden\x0a\x09| selector |\x0a \x0a selector := self selector.\x0a self methodClass allSubclassesDo: [ :each |\x0a\x09 (each includesSelector: selector)\x0a \x09ifTrue: [ ^ true ] ].\x0a\x09^ false",
  538. messageSends: ["selector", "allSubclassesDo:", "methodClass", "ifTrue:", "includesSelector:"],
  539. referencedClasses: []
  540. }),
  541. globals.CompiledMethod);
  542. smalltalk.addMethod(
  543. smalltalk.method({
  544. selector: "isOverride",
  545. protocol: 'testing',
  546. fn: function (){
  547. var self=this;
  548. var superclass;
  549. return smalltalk.withContext(function($ctx1) {
  550. var $1,$2,$3;
  551. $1=self._methodClass();
  552. $ctx1.sendIdx["methodClass"]=1;
  553. superclass=_st($1)._superclass();
  554. $ctx1.sendIdx["superclass"]=1;
  555. $2=superclass;
  556. if(($receiver = $2) == nil || $receiver == null){
  557. return false;
  558. } else {
  559. $2;
  560. };
  561. $3=_st(_st(_st(self._methodClass())._superclass())._lookupSelector_(self._selector()))._notNil();
  562. return $3;
  563. }, function($ctx1) {$ctx1.fill(self,"isOverride",{superclass:superclass},globals.CompiledMethod)})},
  564. args: [],
  565. source: "isOverride\x0a\x09| superclass |\x0a \x0a superclass := self methodClass superclass.\x0a\x09superclass ifNil: [ ^ false ].\x0a\x09\x0a ^ (self methodClass superclass lookupSelector: self selector) notNil",
  566. messageSends: ["superclass", "methodClass", "ifNil:", "notNil", "lookupSelector:", "selector"],
  567. referencedClasses: []
  568. }),
  569. globals.CompiledMethod);
  570. smalltalk.addMethod(
  571. smalltalk.method({
  572. selector: "messageSends",
  573. protocol: 'accessing',
  574. fn: function (){
  575. var self=this;
  576. return smalltalk.withContext(function($ctx1) {
  577. var $1;
  578. $1=self._basicAt_("messageSends");
  579. return $1;
  580. }, function($ctx1) {$ctx1.fill(self,"messageSends",{},globals.CompiledMethod)})},
  581. args: [],
  582. source: "messageSends\x0a\x09^ self basicAt: 'messageSends'",
  583. messageSends: ["basicAt:"],
  584. referencedClasses: []
  585. }),
  586. globals.CompiledMethod);
  587. smalltalk.addMethod(
  588. smalltalk.method({
  589. selector: "methodClass",
  590. protocol: 'accessing',
  591. fn: function (){
  592. var self=this;
  593. return smalltalk.withContext(function($ctx1) {
  594. var $1;
  595. $1=self._basicAt_("methodClass");
  596. return $1;
  597. }, function($ctx1) {$ctx1.fill(self,"methodClass",{},globals.CompiledMethod)})},
  598. args: [],
  599. source: "methodClass\x0a\x09^ self basicAt: 'methodClass'",
  600. messageSends: ["basicAt:"],
  601. referencedClasses: []
  602. }),
  603. globals.CompiledMethod);
  604. smalltalk.addMethod(
  605. smalltalk.method({
  606. selector: "protocol",
  607. protocol: 'accessing',
  608. fn: function (){
  609. var self=this;
  610. return smalltalk.withContext(function($ctx1) {
  611. var $2,$1;
  612. $2=self._basicAt_("protocol");
  613. if(($receiver = $2) == nil || $receiver == null){
  614. $1=self._defaultProtocol();
  615. } else {
  616. $1=$2;
  617. };
  618. return $1;
  619. }, function($ctx1) {$ctx1.fill(self,"protocol",{},globals.CompiledMethod)})},
  620. args: [],
  621. source: "protocol\x0a\x09^ (self basicAt: 'protocol') ifNil: [ self defaultProtocol ]",
  622. messageSends: ["ifNil:", "basicAt:", "defaultProtocol"],
  623. referencedClasses: []
  624. }),
  625. globals.CompiledMethod);
  626. smalltalk.addMethod(
  627. smalltalk.method({
  628. selector: "protocol:",
  629. protocol: 'accessing',
  630. fn: function (aString){
  631. var self=this;
  632. var oldProtocol;
  633. function $SystemAnnouncer(){return globals.SystemAnnouncer||(typeof SystemAnnouncer=="undefined"?nil:SystemAnnouncer)}
  634. function $MethodMoved(){return globals.MethodMoved||(typeof MethodMoved=="undefined"?nil:MethodMoved)}
  635. return smalltalk.withContext(function($ctx1) {
  636. var $1,$2,$3;
  637. oldProtocol=self._protocol();
  638. self._basicAt_put_("protocol",aString);
  639. $1=_st($MethodMoved())._new();
  640. _st($1)._method_(self);
  641. _st($1)._oldProtocol_(oldProtocol);
  642. $2=_st($1)._yourself();
  643. _st(_st($SystemAnnouncer())._current())._announce_($2);
  644. $3=self._methodClass();
  645. if(($receiver = $3) == nil || $receiver == null){
  646. $3;
  647. } else {
  648. var methodClass;
  649. methodClass=$receiver;
  650. _st(_st(methodClass)._organization())._addElement_(aString);
  651. _st(methodClass)._removeProtocolIfEmpty_(oldProtocol);
  652. };
  653. return self}, function($ctx1) {$ctx1.fill(self,"protocol:",{aString:aString,oldProtocol:oldProtocol},globals.CompiledMethod)})},
  654. args: ["aString"],
  655. source: "protocol: aString\x0a\x09| oldProtocol |\x0a\x09oldProtocol := self protocol.\x0a\x09self basicAt: 'protocol' put: aString.\x0a\x0a\x09SystemAnnouncer current announce: (MethodMoved new\x0a\x09\x09method: self;\x0a\x09\x09oldProtocol: oldProtocol;\x0a\x09\x09yourself).\x0a\x0a\x09self methodClass ifNotNil: [ :methodClass |\x0a\x09\x09methodClass organization addElement: aString.\x0a\x09\x09methodClass removeProtocolIfEmpty: oldProtocol ]",
  656. messageSends: ["protocol", "basicAt:put:", "announce:", "current", "method:", "new", "oldProtocol:", "yourself", "ifNotNil:", "methodClass", "addElement:", "organization", "removeProtocolIfEmpty:"],
  657. referencedClasses: ["SystemAnnouncer", "MethodMoved"]
  658. }),
  659. globals.CompiledMethod);
  660. smalltalk.addMethod(
  661. smalltalk.method({
  662. selector: "referencedClasses",
  663. protocol: 'accessing',
  664. fn: function (){
  665. var self=this;
  666. return smalltalk.withContext(function($ctx1) {
  667. var $1;
  668. $1=self._basicAt_("referencedClasses");
  669. return $1;
  670. }, function($ctx1) {$ctx1.fill(self,"referencedClasses",{},globals.CompiledMethod)})},
  671. args: [],
  672. source: "referencedClasses\x0a\x09^ self basicAt: 'referencedClasses'",
  673. messageSends: ["basicAt:"],
  674. referencedClasses: []
  675. }),
  676. globals.CompiledMethod);
  677. smalltalk.addMethod(
  678. smalltalk.method({
  679. selector: "selector",
  680. protocol: 'accessing',
  681. fn: function (){
  682. var self=this;
  683. return smalltalk.withContext(function($ctx1) {
  684. var $1;
  685. $1=self._basicAt_("selector");
  686. return $1;
  687. }, function($ctx1) {$ctx1.fill(self,"selector",{},globals.CompiledMethod)})},
  688. args: [],
  689. source: "selector\x0a\x09^ self basicAt: 'selector'",
  690. messageSends: ["basicAt:"],
  691. referencedClasses: []
  692. }),
  693. globals.CompiledMethod);
  694. smalltalk.addMethod(
  695. smalltalk.method({
  696. selector: "selector:",
  697. protocol: 'accessing',
  698. fn: function (aString){
  699. var self=this;
  700. return smalltalk.withContext(function($ctx1) {
  701. self._basicAt_put_("selector",aString);
  702. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aString:aString},globals.CompiledMethod)})},
  703. args: ["aString"],
  704. source: "selector: aString\x0a\x09self basicAt: 'selector' put: aString",
  705. messageSends: ["basicAt:put:"],
  706. referencedClasses: []
  707. }),
  708. globals.CompiledMethod);
  709. smalltalk.addMethod(
  710. smalltalk.method({
  711. selector: "sendTo:arguments:",
  712. protocol: 'evaluating',
  713. fn: function (anObject,aCollection){
  714. var self=this;
  715. return smalltalk.withContext(function($ctx1) {
  716. var $1;
  717. $1=_st(self._fn())._applyTo_arguments_(anObject,aCollection);
  718. return $1;
  719. }, function($ctx1) {$ctx1.fill(self,"sendTo:arguments:",{anObject:anObject,aCollection:aCollection},globals.CompiledMethod)})},
  720. args: ["anObject", "aCollection"],
  721. source: "sendTo: anObject arguments: aCollection\x0a\x09^ self fn applyTo: anObject arguments: aCollection",
  722. messageSends: ["applyTo:arguments:", "fn"],
  723. referencedClasses: []
  724. }),
  725. globals.CompiledMethod);
  726. smalltalk.addMethod(
  727. smalltalk.method({
  728. selector: "source",
  729. protocol: 'accessing',
  730. fn: function (){
  731. var self=this;
  732. return smalltalk.withContext(function($ctx1) {
  733. var $2,$1;
  734. $2=self._basicAt_("source");
  735. if(($receiver = $2) == nil || $receiver == null){
  736. $1="";
  737. } else {
  738. $1=$2;
  739. };
  740. return $1;
  741. }, function($ctx1) {$ctx1.fill(self,"source",{},globals.CompiledMethod)})},
  742. args: [],
  743. source: "source\x0a\x09^ (self basicAt: 'source') ifNil: [ '' ]",
  744. messageSends: ["ifNil:", "basicAt:"],
  745. referencedClasses: []
  746. }),
  747. globals.CompiledMethod);
  748. smalltalk.addMethod(
  749. smalltalk.method({
  750. selector: "source:",
  751. protocol: 'accessing',
  752. fn: function (aString){
  753. var self=this;
  754. return smalltalk.withContext(function($ctx1) {
  755. self._basicAt_put_("source",aString);
  756. return self}, function($ctx1) {$ctx1.fill(self,"source:",{aString:aString},globals.CompiledMethod)})},
  757. args: ["aString"],
  758. source: "source: aString\x0a\x09self basicAt: 'source' put: aString",
  759. messageSends: ["basicAt:put:"],
  760. referencedClasses: []
  761. }),
  762. globals.CompiledMethod);
  763. smalltalk.addClass('ForkPool', globals.Object, ['poolSize', 'maxPoolSize', 'queue', 'worker'], 'Kernel-Methods');
  764. globals.ForkPool.comment="I am responsible for handling forked blocks.\x0aThe pool size sets the maximum concurrent forked blocks.\x0a\x0a## API\x0a\x0aThe default instance is accessed with `#default`.\x0aThe maximum concurrent forked blocks can be set with `#maxPoolSize:`.\x0a\x0aForking is done via `BlockClosure >> #fork`";
  765. smalltalk.addMethod(
  766. smalltalk.method({
  767. selector: "addWorker",
  768. protocol: 'private',
  769. fn: function (){
  770. var self=this;
  771. return smalltalk.withContext(function($ctx1) {
  772. _st(self["@worker"])._valueWithTimeout_((0));
  773. self["@poolSize"]=_st(self["@poolSize"]).__plus((1));
  774. return self}, function($ctx1) {$ctx1.fill(self,"addWorker",{},globals.ForkPool)})},
  775. args: [],
  776. source: "addWorker\x0a\x09worker valueWithTimeout: 0.\x0a\x09poolSize := poolSize + 1",
  777. messageSends: ["valueWithTimeout:", "+"],
  778. referencedClasses: []
  779. }),
  780. globals.ForkPool);
  781. smalltalk.addMethod(
  782. smalltalk.method({
  783. selector: "defaultMaxPoolSize",
  784. protocol: 'defaults',
  785. fn: function (){
  786. var self=this;
  787. return smalltalk.withContext(function($ctx1) {
  788. var $1;
  789. $1=_st(self._class())._defaultMaxPoolSize();
  790. return $1;
  791. }, function($ctx1) {$ctx1.fill(self,"defaultMaxPoolSize",{},globals.ForkPool)})},
  792. args: [],
  793. source: "defaultMaxPoolSize\x0a\x09^ self class defaultMaxPoolSize",
  794. messageSends: ["defaultMaxPoolSize", "class"],
  795. referencedClasses: []
  796. }),
  797. globals.ForkPool);
  798. smalltalk.addMethod(
  799. smalltalk.method({
  800. selector: "fork:",
  801. protocol: 'actions',
  802. fn: function (aBlock){
  803. var self=this;
  804. return smalltalk.withContext(function($ctx1) {
  805. var $1;
  806. $1=_st(self["@poolSize"]).__lt(self._maxPoolSize());
  807. if(smalltalk.assert($1)){
  808. self._addWorker();
  809. };
  810. _st(self["@queue"])._nextPut_(aBlock);
  811. return self}, function($ctx1) {$ctx1.fill(self,"fork:",{aBlock:aBlock},globals.ForkPool)})},
  812. args: ["aBlock"],
  813. source: "fork: aBlock\x0a\x09poolSize < self maxPoolSize ifTrue: [ self addWorker ].\x0a\x09queue nextPut: aBlock",
  814. messageSends: ["ifTrue:", "<", "maxPoolSize", "addWorker", "nextPut:"],
  815. referencedClasses: []
  816. }),
  817. globals.ForkPool);
  818. smalltalk.addMethod(
  819. smalltalk.method({
  820. selector: "initialize",
  821. protocol: 'initialization',
  822. fn: function (){
  823. var self=this;
  824. function $Queue(){return globals.Queue||(typeof Queue=="undefined"?nil:Queue)}
  825. return smalltalk.withContext(function($ctx1) {
  826. globals.ForkPool.superclass.fn.prototype._initialize.apply(_st(self), []);
  827. self["@poolSize"]=(0);
  828. self["@queue"]=_st($Queue())._new();
  829. self["@worker"]=self._makeWorker();
  830. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.ForkPool)})},
  831. args: [],
  832. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09poolSize := 0.\x0a\x09queue := Queue new.\x0a\x09worker := self makeWorker",
  833. messageSends: ["initialize", "new", "makeWorker"],
  834. referencedClasses: ["Queue"]
  835. }),
  836. globals.ForkPool);
  837. smalltalk.addMethod(
  838. smalltalk.method({
  839. selector: "makeWorker",
  840. protocol: 'initialization',
  841. fn: function (){
  842. var self=this;
  843. var sentinel;
  844. function $Object(){return globals.Object||(typeof Object=="undefined"?nil:Object)}
  845. return smalltalk.withContext(function($ctx1) {
  846. var $2,$1;
  847. sentinel=_st($Object())._new();
  848. $1=(function(){
  849. var block;
  850. return smalltalk.withContext(function($ctx2) {
  851. self["@poolSize"]=_st(self["@poolSize"]).__minus((1));
  852. self["@poolSize"];
  853. block=_st(self["@queue"])._nextIfAbsent_((function(){
  854. return smalltalk.withContext(function($ctx3) {
  855. return sentinel;
  856. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  857. block;
  858. $2=_st(block).__eq_eq(sentinel);
  859. if(! smalltalk.assert($2)){
  860. return _st((function(){
  861. return smalltalk.withContext(function($ctx3) {
  862. return _st(block)._value();
  863. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,4)})}))._ensure_((function(){
  864. return smalltalk.withContext(function($ctx3) {
  865. return self._addWorker();
  866. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,5)})}));
  867. };
  868. }, function($ctx2) {$ctx2.fillBlock({block:block},$ctx1,1)})});
  869. return $1;
  870. }, function($ctx1) {$ctx1.fill(self,"makeWorker",{sentinel:sentinel},globals.ForkPool)})},
  871. args: [],
  872. source: "makeWorker\x0a\x09| sentinel |\x0a\x09sentinel := Object new.\x0a\x09^ [ | block |\x0a\x09\x09poolSize := poolSize - 1.\x0a\x09\x09block := queue nextIfAbsent: [ sentinel ].\x0a\x09\x09block == sentinel ifFalse: [\x0a\x09\x09\x09[ block value ] ensure: [ self addWorker ] ]]",
  873. messageSends: ["new", "-", "nextIfAbsent:", "ifFalse:", "==", "ensure:", "value", "addWorker"],
  874. referencedClasses: ["Object"]
  875. }),
  876. globals.ForkPool);
  877. smalltalk.addMethod(
  878. smalltalk.method({
  879. selector: "maxPoolSize",
  880. protocol: 'accessing',
  881. fn: function (){
  882. var self=this;
  883. return smalltalk.withContext(function($ctx1) {
  884. var $2,$1;
  885. $2=self["@maxPoolSize"];
  886. if(($receiver = $2) == nil || $receiver == null){
  887. $1=self._defaultMaxPoolSize();
  888. } else {
  889. $1=$2;
  890. };
  891. return $1;
  892. }, function($ctx1) {$ctx1.fill(self,"maxPoolSize",{},globals.ForkPool)})},
  893. args: [],
  894. source: "maxPoolSize\x0a\x09^ maxPoolSize ifNil: [ self defaultMaxPoolSize ]",
  895. messageSends: ["ifNil:", "defaultMaxPoolSize"],
  896. referencedClasses: []
  897. }),
  898. globals.ForkPool);
  899. smalltalk.addMethod(
  900. smalltalk.method({
  901. selector: "maxPoolSize:",
  902. protocol: 'accessing',
  903. fn: function (anInteger){
  904. var self=this;
  905. self["@maxPoolSize"]=anInteger;
  906. return self},
  907. args: ["anInteger"],
  908. source: "maxPoolSize: anInteger\x0a\x09maxPoolSize := anInteger",
  909. messageSends: [],
  910. referencedClasses: []
  911. }),
  912. globals.ForkPool);
  913. globals.ForkPool.klass.iVarNames = ['default'];
  914. smalltalk.addMethod(
  915. smalltalk.method({
  916. selector: "default",
  917. protocol: 'accessing',
  918. fn: function (){
  919. var self=this;
  920. return smalltalk.withContext(function($ctx1) {
  921. var $2,$1;
  922. $2=self["@default"];
  923. if(($receiver = $2) == nil || $receiver == null){
  924. self["@default"]=self._new();
  925. $1=self["@default"];
  926. } else {
  927. $1=$2;
  928. };
  929. return $1;
  930. }, function($ctx1) {$ctx1.fill(self,"default",{},globals.ForkPool.klass)})},
  931. args: [],
  932. source: "default\x0a\x09^ default ifNil: [ default := self new ]",
  933. messageSends: ["ifNil:", "new"],
  934. referencedClasses: []
  935. }),
  936. globals.ForkPool.klass);
  937. smalltalk.addMethod(
  938. smalltalk.method({
  939. selector: "defaultMaxPoolSize",
  940. protocol: 'accessing',
  941. fn: function (){
  942. var self=this;
  943. return (100);
  944. },
  945. args: [],
  946. source: "defaultMaxPoolSize\x0a\x09^ 100",
  947. messageSends: [],
  948. referencedClasses: []
  949. }),
  950. globals.ForkPool.klass);
  951. smalltalk.addMethod(
  952. smalltalk.method({
  953. selector: "resetDefault",
  954. protocol: 'accessing',
  955. fn: function (){
  956. var self=this;
  957. self["@default"]=nil;
  958. return self},
  959. args: [],
  960. source: "resetDefault\x0a\x09default := nil",
  961. messageSends: [],
  962. referencedClasses: []
  963. }),
  964. globals.ForkPool.klass);
  965. smalltalk.addClass('Message', globals.Object, ['selector', 'arguments'], 'Kernel-Methods');
  966. globals.Message.comment="In general, the system does not use instances of me for efficiency reasons.\x0aHowever, 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.\x0aThis instance is sent it as an argument with the message `#doesNotUnderstand:` to the receiver.\x0a\x0aSee boot.js, `messageNotUnderstood` and its counterpart `Object >> #doesNotUnderstand:`\x0a\x0a## API\x0a\x0aBesides accessing methods, `#sendTo:` provides a convenient way to send a message to an object.";
  967. smalltalk.addMethod(
  968. smalltalk.method({
  969. selector: "arguments",
  970. protocol: 'accessing',
  971. fn: function (){
  972. var self=this;
  973. var $1;
  974. $1=self["@arguments"];
  975. return $1;
  976. },
  977. args: [],
  978. source: "arguments\x0a\x09^ arguments",
  979. messageSends: [],
  980. referencedClasses: []
  981. }),
  982. globals.Message);
  983. smalltalk.addMethod(
  984. smalltalk.method({
  985. selector: "arguments:",
  986. protocol: 'accessing',
  987. fn: function (anArray){
  988. var self=this;
  989. self["@arguments"]=anArray;
  990. return self},
  991. args: ["anArray"],
  992. source: "arguments: anArray\x0a\x09arguments := anArray",
  993. messageSends: [],
  994. referencedClasses: []
  995. }),
  996. globals.Message);
  997. smalltalk.addMethod(
  998. smalltalk.method({
  999. selector: "printOn:",
  1000. protocol: 'printing',
  1001. fn: function (aStream){
  1002. var self=this;
  1003. return smalltalk.withContext(function($ctx1) {
  1004. var $1;
  1005. globals.Message.superclass.fn.prototype._printOn_.apply(_st(self), [aStream]);
  1006. _st(aStream)._nextPutAll_("(");
  1007. $ctx1.sendIdx["nextPutAll:"]=1;
  1008. _st(aStream)._nextPutAll_(self._selector());
  1009. $ctx1.sendIdx["nextPutAll:"]=2;
  1010. $1=_st(aStream)._nextPutAll_(")");
  1011. return self}, function($ctx1) {$ctx1.fill(self,"printOn:",{aStream:aStream},globals.Message)})},
  1012. args: ["aStream"],
  1013. source: "printOn: aStream\x0a\x09super printOn: aStream.\x0a\x09aStream\x0a\x09\x09nextPutAll: '(';\x0a\x09\x09nextPutAll: self selector;\x0a\x09\x09nextPutAll: ')'",
  1014. messageSends: ["printOn:", "nextPutAll:", "selector"],
  1015. referencedClasses: []
  1016. }),
  1017. globals.Message);
  1018. smalltalk.addMethod(
  1019. smalltalk.method({
  1020. selector: "selector",
  1021. protocol: 'accessing',
  1022. fn: function (){
  1023. var self=this;
  1024. var $1;
  1025. $1=self["@selector"];
  1026. return $1;
  1027. },
  1028. args: [],
  1029. source: "selector\x0a\x09^ selector",
  1030. messageSends: [],
  1031. referencedClasses: []
  1032. }),
  1033. globals.Message);
  1034. smalltalk.addMethod(
  1035. smalltalk.method({
  1036. selector: "selector:",
  1037. protocol: 'accessing',
  1038. fn: function (aString){
  1039. var self=this;
  1040. self["@selector"]=aString;
  1041. return self},
  1042. args: ["aString"],
  1043. source: "selector: aString\x0a\x09selector := aString",
  1044. messageSends: [],
  1045. referencedClasses: []
  1046. }),
  1047. globals.Message);
  1048. smalltalk.addMethod(
  1049. smalltalk.method({
  1050. selector: "sendTo:",
  1051. protocol: 'actions',
  1052. fn: function (anObject){
  1053. var self=this;
  1054. return smalltalk.withContext(function($ctx1) {
  1055. var $1;
  1056. $1=_st(anObject)._perform_withArguments_(self._selector(),self._arguments());
  1057. return $1;
  1058. }, function($ctx1) {$ctx1.fill(self,"sendTo:",{anObject:anObject},globals.Message)})},
  1059. args: ["anObject"],
  1060. source: "sendTo: anObject\x0a\x09^ anObject perform: self selector withArguments: self arguments",
  1061. messageSends: ["perform:withArguments:", "selector", "arguments"],
  1062. referencedClasses: []
  1063. }),
  1064. globals.Message);
  1065. smalltalk.addMethod(
  1066. smalltalk.method({
  1067. selector: "selector:arguments:",
  1068. protocol: 'instance creation',
  1069. fn: function (aString,anArray){
  1070. var self=this;
  1071. return smalltalk.withContext(function($ctx1) {
  1072. var $2,$3,$1;
  1073. $2=self._new();
  1074. _st($2)._selector_(aString);
  1075. _st($2)._arguments_(anArray);
  1076. $3=_st($2)._yourself();
  1077. $1=$3;
  1078. return $1;
  1079. }, function($ctx1) {$ctx1.fill(self,"selector:arguments:",{aString:aString,anArray:anArray},globals.Message.klass)})},
  1080. args: ["aString", "anArray"],
  1081. source: "selector: aString arguments: anArray\x0a\x09^ self new\x0a\x09\x09selector: aString;\x0a\x09\x09arguments: anArray;\x0a\x09\x09yourself",
  1082. messageSends: ["selector:", "new", "arguments:", "yourself"],
  1083. referencedClasses: []
  1084. }),
  1085. globals.Message.klass);
  1086. smalltalk.addClass('MessageSend', globals.Object, ['receiver', 'message'], 'Kernel-Methods');
  1087. globals.MessageSend.comment="I encapsulate message sends to objects. Arguments can be either predefined or supplied when the message send is performed. \x0a\x0a## API\x0a\x0aUse `#value` to perform a message send with its predefined arguments and `#value:*` if additonal arguments have to supplied.";
  1088. smalltalk.addMethod(
  1089. smalltalk.method({
  1090. selector: "arguments",
  1091. protocol: 'accessing',
  1092. fn: function (){
  1093. var self=this;
  1094. return smalltalk.withContext(function($ctx1) {
  1095. var $1;
  1096. $1=_st(self["@message"])._arguments();
  1097. return $1;
  1098. }, function($ctx1) {$ctx1.fill(self,"arguments",{},globals.MessageSend)})},
  1099. args: [],
  1100. source: "arguments\x0a\x09^ message arguments",
  1101. messageSends: ["arguments"],
  1102. referencedClasses: []
  1103. }),
  1104. globals.MessageSend);
  1105. smalltalk.addMethod(
  1106. smalltalk.method({
  1107. selector: "arguments:",
  1108. protocol: 'accessing',
  1109. fn: function (aCollection){
  1110. var self=this;
  1111. return smalltalk.withContext(function($ctx1) {
  1112. _st(self["@message"])._arguments_(aCollection);
  1113. return self}, function($ctx1) {$ctx1.fill(self,"arguments:",{aCollection:aCollection},globals.MessageSend)})},
  1114. args: ["aCollection"],
  1115. source: "arguments: aCollection\x0a\x09message arguments: aCollection",
  1116. messageSends: ["arguments:"],
  1117. referencedClasses: []
  1118. }),
  1119. globals.MessageSend);
  1120. smalltalk.addMethod(
  1121. smalltalk.method({
  1122. selector: "initialize",
  1123. protocol: 'initialization',
  1124. fn: function (){
  1125. var self=this;
  1126. function $Message(){return globals.Message||(typeof Message=="undefined"?nil:Message)}
  1127. return smalltalk.withContext(function($ctx1) {
  1128. globals.MessageSend.superclass.fn.prototype._initialize.apply(_st(self), []);
  1129. self["@message"]=_st($Message())._new();
  1130. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},globals.MessageSend)})},
  1131. args: [],
  1132. source: "initialize\x0a\x09super initialize.\x0a\x09message := Message new",
  1133. messageSends: ["initialize", "new"],
  1134. referencedClasses: ["Message"]
  1135. }),
  1136. globals.MessageSend);
  1137. smalltalk.addMethod(
  1138. smalltalk.method({
  1139. selector: "printOn:",
  1140. protocol: 'printing',
  1141. fn: function (aStream){
  1142. var self=this;
  1143. return smalltalk.withContext(function($ctx1) {
  1144. var $1;
  1145. globals.MessageSend.superclass.fn.prototype._printOn_.apply(_st(self), [aStream]);
  1146. _st(aStream)._nextPutAll_("(");
  1147. $ctx1.sendIdx["nextPutAll:"]=1;
  1148. _st(aStream)._nextPutAll_(self._receiver());
  1149. $ctx1.sendIdx["nextPutAll:"]=2;
  1150. _st(aStream)._nextPutAll_(" >> ");
  1151. $ctx1.sendIdx["nextPutAll:"]=3;
  1152. _st(aStream)._nextPutAll_(self._selector());
  1153. $ctx1.sendIdx["nextPutAll:"]=4;
  1154. $1=_st(aStream)._nextPutAll_(")");
  1155. return self}, function($ctx1) {$ctx1.fill(self,"printOn:",{aStream:aStream},globals.MessageSend)})},
  1156. args: ["aStream"],
  1157. source: "printOn: aStream\x0a\x09super printOn: aStream.\x0a\x09aStream\x0a\x09\x09nextPutAll: '(';\x0a\x09\x09nextPutAll: self receiver;\x0a\x09\x09nextPutAll: ' >> ';\x0a\x09\x09nextPutAll: self selector;\x0a\x09\x09nextPutAll: ')'",
  1158. messageSends: ["printOn:", "nextPutAll:", "receiver", "selector"],
  1159. referencedClasses: []
  1160. }),
  1161. globals.MessageSend);
  1162. smalltalk.addMethod(
  1163. smalltalk.method({
  1164. selector: "receiver",
  1165. protocol: 'accessing',
  1166. fn: function (){
  1167. var self=this;
  1168. var $1;
  1169. $1=self["@receiver"];
  1170. return $1;
  1171. },
  1172. args: [],
  1173. source: "receiver\x0a\x09^ receiver",
  1174. messageSends: [],
  1175. referencedClasses: []
  1176. }),
  1177. globals.MessageSend);
  1178. smalltalk.addMethod(
  1179. smalltalk.method({
  1180. selector: "receiver:",
  1181. protocol: 'accessing',
  1182. fn: function (anObject){
  1183. var self=this;
  1184. self["@receiver"]=anObject;
  1185. return self},
  1186. args: ["anObject"],
  1187. source: "receiver: anObject\x0a\x09receiver := anObject",
  1188. messageSends: [],
  1189. referencedClasses: []
  1190. }),
  1191. globals.MessageSend);
  1192. smalltalk.addMethod(
  1193. smalltalk.method({
  1194. selector: "selector",
  1195. protocol: 'accessing',
  1196. fn: function (){
  1197. var self=this;
  1198. return smalltalk.withContext(function($ctx1) {
  1199. var $1;
  1200. $1=_st(self["@message"])._selector();
  1201. return $1;
  1202. }, function($ctx1) {$ctx1.fill(self,"selector",{},globals.MessageSend)})},
  1203. args: [],
  1204. source: "selector\x0a\x09^ message selector",
  1205. messageSends: ["selector"],
  1206. referencedClasses: []
  1207. }),
  1208. globals.MessageSend);
  1209. smalltalk.addMethod(
  1210. smalltalk.method({
  1211. selector: "selector:",
  1212. protocol: 'accessing',
  1213. fn: function (aString){
  1214. var self=this;
  1215. return smalltalk.withContext(function($ctx1) {
  1216. _st(self["@message"])._selector_(aString);
  1217. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aString:aString},globals.MessageSend)})},
  1218. args: ["aString"],
  1219. source: "selector: aString\x0a\x09message selector: aString",
  1220. messageSends: ["selector:"],
  1221. referencedClasses: []
  1222. }),
  1223. globals.MessageSend);
  1224. smalltalk.addMethod(
  1225. smalltalk.method({
  1226. selector: "value",
  1227. protocol: 'evaluating',
  1228. fn: function (){
  1229. var self=this;
  1230. return smalltalk.withContext(function($ctx1) {
  1231. var $1;
  1232. $1=_st(self["@message"])._sendTo_(self._receiver());
  1233. return $1;
  1234. }, function($ctx1) {$ctx1.fill(self,"value",{},globals.MessageSend)})},
  1235. args: [],
  1236. source: "value\x0a\x09^ message sendTo: self receiver",
  1237. messageSends: ["sendTo:", "receiver"],
  1238. referencedClasses: []
  1239. }),
  1240. globals.MessageSend);
  1241. smalltalk.addMethod(
  1242. smalltalk.method({
  1243. selector: "value:",
  1244. protocol: 'evaluating',
  1245. fn: function (anObject){
  1246. var self=this;
  1247. return smalltalk.withContext(function($ctx1) {
  1248. var $2,$3,$1;
  1249. $2=self["@message"];
  1250. _st($2)._arguments_([anObject]);
  1251. $3=_st($2)._sendTo_(self._receiver());
  1252. $1=$3;
  1253. return $1;
  1254. }, function($ctx1) {$ctx1.fill(self,"value:",{anObject:anObject},globals.MessageSend)})},
  1255. args: ["anObject"],
  1256. source: "value: anObject\x0a\x09^ message \x0a\x09\x09arguments: { anObject };\x0a\x09\x09sendTo: self receiver",
  1257. messageSends: ["arguments:", "sendTo:", "receiver"],
  1258. referencedClasses: []
  1259. }),
  1260. globals.MessageSend);
  1261. smalltalk.addMethod(
  1262. smalltalk.method({
  1263. selector: "value:value:",
  1264. protocol: 'evaluating',
  1265. fn: function (firstArgument,secondArgument){
  1266. var self=this;
  1267. return smalltalk.withContext(function($ctx1) {
  1268. var $2,$3,$1;
  1269. $2=self["@message"];
  1270. _st($2)._arguments_([firstArgument,secondArgument]);
  1271. $3=_st($2)._sendTo_(self._receiver());
  1272. $1=$3;
  1273. return $1;
  1274. }, function($ctx1) {$ctx1.fill(self,"value:value:",{firstArgument:firstArgument,secondArgument:secondArgument},globals.MessageSend)})},
  1275. args: ["firstArgument", "secondArgument"],
  1276. source: "value: firstArgument value: secondArgument\x0a\x09^ message \x0a\x09\x09arguments: { firstArgument. secondArgument };\x0a\x09\x09sendTo: self receiver",
  1277. messageSends: ["arguments:", "sendTo:", "receiver"],
  1278. referencedClasses: []
  1279. }),
  1280. globals.MessageSend);
  1281. smalltalk.addMethod(
  1282. smalltalk.method({
  1283. selector: "value:value:value:",
  1284. protocol: 'evaluating',
  1285. fn: function (firstArgument,secondArgument,thirdArgument){
  1286. var self=this;
  1287. return smalltalk.withContext(function($ctx1) {
  1288. var $2,$3,$1;
  1289. $2=self["@message"];
  1290. _st($2)._arguments_([firstArgument,secondArgument,thirdArgument]);
  1291. $3=_st($2)._sendTo_(self._receiver());
  1292. $1=$3;
  1293. return $1;
  1294. }, function($ctx1) {$ctx1.fill(self,"value:value:value:",{firstArgument:firstArgument,secondArgument:secondArgument,thirdArgument:thirdArgument},globals.MessageSend)})},
  1295. args: ["firstArgument", "secondArgument", "thirdArgument"],
  1296. source: "value: firstArgument value: secondArgument value: thirdArgument\x0a\x09^ message \x0a\x09\x09arguments: { firstArgument. secondArgument. thirdArgument };\x0a\x09\x09sendTo: self receiver",
  1297. messageSends: ["arguments:", "sendTo:", "receiver"],
  1298. referencedClasses: []
  1299. }),
  1300. globals.MessageSend);
  1301. smalltalk.addMethod(
  1302. smalltalk.method({
  1303. selector: "valueWithPossibleArguments:",
  1304. protocol: 'evaluating',
  1305. fn: function (aCollection){
  1306. var self=this;
  1307. return smalltalk.withContext(function($ctx1) {
  1308. var $1;
  1309. self._arguments_(aCollection);
  1310. $1=self._value();
  1311. return $1;
  1312. }, function($ctx1) {$ctx1.fill(self,"valueWithPossibleArguments:",{aCollection:aCollection},globals.MessageSend)})},
  1313. args: ["aCollection"],
  1314. source: "valueWithPossibleArguments: aCollection\x0a\x09self arguments: aCollection.\x0a\x09^ self value",
  1315. messageSends: ["arguments:", "value"],
  1316. referencedClasses: []
  1317. }),
  1318. globals.MessageSend);
  1319. smalltalk.addClass('MethodContext', globals.Object, [], 'Kernel-Methods');
  1320. globals.MethodContext.comment="I hold all the dynamic state associated with the execution of either a method activation resulting from a message send. I am used to build the call stack while debugging.\x0a\x0aMy instances are JavaScript `SmalltalkMethodContext` objects defined in `boot.js`.";
  1321. smalltalk.addMethod(
  1322. smalltalk.method({
  1323. selector: "asString",
  1324. protocol: 'converting',
  1325. fn: function (){
  1326. var self=this;
  1327. return smalltalk.withContext(function($ctx1) {
  1328. var $2,$3,$1;
  1329. $2=self._isBlockContext();
  1330. if(smalltalk.assert($2)){
  1331. $3="a block (in ".__comma(_st(self._methodContext())._asString());
  1332. $ctx1.sendIdx[","]=2;
  1333. $1=_st($3).__comma(")");
  1334. $ctx1.sendIdx[","]=1;
  1335. } else {
  1336. $1=_st(_st(_st(_st(self._receiver())._class())._name()).__comma(" >> ")).__comma(self._selector());
  1337. $ctx1.sendIdx[","]=3;
  1338. };
  1339. return $1;
  1340. }, function($ctx1) {$ctx1.fill(self,"asString",{},globals.MethodContext)})},
  1341. args: [],
  1342. source: "asString\x0a\x09^ self isBlockContext\x0a\x09\x09ifTrue: [ 'a block (in ', self methodContext asString, ')' ]\x0a\x09\x09ifFalse: [ self receiver class name, ' >> ', self selector ]",
  1343. messageSends: ["ifTrue:ifFalse:", "isBlockContext", ",", "asString", "methodContext", "name", "class", "receiver", "selector"],
  1344. referencedClasses: []
  1345. }),
  1346. globals.MethodContext);
  1347. smalltalk.addMethod(
  1348. smalltalk.method({
  1349. selector: "evaluatedSelector",
  1350. protocol: 'accessing',
  1351. fn: function (){
  1352. var self=this;
  1353. return self.evaluatedSelector;
  1354. return self},
  1355. args: [],
  1356. source: "evaluatedSelector\x0a\x09<return self.evaluatedSelector>",
  1357. messageSends: [],
  1358. referencedClasses: []
  1359. }),
  1360. globals.MethodContext);
  1361. smalltalk.addMethod(
  1362. smalltalk.method({
  1363. selector: "home",
  1364. protocol: 'accessing',
  1365. fn: function (){
  1366. var self=this;
  1367. return self.homeContext;
  1368. return self},
  1369. args: [],
  1370. source: "home\x0a\x09<return self.homeContext>",
  1371. messageSends: [],
  1372. referencedClasses: []
  1373. }),
  1374. globals.MethodContext);
  1375. smalltalk.addMethod(
  1376. smalltalk.method({
  1377. selector: "index",
  1378. protocol: 'accessing',
  1379. fn: function (){
  1380. var self=this;
  1381. return self.index || 0;
  1382. return self},
  1383. args: [],
  1384. source: "index\x0a\x09<return self.index || 0>",
  1385. messageSends: [],
  1386. referencedClasses: []
  1387. }),
  1388. globals.MethodContext);
  1389. smalltalk.addMethod(
  1390. smalltalk.method({
  1391. selector: "isBlockContext",
  1392. protocol: 'testing',
  1393. fn: function (){
  1394. var self=this;
  1395. return smalltalk.withContext(function($ctx1) {
  1396. var $1;
  1397. $1=_st(self._selector())._isNil();
  1398. return $1;
  1399. }, function($ctx1) {$ctx1.fill(self,"isBlockContext",{},globals.MethodContext)})},
  1400. args: [],
  1401. source: "isBlockContext\x0a\x09\x22Block context do not have selectors.\x22\x0a\x09\x0a\x09^ self selector isNil",
  1402. messageSends: ["isNil", "selector"],
  1403. referencedClasses: []
  1404. }),
  1405. globals.MethodContext);
  1406. smalltalk.addMethod(
  1407. smalltalk.method({
  1408. selector: "locals",
  1409. protocol: 'accessing',
  1410. fn: function (){
  1411. var self=this;
  1412. return self.locals || {};
  1413. return self},
  1414. args: [],
  1415. source: "locals\x0a\x09<return self.locals || {}>",
  1416. messageSends: [],
  1417. referencedClasses: []
  1418. }),
  1419. globals.MethodContext);
  1420. smalltalk.addMethod(
  1421. smalltalk.method({
  1422. selector: "method",
  1423. protocol: 'accessing',
  1424. fn: function (){
  1425. var self=this;
  1426. return smalltalk.withContext(function($ctx1) {
  1427. var $2,$5,$4,$3,$1;
  1428. $2=self._methodContext();
  1429. $ctx1.sendIdx["methodContext"]=1;
  1430. if(($receiver = $2) == nil || $receiver == null){
  1431. $1=$2;
  1432. } else {
  1433. $5=self._methodContext();
  1434. $ctx1.sendIdx["methodContext"]=2;
  1435. $4=_st($5)._receiver();
  1436. $3=_st($4)._class();
  1437. $1=_st($3)._lookupSelector_(_st(self._methodContext())._selector());
  1438. };
  1439. return $1;
  1440. }, function($ctx1) {$ctx1.fill(self,"method",{},globals.MethodContext)})},
  1441. args: [],
  1442. source: "method\x0a\x09^ self methodContext ifNotNil: [\x0a\x09\x09self methodContext receiver class lookupSelector: self methodContext selector ]",
  1443. messageSends: ["ifNotNil:", "methodContext", "lookupSelector:", "class", "receiver", "selector"],
  1444. referencedClasses: []
  1445. }),
  1446. globals.MethodContext);
  1447. smalltalk.addMethod(
  1448. smalltalk.method({
  1449. selector: "methodContext",
  1450. protocol: 'accessing',
  1451. fn: function (){
  1452. var self=this;
  1453. return smalltalk.withContext(function($ctx1) {
  1454. var $1,$3,$2;
  1455. $1=self._isBlockContext();
  1456. if(! smalltalk.assert($1)){
  1457. return self;
  1458. };
  1459. $3=self._outerContext();
  1460. if(($receiver = $3) == nil || $receiver == null){
  1461. $2=$3;
  1462. } else {
  1463. var outer;
  1464. outer=$receiver;
  1465. $2=_st(outer)._methodContext();
  1466. };
  1467. return $2;
  1468. }, function($ctx1) {$ctx1.fill(self,"methodContext",{},globals.MethodContext)})},
  1469. args: [],
  1470. source: "methodContext\x0a\x09self isBlockContext ifFalse: [ ^ self ].\x0a\x09\x0a\x09^ self outerContext ifNotNil: [ :outer |\x0a\x09\x09outer methodContext ]",
  1471. messageSends: ["ifFalse:", "isBlockContext", "ifNotNil:", "outerContext", "methodContext"],
  1472. referencedClasses: []
  1473. }),
  1474. globals.MethodContext);
  1475. smalltalk.addMethod(
  1476. smalltalk.method({
  1477. selector: "outerContext",
  1478. protocol: 'accessing',
  1479. fn: function (){
  1480. var self=this;
  1481. return self.outerContext || self.homeContext;
  1482. return self},
  1483. args: [],
  1484. source: "outerContext\x0a\x09<return self.outerContext || self.homeContext>",
  1485. messageSends: [],
  1486. referencedClasses: []
  1487. }),
  1488. globals.MethodContext);
  1489. smalltalk.addMethod(
  1490. smalltalk.method({
  1491. selector: "printOn:",
  1492. protocol: 'printing',
  1493. fn: function (aStream){
  1494. var self=this;
  1495. return smalltalk.withContext(function($ctx1) {
  1496. var $1;
  1497. globals.MethodContext.superclass.fn.prototype._printOn_.apply(_st(self), [aStream]);
  1498. _st(aStream)._nextPutAll_("(");
  1499. $ctx1.sendIdx["nextPutAll:"]=1;
  1500. _st(aStream)._nextPutAll_(self._asString());
  1501. $ctx1.sendIdx["nextPutAll:"]=2;
  1502. $1=_st(aStream)._nextPutAll_(")");
  1503. return self}, function($ctx1) {$ctx1.fill(self,"printOn:",{aStream:aStream},globals.MethodContext)})},
  1504. args: ["aStream"],
  1505. source: "printOn: aStream\x0a\x09super printOn: aStream.\x0a\x09aStream \x0a\x09\x09nextPutAll: '(';\x0a\x09\x09nextPutAll: self asString;\x0a\x09\x09nextPutAll: ')'",
  1506. messageSends: ["printOn:", "nextPutAll:", "asString"],
  1507. referencedClasses: []
  1508. }),
  1509. globals.MethodContext);
  1510. smalltalk.addMethod(
  1511. smalltalk.method({
  1512. selector: "receiver",
  1513. protocol: 'accessing',
  1514. fn: function (){
  1515. var self=this;
  1516. return self.receiver;
  1517. return self},
  1518. args: [],
  1519. source: "receiver\x0a\x09<return self.receiver>",
  1520. messageSends: [],
  1521. referencedClasses: []
  1522. }),
  1523. globals.MethodContext);
  1524. smalltalk.addMethod(
  1525. smalltalk.method({
  1526. selector: "selector",
  1527. protocol: 'accessing',
  1528. fn: function (){
  1529. var self=this;
  1530. if(self.selector) {
  1531. return smalltalk.convertSelector(self.selector);
  1532. } else {
  1533. return nil;
  1534. }
  1535. ;
  1536. return self},
  1537. args: [],
  1538. source: "selector\x0a\x09<\x0a\x09\x09if(self.selector) {\x0a\x09\x09\x09return smalltalk.convertSelector(self.selector);\x0a\x09\x09} else {\x0a\x09\x09\x09return nil;\x0a\x09\x09}\x0a\x09>",
  1539. messageSends: [],
  1540. referencedClasses: []
  1541. }),
  1542. globals.MethodContext);
  1543. smalltalk.addMethod(
  1544. smalltalk.method({
  1545. selector: "sendIndexAt:",
  1546. protocol: 'accessing',
  1547. fn: function (aSelector){
  1548. var self=this;
  1549. return self.sendIdx[aSelector] || 0;
  1550. return self},
  1551. args: ["aSelector"],
  1552. source: "sendIndexAt: aSelector\x0a\x09<return self.sendIdx[aSelector] || 0>",
  1553. messageSends: [],
  1554. referencedClasses: []
  1555. }),
  1556. globals.MethodContext);
  1557. smalltalk.addMethod(
  1558. smalltalk.method({
  1559. selector: "sendIndexes",
  1560. protocol: 'accessing',
  1561. fn: function (){
  1562. var self=this;
  1563. return self.sendIdx;
  1564. return self},
  1565. args: [],
  1566. source: "sendIndexes\x0a\x09<return self.sendIdx>",
  1567. messageSends: [],
  1568. referencedClasses: []
  1569. }),
  1570. globals.MethodContext);
  1571. smalltalk.addMethod(
  1572. smalltalk.method({
  1573. selector: "temps",
  1574. protocol: 'accessing',
  1575. fn: function (){
  1576. var self=this;
  1577. return smalltalk.withContext(function($ctx1) {
  1578. var $1;
  1579. self._deprecatedAPI();
  1580. $1=self._locals();
  1581. return $1;
  1582. }, function($ctx1) {$ctx1.fill(self,"temps",{},globals.MethodContext)})},
  1583. args: [],
  1584. source: "temps\x0a\x09self deprecatedAPI.\x0a\x09\x0a\x09^ self locals",
  1585. messageSends: ["deprecatedAPI", "locals"],
  1586. referencedClasses: []
  1587. }),
  1588. globals.MethodContext);
  1589. smalltalk.addClass('NativeFunction', globals.Object, [], 'Kernel-Methods');
  1590. globals.NativeFunction.comment="I am a wrapper around native functions, such as `WebSocket`.\x0aFor 'normal' functions (whose constructor is the JavaScript `Function` object), use `BlockClosure`.\x0a\x0a## API\x0a\x0aSee the class-side `instance creation` methods for instance creation.\x0a\x0aCreated instances will most probably be instance of `JSObjectProxy`.\x0a\x0a## Usage example:\x0a\x0a\x09| ws |\x0a\x09ws := NativeFunction constructor: 'WebSocket' value: 'ws://localhost'.\x0a\x09ws at: 'onopen' put: [ ws send: 'hey there from Amber' ]";
  1591. smalltalk.addMethod(
  1592. smalltalk.method({
  1593. selector: "constructor:",
  1594. protocol: 'instance creation',
  1595. fn: function (aString){
  1596. var self=this;
  1597. var native=eval(aString);
  1598. return new native();
  1599. ;
  1600. return self},
  1601. args: ["aString"],
  1602. source: "constructor: aString\x0a\x09<\x0a\x09\x09var native=eval(aString);\x0a\x09\x09return new native();\x0a\x09>",
  1603. messageSends: [],
  1604. referencedClasses: []
  1605. }),
  1606. globals.NativeFunction.klass);
  1607. smalltalk.addMethod(
  1608. smalltalk.method({
  1609. selector: "constructor:value:",
  1610. protocol: 'instance creation',
  1611. fn: function (aString,anObject){
  1612. var self=this;
  1613. var native=eval(aString);
  1614. return new native(anObject);
  1615. ;
  1616. return self},
  1617. args: ["aString", "anObject"],
  1618. source: "constructor: aString value:anObject\x0a\x09<\x0a\x09\x09var native=eval(aString);\x0a\x09\x09return new native(anObject);\x0a\x09>",
  1619. messageSends: [],
  1620. referencedClasses: []
  1621. }),
  1622. globals.NativeFunction.klass);
  1623. smalltalk.addMethod(
  1624. smalltalk.method({
  1625. selector: "constructor:value:value:",
  1626. protocol: 'instance creation',
  1627. fn: function (aString,anObject,anObject2){
  1628. var self=this;
  1629. var native=eval(aString);
  1630. return new native(anObject,anObject2);
  1631. ;
  1632. return self},
  1633. args: ["aString", "anObject", "anObject2"],
  1634. source: "constructor: aString value:anObject value: anObject2\x0a\x09<\x0a\x09\x09var native=eval(aString);\x0a\x09\x09return new native(anObject,anObject2);\x0a\x09>",
  1635. messageSends: [],
  1636. referencedClasses: []
  1637. }),
  1638. globals.NativeFunction.klass);
  1639. smalltalk.addMethod(
  1640. smalltalk.method({
  1641. selector: "constructor:value:value:value:",
  1642. protocol: 'instance creation',
  1643. fn: function (aString,anObject,anObject2,anObject3){
  1644. var self=this;
  1645. var native=eval(aString);
  1646. return new native(anObject,anObject2, anObject3);
  1647. ;
  1648. return self},
  1649. args: ["aString", "anObject", "anObject2", "anObject3"],
  1650. source: "constructor: aString value:anObject value: anObject2 value:anObject3\x0a\x09<\x0a\x09\x09var native=eval(aString);\x0a\x09\x09return new native(anObject,anObject2, anObject3);\x0a\x09>",
  1651. messageSends: [],
  1652. referencedClasses: []
  1653. }),
  1654. globals.NativeFunction.klass);
  1655. smalltalk.addMethod(
  1656. smalltalk.method({
  1657. selector: "exists:",
  1658. protocol: 'testing',
  1659. fn: function (aString){
  1660. var self=this;
  1661. function $PlatformInterface(){return globals.PlatformInterface||(typeof PlatformInterface=="undefined"?nil:PlatformInterface)}
  1662. return smalltalk.withContext(function($ctx1) {
  1663. var $1;
  1664. $1=_st($PlatformInterface())._existsGlobal_(aString);
  1665. return $1;
  1666. }, function($ctx1) {$ctx1.fill(self,"exists:",{aString:aString},globals.NativeFunction.klass)})},
  1667. args: ["aString"],
  1668. source: "exists: aString\x0a\x09^ PlatformInterface existsGlobal: aString",
  1669. messageSends: ["existsGlobal:"],
  1670. referencedClasses: ["PlatformInterface"]
  1671. }),
  1672. globals.NativeFunction.klass);
  1673. smalltalk.addClass('Timeout', globals.Object, ['rawTimeout'], 'Kernel-Methods');
  1674. globals.Timeout.comment="I am wrapping the returns from `set{Timeout,Interval}`.\x0a\x0a## Motivation\x0a\x0aNumber suffices in browsers, but node.js returns an object.";
  1675. smalltalk.addMethod(
  1676. smalltalk.method({
  1677. selector: "clearInterval",
  1678. protocol: 'timeout/interval',
  1679. fn: function (){
  1680. var self=this;
  1681. var interval = self["@rawTimeout"];
  1682. clearInterval(interval);
  1683. ;
  1684. return self},
  1685. args: [],
  1686. source: "clearInterval\x0a\x09<\x0a\x09\x09var interval = self[\x22@rawTimeout\x22];\x0a\x09\x09clearInterval(interval);\x0a\x09>",
  1687. messageSends: [],
  1688. referencedClasses: []
  1689. }),
  1690. globals.Timeout);
  1691. smalltalk.addMethod(
  1692. smalltalk.method({
  1693. selector: "clearTimeout",
  1694. protocol: 'timeout/interval',
  1695. fn: function (){
  1696. var self=this;
  1697. var timeout = self["@rawTimeout"];
  1698. clearTimeout(timeout);
  1699. ;
  1700. return self},
  1701. args: [],
  1702. source: "clearTimeout\x0a\x09<\x0a\x09\x09var timeout = self[\x22@rawTimeout\x22];\x0a\x09\x09clearTimeout(timeout);\x0a\x09>",
  1703. messageSends: [],
  1704. referencedClasses: []
  1705. }),
  1706. globals.Timeout);
  1707. smalltalk.addMethod(
  1708. smalltalk.method({
  1709. selector: "rawTimeout:",
  1710. protocol: 'accessing',
  1711. fn: function (anObject){
  1712. var self=this;
  1713. self["@rawTimeout"]=anObject;
  1714. return self},
  1715. args: ["anObject"],
  1716. source: "rawTimeout: anObject\x0a\x09rawTimeout := anObject",
  1717. messageSends: [],
  1718. referencedClasses: []
  1719. }),
  1720. globals.Timeout);
  1721. smalltalk.addMethod(
  1722. smalltalk.method({
  1723. selector: "on:",
  1724. protocol: 'instance creation',
  1725. fn: function (anObject){
  1726. var self=this;
  1727. return smalltalk.withContext(function($ctx1) {
  1728. var $2,$3,$1;
  1729. $2=self._new();
  1730. _st($2)._rawTimeout_(anObject);
  1731. $3=_st($2)._yourself();
  1732. $1=$3;
  1733. return $1;
  1734. }, function($ctx1) {$ctx1.fill(self,"on:",{anObject:anObject},globals.Timeout.klass)})},
  1735. args: ["anObject"],
  1736. source: "on: anObject\x0a\x09^ self new rawTimeout: anObject; yourself",
  1737. messageSends: ["rawTimeout:", "new", "yourself"],
  1738. referencedClasses: []
  1739. }),
  1740. globals.Timeout.klass);
  1741. });