Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLListCollection: exception in constructor #167

Open
SemiConscious opened this issue Dec 13, 2020 · 4 comments
Open

XMLListCollection: exception in constructor #167

SemiConscious opened this issue Dec 13, 2020 · 4 comments
Labels

Comments

@SemiConscious
Copy link
Contributor

SemiConscious commented Dec 13, 2020

Test case code:

i2.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:mx="library://ns.apache.org/royale/mx"
                   width="600" height="400" >
	<fx:Script>
		<![CDATA[

			// this works
			// import mx.collections.XMLListCollection; 
			// static public var xmllc:XMLListCollection=new XMLListCollection();

			// this doesn't
			import testglob;
			public var h:String = testglob.Hello;
		]]>
	</fx:Script>
	<mx:Label text="{xmllc.toString()}"/>
</mx:Application>

testglob.as:

package
{
	import mx.collections.XMLListCollection;

	[Bindable]
	public class testglob
	{
		static public var Hello:String = "Hello";
 		static public var Devices:XMLListCollection=new XMLListCollection();
	}
}

When the XMLListCollection is initialised in the mxml file, everything is fine and the initialisation is successful.

When it's initialised by importing the testglob.as class, I get an exception:

Uncaught TypeError: Cannot read property 'createUID' of undefined
    at mx.collections.XMLListAdapter.set__source (XMLListAdapter.js:615)
    at new mx.collections.XMLListAdapter (XMLListAdapter.js:37)
    at mx.collections.XMLListCollection.set__source (XMLListCollection.js:362)
    at new mx.collections.XMLListCollection (XMLListCollection.js:37)
    at testglob.js:50

On the face of it it seems a bit like the other XML bug I reported a couple of days ago, where the framework is calling an internal function that seems not to be there. So it's either never loaded (it looks as if it is) or something is treading on it. Or something else completely different.

I am running the nightly build on OSX big sur, log follows:

Using Royale Compiler codebase: /Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../..
Using Royale SDK: /Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../..
MXMLJSC
+royalelib=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../../frameworks
-sdk-js-lib=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/bin/../../frameworks/js/Royale/generated-sources
-source-path
./src/
-compiler.services=src/services-config.xml
-locale=en_US,es_ES
-allow-source-path-overlap=true
-source-path=./src/locale/{locale}
-compiler.fonts.managers=flash.fonts.AFEFontManager
-target-player=32.0.0
-compiler.optimize=false
-define+=config::DEBUG,true
-define+=goog::DEBUG,false
+configname=flex
-compiler.targets=JSRoyale
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/js/libs/royale-typedefs-gcl-0.9.8-SNAPSHOT-typedefs.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Core-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Language-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/HTML-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Basic-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Collections-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Binding-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Graphics-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/MXRoyale-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/DragDrop-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Express-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Effects-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Formatters-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Charts-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Network-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/Reflection-0.9.8-SNAPSHOT-js.swc
-library-path+=/Users/jim.page/Documents/Royale/nightly-mvn/SDKs/frameworks/libs/XML-0.9.8-SNAPSHOT-js.swc
-link-report=./report.xml
-output
bld/index.swf
--
src/i2.mxml
Dec 13, 2020 3:24:40 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: /Users/jim.page/Documents/git/flexportal/bin/js-debug/mx/core/UIComponent.js:3357: WARNING - Suspicious code. This code lacks side-effects. Is there a bug?
  } else if ((this.mx_core_UIComponent__toolTip == null || this.mx_core_UIComponent__toolTip == "") && this.mx_core_UIComponent__toolTipBead != null) {
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Dec 13, 2020 3:24:40 AM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 0 error(s), 2 warning(s), 98.2% typed
The project 'i2' has been successfully compiled and optimized.
40.123570103 seconds
@SemiConscious
Copy link
Contributor Author

Some further info. I placed a breakpoint just before the line causing the exception in both cases. In the version that works, this.org.apache.royale.utils looks like this:

Screenshot 2020-12-13 at 21 49 37

In the broken version it looks like this:

image

So there are a lot fewer imports happening. Is my issue that I should be importing something into the as file that i am not?

@yishayw
Copy link
Contributor

yishayw commented Dec 14, 2020

This may be a problem with static initializers. I haven't tried, but as a workaround maybe use a getter with lazy initialization for Devices.

In other words, try replacing

static public var Devices:XMLListCollection=new XMLListCollection();

with

static private var _Devices:XMListCollection;
static public function get Devices():XMLListCollection()
{
if (!_Devices) _Devices = new XMLListCollection();
return _Devices;
}

@joshtynjala joshtynjala added the bug label Jan 6, 2022
@joshtynjala
Copy link
Member

Just confirming that I able still able to reproduce this issue with the latest compiler. It does appear to be a static dependency ordering issue. org.apache.royale.utils.UIDUtil is not being loaded before mx.collections.XMLListAdapter, as it should when mx.collections.XMLListCollection is accessed from a static variable.

I assume that the goog.addDependency() calls that we generate need to be tweaked a bit to fix this. However, I am not super familiar with that part of the compiler code, so I don't have a plan for how to proceed at this time.

@Harbs
Copy link
Contributor

Harbs commented Jan 6, 2022

Yeah. This is a known problem.

Currently it's only possible to reliably use native types in static initializers. Static initializers are evaluated when the JS file loads. The only way to get that to work with the current system is to ensure that the dependencies load first. There are cases where it's impossible to resolve that because you can have A which references B and B which references A.

One potential solution which I mentioned in the past is to collect all non-native static initializers collected and loaded after all the other files. I think @aharui might have had a different solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants