Author: ptw
Date: 2008-01-22 04:57:17 -0800 (Tue, 22 Jan 2008)
New Revision: 7868
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs
openlaszlo/trunk/WEB-INF/lps/lfc/core/UserClass.lzs
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
Log:
Change 20080122-ptw-p by [EMAIL PROTECTED] on 2008-01-22 07:42:43 EST
in /Users/ptw/OpenLaszlo/ringding
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: Declare anonymous setters as methods at compile time
Bugs Fixed:
LPP-1587 'ECMA4: Compile LZX declarations as JS declarations' (partial)
Technical Reviewer: [EMAIL PROTECTED] (pending)
QA Reviewer: [EMAIL PROTECTED] (pending)
Details:
LzNode, UserClass: $setters is now a map of attribute name to
setter method name (not function expressions that need to be
dynamically installed as methods).
NodeModel: Translate setter bodies into methods in the 'lzc' namespace.
Tests:
smokecheck, amazon, ant lztest
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs 2008-01-22 12:55:32 UTC
(rev 7867)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs 2008-01-22 12:57:17 UTC
(rev 7868)
@@ -1141,13 +1141,23 @@
* @access private
*/
function __LZsetSetters ( o ) {
+ if (! this.hasOwnProperty('setters')) {
+ this.setters = new LzInheritedHash(this.setters);
+ }
+ if ('put' in this.setters) {
for ( var s in o ){
- var attrSet = "_anonSet" + s;
- this.__LZaddSetter( s , attrSet );
- this[ attrSet ] = o[ s ];
+ // inlined: this.__LZaddSetter( s , o[s] );
+ this.setters.put(s, o[s]);
}
+ } else {
+ for ( var s in o ){
+ // inlined: this.__LZaddSetter( s , o[s] );
+ this.setters[s] = o[s];
+ }
+ }
}
+
/**
* @access private
*/
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/core/UserClass.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/core/UserClass.lzs 2008-01-22 12:55:32 UTC
(rev 7867)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/core/UserClass.lzs 2008-01-22 12:57:17 UTC
(rev 7868)
@@ -186,14 +186,12 @@
var customsetters = '$setters' in attrs ? attrs.$setters : null;
if (customsetters) {
- delete attrs.$setters;
-
- for ( var s in customsetters ){
- var attrSet = "_anonSet" + s;
- newproto.addProperty(attrSet, customsetters[ s ]);
- newproto.setters[ s ] = attrSet;
+ delete attrs.$setters;
+
+ for ( var s in customsetters ){
+ newproto.setters[ s ] = customsetters[ s ];
+ }
}
- }
// TODO: [2006-05-25 ptw] Share this crud with LzNode
// LzNode class initializer assures that we already have a
Modified:
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
===================================================================
---
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
2008-01-22 12:55:32 UTC (rev 7867)
+++
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
2008-01-22 12:57:17 UTC (rev 7868)
@@ -720,7 +720,7 @@
ComparisonMap attrs, ComparisonMap events,
ComparisonMap references, ComparisonMap paths,
ComparisonMap styles) {
- if (cattr.type == cattr.ATTRIBUTE) {
+ if (cattr.type == cattr.ATTRIBUTE || cattr.type == cattr.EVENT) {
if (attrs.containsKey(name, caseSensitive)) {
env.warn(
/* (non-Javadoc)
@@ -1602,20 +1602,25 @@
// Add entry for attribute setter function
String setter = element.getAttributeValue("setter");
- // Backward compatibility
- if (setter == null) {
- setter = element.getAttributeValue("onset");
- }
+
if (setter != null) {
String srcloc =
CompilerUtils.sourceLocationDirective(element, true);
+ // By convention 'anonymous' setters are put in the 'lzc'
+ // namespace with the name set_<property name>
+ String settername = "$lzc$" + "set_" + name;
// Maybe we need a new type for "function"?
- String setterfn =
- srcloc + "function " +
- parent_name + "_" + name + "_onset" +
- " (" + name + ") {" +
- "\n#pragma 'withThis'\n" +
- srcloc + setter + "\n}";
+ Function setterfn = new
+ Function(
+ settername,
+ // the lone argument to a setter is named after
+ // the attribute
+ name,
+ "\n#beginContent\n" +
+ "\n#pragma 'withThis'\n" +
+ srcloc +
+ setter + "\n#endContent",
+ srcloc);
if (setters.get(name) != null) {
env.warn(
@@ -1624,7 +1629,10 @@
element);
}
- setters.put(name, setterfn);
+ // TODO: [2008-01-21 ptw] some day this will be coalesed
+ // into just creating a method named `"set" + name`
+ attrs.put(settername, setterfn);
+ setters.put(name, ScriptCompiler.quote(settername));
}
}
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins