2
0

Kernel-Methods.js 64 KB

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