[Laszlo-dev] For Review: Change 20081121-dda-q Summary: Add ability to insert try/catch blocks around functions
Donald Anderson
dda at ddanderson.com
Wed Nov 26 10:03:39 PST 2008
Change 20081121-dda-q by dda at lester.local on 2008-11-21 10:21:40 EST
in /Users/dda/laszlo/src/svn/openlaszlo/trunk-g
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: Add ability to insert try/catch blocks around functions
New Features:
Bugs Fixed: LPP-7270 (swf9: debugger hanging)
Technical Reviewer: ptw (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
This requested feature makes SWF9 similar like SWF8 and DHTML in
the face of
exceptions - in those systems, the exceptions are caught at the
top level, and
the program allowed to continue. In our case, we catch the
exceptions within
every function body, report the error to the debug console, and
return from the function.
. To enable the feature, compile with -DcatchFunctionExceptions=true
Some compilation problems were found in trying to use this feature
with smokecheck.lzx
for SWF9, so for the moment, this is not tied to the debug switch,
but must be
enabled explicitly. This may be fixed soon.
The basic premise is to change the ORIGINAL CONTENTS of a function
to this:
var $lzsc$ret:* = 0;
try {
$lzsc$ret = (function () {
with (this) {
//ORIGINAL CONTENTS
}}).call(this)
}
catch ($lzsc$e) {
$lzsc$runtime.reportException("LPP-7270.lzx", 5, $lzsc$e)
}
finally {
return $lzsc$ret
}
with the slight variation that if the original function is
declared to return a type,
then the closure is also typed e.g. function (): String { ...
This construct has the property that it will compile almost any
contents the same,
preserving return values and reporting the same compiler errors,
including paths
that do not return a value. For some reason, if the ORIGINAL
CONTENTS contains a closure,
the flex compiler will report errors that attributes and even
globals
cannot be seen within that closure. So this transformation is not
done when
the function contains a closure. Also, super() calls cannot be
pushed into a closure, so the
transformation is not done if a super call is contained.
A toString() function was added to ASTFormalParameterList to show
the return type of the function.
catchFunctionExceptions=false is added to the build scripts for
the LFC. This is technically
not needed at the moment, but when we attach the
catchFunctionExceptions option to the debug
option, it will be.
Tests:
Regression (swf8,swf9,dhtml) x (smokecheck,lzpix,weather)
This change tested using the following test program, compiling
with both
-DcatchFunctionExceptions=true and false, observing generated
compiler output
for both cases, and running it with both cases. Only the
catchFunctionExceptions=true
allows the program to proceed after an exception.
test program:
<!-- ================================= -->
<canvas debug="true">
<simplelayout spacing="10" axis="y" />
<class name="mywindow" width="300">
<button onclick="this.parent.parent.canvas_f()"
>BaseClass mywindow</button>
</class>
<method name="canvas_f">
Debug.info("1 zebra");
Debug.info("2");
t1.setText("Before exception");
Debug.info("3...?");
throwexcept(7,0);
Debug.info("4!!");
t2.setText("After exception");
</method>
<button name="b1" onclick="this.parent.canvas_f()"
width="100" height="30" y="10">Press me</button>
<text name="t1" bgcolor="#ccffcc" width="100" height="30"
y="50"/>
<text name="t2" bgcolor="#ccffcc" width="100" height="30"
y="100"/>
<mywindow bgcolor="#cc8c8c"/>
<script>
function throwexcept(w, x) {
// divide by zero doesn't give an exception, but
// an array reference of a non array will.
return w[x]/x;
}
</script>
</canvas>
<!-- ================================= -->
Files:
M WEB-INF/lps/lfc/buildlfc
M WEB-INF/lps/lfc/buildlfcdebug
M WEB-INF/lps/lfc/build.xml
M WEB-INF/lps/lfc/compiler/LzRuntime.lzs
M WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
M WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
M WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/
ASTFormalParameterList.java
Changeset: http://svn.openlaszlo.org/openlaszlo/patches/20081121-dda-q.tar
--
Don Anderson
Java/C/C++, Berkeley DB, systems consultant
voice: 617-547-7881
email: dda at ddanderson.com
www: http://www.ddanderson.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openlaszlo.org/pipermail/laszlo-dev/attachments/20081126/772483a5/attachment-0001.html
More information about the Laszlo-dev
mailing list