상속: IdScriptableObject
예제 #1
0
		/// <summary>Convert the value to an object.</summary>
		/// <remarks>
		/// Convert the value to an object.
		/// See ECMA 9.9.
		/// </remarks>
		public static Scriptable ToObject(Context cx, Scriptable scope, object val)
		{
			if (val is Scriptable)
			{
				return (Scriptable)val;
			}
			if (val is CharSequence)
			{
				// FIXME we want to avoid toString() here, especially for concat()
				NativeString result = new NativeString((CharSequence)val);
				SetBuiltinProtoAndParent(result, scope, TopLevel.Builtins.String);
				return result;
			}
			if (val is Number)
			{
				NativeNumber result = new NativeNumber(System.Convert.ToDouble(((Number)val)));
				SetBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Number);
				return result;
			}
			if (val is bool)
			{
				NativeBoolean result = new NativeBoolean(((bool)val));
				SetBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Boolean);
				return result;
			}
			if (val == null)
			{
				throw TypeError0("msg.null.to.object");
			}
			if (val == Undefined.instance)
			{
				throw TypeError0("msg.undef.to.object");
			}
			// Extension: Wrap as a LiveConnect object.
			object wrapped = cx.GetWrapFactory().Wrap(cx, scope, val, null);
			if (wrapped is Scriptable)
			{
				return (Scriptable)wrapped;
			}
			throw ErrorWithClassName("msg.invalid.type", val);
		}
예제 #2
0
		internal static void Init(Scriptable scope, bool @sealed)
		{
			Rhino.NativeBoolean obj = new Rhino.NativeBoolean(false);
			obj.ExportAsJSClass(MAX_PROTOTYPE_ID, scope, @sealed);
		}