Kernel-Exceptions.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. smalltalk.addPackage('Kernel-Exceptions', {});
  2. smalltalk.addClass('Error', smalltalk.Object, ['messageText'], 'Kernel-Exceptions');
  3. smalltalk.Error.comment="From the ANSI standard:\x0a\x0aThis protocol describes the behavior of instances of class `Error`. \x0aThese are used to represent error conditions that prevent the normal continuation of processing. \x0aActual error exceptions used by an application may be subclasses of this class.\x0aAs `Error` is explicitly specified to be subclassable, conforming implementations must implement its behavior in a non-fragile manner."
  4. smalltalk.addMethod(
  5. "_context",
  6. smalltalk.method({
  7. selector: "context",
  8. category: 'accessing',
  9. fn: function (){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) { return self.context;
  12. return self}, function($ctx1) {$ctx1.fill(self,"context",{}, smalltalk.Error)})},
  13. args: [],
  14. source: "context\x0a\x09<return self.context>",
  15. messageSends: [],
  16. referencedClasses: []
  17. }),
  18. smalltalk.Error);
  19. smalltalk.addMethod(
  20. "_initialize",
  21. smalltalk.method({
  22. selector: "initialize",
  23. category: 'initialization',
  24. fn: function (){
  25. var self=this;
  26. return smalltalk.withContext(function($ctx1) { _st(self)._messageText_(_st("Errorclass: ").__comma(_st(_st(self)._class())._name()));
  27. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.Error)})},
  28. args: [],
  29. source: "initialize\x0a\x09self messageText: 'Errorclass: ', (self class name).",
  30. messageSends: ["messageText:", ",", "name", "class"],
  31. referencedClasses: []
  32. }),
  33. smalltalk.Error);
  34. smalltalk.addMethod(
  35. "_isSmalltalkError",
  36. smalltalk.method({
  37. selector: "isSmalltalkError",
  38. category: 'testing',
  39. fn: function (){
  40. var self=this;
  41. return smalltalk.withContext(function($ctx1) { return self.smalltalkError === true;
  42. return self}, function($ctx1) {$ctx1.fill(self,"isSmalltalkError",{}, smalltalk.Error)})},
  43. args: [],
  44. source: "isSmalltalkError\x0a\x09<return self.smalltalkError === true>",
  45. messageSends: [],
  46. referencedClasses: []
  47. }),
  48. smalltalk.Error);
  49. smalltalk.addMethod(
  50. "_jsStack",
  51. smalltalk.method({
  52. selector: "jsStack",
  53. category: 'accessing',
  54. fn: function (){
  55. var self=this;
  56. return smalltalk.withContext(function($ctx1) { return self.stack;
  57. return self}, function($ctx1) {$ctx1.fill(self,"jsStack",{}, smalltalk.Error)})},
  58. args: [],
  59. source: "jsStack\x0a\x09<return self.stack>",
  60. messageSends: [],
  61. referencedClasses: []
  62. }),
  63. smalltalk.Error);
  64. smalltalk.addMethod(
  65. "_messageText",
  66. smalltalk.method({
  67. selector: "messageText",
  68. category: 'accessing',
  69. fn: function (){
  70. var self=this;
  71. return smalltalk.withContext(function($ctx1) { var $1;
  72. $1=self["@messageText"];
  73. return $1;
  74. }, function($ctx1) {$ctx1.fill(self,"messageText",{}, smalltalk.Error)})},
  75. args: [],
  76. source: "messageText\x0a\x09^messageText",
  77. messageSends: [],
  78. referencedClasses: []
  79. }),
  80. smalltalk.Error);
  81. smalltalk.addMethod(
  82. "_messageText_",
  83. smalltalk.method({
  84. selector: "messageText:",
  85. category: 'accessing',
  86. fn: function (aString){
  87. var self=this;
  88. return smalltalk.withContext(function($ctx1) { self["@messageText"]=aString;
  89. return self}, function($ctx1) {$ctx1.fill(self,"messageText:",{aString:aString}, smalltalk.Error)})},
  90. args: ["aString"],
  91. source: "messageText: aString\x0a\x09messageText := aString",
  92. messageSends: [],
  93. referencedClasses: []
  94. }),
  95. smalltalk.Error);
  96. smalltalk.addMethod(
  97. "_signal",
  98. smalltalk.method({
  99. selector: "signal",
  100. category: 'signaling',
  101. fn: function (){
  102. var self=this;
  103. return smalltalk.withContext(function($ctx1) { self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self);
  104. return self}, function($ctx1) {$ctx1.fill(self,"signal",{}, smalltalk.Error)})},
  105. args: [],
  106. source: "signal\x0a\x09<self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>",
  107. messageSends: [],
  108. referencedClasses: []
  109. }),
  110. smalltalk.Error);
  111. smalltalk.addMethod(
  112. "_signal_",
  113. smalltalk.method({
  114. selector: "signal:",
  115. category: 'signaling',
  116. fn: function (aString){
  117. var self=this;
  118. return smalltalk.withContext(function($ctx1) { _st(self)._messageText_(aString);
  119. _st(self)._signal();
  120. return self}, function($ctx1) {$ctx1.fill(self,"signal:",{aString:aString}, smalltalk.Error)})},
  121. args: ["aString"],
  122. source: "signal: aString\x0a\x09self messageText: aString.\x0a\x09self signal",
  123. messageSends: ["messageText:", "signal"],
  124. referencedClasses: []
  125. }),
  126. smalltalk.Error);
  127. smalltalk.addMethod(
  128. "_signal",
  129. smalltalk.method({
  130. selector: "signal",
  131. category: 'instance creation',
  132. fn: function (){
  133. var self=this;
  134. return smalltalk.withContext(function($ctx1) { var $1;
  135. $1=_st(_st(self)._new())._signal();
  136. return $1;
  137. }, function($ctx1) {$ctx1.fill(self,"signal",{}, smalltalk.Error.klass)})},
  138. args: [],
  139. source: "signal\x0a\x09^self new signal",
  140. messageSends: ["signal", "new"],
  141. referencedClasses: []
  142. }),
  143. smalltalk.Error.klass);
  144. smalltalk.addMethod(
  145. "_signal_",
  146. smalltalk.method({
  147. selector: "signal:",
  148. category: 'instance creation',
  149. fn: function (aString){
  150. var self=this;
  151. return smalltalk.withContext(function($ctx1) { var $1;
  152. $1=_st(_st(self)._new())._signal_(aString);
  153. return $1;
  154. }, function($ctx1) {$ctx1.fill(self,"signal:",{aString:aString}, smalltalk.Error.klass)})},
  155. args: ["aString"],
  156. source: "signal: aString\x0a\x09 ^self new\x0a\x09\x09signal: aString",
  157. messageSends: ["signal:", "new"],
  158. referencedClasses: []
  159. }),
  160. smalltalk.Error.klass);
  161. smalltalk.addClass('MessageNotUnderstood', smalltalk.Error, ['message', 'receiver'], 'Kernel-Exceptions');
  162. smalltalk.MessageNotUnderstood.comment="This exception is provided to support `Object>>doesNotUnderstand:`."
  163. smalltalk.addMethod(
  164. "_message",
  165. smalltalk.method({
  166. selector: "message",
  167. category: 'accessing',
  168. fn: function (){
  169. var self=this;
  170. return smalltalk.withContext(function($ctx1) { var $1;
  171. $1=self["@message"];
  172. return $1;
  173. }, function($ctx1) {$ctx1.fill(self,"message",{}, smalltalk.MessageNotUnderstood)})},
  174. args: [],
  175. source: "message\x0a\x09^message",
  176. messageSends: [],
  177. referencedClasses: []
  178. }),
  179. smalltalk.MessageNotUnderstood);
  180. smalltalk.addMethod(
  181. "_message_",
  182. smalltalk.method({
  183. selector: "message:",
  184. category: 'accessing',
  185. fn: function (aMessage){
  186. var self=this;
  187. return smalltalk.withContext(function($ctx1) { self["@message"]=aMessage;
  188. return self}, function($ctx1) {$ctx1.fill(self,"message:",{aMessage:aMessage}, smalltalk.MessageNotUnderstood)})},
  189. args: ["aMessage"],
  190. source: "message: aMessage\x0a\x09message := aMessage",
  191. messageSends: [],
  192. referencedClasses: []
  193. }),
  194. smalltalk.MessageNotUnderstood);
  195. smalltalk.addMethod(
  196. "_messageText",
  197. smalltalk.method({
  198. selector: "messageText",
  199. category: 'accessing',
  200. fn: function (){
  201. var self=this;
  202. return smalltalk.withContext(function($ctx1) { var $1;
  203. $1=_st(_st(_st(_st(self)._receiver())._asString()).__comma(" does not understand #")).__comma(_st(_st(self)._message())._selector());
  204. return $1;
  205. }, function($ctx1) {$ctx1.fill(self,"messageText",{}, smalltalk.MessageNotUnderstood)})},
  206. args: [],
  207. source: "messageText\x0a\x09^self receiver asString, ' does not understand #', self message selector",
  208. messageSends: [",", "selector", "message", "asString", "receiver"],
  209. referencedClasses: []
  210. }),
  211. smalltalk.MessageNotUnderstood);
  212. smalltalk.addMethod(
  213. "_receiver",
  214. smalltalk.method({
  215. selector: "receiver",
  216. category: 'accessing',
  217. fn: function (){
  218. var self=this;
  219. return smalltalk.withContext(function($ctx1) { var $1;
  220. $1=self["@receiver"];
  221. return $1;
  222. }, function($ctx1) {$ctx1.fill(self,"receiver",{}, smalltalk.MessageNotUnderstood)})},
  223. args: [],
  224. source: "receiver\x0a\x09^receiver",
  225. messageSends: [],
  226. referencedClasses: []
  227. }),
  228. smalltalk.MessageNotUnderstood);
  229. smalltalk.addMethod(
  230. "_receiver_",
  231. smalltalk.method({
  232. selector: "receiver:",
  233. category: 'accessing',
  234. fn: function (anObject){
  235. var self=this;
  236. return smalltalk.withContext(function($ctx1) { self["@receiver"]=anObject;
  237. return self}, function($ctx1) {$ctx1.fill(self,"receiver:",{anObject:anObject}, smalltalk.MessageNotUnderstood)})},
  238. args: ["anObject"],
  239. source: "receiver: anObject\x0a\x09receiver := anObject",
  240. messageSends: [],
  241. referencedClasses: []
  242. }),
  243. smalltalk.MessageNotUnderstood);
  244. smalltalk.addClass('NonBooleanReceiver', smalltalk.Error, ['object'], 'Kernel-Exceptions');
  245. smalltalk.NonBooleanReceiver.comment="NonBooleanReceiver exceptions may be thrown when executing inlined methods such as `#ifTrue:` with a non boolean receiver."
  246. smalltalk.addMethod(
  247. "_object",
  248. smalltalk.method({
  249. selector: "object",
  250. category: 'accessing',
  251. fn: function (){
  252. var self=this;
  253. return smalltalk.withContext(function($ctx1) { var $1;
  254. $1=self["@object"];
  255. return $1;
  256. }, function($ctx1) {$ctx1.fill(self,"object",{}, smalltalk.NonBooleanReceiver)})},
  257. args: [],
  258. source: "object\x0a\x09^ object",
  259. messageSends: [],
  260. referencedClasses: []
  261. }),
  262. smalltalk.NonBooleanReceiver);
  263. smalltalk.addMethod(
  264. "_object_",
  265. smalltalk.method({
  266. selector: "object:",
  267. category: 'accessing',
  268. fn: function (anObject){
  269. var self=this;
  270. return smalltalk.withContext(function($ctx1) { self["@object"]=anObject;
  271. return self}, function($ctx1) {$ctx1.fill(self,"object:",{anObject:anObject}, smalltalk.NonBooleanReceiver)})},
  272. args: ["anObject"],
  273. source: "object: anObject\x0a\x09object := anObject",
  274. messageSends: [],
  275. referencedClasses: []
  276. }),
  277. smalltalk.NonBooleanReceiver);
  278. smalltalk.addClass('ErrorHandler', smalltalk.Object, [], 'Kernel-Exceptions');
  279. smalltalk.ErrorHandler.comment="ErrorHandler is used to manage Smalltalk errors. \x0aSee `boot.js` `handleError()` function.\x0a\x0aSubclasses of `ErrorHandler` can register themselves as the current handler with\x0a`ErrorHandler class >> register`.\x0a\x0aSubclasses may override `#handleError:` to perform an action on the thrown exception.\x0aThe default behavior is to log the error and the context stack to the JavaScript console."
  280. smalltalk.addMethod(
  281. "_handleError_",
  282. smalltalk.method({
  283. selector: "handleError:",
  284. category: 'error handling',
  285. fn: function (anError){
  286. var self=this;
  287. return smalltalk.withContext(function($ctx1) { var $1;
  288. $1=_st(anError)._context();
  289. if(($receiver = $1) == nil || $receiver == undefined){
  290. $1;
  291. } else {
  292. _st(self)._logErrorContext_(_st(anError)._context());
  293. };
  294. _st(self)._logError_(anError);
  295. return self}, function($ctx1) {$ctx1.fill(self,"handleError:",{anError:anError}, smalltalk.ErrorHandler)})},
  296. args: ["anError"],
  297. source: "handleError: anError\x0a\x09anError context ifNotNil: [self logErrorContext: anError context].\x0a\x09self logError: anError",
  298. messageSends: ["ifNotNil:", "logErrorContext:", "context", "logError:"],
  299. referencedClasses: []
  300. }),
  301. smalltalk.ErrorHandler);
  302. smalltalk.addMethod(
  303. "_log_",
  304. smalltalk.method({
  305. selector: "log:",
  306. category: 'private',
  307. fn: function (aString){
  308. var self=this;
  309. return smalltalk.withContext(function($ctx1) { _st(console)._log_(aString);
  310. return self}, function($ctx1) {$ctx1.fill(self,"log:",{aString:aString}, smalltalk.ErrorHandler)})},
  311. args: ["aString"],
  312. source: "log: aString\x0a\x09console log: aString",
  313. messageSends: ["log:"],
  314. referencedClasses: []
  315. }),
  316. smalltalk.ErrorHandler);
  317. smalltalk.addMethod(
  318. "_logContext_",
  319. smalltalk.method({
  320. selector: "logContext:",
  321. category: 'private',
  322. fn: function (aContext){
  323. var self=this;
  324. return smalltalk.withContext(function($ctx1) { var $1;
  325. $1=_st(aContext)._home();
  326. if(($receiver = $1) == nil || $receiver == undefined){
  327. $1;
  328. } else {
  329. _st(self)._logContext_(_st(aContext)._home());
  330. };
  331. _st(self)._log_(_st(_st(_st(_st(aContext)._receiver())._asString()).__comma(">>")).__comma(_st(_st(aContext)._selector())._asString()));
  332. return self}, function($ctx1) {$ctx1.fill(self,"logContext:",{aContext:aContext}, smalltalk.ErrorHandler)})},
  333. args: ["aContext"],
  334. source: "logContext: aContext\x0a\x09aContext home ifNotNil: [\x0a\x09\x09self logContext: aContext home].\x0a\x09self log: aContext receiver asString, '>>', aContext selector asString",
  335. messageSends: ["ifNotNil:", "logContext:", "home", "log:", ",", "asString", "selector", "receiver"],
  336. referencedClasses: []
  337. }),
  338. smalltalk.ErrorHandler);
  339. smalltalk.addMethod(
  340. "_logError_",
  341. smalltalk.method({
  342. selector: "logError:",
  343. category: 'private',
  344. fn: function (anError){
  345. var self=this;
  346. return smalltalk.withContext(function($ctx1) { _st(self)._log_(_st(anError)._messageText());
  347. return self}, function($ctx1) {$ctx1.fill(self,"logError:",{anError:anError}, smalltalk.ErrorHandler)})},
  348. args: ["anError"],
  349. source: "logError: anError\x0a\x09self log: anError messageText",
  350. messageSends: ["log:", "messageText"],
  351. referencedClasses: []
  352. }),
  353. smalltalk.ErrorHandler);
  354. smalltalk.addMethod(
  355. "_logErrorContext_",
  356. smalltalk.method({
  357. selector: "logErrorContext:",
  358. category: 'private',
  359. fn: function (aContext){
  360. var self=this;
  361. return smalltalk.withContext(function($ctx1) { var $1,$3,$2;
  362. $1=aContext;
  363. $2=(function(){
  364. return smalltalk.withContext(function($ctx2) { $3=_st(aContext)._home();
  365. if(($receiver = $3) == nil || $receiver == undefined){
  366. return $3;
  367. } else {
  368. return _st(self)._logContext_(_st(aContext)._home());
  369. };
  370. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})});
  371. _st($1)._ifNotNil_($2);
  372. return self}, function($ctx1) {$ctx1.fill(self,"logErrorContext:",{aContext:aContext}, smalltalk.ErrorHandler)})},
  373. args: ["aContext"],
  374. source: "logErrorContext: aContext\x0a\x09aContext ifNotNil: [\x0a\x09\x09aContext home ifNotNil: [\x0a\x09\x09\x09self logContext: aContext home]]",
  375. messageSends: ["ifNotNil:", "logContext:", "home"],
  376. referencedClasses: []
  377. }),
  378. smalltalk.ErrorHandler);
  379. smalltalk.ErrorHandler.klass.iVarNames = ['current'];
  380. smalltalk.addMethod(
  381. "_current",
  382. smalltalk.method({
  383. selector: "current",
  384. category: 'accessing',
  385. fn: function (){
  386. var self=this;
  387. return smalltalk.withContext(function($ctx1) { var $2,$1;
  388. $2=self["@current"];
  389. if(($receiver = $2) == nil || $receiver == undefined){
  390. self["@current"]=_st(self)._new();
  391. $1=self["@current"];
  392. } else {
  393. $1=$2;
  394. };
  395. return $1;
  396. }, function($ctx1) {$ctx1.fill(self,"current",{}, smalltalk.ErrorHandler.klass)})},
  397. args: [],
  398. source: "current\x0a\x09^current ifNil: [current := self new]",
  399. messageSends: ["ifNil:", "new"],
  400. referencedClasses: []
  401. }),
  402. smalltalk.ErrorHandler.klass);
  403. smalltalk.addMethod(
  404. "_initialize",
  405. smalltalk.method({
  406. selector: "initialize",
  407. category: 'initialization',
  408. fn: function (){
  409. var self=this;
  410. return smalltalk.withContext(function($ctx1) { _st(self)._register();
  411. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.ErrorHandler.klass)})},
  412. args: [],
  413. source: "initialize\x0a\x09self register",
  414. messageSends: ["register"],
  415. referencedClasses: []
  416. }),
  417. smalltalk.ErrorHandler.klass);
  418. smalltalk.addMethod(
  419. "_register",
  420. smalltalk.method({
  421. selector: "register",
  422. category: 'initialization',
  423. fn: function (){
  424. var self=this;
  425. return smalltalk.withContext(function($ctx1) { _st((smalltalk.ErrorHandler || ErrorHandler))._setCurrent_(_st(self)._new());
  426. return self}, function($ctx1) {$ctx1.fill(self,"register",{}, smalltalk.ErrorHandler.klass)})},
  427. args: [],
  428. source: "register\x0a\x09ErrorHandler setCurrent: self new",
  429. messageSends: ["setCurrent:", "new"],
  430. referencedClasses: ["ErrorHandler"]
  431. }),
  432. smalltalk.ErrorHandler.klass);
  433. smalltalk.addMethod(
  434. "_setCurrent_",
  435. smalltalk.method({
  436. selector: "setCurrent:",
  437. category: 'accessing',
  438. fn: function (anHandler){
  439. var self=this;
  440. return smalltalk.withContext(function($ctx1) { self["@current"]=anHandler;
  441. return self}, function($ctx1) {$ctx1.fill(self,"setCurrent:",{anHandler:anHandler}, smalltalk.ErrorHandler.klass)})},
  442. args: ["anHandler"],
  443. source: "setCurrent: anHandler\x0a\x09current := anHandler",
  444. messageSends: [],
  445. referencedClasses: []
  446. }),
  447. smalltalk.ErrorHandler.klass);