ExportAsScopeProperty() public méthode

public ExportAsScopeProperty ( ) : void
Résultat void
Exemple #1
0
		internal static void Init(Scriptable scope, bool @sealed)
		{
			Rhino.NativeWith obj = new Rhino.NativeWith();
			obj.SetParentScope(scope);
			obj.SetPrototype(ScriptableObject.GetObjectPrototype(scope));
			IdFunctionObject ctor = new IdFunctionObject(obj, FTAG, Id_constructor, "With", 0, scope);
			ctor.MarkAsConstructor(obj);
			if (@sealed)
			{
				ctor.SealObject();
			}
			ctor.ExportAsScopeProperty();
		}
		public static void Init(Context cx, Scriptable scope, bool @sealed)
		{
			ClassLoader loader = cx.GetApplicationClassLoader();
			Rhino.NativeJavaTopPackage top = new Rhino.NativeJavaTopPackage(loader);
			top.SetPrototype(GetObjectPrototype(scope));
			top.SetParentScope(scope);
			for (int i = 0; i != commonPackages.Length; i++)
			{
				NativeJavaPackage parent = top;
				for (int j = 0; j != commonPackages[i].Length; j++)
				{
					parent = parent.ForcePackage(commonPackages[i][j], scope);
				}
			}
			// getClass implementation
			IdFunctionObject getClass = new IdFunctionObject(top, FTAG, Id_getClass, "getClass", 1, scope);
			// We want to get a real alias, and not a distinct JavaPackage
			// with the same packageName, so that we share classes and top
			// that are underneath.
			string[] topNames = ScriptRuntime.GetTopPackageNames();
			NativeJavaPackage[] topPackages = new NativeJavaPackage[topNames.Length];
			for (int i_1 = 0; i_1 < topNames.Length; i_1++)
			{
				topPackages[i_1] = (NativeJavaPackage)top.Get(topNames[i_1], top);
			}
			// It's safe to downcast here since initStandardObjects takes
			// a ScriptableObject.
			ScriptableObject global = (ScriptableObject)scope;
			if (@sealed)
			{
				getClass.SealObject();
			}
			getClass.ExportAsScopeProperty();
			global.DefineProperty("Packages", top, ScriptableObject.DONTENUM);
			for (int i_2 = 0; i_2 < topNames.Length; i_2++)
			{
				global.DefineProperty(topNames[i_2], topPackages[i_2], ScriptableObject.DONTENUM);
			}
		}
Exemple #3
0
		public static void Init(Context cx, Scriptable scope, bool @sealed)
		{
			NativeGlobal obj = new NativeGlobal();
			for (int id = 1; id <= LAST_SCOPE_FUNCTION_ID; ++id)
			{
				string name;
				int arity = 1;
				switch (id)
				{
					case Id_decodeURI:
					{
						name = "decodeURI";
						break;
					}

					case Id_decodeURIComponent:
					{
						name = "decodeURIComponent";
						break;
					}

					case Id_encodeURI:
					{
						name = "encodeURI";
						break;
					}

					case Id_encodeURIComponent:
					{
						name = "encodeURIComponent";
						break;
					}

					case Id_escape:
					{
						name = "escape";
						break;
					}

					case Id_eval:
					{
						name = "eval";
						break;
					}

					case Id_isFinite:
					{
						name = "isFinite";
						break;
					}

					case Id_isNaN:
					{
						name = "isNaN";
						break;
					}

					case Id_isXMLName:
					{
						name = "isXMLName";
						break;
					}

					case Id_parseFloat:
					{
						name = "parseFloat";
						break;
					}

					case Id_parseInt:
					{
						name = "parseInt";
						arity = 2;
						break;
					}

					case Id_unescape:
					{
						name = "unescape";
						break;
					}

					case Id_uneval:
					{
						name = "uneval";
						break;
					}

					default:
					{
						throw Kit.CodeBug();
					}
				}
				IdFunctionObject f = new IdFunctionObject(obj, FTAG, id, name, arity, scope);
				if (@sealed)
				{
					f.SealObject();
				}
				f.ExportAsScopeProperty();
			}
			ScriptableObject.DefineProperty(scope, "NaN", ScriptRuntime.NaNobj, ScriptableObject.READONLY | ScriptableObject.DONTENUM | ScriptableObject.PERMANENT);
			ScriptableObject.DefineProperty(scope, "Infinity", ScriptRuntime.WrapNumber(double.PositiveInfinity), ScriptableObject.READONLY | ScriptableObject.DONTENUM | ScriptableObject.PERMANENT);
			ScriptableObject.DefineProperty(scope, "undefined", Undefined.instance, ScriptableObject.READONLY | ScriptableObject.DONTENUM | ScriptableObject.PERMANENT);
			string[] errorMethods = new string[] { "ConversionError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "InternalError", "JavaException" };
			for (int i = 0; i < errorMethods.Length; i++)
			{
				string name = errorMethods[i];
				ScriptableObject errorProto = (ScriptableObject)ScriptRuntime.NewObject(cx, scope, "Error", ScriptRuntime.emptyArgs);
				errorProto.Put("name", errorProto, name);
				errorProto.Put("message", errorProto, string.Empty);
				IdFunctionObject ctor = new IdFunctionObject(obj, FTAG, Id_new_CommonError, name, 1, scope);
				ctor.MarkAsConstructor(errorProto);
				errorProto.Put("constructor", errorProto, ctor);
				errorProto.SetAttributes("constructor", ScriptableObject.DONTENUM);
				if (@sealed)
				{
					errorProto.SealObject();
					ctor.SealObject();
				}
				ctor.ExportAsScopeProperty();
			}
		}