Author: ptw
Date: 2008-02-22 11:02:04 -0800 (Fri, 22 Feb 2008)
New Revision: 8090

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/compiler/LzFormatter.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/helpers/LzState.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs
   
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java
   
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java
   openlaszlo/trunk/lps/components/lzunit/lzunit.lzx
   openlaszlo/trunk/test/style/constraints/subclassing.lzx
Log:
Change 20080220-ptw-t by [EMAIL PROTECTED] on 2008-02-20 19:36:51 EST
    in /Users/ptw/OpenLaszlo/ringding
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Handle $style constraints in the unified argument processor

Bugs Fixed:
LPP-1187 'overriding a literal with a constraint results in wrong value being 
assigned before constraint is resolved'
LPP-1587 'ECMA4: Compile LZX declarations as JS declarations' (partial)
LPP-4451 '$style cannot override other constraints'
LPP-5444 'Now we've got Super-Constraints!'


Technical Reviewer: max (pending)
QA Reviewer: mamye (pending)

Details:
    subclassing.lzx:  Uncomment test for lpp-4451, add inverse test,
    annotate some assertions for easier debugging.

    LzFocus: Fix a type inconsistency that was triggering a warning in
    smokecheck.

    LzNode: Delete old $style implementation, add styleBinder, add some
    debug checks, permit constraints with no dependencies.

    LzDefs: Add style init expressions and style attribute binders.

    LzText: Teeny optimization.

    LzState: Simplify cloning.  Back out restoration of constraints
    added in r8032 because it breaks dragstate and resizestate.

    LzFormatter: Fix pad to enforce max decimals bug revealed by
    Firefox precision improvements in smokecheck.

    CSSHandler: Use style expressions instead of closures.

    ReferenceCollector: Correct comment

    NodeModel: Move style processing into unified attribute list, add
    some asserts.

    lzunit.lzx: fail now will supply file/line for failed assertions
    if backtracing is on.

Tests:
    test/style/constraints/subclassing.lzx
    Test cases from LPP-1187, 4451
    smokecheck, Amazon



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/compiler/LzFormatter.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/compiler/LzFormatter.lzs   2008-02-21 
22:26:37 UTC (rev 8089)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/compiler/LzFormatter.lzs   2008-02-22 
19:02:04 UTC (rev 8090)
@@ -117,7 +117,11 @@
         } else {
           var decimals = strlen - (decimal + 1);
         }
-        for (var i = decimals; i < decMax; i++) value += '0';
+        if (decimals > decMax) {
+          value = value.substring(0, strlen - (decimals - decMax));
+        } else {
+          for (var i = decimals; i < decMax; i++) value += '0';
+        }
       } else {
         value = value.substring(0, decMax);
       }

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs    2008-02-21 22:26:37 UTC 
(rev 8089)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs    2008-02-22 19:02:04 UTC 
(rev 8090)
@@ -51,29 +51,92 @@
 
 /**
  * Private class used to distinguish an init expression from an
- * initial value in node attributes
+ * initial value in node attributes.  All forms of 'constraints' are a
+ * subclass of this class
  * @access private
  */
 class LzInitExpr {
+}
+
+/**
+ * Private class used to define a 'once' or 'path' constraint
+ * @access private
+ */
+class LzOnceExpr extends LzInitExpr {
   var methodName:String;
-  function LzInitExpr(initMethod:String) {
+  function LzOnceExpr(initMethod:String) {
     this.methodName = initMethod;
   }
 }
 
 /**
- * Private class used to distinguish an constraint expression from an
- * initial value in node attributes
+ * Private class used to define an 'always' constraint
  * @access private
  */
-class LzConstraintExpr extends LzInitExpr {
+class LzConstraintExpr extends LzOnceExpr {
   function LzConstraintExpr(constraintMethod:String) {
     super(constraintMethod);
   }
 }
 
+/**
+ * Private class used to define a constraint in a style value
+ * @access private
+ */
+class LzStyleExpr extends LzInitExpr {
+  var sourceAttributeName:String;
+  function LzStyleExpr(sourceAttributeName:String) {
+    this.sourceAttributeName = sourceAttributeName;
+  }
+}
 
 /**
+ * Private class used to define an 'attr()' constraint
+ * @access private
+ */
+class LzStyleAttr extends LzStyleExpr {
+  function LzStyleAttr(sourceAttributeName:String) {
+    super(sourceAttributeName);
+  }
+};
+
+/**
+ * Private class used to create the binder for `LzStyleAttr` bindings.
+ *
+ * @param lz.node target: The target node
+ * @param String dest: The destination attribute
+ * @param String source: The source attribute
+ *
+ [EMAIL PROTECTED] private
+ */
+class LzStyleAttrBinder {
+  var target:LzNode;
+  var dest:String;
+  var source:String;
+
+  function LzStyleAttrBinder (target:LzNode, dest:String, source:String) {
+    this.target = target;
+    this.dest = dest;
+    this.source = source;
+  }
+
+  function bind() {
+    var target = this.target;
+    target.setAttribute(this.dest, target[this.source]);
+  }
+}
+
+/**
+ * Private class used to define an identifier constraint
+ * @access private
+ */
+class LzStyleIdent extends LzStyleExpr {
+  function LzStyleIdent(sourceAttributeName:String) {
+    super(sourceAttributeName);
+  }
+}
+
+/**
   * Used to efficiently clone hashtables using Object's
   * N.B. these tables incorrectly will appear to have entries for all
   * the properties of Object.prototype.  To avoid this (but pay the

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs    2008-02-21 22:26:37 UTC 
(rev 8089)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs    2008-02-22 19:02:04 UTC 
(rev 8090)
@@ -167,11 +167,6 @@
         // If a replicator was made, we're deleted, if pooling is off.
         if (this.__LZdeleted) { return; }
 
-        var styleMap = this.$styles();
-        if ( styleMap ) {
-            this.__LZstyleConstraints = this.__LZapplyStyleMap( styleMap, 
attrs );
-        }
-
         /**
           * @todo 2006-05-24 ptw Adam says this is a hack that we should get
           * rid of.
@@ -495,88 +490,52 @@
     }
 }
 
-
-/**
-  * Default style map.  Will be overridden for classes that have $style
-  * constraints.
-  *
-  * @access private
-  */
-function $styles() {
-  return null;
-}
-
-/**
-  * Process the style map.
-  * For each style-constrained attribute, if it does not have an
-  * explicit value defined by the instance, lookup the css value that
-  * it should be constrained to.  If it is a simple value, set it
-  * directly, otherwise save it to be applied after the instance is
-  * fully inited (since the constraint may depend on other attributes).
-  *
-  * @param Object stylemap: a map of attribute names to the css style
-  * they are to be constrained to.
-  * @param Object initialArgs: the attributes specified explicitly for
-  * this instance (which may override style constraints).
-  * @access private
-  */
-function __LZapplyStyleMap( stylemap, initialArgs ){
-    var styleConstraints = {};    
-    for ( var k in stylemap ){
-        //we are going to bypass the CSS API and call the underlying
-        //implementation because we're concerned about speed
-        if (initialArgs[k] != null) {
-            // Don't get CSS value if it would be overridden by a 
instance/class attribute later
-            continue;
-        }
-        var v = LzCSSStyle.getPropertyValueFor( this , stylemap[ k ] );
-
-        // This is a hack because people want to give color styles as
-        // Ox... which is not valid CSS, so they pass it as a string.
-        // They really should be using #...
-        if ((typeof v == 'string') && (v.length > 2) && (v.indexOf('0x') == 0) 
&& (! isNaN(v))) {
-            if ($debug) {
-                Debug.warn("Invalid CSS value for %w.%s: `%#w`.  Use: 
`#%06x`.", this, k, v, Number(v));
-            }
-            v = Number(v);
-        }
-
-        // A style does not override an explicit attribute
-        if (! (k in initialArgs)) {
-            // A style that is a function is a constraint
-            if (v instanceof Function) {
-                //Only set styleConstraints[k] if this[k] is null.  See 
LPP-2894 - CSS: subclasses and instances can't override style constraints set 
on superclass* 
-                if (this[k] == null) {
-//                    Debug.warn("setting %w[%w] to %w, was %w", this, k, v, 
this[k]);
-                    styleConstraints[k] = v;
-                }
-            } else {
-//                 Debug.format("%w[%s] (%#w) %#w -> %#w", this, k, 
stylemap[k], this.k, v);
-                if (v != null) this.setAttribute(k, v);
-            }
-        }
+  /**
+   * Bind an attribute to a (CSS) style property
+   *
+   * @param String attr: The name of the attribute to bind
+   * @param String prop: The name of the CSS property whose value the
+   * attribute will be bound to
+   *
+   * @access private
+   */
+  function __LZstyleBindAttribute(attr, prop) {
+    // we are going to bypass the CSS API and call the underlying
+    // implementation because we're concerned about speed
+    var val = LzCSSStyle.getPropertyValueFor(this, prop);
+    // This is a hack because people want to give color styles as
+    // Ox... which is not valid CSS, so they pass it as a string.
+    // They really should be using #...
+    if ((typeof styleValue == 'string') && (styleValue.length > 2) && 
(styleValue.indexOf('0x') == 0) && (! isNaN(styleValue))) {
+      if ($debug) {
+        Debug.warn("Invalid CSS value for %w.%s: `%#w`.  Use: `#%06x`.", this, 
k, styleValue, Number(styleValue));
+      }
+      styleValue = Number(styleValue);
     }
-    return styleConstraints;
-}
-
-
-/**
-  * Process style constraints
-  *
-  * Compute each of the style constraints that were saved above and
-  * apply them
-  *
-  * @keywords private
-  */
-function __LZapplyStyleConstraints() {
-    var styleConstraints = this.__LZstyleConstraints;
-    for ( var k in styleConstraints ) {
-        var fn = styleConstraints[ k ];
-        var v = fn.call(this);
-//             Debug.format("%w[%s] (%#w) %#w -> %#w", this, k, stylemap[k], 
this.k, v);
-        this.setAttribute(k, v);
+    // Style expressions are constraints
+    if (val instanceof LzStyleExpr) {
+      var source = val.sourceAttributeName;
+      if (val instanceof LzStyleAttr) {
+        // Create a new binder to update the destination attribute,
+        var binder = new LzStyleAttrBinder(this, attr, source);
+        // register it on the source attribute,
+        if (! this.__LZdelegates) { this.__LZdelegates = []; }
+        // TODO: [2008-02-20 ptw] The delegate and binder could be
+        // collapsed into a single object, a custom delegate with the
+        // bind method as its execute method, but I don't think these
+        // are common enough to warrant optimization at this time.
+        this.__LZdelegates.push(new LzDelegate(binder, 'bind', this, 'on' + 
source));
+        // bind it
+        binder.bind();
+      } else if (val instanceof LzStyleIdent) {
+        this.setAttribute(attr, global[source]);
+      } else if ($debug) {
+        Debug.error("Unknown style expression %w", val);
+      }
+    } else {
+      this.setAttribute(attr, val);
     }
-}
+  };
 
 
 /**
@@ -745,7 +704,6 @@
     // Install computed initializations
     this.__LZresolveReferences();
 
-    if (this.__LZstyleConstraints) this.__LZapplyStyleConstraints();
     var sl = this.subnodes;
     if (sl) {
         var i = 0;
@@ -858,9 +816,11 @@
             if (val instanceof LzConstraintExpr) {
               if (constraints == null) { constraints = []; }
               constraints.push(val);
-            } else {
+            } else if (val instanceof LzOnceExpr) {
               if (inits == null) { inits = []; }
               inits.push(val);
+            } else if ($debug) {
+              Debug.debug("Unknown init expr: %w", val);
             }
             // NOTE: [2007-05-16 ptw] This check ensures that each
             // constrained attribute exists in the new instance.
@@ -1218,6 +1178,12 @@
   * bind the attribute.
   */
 function dataBindAttribute ( attr , path  ) {
+    if ( $debug ){
+      if ( path == null ){
+        Debug.warn( 'No value for %w.%s="$path{%w}"', this, attr, path );
+      }
+    }
+
     if ( !this.datapath ){
         this.setDatapath( "." );
     }
@@ -1328,8 +1294,11 @@
                         Debug.debug("Bad constraint %w on %w", c, this);
                     }
                 }
-                var dependencyMethod = cm.dependencies;
-                this.applyConstraintMethod(constraintMethodName , 
dependencyMethod.call(this));
+                var dependencies = null;
+                if ('dependencies' in cm) {
+                  dependencies = cm.dependencies.call(this);
+                }
+                this.applyConstraintMethod(constraintMethodName , 
dependencies);
             }
         }
         // Backward compatibility -- are there any other delayed setters?
@@ -1421,12 +1390,11 @@
         if (! ((arguments.length == 2) &&
                (typeof constraintMethodName == 'string') &&
                (this[constraintMethodName] instanceof Function) &&
-               (dependencies instanceof Array))) {
+               (dependencies == null || (dependencies instanceof Array)))) {
             Debug.error("%w.%s: invalid arguments %w", this, arguments.callee, 
arguments);
         }
     }
-    var l = dependencies.length;
-    if (l){
+    if (dependencies && dependencies.length > 0){
         if ( !this.__LZdelegates ){
             this.__LZdelegates = [];
         }
@@ -1443,7 +1411,7 @@
         // a separate delegate for each dependency, and people have
         // written code that only works because of this loophole...
         var dp;
-        for (var i = 0; i < l; i += 2) {
+        for (var i = 0, l = dependencies.length; i < l; i += 2) {
             dp = dependencies[i];
             if (dp) {
                 var d = new LzDelegate(this, constraintMethodName, dp, "on" + 
dependencies[i + 1]);
@@ -1457,6 +1425,25 @@
     this[constraintMethodName]();
 }
 
+  /**
+   * Release a constraint on an attribute
+   *
+   * Only works for initial constraints.  Constraints applied at
+   * runtime should be applied and released with
+   * `applyConstraintMethod` and `releaseConstraintMethod`.
+   *
+   * @param String attr: The name of the attribute to release the
+   * constraint from
+   */
+  function releaseConstraint(attr:String) {
+    var c = this._instanceAttrs[attr];
+    if (c instanceof LzConstraintExpr) {
+      var m = c.methodName;
+      return this.releaseConstraintMethod(m);
+    }
+    return false;
+  }
+
 /**
   * Release a constraint method
   *

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/helpers/LzState.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/helpers/LzState.lzs        2008-02-21 
22:26:37 UTC (rev 8089)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/helpers/LzState.lzs        2008-02-22 
19:02:04 UTC (rev 8090)
@@ -127,6 +127,11 @@
   */
 setters.__LZsourceLocation = "__LZsetProperty";
 
+var heldargs;
+var releasedconstraints;
+var appliedchildren;
+var isapplied = false;
+
 /**
   * @access private
   */
@@ -134,7 +139,6 @@
     super.construct.apply(this, arguments);
     this.heldArgs = {};
     this.appliedChildren = [];
-    this.isapplied = false;
 }
 
 /**
@@ -194,8 +198,11 @@
     var pia = parent._instanceAttrs;
     for (var key in this.heldArgs) {
       if (pia && key in pia && pia[key] instanceof LzConstraintExpr) {
+        if (this.releasedconstraints == null) { this.releasedconstraints = []; 
}
         var constraintMethodName = pia[key].methodName;
-        parent.releaseConstraintMethod(constraintMethodName);
+        if (parent.releaseConstraintMethod(constraintMethodName)) {
+          this.releasedconstraints.push(constraintMethodName);
+        }
       }
     }
 
@@ -267,25 +274,29 @@
 
     this.appliedChildren = [];
 
-    // re-apply any constraints you released
-    var parent = this.parent;
-    // NOTE: [2008-02-13 ptw] Keep in sync with LzNode#__LZresolveReferences
-    var pia = parent._instanceAttrs;
-    for (var key in this.heldArgs) {
-      if (pia && key in pia && pia[key] instanceof LzConstraintExpr) {
-        var constraintMethodName = pia[key].methodName;
-        // TODO: [2008-02-06 ptw] the dependency computation needs
-        // to be a method also, probably stored in the
-        // LzConstraintExpr object
-        var cm = parent[constraintMethodName];
-        if ($debug) {
-          if (!(cm && cm instanceof Function)) {
-            Debug.debug("Bad constraint %w on %w", c, this);
-          }
-        }
-        var dependencyMethod = cm.dependencies;
-        parent.applyConstraintMethod(constraintMethodName , 
dependencyMethod.call(parent));
-      }
+    // This sounds good in theory, but breaks dragstate and
+    // resizestate which expect their effect to stick when they are
+    // removed.
+    if (this.releasedconstraints != null) {
+//       // re-apply any constraints you released
+//       var parent = this.parent;
+//       // NOTE: [2008-02-13 ptw] Keep in sync with 
LzNode#__LZresolveReferences
+//       var rc = this.releasedconstraints;
+//       for (var i = 0, l = rc.length; i < l; i++) {
+//         var constraintMethodName = rc[i];
+//         // TODO: [2008-02-06 ptw] the dependency computation needs
+//         // to be a method also, probably stored in the
+//         // LzConstraintExpr object
+//         var cm = parent[constraintMethodName];
+//         if ($debug) {
+//           if (!(cm && cm instanceof Function)) {
+//             Debug.debug("Bad constraint %w on %w", c, this);
+//           }
+//         }
+//         var dependencyMethod = cm.dependencies;
+//         parent.applyConstraintMethod(constraintMethodName , 
dependencyMethod.call(parent));
+//       }
+      this.releasedconstraints = null;
     }
 }
 
@@ -360,7 +371,8 @@
       var val = held[key];
       var methodName = val.methodName;
       var newMethodName = methodName + this.__LZUID;
-      held[key] = new (val instanceof 
LzConstraintExpr?LzConstraintExpr:LzInitExpr)(newMethodName);
+      // Clone the init expr with the new name
+      held[key] = new (val.constructor)(newMethodName);
       held[newMethodName] = held[methodName];
       delete held[methodName];
     }

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs       2008-02-21 
22:26:37 UTC (rev 8089)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs       2008-02-22 
19:02:04 UTC (rev 8090)
@@ -1,6 +1,6 @@
 /**
   *
-  * @copyright Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.
+  * @copyright Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.
   *            Use is subject to license terms.
   *
   * @affects lzbrowser
@@ -43,7 +43,7 @@
   * unchanged from its last value.
   * @type Boolean
   */
-LzFocus.focuswithkey = null;
+LzFocus.focuswithkey = false;
 
 /** @access private */
 LzFocus.__LZskipblur = false;

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs   2008-02-21 22:26:37 UTC 
(rev 8089)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/views/LzText.lzs   2008-02-22 19:02:04 UTC 
(rev 8090)
@@ -221,7 +221,7 @@
         this.setMaxLength(args.maxlength);
     }
 
-    this.text =  (!('text' in args) || args.text == null || args.text 
instanceof LzConstraintExpr || args.text instanceof LzInitExpr) ? "" : 
args.text;
+    this.text =  (!('text' in args) || args.text == null || args.text 
instanceof LzInitExpr) ? "" : args.text;
     if(this.maxlength != null && this.text.length > this.maxlength){
         this.text = this.text.substring(0, this.maxlength);
     }

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-02-21 22:26:37 UTC (rev 8089)
+++ 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java  
    2008-02-22 19:02:04 UTC (rev 8090)
@@ -721,7 +721,8 @@
                       ComparisonMap references, ComparisonMap paths,
                       ComparisonMap styles) {
         if (cattr.type == cattr.ATTRIBUTE || cattr.type == cattr.EVENT ||
-            (cattr.type == cattr.REFERENCE) || (cattr.type == cattr.PATH)) {
+            (cattr.type == cattr.REFERENCE) || (cattr.type == cattr.PATH) ||
+            (cattr.type == cattr.STYLE)) {
             if (attrs.containsKey(name, caseSensitive)) {
                 env.warn(
 /* (non-Javadoc)
@@ -733,14 +734,6 @@
                     ,element);
             }
             attrs.put(name, cattr.value);
-        } else if (cattr.type == cattr.STYLE) {
-            if (styles.containsKey(name, caseSensitive)) {
-                env.warn(
-                    // TODO [2006-08-22 ptw] i18n this
-                    "duplicate $style binding for '" + name + "' in " + 
getMessageName(),
-                    element);
-            }
-            styles.put(name, cattr.value);
         } else {
             assert false: "Unknown cattr.type: " + cattr.type;
         }
@@ -1344,19 +1337,25 @@
             // Handle when cases
             // N.B., $path and $style are not really when values, but
             // there you go...
-            if (when.equals(WHEN_PATH) || when.equals(WHEN_ONCE) || 
when.equals(WHEN_ALWAYS)) {
+            if (when.equals(WHEN_PATH) || (when.equals(WHEN_STYLE)) || 
when.equals(WHEN_ONCE) || when.equals(WHEN_ALWAYS)) {
                 String installer = "setAttribute";
-                String pragmas = "";
-                String kind = "LzInitExpr";
-                if (when.equals(WHEN_PATH)) {
-                    installer = "dataBindAttribute";
-                    pragmas =
+                String body = "\n#beginAttribute\n" + srcloc + canonicalValue 
+ "\n#endAttribute\n)";
+                String pragmas =
                         // Should be unnecessary for JS2 methods
                         "\n#pragma 'withThis'\n";
-                } else if (when.equals(WHEN_ONCE)) {
-                    pragmas =
-                        // Should be unnecessary for JS2 methods
-                        "\n#pragma 'withThis'\n";
+                String kind = "LzOnceExpr";
+                if (when.equals(WHEN_ONCE)) {
+                    // default
+                } else if (when.equals(WHEN_PATH)) {
+                    installer = "dataBindAttribute";
+                } else if (when.equals(WHEN_STYLE)) {
+                    // Styles are processed as constraints, although
+                    // they are not compiled as constraints.  Whether
+                    // a style results in a constraint or not cannot
+                    // be determined until the style property value is
+                    // derived (at run time)
+                    kind = "LzConstraintExpr";
+                    installer = "__LZstyleBindAttribute";
                 } else if (when.equals(WHEN_ALWAYS)) {
                     pragmas =
                         "\n#pragma 'constraintFunction'\n" +
@@ -1373,16 +1372,12 @@
                     pragmas +
                     "this." + installer + "(" +
                     ScriptCompiler.quote(name) + "," +
-                    "\n#beginAttribute\n" + srcloc + canonicalValue + 
"\n#endAttribute\n)",
+                    body,
                     srcloc);
                 // Add the binder as a method
                 attrs.put(bindername, binder);
                 // Return an initExpr as the 'value' of the attribute
                 return new CompiledAttribute("new " + kind + "(" + 
ScriptCompiler.quote(bindername) +")");
-            } else if (when.equals(WHEN_STYLE)) {
-                return new CompiledAttribute(
-                    CompiledAttribute.STYLE,
-                    srcloc + value + "\n");
             } else if (when.equals(WHEN_IMMEDIATELY)) {
                 if ((CanvasCompiler.isElement(source) &&
                      ("width".equals(name) || "height".equals(name))) ||
@@ -1662,10 +1657,10 @@
             attrs.put("$delegates", delegateList);
         }
         if (!references.isEmpty()) {
-            attrs.put("$refs", references);
+            assert false : "There should not be any $refs";
         }
         if (!paths.isEmpty()) {
-            attrs.put("$paths", paths);
+            assert false : "There should not be any $paths";
         }
         if (datapath != null) {
             attrs.put("$datapath", datapath.asMap());
@@ -1675,34 +1670,8 @@
             // overridden by an inherited value from the class.
             attrs.put("datapath", "LzNode._ignoreAttribute");
         }
-
         if (!styles.isEmpty()) {
-            String styleMap;
-            try {
-                java.io.Writer writer = new java.io.StringWriter();
-                ScriptCompiler.writeObject(styles, writer);
-                styleMap = writer.toString();
-            } catch (java.io.IOException e) {
-                throw new ChainedException(e);
-            }
-            // NOTE: [2006-09-04 ptw] The $styles method _must_ create
-            // a new map each time, because the sub-class or instance
-            // may modify it.
-            attrs.put("$styles",
-                      new
-                      Function(
-                          "",
-                          "",
-                          "\n#beginContent" +
-                          "\n#pragma 'withThis'" +
-                          "\n#pragma 'methodName=$styles'" +
-                          "\nvar map = super.$styles() || (new Object);" +
-                          "\nvar s = " + styleMap + ";" +
-                          "\nfor (var k in s) { map[k] = s[k]; };" +
-                          "\nreturn map;" +
-                          "\n#endContent" +
-                          "\n")
-                      );
+            assert false : "There should not be any $styles";
         }
     }
 

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java  
2008-02-21 22:26:37 UTC (rev 8089)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/css/CSSHandler.java  
2008-02-22 19:02:04 UTC (rev 8090)
@@ -3,7 +3,7 @@
 * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -298,11 +298,11 @@
          switch (lu.getLexicalUnitType()) {
 
          case LexicalUnit.SAC_ATTR:
-             str = "function () { return this['" + 
processEscapes(lu.getStringValue()) + "']; }";
+             str = "new LzStyleAttr('" + processEscapes(lu.getStringValue()) + 
"')";
            break;
 
          case LexicalUnit.SAC_IDENT:
-             str = "function () { return global['" + 
processEscapes(lu.getStringValue()) + "']; }";
+             str = "new LzStyleIdent('" + processEscapes(lu.getStringValue()) 
+ "')";
            break;
 
          case LexicalUnit.SAC_STRING_VALUE:

Modified: 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java
===================================================================
--- 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java
   2008-02-21 22:26:37 UTC (rev 8089)
+++ 
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java
   2008-02-22 19:02:04 UTC (rev 8090)
@@ -1,7 +1,7 @@
 /* -*- mode: Java; c-basic-offset: 2; -*- */
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -64,8 +64,8 @@
     return s;
   }
 
-  // f(args...) -> f["dependencies"](undefined, args...)
-  // a.f(args...) -> f["dependencies"](a, args...)
+  // f(args...) -> f["dependencies"](this, undefined, args...)
+  // a.f(args...) -> f["dependencies"](this, a, args...)
   private SimpleNode fsubst(SimpleNode node) {
     SimpleNode fn = node.get(0);
     SimpleNode callee;

Modified: openlaszlo/trunk/lps/components/lzunit/lzunit.lzx
===================================================================
--- openlaszlo/trunk/lps/components/lzunit/lzunit.lzx   2008-02-21 22:26:37 UTC 
(rev 8089)
+++ openlaszlo/trunk/lps/components/lzunit/lzunit.lzx   2008-02-22 19:02:04 UTC 
(rev 8090)
@@ -342,9 +342,17 @@
           Debug.debug('result is null on fail call: "' + message + '"');
         }
         if ($debug) {
+          var file = null, line = null;
+          // Find the failing test, which is four frames up
+          var bt = Debug.backtrace(4);
+          if (bt != null) {
+            var sf = bt[bt.length - 1];
+            file = sf.filename();
+            line = sf.lineno();
+          }
           Debug.freshLine();
           // create an error, which will include a backtrace, if applicable
-          Debug.__write(new LzError(null, null, message));
+          Debug.__write(new LzError(file, line, message));
         }
     </method>
 

Modified: openlaszlo/trunk/test/style/constraints/subclassing.lzx
===================================================================
--- openlaszlo/trunk/test/style/constraints/subclassing.lzx     2008-02-21 
22:26:37 UTC (rev 8089)
+++ openlaszlo/trunk/test/style/constraints/subclassing.lzx     2008-02-22 
19:02:04 UTC (rev 8090)
@@ -1,4 +1,4 @@
-<!-- Copyright 2007 Laszlo Systems -->
+<!-- Copyright 2007, 2008 Laszlo Systems -->
 <library>
 
     <!-- [bshine 10.06.2006] This test validates (LPP-2894) The
@@ -15,8 +15,6 @@
         }
     </stylesheet>
 
-    <simplelayout axis="y" spacing="5" />
-
     <!-- This class has a bgcolor defined by a style and an inner view
          whose bgcolor is defined by a style that references an
          attribute of the view that is constrained to an attribute of
@@ -46,41 +44,45 @@
     </class>
 
     <class name="lpp_4451" extends="happystyledbox" width="${parent.width/2}" 
/>
+    <class name="lpp_4451_inverse" extends="happystyledbox" 
width="$style{'stylewidth'}" />
 
-    <happystyledbox id="sb0" />
+    <view id="testing" width="400" layout="axis: y; spacing: 5">
 
-    <!-- This box is maroon with an inner view of red -->
-    <happystyledbox id="sb1" bgcolor="maroon" innerColor="red" />
+      <happystyledbox id="sb0" />
 
-    <subclassbox id="sb2" />
-    <otherlassbox id="sb3" width="$style{'stylewidth'}"/>
+      <!-- This box is maroon with an inner view of red -->
+      <happystyledbox id="sb1" bgcolor="maroon" innerColor="red" />
 
-    <subclassbox id="sb4" />
+      <subclassbox id="sb2" />
+      <otherlassbox id="sb3" width="$style{'stylewidth'}"/>
 
-    <lpp_4451 id="sb5" width="$style{'stylewidth'}"/>
+      <subclassbox id="sb4" />
 
+      <lpp_4451 id="sb5" width="$style{'stylewidth'}"/>
+      <lpp_4451_inverse id="sb6" width="${parent.width/2}"/>
+    </view>
     <class name="CSSSubclassingTestCase" extends="TestCase" >
 
          <method name="testClassConstraint">
-             this.assertEquals(purple, sb0.getAttribute("bgcolor"));
-             this.assertEquals(fuchsia, sb0.inner.getAttribute("bgcolor"));
+             this.assertEquals(purple, sb0.getAttribute("bgcolor"), "Class CSS 
value");
+             this.assertEquals(fuchsia, sb0.inner.getAttribute("bgcolor"), 
"Class CSS attr");
          </method>
 
          <method name="testInstanceOverrideConstraint">
-             this.assertEquals(maroon, sb1.getAttribute("bgcolor"));
-             this.assertEquals(red, sb1.inner.getAttribute("bgcolor"));
+             this.assertEquals(maroon, sb1.getAttribute("bgcolor"), "Instance 
override CSS value");
+             this.assertEquals(red, sb1.inner.getAttribute("bgcolor"), 
"Instance override CSS attr");
          </method>
 
          <method name="testSubclassOverrideConstraint">
              <![CDATA[
-             this.assertEquals("150", sb2.getAttribute("width"));
-             this.assertEquals(navy, sb2.getAttribute("bgcolor")); // fails! 
[2007.05.28 bshine]
-             this.assertEquals(blue, sb2.inner.getAttribute("bgcolor"));
-             this.assertEquals(green, sb3.getAttribute("bgcolor")); // fails! 
[2007.05.28 bshine]
-             this.assertEquals(999, sb3.getAttribute("width"));
-             this.assertEquals(lime, sb3.inner.getAttribute("bgcolor"));
-             // FIXME: [2007-08-08 ptw] (LPP-4451) Uncomment when fixed
-             // this.assertEquals(999, sb5.width, "LPP-4451");
+             this.assertEquals("150", sb2.getAttribute("width"), "Subclass 
override attribute");
+             this.assertEquals(navy, sb2.getAttribute("bgcolor"), "Subclass 
override CSS value");
+             this.assertEquals(blue, sb2.inner.getAttribute("bgcolor"), 
"Subclass override CSS attr");
+             this.assertEquals(green, sb3.getAttribute("bgcolor"), "Subclass 
override CSS value");
+             this.assertEquals(999, sb3.getAttribute("width"), "Subclass CSS 
value override");
+             this.assertEquals(lime, sb3.inner.getAttribute("bgcolor"), 
"Subclass override CSS attr attribute");
+             this.assertEquals(999, sb5.width, "LPP-4451");
+             this.assertEquals(testing.width/2, sb6.width, "LPP-4451-inverse");
              ]]>
          </method>
      </class>


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to