[Laszlo-checkins] r11827 - in openlaszlo/trunk: WEB-INF/lps/lfc/kernel/swf9 WEB-INF/lps/server/src/org/openlaszlo/compiler test/snippets

hqm@openlaszlo.org hqm at openlaszlo.org
Wed Nov 19 07:17:21 PST 2008


Author: hqm
Date: 2008-11-19 07:17:17 -0800 (Wed, 19 Nov 2008)
New Revision: 11827

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzLibrary.as
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/DataCompiler.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java
   openlaszlo/trunk/test/snippets/dataset-library.lzx
   openlaszlo/trunk/test/snippets/import-globals-lib.lzx
   openlaszlo/trunk/test/snippets/import-globals.lzx
Log:
Change 20081118-hqm-p by hqm at badtzmaru.home on 2008-11-18 21:42:12 EST
    in /Users/hqm/openlaszlo/trunk4
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: fixes for swf9 import libraries

New Features:

Bugs Fixed: LPP-7370, LPP-7639

Technical Reviewer: ptw
QA Reviewer: dda
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:

+ When nodes with id's are declared in a <import> library, we need to
make a reference to the var in the code so that it gets compiled in
loaded by the flash loader.

We need to declare the global both in the main app and in the library,
because these are compiled as separate apps with separate intermediate
.as files in difference source code directories.

+ resources can now be embedded and accessed in the library .swf, and
should be compiled into the library, we don't need to do the swf7/8 hack
of compiling them into the main app.
    

Tests:
test/snippets/import-globals.lzx
test/snippets/import-resource.lzx




Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzLibrary.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzLibrary.as	2008-11-19 09:00:10 UTC (rev 11826)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzLibrary.as	2008-11-19 15:17:17 UTC (rev 11827)
@@ -168,8 +168,11 @@
 public function handleLoadComplete(event:Event):void {
     var library:Object = event.target.content;
     library.exportClassDefs(null);
+    this.libapp = library;
 }
 
+var libapp;
+
 /** 
  * Called by LzLibraryCleanup when this library has finished loading.
  * 

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2008-11-19 09:00:10 UTC (rev 11826)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2008-11-19 15:17:17 UTC (rev 11827)
@@ -441,12 +441,12 @@
      */
 
     ObjectWriter getResourceGenerator() {
-        return mMainObjectWriter;
-        
-        // Note: Returning the library's SWFWriter, as shown below,
-        // would make the compiler compile the resources into the
-        // loadable library:
-        //return mObjectWriter; 
+        if (this.getRuntime().equals("swf9")) {
+            // For swf9, we can embed the resource into the library
+            return mObjectWriter;
+        } else {
+            return mMainObjectWriter;
+        }
      }
      
     private boolean mSnippet = false;

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/DataCompiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/DataCompiler.java	2008-11-19 09:00:10 UTC (rev 11826)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/DataCompiler.java	2008-11-19 15:17:17 UTC (rev 11827)
@@ -62,10 +62,14 @@
       boolean trimwhitespace = "true".equals(element.getAttributeValue("trimwhitespace"));
       String content = NodeModel.getDatasetContent(element, mEnv, trimwhitespace);
       // Initialize the global declaration
-      mEnv.compileScript(dsetname+" = "+
+      mEnv.compileScript("var "+ dsetname+" = "+
                          LOCAL_DATA_FNAME+"("+ScriptCompiler.quote(dsetname) +
                          ", " +content+
                          "," + trimwhitespace+");\n");
+      // For swf9, make sure the global variable is referenced or the
+      // Flash class loader won't load it.
+      mEnv.compileScript(dsetname+" == true;");
+
     } catch (org.openlaszlo.xml.internal.MissingAttributeException err) {
       throw new CompilationError(element, err);
     }

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java	2008-11-19 09:00:10 UTC (rev 11826)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java	2008-11-19 15:17:17 UTC (rev 11827)
@@ -225,6 +225,19 @@
                 }
 
                 ViewCompiler.checkUnresolvedResourceReferences (env);
+                
+                // Need to emit a copy of the globals declarations
+                // into the library app code we're building, because
+                // the swf9 compiler needs to be able to have
+                // declarations for them to compile references to
+                // them.
+                String globals = "";
+                for (Iterator v = mEnv.getIds().keySet().iterator(); v.hasNext(); ) {
+                    String id = (String)v.next();
+                    globals += ("var " +id + " = null;\n");
+                }
+                env.compileScript(globals);
+
                 writer.closeSnippet();
                 env.compileScript("// FINISH compiling <IMPORT> Library "+liburl+"\n");
             } finally {

Modified: openlaszlo/trunk/test/snippets/dataset-library.lzx
===================================================================
--- openlaszlo/trunk/test/snippets/dataset-library.lzx	2008-11-19 09:00:10 UTC (rev 11826)
+++ openlaszlo/trunk/test/snippets/dataset-library.lzx	2008-11-19 15:17:17 UTC (rev 11827)
@@ -1,5 +1,5 @@
 <library>
-  <text>[loaded dataset library]</text>
+  <text text="${'mylibdset = ' + mylibdset}"/>
   <dataset name="mylibdset">
     <items>
       <item> Lorem ipsum dolor sit amet</item>
@@ -18,3 +18,7 @@
     </items>
   </dataset>
 </library>
+<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
+* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Use is subject to license terms.                                            *
+* X_LZ_COPYRIGHT_END ****************************************************** -->

Modified: openlaszlo/trunk/test/snippets/import-globals-lib.lzx
===================================================================
--- openlaszlo/trunk/test/snippets/import-globals-lib.lzx	2008-11-19 09:00:10 UTC (rev 11826)
+++ openlaszlo/trunk/test/snippets/import-globals-lib.lzx	2008-11-19 15:17:17 UTC (rev 11827)
@@ -1,12 +1,12 @@
 <library>
   <script>
     var blah = 0xff0000;
-    function foo() {
+    canvas.foo = function ()  {
         Debug.write('This is a message from a snippet script function');
     }
 
-    new lz.view(_root.canvas, {width: 50, height: 50, bgcolor: blah});
-    new lz.view(_root.canvas, {width: 50, height: 50, bgcolor: canvas.greencolor});
+    new lz.view(canvas, {width: 50, height: 50, bgcolor: blah});
+    new lz.view(canvas, {width: 50, height: 50, bgcolor: canvas.greencolor});
   </script>
   <view bgcolor="yellow" width="50" height="50" id="libview"
         oninit="Debug.write('This is a message from a snippet method')">

Modified: openlaszlo/trunk/test/snippets/import-globals.lzx
===================================================================
--- openlaszlo/trunk/test/snippets/import-globals.lzx	2008-11-19 09:00:10 UTC (rev 11826)
+++ openlaszlo/trunk/test/snippets/import-globals.lzx	2008-11-19 15:17:17 UTC (rev 11827)
@@ -21,7 +21,7 @@
   </text>
 
 
-  <import name="lib" href="import-globals-lib.lzx" stage="late" onload="foo()"/>
+  <import name="lib" href="import-globals-lib.lzx" stage="late" onload="canvas.foo()"/>
 
   <handler name="oninit">
     Debug.write("canvas got oninit event");



More information about the Laszlo-checkins mailing list