示例#1
0
	// HACK snewman 7/26/01: ensure that the type analysis in these methods is
	// complete, e.g. that "value is double" will fire for all numeric values.
	// Might need to add additional tests for 64-bit int, for example.
	
	// Convert the given value to a primitive type.
	public static object ToPrimitive(object value, JObject.ValueHintType hint)
		{
		// If the value is already a JavaScript primitive type, just return it.
		if (JObject.IsPrimitive(value))
			return value;
		
		// Otherwise, convert it to a primitive.
		JObject asObj = value as JObject;
		if (asObj != null)
			return asObj.DefaultValue(hint);
		else
			throw new TypeError("attempt to convert non-JavaScript object to primitive");
		
		} // ToPrimitive