Преглед на файлове

Added back in necessary code to permit Reflection on Math, moving
back to using only std/Math instead of js specific file.

Luca Deltodesco преди 12 години
родител
ревизия
57c6ccff1f
променени са 3 файла, в които са добавени 106 реда и са изтрити 150 реда
  1. 102 69
      std/Math.hx
  2. 0 78
      std/js/_std/Math.hx
  3. 4 3
      std/js/_std/Reflect.hx

+ 102 - 69
std/Math.hx

@@ -23,203 +23,219 @@
 	This class defines mathematical functions and constants.
 **/
 #if cpp @:include("hxMath") #end
+@:keepInit
 extern class Math
 {
 	static var PI(default,null) : Float;
-	
+
 	/**
 		A special Float constant which denotes negative infinity.
-		
+
 		For example, this is the result of -1.0 / 0.0.
-		
+
 		Operations with NEGATIVE_INFINITY as an operand may result in
 		Operations with NEGATIVE_INFINITY as an operand may result in
 		NEGATIVE_INFINITY, POSITIVE_INFINITY or NaN. For detailed information,
 		see ...
-		
+
 		If this constant is converted to an Int, e.g. through Std.int(), the
 		result is unspecified.
 	**/
+#if js
+	static var NEGATIVE_INFINITY(get, null) : Float;
+	static inline function get_NEGATIVE_INFINITY() : Float return untyped __js__("$Number").NEGATIVE_INFINITY;
+#else
 	static var NEGATIVE_INFINITY(default, null) : Float;
+#end
 	/**
 		A special Float constant which denotes negative infinity.
-		
+
 		For example, this is the result of 1.0 / 0.0.
-		
+
 		Operations with POSITIVE_INFINITY as an operand may result in
 		NEGATIVE_INFINITY, POSITIVE_INFINITY or NaN. For detailed information,
 		see ...
-	
+
 		If this constant is converted to an Int, e.g. through Std.int(), the
 		result is unspecified.
 	**/
-	static var POSITIVE_INFINITY(default,null) : Float;
+#if js
+	static var POSITIVE_INFINITY(get, null) : Float;
+	static inline function get_POSITIVE_INFINITY() : Float return untyped __js__("$Number").POSITIVE_INFINITY;
+#else
+	static var POSITIVE_INFINITY(default, null) : Float;
+#end
 
 	/**
 		A special Float constant which denotes an invalid number.
-		
+
 		NaN stands for "Not a Number". It occurs when a mathematically incorrect
 		operation is executed, such as taking the square root of a negative
 		number: Math.sqrt(-1).
-		
+
 		All further operations with NaN as an operand will result in NaN.
-		
+
 		If this constant is converted to an Int, e.g. through Std.int(), the
 		result is unspecified.
-		
+
 		In order to test if a value is NaN, you should use Math.isNaN() function.
-		
+
 		(Php) In PHP versions prior to 5.3.1 VC 9 there may be unexpected
 		results when performing arithmetic operations with NaN on Windows, see:
 			https://bugs.php.net/bug.php?id=42143
 	**/
+#if js
+	static var NaN(get, null) : Float;
+	static inline function get_NaN() : Float return untyped __js__("$Number").NaN;
+#else
 	static var NaN(default, null) : Float;
+#end
 
 	/**
 		Returns the absolute value of `v`.
-		
+
 		If `v` is positive or 0, the result is unchanged. Otherwise the result
 		is -`v`.
-		
+
 		If `v` is NEGATIVE_INFINITY or POSITIVE_INFINITY, the result is
 		POSITIVE_INFINITY.
-		
+
 		If `v` is NaN, the result is NaN.
 	**/
 	static function abs(v:Float):Float;
-	
+
 	/**
 		Returns the smaller of values `a` and `b`.
-		
+
 		If `a` or `b` are NaN, the result is NaN.
-		
+
 		If `a` or `b` are NEGATIVE_INFINITY, the result is NEGATIVE_INFINITY.
-		
+
 		If `a` and `b` are POSITIVE_INFINITY, the result is POSITIVE_INFINITY.
 	**/
 	static function min(a:Float, b:Float):Float;
-	
+
 	/**
 		Returns the greater of values `a` and `b`.
-		
+
 		If `a` or `b` are NaN, the result is NaN.
-		
+
 		If `a` or `b` are POSITIVE_INFINITY, the result is POSITIVE_INFINITY.
-		
+
 		If `a` and `b` are NEGATIVE_INFINITY, the result is NEGATIVE_INFINITY.
 	**/
 	static function max(a:Float, b:Float):Float;
-	
+
 	/**
 		Returns the trigonometric sine of `v`.
-		
+
 		The unit of `v` is radians.
-		
+
 		If `v` is NaN or infinite, the result is NaN.
 	**/
 	static function sin(v:Float):Float;
-	
+
 	/**
 		Returns the trigonometric cosine of `v`.
-		
+
 		The unit of `v` is radians.
-		
+
 		If `v` is NaN or infinite, the result is NaN.
 	**/
 	static function cos(v:Float):Float;
-	
+
 	// TODO
 	static function tan(v:Float):Float;
 	static function asin(v:Float):Float;
 	static function acos(v:Float):Float;
 	static function atan(v:Float):Float;
 	static function atan2(y:Float, x:Float):Float;
-	
+
 	/**
 		Returns Euler's number, raised to the power of `v`.
-		
+
 		exp(1.0) is approximately 2.718281828459.
-		
+
 		If `v` is POSITIVE_INFINITY, the result is POSITIVE_INFINITY.
-		
+
 		If `v` is NEGATIVE_INFINITY, the result is 0.0.
-		
+
 		If `v` is NaN, the result is NaN.
 	**/
 	static function exp(v:Float):Float;
-	
+
 	/**
 		Returns the natural logarithm of `v`.
-		
+
 		If `v` is negative (including NEGATIVE_INFINITY) or NaN, the result is
 		NaN.
-		
+
 		If `v` is POSITIVE_INFINITY, the result is POSITIVE_INFINITY.
-		
+
 		If `v` is 0.0, the result is NEGATIVE_INFINITY.
-		
+
 		This is the inverse operation of exp, i.e. log(exp(v)) == v always
 		holds.
 	**/
 	static function log(v:Float):Float;
-	
+
 	// TODO
 	// http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html#pow(double, double) <-- wtf?
 	static function pow(v:Float, exp:Float):Float;
-	
+
 	/**
 		Returns the square root of `v`.
-		
+
 		If `v` is negative (including NEGATIVE_INFINITY) or NaN, the result is
 		NaN.
-		
+
 		If `v` is POSITIVE_INFINITY, the result is POSITIVE_INFINITY.
-		
+
 		If `v` is 0.0, the result is 0.0.
 	**/
 	static function sqrt(v:Float):Float;
-	
+
 	/**
 		Rounds `v` to the nearest Int value.
 
 		If v is outside of the signed Int32 range, or is NaN, NEGATIVE_INFINITY or POSITIVE_INFINITY, the result is unspecified.
-		
+
 		TODO: need spec
 	**/
 	static function round(v:Float):Int;
-	
+
 	/**
 		Returns the largest Int value that is not greater than `v`.
-		
-		If v is outside of the signed Int32 range, or is NaN, NEGATIVE_INFINITY or POSITIVE_INFINITY, the result is unspecified.		
-		
+
+		If v is outside of the signed Int32 range, or is NaN, NEGATIVE_INFINITY or POSITIVE_INFINITY, the result is unspecified.
+
 		TODO: need spec
 	**/
 	static function floor(v:Float):Int;
-	
+
 	/**
 		Returns the smallest Int value that is not less than `v`.
 
 		If v is outside of the signed Int32 range, or is NaN, NEGATIVE_INFINITY or POSITIVE_INFINITY, the result is unspecified.
-		
+
 		TODO: need spec
 	**/
 	static function ceil(v:Float):Int;
-	
+
 	/**
 		Returns a pseudo-random number which is greater than or equal to 0.0,
 		and less than 1.0.
 	**/
 	static function random() : Float;
-	
+
 	#if ((flash9 && !as3) || cpp)
-	
+
 	static function ffloor( v : Float ) : Float;
 	static function fceil( v : Float ) : Float;
 	static function fround( v : Float ) : Float;
-	
+
 	#else
-	
+
 	static inline function ffloor( v : Float ) : Float {
 		return floor(v);
 	}
@@ -231,45 +247,61 @@ extern class Math
 	static inline function fround( v : Float ) : Float {
 		return round(v);
 	}
-	
+
 	#end
-	
+
 
 	/**
 		Tells if `f` is a finite number.
-		
+
 		If `f` is POSITIVE_INFINITY, NEGATIVE_INFINITY or NaN, the result is
 		false.
-		
+
 		Otherwise the result is true.
 	**/
+#if js
+	static inline function isFinite( f : Float ) : Bool return untyped __js__("$isFinite")(f);
+#else
 	static function isFinite( f : Float ) : Bool;
-	
+#end
+
 	/**
 		Tells if `f` is not a valid number.
-		
+
 		If `f` is NaN, the result is true.
-		
+
 		Otherwise the result is false. In particular, both POSITIVE_INFINITY and
 		NEGATIVE_INFINITY are not considered NaN.
 	**/
+#if js
+	static inline function isNaN( f : Float ) : Bool return untyped __js__("$isNaN")(f);
+#else
 	static function isNaN( f : Float ) : Bool;
+#end
 
 	private static function __init__() : Void untyped {
 	#if flash9
 		NaN = __global__["Number"].NaN;
 		NEGATIVE_INFINITY = __global__["Number"].NEGATIVE_INFINITY;
 		POSITIVE_INFINITY = __global__["Number"].POSITIVE_INFINITY;
-	#else
+	#elseif flash
 		Math.__name__ = ["Math"];
 		Math.NaN = Number["NaN"];
 		Math.NEGATIVE_INFINITY = Number["NEGATIVE_INFINITY"];
 		Math.POSITIVE_INFINITY = Number["POSITIVE_INFINITY"];
+	#else
+		__js__("Math").__name__ = ["Math"];
+		__js__("Math").NaN = Number["NaN"];
+		__js__("Math").NEGATIVE_INFINITY = Number["NEGATIVE_INFINITY"];
+		__js__("Math").POSITIVE_INFINITY = Number["POSITIVE_INFINITY"];
 	#end
 	#if js
 		__feature__("Type.resolveClass",$hxClasses['Math'] = Math);
+		__js__("var $Number = Number");
+		__js__("var $isFinite = isFinite");
+		__js__("var $isNaN = isNaN");
 	#end
-		Math.isFinite = function(i) {
+		#if js __js__("Math") #else Math #end.isFinite = function(i) {
 			return
 			#if flash9
 			__global__["isFinite"](i);
@@ -281,7 +313,7 @@ extern class Math
 			false;
 			#end
 		};
-		Math.isNaN = function(i) {
+		#if js __js__("Math") #else Math #end.isNaN = function(i) {
 			return
 			#if flash9
 			__global__["isNaN"](i);
@@ -298,3 +330,4 @@ extern class Math
 }
 
 
+

+ 0 - 78
std/js/_std/Math.hx

@@ -1,78 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * 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.
- *
- * THE 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.
- */
-
-@:native("Math")
-extern class Math
-{
-	static var PI(default,null) : Float;
-
-	static var POSITIVE_INFINITY(get, null) : Float;
-	static inline function get_POSITIVE_INFINITY() : Float
-		return untyped __js__("$Number").POSITIVE_INFINITY;
-
-	static var NEGATIVE_INFINITY(get, null) : Float;
-	static inline function get_NEGATIVE_INFINITY() : Float
-		return untyped __js__("$Number").NEGATIVE_INFINITY;
-
-	static var NaN(get, null) : Float;
-	static inline function get_NaN() : Float
-		return untyped __js__("$Number").NaN;
-
-	static function abs(v:Float):Float;
-	static function min(a:Float, b:Float):Float;
-	static function max(a:Float, b:Float):Float;
-	static function sin(v:Float):Float;
-	static function cos(v:Float):Float;
-	static function tan(v:Float):Float;
-	static function asin(v:Float):Float;
-	static function acos(v:Float):Float;
-	static function atan(v:Float):Float;
-	static function atan2(y:Float, x:Float):Float;
-	static function exp(v:Float):Float;
-	static function log(v:Float):Float;
-	static function pow(v:Float, exp:Float):Float;
-	static function sqrt(v:Float):Float;
-	static function round(v:Float):Int;
-	static function floor(v:Float):Int;
-	static function ceil(v:Float):Int;
-	static function random() : Float;
-
-	static inline function ffloor( v : Float ) : Float
-		return floor(v);
-	static inline function fceil( v : Float ) : Float
-		return ceil(v);
-	static inline function fround( v : Float ) : Float
-		return round(v);
-
-	static inline function isFinite( f : Float ) : Bool
-        return untyped __js__("$isFinite")(f);
-	static inline function isNaN( f : Float ) : Bool
-        return untyped __js__("$isNaN")(f);
-
-	static function __init__() : Void {
-        untyped __js__("var $Number = Number");
-		untyped __js__("var $isFinite = isFinite");
-		untyped __js__("var $isNaN = isNaN");
-	}
-
-}
-

+ 4 - 3
std/js/_std/Reflect.hx

@@ -19,7 +19,9 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-extern class Reflect {
+@:coreApi
+@:keepInit
+class Reflect {
 
 	public static inline function hasField( o : Dynamic, field : String ) : Bool
 		return untyped __js__("$hasOwnProperty").call(o, field);
@@ -47,9 +49,8 @@ extern class Reflect {
 	public static function fields( o : Dynamic ) : Array<String> {
 		var a = [];
 		if (o != null) untyped {
-			var hasOwnProperty = __js__("$hasOwnProperty");
 			__js__("for( var f in o ) {");
-			if( f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o, f) ) a.push(f);
+			if( f != "__id__" && f != "hx__closures__" && __js__("$hasOwnProperty").call(o, f) ) a.push(f);
 			__js__("}");
 		}
 		return a;