⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel.js

📁 《JavaScript王者归来》examples.rar
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------\|                                JSVM 2.0                                     ||-----------------------------------------------------------------------------||                         Created by Wan.Changhua                             ||                      (Email,MSN: wch3116@hotmail.com)                       ||                      For JSVM Team (http://jsvm.org/)                       ||-----------------------------------------------------------------------------|| An object based javascript framework, targeted at rich web applications,    || JSVM (JavaScript Virtual Machine) is implemented in JavaScript. Currently   |
| only internet explorer 5.5 and later and firefox and opera are supported.   ||-----------------------------------------------------------------------------||                    Copyright (c) 2004 - 2005 JSVM Team                      ||-----------------------------------------------------------------------------||                                                                             || BSD - FreeBSD Copyright Information License                                 |
|                                                                             |
| Permission is hereby granted, free of charge, to any person obtaining a     |
| copy of this software and associated documentation files (the "Software"),  |
| to deal in the Software without restriction, including without limitation   |
| the rights to use, copy, modify, merge, publish, distribute, sublicense,    |
| and/or sell copies of the Software, and to permit persons to whom the       |
| Software is furnished to do so, subject to the following conditions:        |
|                                                                             |
| The above copyright notice and this permission notice shall be included     |
| in all copies or substantial portions of the Software.                      |
|                                                                             |
| This software is provided "as is", without warranty of any kind, express or || implied, including  but not limited  to the warranties of  merchantability, || fitness for a particular purpose and noninfringement. In no event shall the || authors or  copyright  holders be  liable for any claim,  damages or  other || liability, whether  in an  action of  contract, tort  or otherwise, arising || from,  out of  or in  connection with  the software or  the  use  or  other || dealings in the software.                                                   |
|                                                                             ||-----------------------------------------------------------------------------|| Dependencies: ../jsre.js, ../rtenv.conf, ./*.js                             ||-----------------------------------------------------------------------------|| 2005-01-02 | Renamed filename to jsre.js and updated the version to 2.01.   |
| 2005-11-11 | Added Error,Exception Class public method: getCause.           |
| 2005-11-14 | Canceled the operation that the class $extends _JSVM_Namespace.|
|            | -kernel.Object when it's $super property is null.              |
| 2005-12-06 | Fixed a bug of the isClass function & modified default engine. |
| 2005-12-30 | Added isInstance(Object obj) method for all classes.           |
| 2006-05-15 | Added the Class.create(classname, constructor) method.         |
| 2006-05-25 | Changed temp method name of call() & apply() to an uuid string.|
| 2006-06-04 | Fixed a bug: the native parser definition on firefox v1.0.     ||-----------------------------------------------------------------------------|| Created 2005-01-02 | All changes are in the log above. | Updated 2006-06-04 |\----------------------------------------------------------------------------*/

/**
 * JSVM, core module
 * @file:	kernel.js
 * @function:	define JSVM & core components
 * @author:	Wan Changhua
 * @date:	2005.01.02
 *
 */

_JSVM_Namespace.runtimeEnvironment.loadModule("kernel", function()

{
	/**
	  * Check _JSVM_Namespace Variable.
	  */
	var jsre = _JSVM_Namespace.runtimeEnvironment;
	//var jsre = this;

	if (jsre.JSVM != null)
	{
		throw ("kernel.js/JSVM already exist!");
	}

	/* Class Definition */

	var Class = _JSVM_Namespace.kernel.Class = Function;

	Class.prototype.$super = null;
	Class.prototype.$class = Class;
	Class.prototype.$name = "Class";
	Class.prototype.$window = window;

	Class.forName = function(name)
	{
		return jsre.JSVM.loadClass(name);
	}

	Class.create = function(name, constructor, base)
	{
		var clazz = (constructor == null) ?	new Class()	:
			function ()	{return constructor.apply(this, arguments);};
		clazz.$extends(base || _JSVM_Namespace.kernel.Object);
		clazz.$name = name;
		return clazz;
	}

	Class.prototype.newInstance = function()
	{
		var s = "new this(";
		for (var i = 0; i < arguments.length; i++)
		{
			s += "arguments[" + i +"],";
		}
		return eval(s.replace(/,$/,"") + ");");
	}
	Class.prototype.isInstance = function (o)
	{
		return (o instanceof this) ||
			(o != null && o.instanceOf != null &&
				o.instanceOf(this.getName()));
	}
	Class.prototype.getName = function()
	{
		return this.$name;
	}
	Class.prototype.getSuperclass = function()
	{
		return this.$super;
	}
	Class.prototype.$extends = function(clazz)
	{
		try
		{
			if (typeof((typeof(clazz) != "string") ? clazz
				: (clazz = Class.forName(clazz))) != "function")
			{
				throw new Exception(0x0017, "Class.$extends(clazz) error:"
					+ " the super class '" + clazz + "' is an invalid class.");
			}
			var p = this.prototype = new clazz();
			p.$class = p.constructor = this;
			this.$super = clazz;
			return p;
		}
		catch(ex)
		{
			throw new Exception(0x0018, "class.$extends(clazz) fail.", ex);
		}
	}

	/* define call method for ie5 */

	if (typeof(Class.prototype.call) != "function")
	{
		Class.prototype.call = function(obj)
		{
			if (obj == null || typeof(obj) != "object")
			{
				throw new Exception(0x0010,
					"Class.call() argument is not a object!");
			}
			obj.__10b7bd87308899eaa62fc9cce5620376 = this;
			var args = [];
			for (var i = 0; i < arguments.length - 1; i++)
			{
				args[i] = "arguments[" + (i + 1) + "]";
			}
			var r = eval("obj.__10b7bd87308899eaa62fc9cce5620376("
				+ args.join(",") + ");");
			delete obj.__10b7bd87308899eaa62fc9cce5620376;
			return r;
		}
	}

	/* define apply method for ie5 */

	if (typeof(Class.prototype.apply) != "function")
	{
		Class.prototype.apply = function(obj, _arguments)
		{
			if (obj == null || typeof(obj) != "object")
			{
				throw new Exception(0x0011,
					"Class.apply() argument is not a object!");
			}
			obj.__10b7bdb5dd95e4f2708cfa36f3569503 = this;
			var args = [];
			for (var i = 0; i < _arguments.length; i++)
			{
				args[i] = "_arguments[" + i + "]";
			}
			var r = eval("obj.__10b7bdb5dd95e4f2708cfa36f3569503("
				+ args.join(",") + ");");
			delete obj.__10b7bdb5dd95e4f2708cfa36f3569503;
			return r;
		}
	}

	// the prototype of all class

	var Object = _JSVM_Namespace.kernel.Object = function(){};
	Object.$name = "Object";
	Object.prototype.$class = Object;
	Object.prototype.$___hc = 0x0;
	Object.prototype.window = window;
	Object.prototype.getClass = function()
	{
		return this.$class;
	}
	Object.prototype.live = function ()
	{
		return (this.window.closed == false);
	}
	Object.prototype.hashCode = function ()
	{
		return (this.$___hc != 0) ? this.$___hc
			: (this.$___hc = (0x10000000 + Math.round(
			Math.random() * 0x10000000)));
	}
	Object.prototype.toString = function ()
	{
		return("[Object " + this.getClass().getName()
			+ "@" + this.hashCode().toString(16) + "]");
	}
	Object.prototype.instanceOf = function (c)
	{
		return (this instanceof (typeof(c)
			== "string"	?	Class.forName(c) : c));
	}
	Object = window.Object;

	/* Package Definition */

	var Package = _JSVM_Namespace.kernel.Package = function(name)
	{
		this.getName = function()
		{
			return name;
		}
		this.getChildClass = function(clzname)
		{
			return Class.forName(name
				+ "." + clzname);
		}
	}
	Package.$name = "Package";
	Package.prototype.$class = Package;

	/* Exception Definition */

	Error.$super = null;
	Error.$name = "Error";
	Error.prototype.$class = Error;
	Error.prototype.getName = function ()
	{
		return this.name;
	}
	Error.prototype.getMessage = function ()
	{
		return this.message;
	}
	Error.prototype.getCause = function ()
	{
		return null;
	}
	if (Error.prototype.name == null)
	{
		Error.prototype.name = "Error";
		Error.prototype.getMessage = function ()
		{
			return this.description;
		}
	}

	var Exception =
		_JSVM_Namespace.kernel.Exception =
			function(number, message, cause)
	{
		this.number = _JSVM_Namespace.deviceNumber * 0x10000 + number;
		this.message = message;
		this.cause = cause;
	}
	Exception.$extends(_JSVM_Namespace.kernel.Object);
	Exception.prototype.constructor =
	Exception.prototype.$class = Exception;
	Exception.$name = "Exception";

	Exception.prototype.getName = function ()
	{
		return this.getClass().getName();
	}
	Exception.prototype.getMessage = function ()
	{
		return this.message;
	}
	Exception.prototype.getCause = function ()
	{
		return this.cause;
	}
	Exception.prototype.toString =
		Error.prototype.toString = function()
	{
		return this.getName()	+ ":" + this.getMessage();
	}
	Exception.prototype.printStackTrace =
		Error.prototype.printStackTrace = function()
	{
		var s = this.toString();
		var e = this.cause;
		while(e != null)
		{
			s += "\r\n\tat " + e.toString();
			e = e.cause;
		}
		(arguments.length > 0 &&
			typeof(arguments[0].println) == "function") ?
				arguments[0].println(s) :
					jsre.JSVM.console.output(s + "\r\n");
	}

	/**
	  * Define JSVM Abstract Class
	  */
	_JSVM_Namespace.kernel.JSVM_V2_04_060820 = function()
	{

		/* Check Caller */
		if (this == window)
		{
			throw new Error("create instance must by \"new\" .");
		}

		this.version = "2.04.060820";
		this.state = 0;

		/* jsvm core component */

		/* component: Classloader */
		var classloader = null;
		this.setClassloader = function(oClassloader)
		{
			classloader = oClassloader;
			this.logger.log("JSVM set classloader succ.");
		}
		this.getClassloader = function()
		{
			return classloader;
		}

		/* Public Method */

		/* component: Console */
		this.console = null;
		this.setConsole = function(oConsole)
		{
			this.console = oConsole;
			this.logger.log("JSVM set console succ.");
		}

		/* component: Container */
		var container = null;
		this.setContainer = function(oContainer)
		{
			container = oContainer;
			this.logger.log("JSVM set container succ.");
		}
		this.getContainer = function()
		{
			return container;
		}

		/* component: Compiler */
		var compiler = null;
		this.setCompiler = function(oCompiler)
		{
			compiler = oCompiler;
			this.logger.log("JSVM set compiler succ.");
		}
		this.getCompiler = function()
		{
			return compiler;
		}

		/* component: Engine */
		var engine = null;
		this.setEngine = function(oEngine)
		{
			engine = oEngine;
			this.logger.log("JSVM set engine succ.");
		}
		this.getEngine = function()
		{
			return engine;
		}

		/* public method: load class */
		this.loadClass = function(name)
		{
			try
			{
				var clazz = container.getClass(name);
				if (clazz != null)
				{
					return clazz;
				}
				var code = container.getClassCode(name);
				if (code == null)
				{
					code = classloader.loadClass(name);
					code = compiler.compile(code);
					container.putClassCode(name, code);
				}
				clazz = engine.defineClass(name, code);
				container.putClass(name, clazz);
				return clazz;
			}
			catch (ex)
			{
				var err = new Exception(0x0018,
					"kernel.js/JSVM.loadClass() fail."
					+ " [classname:" + name + "]", ex);
				this.logger.log(err);
				throw err;
			}
		}

		this.loadPackage = function(name)
		{
			var err = new Exception(0x001B,
				"kernel.js/JSVM.loadPackage() not implemented.");
			this.logger.log(err);
			throw err;
		}

		/* Component: logger */
		this.logger = new function()
		{
			var list = [];
			this.onchange = null;
			this.log = function (s)
			{
				var l = list.length;
				var d = new Date();
				list[l] = ['[', d.toLocaleString(), ':' ,
					d.getMilliseconds(), ' JSVM] ', s].join('');
				if (this.onchange != null)
				{
					this.onchange(list[l]);
				}
			}
			this.getLogs = function()
			{
				return list.concat([]);
			}
		}

		this.initialize = function() {}
		this.destroy = function() {}

	}

	var JSVM = jsre.JSVM = new _JSVM_Namespace.kernel.JSVM_V2_04_060820();
	JSVM.initialize();
	JSVM.logger.log("JSVM initialized.");

	/* Set Default Core Components */

	/* Set Default Container */
	JSVM.setContainer(new function()
		{
			/* Class Cache */
			var classesCache = {};
			this.putClass = function(name, entity)
			{
				classesCache[name] = entity;
			}
			this.getClass = function(name)
			{
				return classesCache[name];
			}
			/* ClassCode Cache */
			var classesCodeCache = {};
			this.putClassCode = function(name, code)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -