# HG changeset patch -- Bitbucket.org # Project clamato [abbat] # URL http://bitbucket.org/abbat/clamato-abbat/overview/ # User Alx@home-comp # Date 1254978611 -14400 # Node ID d34b959f9b3f28b2bc140866bbff5fccabbcd215 # Parent d4f7ff03745f06d4a5a937491aae4b2b3d9087cd Wrapp JavaScript object Error and small refctoring of error handling in Workspace. --- a/js/bootstrap.js +++ b/js/bootstrap.js @@ -67,6 +67,8 @@ clamato.wrap("Clamato", Clamato); clamato.wrap("Nil", ClamatoNil); clamato.wrap("Object", ClamatoObject); clamato.wrap("Class", ClamatoClass); +clamato.wrap("Error", Error); + // compiled: lib/lib.st clamato.define("Object", ["class"]); @@ -2054,6 +2056,29 @@ instanceVariableNames: []}, function(){// Boolean class var self = this; return clamato.Boolean}); +clamato.define("Error", []); +clamato.install("Error", +"class", "_class", false, +{source: unescape("-%20class%0A%09Error."), +filename: unescape("lib/lib.st"), +selectorsSent: [], +classesReferenced: ["Error"], +instanceVariableNames: []}, +function(){// Error class +var self = this; +return clamato.Error}); +clamato.install("Error", +"message", "_message", false, +{source: unescape("-%20message%0A%7B%0A%09return%20this.message%20%3F%20this.message%20%3A%20clamato.Nil._new%28%29%3B%0A%7D."), +filename: unescape("lib/lib.st"), +selectorsSent: [], +classesReferenced: [], +instanceVariableNames: []}, +function(){// Error message +var self = this; + + return this.message ? this.message : clamato.Nil._new(); +}); // compiled: lib/peg.st --- a/js/clamato.js +++ b/js/clamato.js @@ -67,3 +67,5 @@ clamato.wrap("Clamato", Clamato); clamato.wrap("Nil", ClamatoNil); clamato.wrap("Object", ClamatoObject); clamato.wrap("Class", ClamatoClass); +clamato.wrap("Error", Error); + --- a/js/libweb.js +++ b/js/libweb.js @@ -85,6 +85,8 @@ clamato.wrap("Clamato", Clamato); clamato.wrap("Nil", ClamatoNil); clamato.wrap("Object", ClamatoObject); clamato.wrap("Class", ClamatoClass); +clamato.wrap("Error", Error); + window.print = function(x) {}; clamato.wrap("Event", jQuery.Event); // compiled: lib/lib.st @@ -2074,6 +2076,29 @@ instanceVariableNames: []}, function(){// Boolean class var self = this; return clamato.Boolean}); +clamato.define("Error", []); +clamato.install("Error", +"class", "_class", false, +{source: unescape("-%20class%0A%09Error."), +filename: unescape("lib/lib.st"), +selectorsSent: [], +classesReferenced: ["Error"], +instanceVariableNames: []}, +function(){// Error class +var self = this; +return clamato.Error}); +clamato.install("Error", +"message", "_message", false, +{source: unescape("-%20message%0A%7B%0A%09return%20this.message%20%3F%20this.message%20%3A%20clamato.Nil._new%28%29%3B%0A%7D."), +filename: unescape("lib/lib.st"), +selectorsSent: [], +classesReferenced: [], +instanceVariableNames: []}, +function(){// Error message +var self = this; + + return this.message ? this.message : clamato.Nil._new(); +}); // compiled: lib/web.st --- a/lib/lib.st +++ b/lib/lib.st @@ -656,3 +656,13 @@ - class Boolean. + + + +- class + Error. + +- message +{ + return this.message ? this.message : clamato.Nil._new(); +}. --- a/lib/workspace.st +++ b/lib/workspace.st @@ -6,7 +6,11 @@ @workspace := '#code' q. @className := 'DoIt'. -- eval: aString { return $.globalEval(aString); }. +- eval: aString +{ + var res = $.globalEval(aString) ; + return res === undefined ? true : res; +}. - compile: aString | code src | @@ -32,15 +36,11 @@ - printIt | output tempStart tempEnd res1| res1 := [self compile: self selection] catch: [:e | e]. - (Clamato isJSError: res1) ifTrueRet: - [ |msg| - msg := Clamato getJSErrorMessageFrom: res1. - Clamato alert: 'Compile error: ', msg ]. + res1 class = Error ifTrueRet: + [Clamato alert: res1]. result := [(clamato at: self className) doIt] catch: [:e | e]. - (Clamato isJSError: result) ifTrueRet: - [ |msg| - msg := Clamato getJSErrorMessageFrom: result. - Clamato alert: 'Eval error: ', msg]. + result class = Error ifTrueRet: + [Clamato alert: result]. tempStart := self end. tempEnd := self end + 1 + result asString size. output := (@workspace value copyFrom: 0 to: self end - 1), ' ', result, (@workspace value copyFrom: self end to: @workspace value size - 1). --- a/js/libs.js +++ b/js/libs.js @@ -1985,6 +1985,29 @@ instanceVariableNames: []}, function(){// Boolean class var self = this; return clamato.Boolean}); +clamato.define("Error", []); +clamato.install("Error", +"class", "_class", false, +{source: unescape("-%20class%0A%09Error."), +filename: unescape("lib/lib.st"), +selectorsSent: [], +classesReferenced: ["Error"], +instanceVariableNames: []}, +function(){// Error class +var self = this; +return clamato.Error}); +clamato.install("Error", +"message", "_message", false, +{source: unescape("-%20message%0A%7B%0A%09return%20this.message%20%3F%20this.message%20%3A%20clamato.Nil._new%28%29%3B%0A%7D."), +filename: unescape("lib/lib.st"), +selectorsSent: [], +classesReferenced: [], +instanceVariableNames: []}, +function(){// Error message +var self = this; + + return this.message ? this.message : clamato.Nil._new(); +}); // compiled: lib/peg.st @@ -6838,14 +6861,17 @@ var self = this; return (self["@className"] = "DoIt")}); clamato.install("Workspace", "eval:", "_eval_", false, -{source: unescape("-%20eval%3A%20aString%20%7B%20return%20%24.globalEval%28aString%29%3B%20%7D."), +{source: unescape("-%20eval%3A%20aString%20%0A%7B%20%0A%09var%20res%20%3D%20%24.globalEval%28aString%29%20%3B%0A%09return%20res%20%3D%3D%3D%20undefined%20%3F%20true%20%3A%20%20res%3B%20%0A%7D."), filename: unescape("lib/workspace.st"), selectorsSent: [], classesReferenced: [], instanceVariableNames: []}, function(aString){// Workspace eval: var self = this; - return $.globalEval(aString); }); + + var res = $.globalEval(aString) ; + return res === undefined ? true : res; +}); clamato.install("Workspace", "compile:", "_compile_", false, {source: unescape("-%20compile%3A%20aString%20%0A%20%20%20%20%7C%20code%20src%20%7C%0A%20%20%20%20clamato%20filename%3A%20%27doIt.st%27.%0A%20%20%20%20src%20%3A%3D%20%28aString%20matches%3A%20%27%5C.%24%27%29%0A%20%20%20%20%20%20%20%20ifTrue%3A%20%5BaString%5D%0A%20%20%20%20%20%20%20%20ifFalse%3A%20%5BaString%2C%20%27.%27%5D.%0A%20%20%20%20code%20%3A%3D%20%27%3C%27%2C%20self%20className%2C%20%27%3E%20+doIt%20%27%2C%20src.%0A%20%20%20%20self%20eval%3A%20%28clamato%20compile%3A%20code%29."), @@ -6884,10 +6910,10 @@ var self = this; return (self["@workspace"] = aTextareaElement)}); clamato.install("Workspace", "printIt", "_printIt", false, -{source: unescape("-%20printIt%0A%09%7C%20output%20tempStart%20tempEnd%20res1%7C%0A%09res1%20%3A%3D%20%5Bself%20compile%3A%20self%20selection%5D%20catch%3A%20%5B%3Ae%20%7C%20e%5D.%0A%09%28Clamato%20isJSError%3A%20res1%29%20ifTrueRet%3A%20%0A%09%09%5B%20%7Cmsg%7C%0A%09%09msg%20%3A%3D%20Clamato%20getJSErrorMessageFrom%3A%20res1.%0A%09%09Clamato%20alert%3A%20%27Compile%20error%3A%20%27%2C%20msg%20%5D.%0A%09result%20%3A%3D%20%5B%28clamato%20at%3A%20self%20className%29%20doIt%5D%20catch%3A%20%5B%3Ae%20%7C%20e%5D.%0A%09%28Clamato%20isJSError%3A%20result%29%20ifTrueRet%3A%20%0A%09%09%5B%20%7Cmsg%7C%0A%09%09msg%20%3A%3D%20Clamato%20getJSErrorMessageFrom%3A%20result.%0A%09%09Clamato%20alert%3A%20%27Eval%20error%3A%20%27%2C%20msg%5D.%0A%09tempStart%20%3A%3D%20self%20end.%0A%09tempEnd%20%3A%3D%20self%20end%20+%201%20+%20result%20asString%20size.%0A%09output%20%3A%3D%20%28@workspace%20value%20copyFrom%3A%200%20to%3A%20self%20end%20-%201%29%2C%20%27%20%27%2C%20result%2C%20%28@workspace%20value%20copyFrom%3A%20self%20end%20to%3A%20@workspace%20value%20size%20-%201%29.%0A%09@workspace%20value%3A%20output.%0A%09@workspace%20selectionStart%3A%20tempStart.%0A%09@workspace%20selectionEnd%3A%20tempEnd.%0A%09self%20start%3A%20tempStart.%0A%09self%20end%3A%20tempEnd."), -filename: unescape("lib/workspace.st"), -selectorsSent: [unescape("+"), unescape("%2C"), unescape("-"), "alert:", "asString", "at:", "catch:", "className", "compile:", "copyFrom:to:", "doIt", "end", "end:", "getJSErrorMessageFrom:", "ifTrueRet:", "isJSError:", "selection", "selectionEnd:", "selectionStart:", "size", "start:", "value", "value:"], -classesReferenced: ["Clamato"], +{source: unescape("-%20printIt%0A%09%7C%20output%20tempStart%20tempEnd%20res1%7C%0A%09res1%20%3A%3D%20%5Bself%20compile%3A%20self%20selection%5D%20catch%3A%20%5B%3Ae%20%7C%20e%5D.%0A%09res1%20class%20%3D%20Error%20ifTrueRet%3A%20%0A%09%09%5BClamato%20alert%3A%20res1%5D.%0A%09result%20%3A%3D%20%5B%28clamato%20at%3A%20self%20className%29%20doIt%5D%20catch%3A%20%5B%3Ae%20%7C%20e%5D.%0A%09result%20class%20%3D%20Error%20ifTrueRet%3A%20%0A%09%09%5BClamato%20alert%3A%20result%5D.%0A%09tempStart%20%3A%3D%20self%20end.%0A%09tempEnd%20%3A%3D%20self%20end%20+%201%20+%20result%20asString%20size.%0A%09output%20%3A%3D%20%28@workspace%20value%20copyFrom%3A%200%20to%3A%20self%20end%20-%201%29%2C%20%27%20%27%2C%20result%2C%20%28@workspace%20value%20copyFrom%3A%20self%20end%20to%3A%20@workspace%20value%20size%20-%201%29.%0A%09@workspace%20value%3A%20output.%0A%09@workspace%20selectionStart%3A%20tempStart.%0A%09@workspace%20selectionEnd%3A%20tempEnd.%0A%09self%20start%3A%20tempStart.%0A%09self%20end%3A%20tempEnd."), +filename: unescape("lib/workspace.st"), +selectorsSent: [unescape("+"), unescape("%2C"), unescape("-"), unescape("%3D"), "alert:", "asString", "at:", "catch:", "class", "className", "compile:", "copyFrom:to:", "doIt", "end", "end:", "ifTrueRet:", "selection", "selectionEnd:", "selectionStart:", "size", "start:", "value", "value:"], +classesReferenced: ["Clamato", "Error"], instanceVariableNames: ["workspace"]}, function(){// Workspace printIt var self = this; @@ -6896,9 +6922,9 @@ var tempStart = nil; var tempEnd = nil; var res1 = nil; (res1 = (function(){return self._compile_(self._selection())})._catch_((function(e){return e}))); -if (clamato.Clamato._isJSError_(res1)) return (msg = clamato.Clamato._getJSErrorMessageFrom_(res1)), clamato.Clamato._alert_("Compile error: ".$comma(msg)); +if (res1._class().$eq(clamato.Error)) return clamato.Clamato._alert_(res1); (result = (function(){return clamato._at_(self._className())._doIt()})._catch_((function(e){return e}))); -if (clamato.Clamato._isJSError_(result)) return (msg = clamato.Clamato._getJSErrorMessageFrom_(result)), clamato.Clamato._alert_("Eval error: ".$comma(msg)); +if (result._class().$eq(clamato.Error)) return clamato.Clamato._alert_(result); (tempStart = self._end()); (tempEnd = self._end().$plus((1)).$plus(result._asString()._size())); (output = self["@workspace"]._value()._copyFrom_to_((0), self._end().$minus((1))).$comma(" ").$comma(result).$comma(self["@workspace"]._value()._copyFrom_to_(self._end(), self["@workspace"]._value()._size().$minus((1)))));