<?xml version="1.0"?>
<mx:Application name="lightspark_prototype_test"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	applicationComplete="appComplete();"
	backgroundColor="white">

<mx:Script>
	<![CDATA[
	import Tests;
	import packageNewFunc;
	private function appComplete():void
	{
		var newFunc:Function = function():void{this["test"] = "foobar";};
		Tests.assertNotNull(newFunc.prototype, "Function object prototype");
		newFunc.prototype["protTest"]="foobar2";

		Function.prototype["FunctionProtTest"]="foobar5";

		Tests.assertEquals("foobar5",newFunc["FunctionProtTest"], "Access Function.prototype from function object");
		Tests.assertNull(newFunc.prototype["FunctionProtTest"], "Access Function.prototype from function prototype");

		Tests.assertNull(packageNewFunc.prototype, "Function object in package prototype");

		var f2:Object = new newFunc();
		Tests.assertTrue(f2.hasOwnProperty("test"), "Variable for function based constructors");
		Tests.assertFalse(f2.hasOwnProperty("protTest"), "hasOwnProperty of prototype variable");
		Tests.assertEquals("foobar2",f2["protTest"], "Access to prototype variable");
		Tests.assertNull(f2.prototype, "(new newFunc).prototype");
		Tests.assertEquals("foobar", f2["test"], "Prototype does not override instance variables");
		newFunc.prototype["test"]="foobar4";
		Tests.assertEquals("foobar", f2["test"], "Prototype does not override instance variables");
		newFunc.prototype = new Object();
		newFunc.prototype["protTest"]="foobar3";
		Tests.assertEquals("foobar2",f2["protTest"], "Access to prototype variable, after change of prototype");
		Tests.assertFalse(f2.hasOwnProperty("protTest"),"hasOwnProperty ignores prototype on Function_object");

		var f:Function = new Function();
		Tests.assertNotNull(f.prototype, "(new Function).prototype");

		Tests.assertNull(trace.prototype, "Builtin methods have no prototype");

		var o:Object = new Object();
		Tests.assertNull(o.prototype, "Instance have no prototype");

		Tests.assertTrue(Object.prototype is Object, "Object prototype is object");
		Tests.assertFalse(DisplayObject.prototype is DisplayObject, "DisplayObject prototype is object");

		Object.prototype["test"]="foo";
		Tests.assertNotNull(Function.prototype, "Function.prototype");
		Tests.assertNotNull(Object.prototype, "Object.prototype");
		Tests.assertNotNull(Function.prototype.prototype, "Function.prototype.prototype");
		Tests.assertEquals("foo",Object.prototype["test"], "Object.Prototype is modifiable");

		DisplayObject.prototype["test2"]="bar";
		Tests.assertEquals("bar",this["test2"],"Access prototype variable from instance [1/2]");
		Tests.assertEquals("bar",DisplayObjectContainer.prototype["test2"],"Access prototype variable from instance [2/2]");
		Tests.assertFalse(this.hasOwnProperty("test2"),"hasOwnProperty ignores prototype in instance");
		Tests.assertNotNull(DisplayObject.prototype, "DisplayObject.prototype");
		Tests.assertNotNull(DisplayObjectContainer.prototype, "DisplayObjectContainer.prototype");
		Tests.assertEquals("bar",DisplayObject.prototype["test2"], "DisplayObject.prototype is modifiable");
		Tests.assertNull(DisplayObjectContainer.prototype.prototype, "DisplayObjectContainer.prototype.prototype is not DisplayObject.prototype");

		Tests.assertNull(DisplayObject.prototype.prototype, "DisplayObject.prototype.prototype is not Object.prototype");

		Tests.assertTrue(Function.prototype is Function, "Function.prototype is a function");
		Tests.assertNotNull(Function.prototype.prototype, "Function.prototype.prototype is valid");

		Tests.assertEquals(Function,Function.prototype["constructor"], "constructor in prototype [1/2]");
		Tests.assertEquals(DisplayObject,DisplayObject.prototype["constructor"], "constructor in prototype [2/2]");
		Tests.assertFalse(this.hasOwnProperty("constructor"), "no constructor in regular instance");

		//Setting prototype test
		var o2:Object = new Object();
		Object.prototype["settable"]=1;
		Tests.assertEquals(1,Object.prototype["settable"],"Prototype var is not modifiable from instances [1/2]");
		o2["settable"]=2;
		Tests.assertEquals(1,Object.prototype["settable"],"Prototype var is not modifiable from instances [2/2]");

		Tests.report(visual, this.name);
	}
	]]>
</mx:Script>

<mx:UIComponent id="visual" />

</mx:Application>
