Browse Source

* trunc now dynamically creates Math.trunc on IE

michael 7 years ago
parent
commit
0daa2404ea
2 changed files with 18 additions and 1 deletions
  1. 14 1
      packages/rtl/system.pas
  2. 4 0
      packages/rtl/web.pas

+ 14 - 1
packages/rtl/system.pas

@@ -151,7 +151,7 @@ function Sin(const A: Double): Double; external name 'Math.sin';
 function Sqr(const A: Integer): Integer; assembler; overload;
 function Sqr(const A: Double): Double; assembler; overload;
 function sqrt(const A: Double): Double; external name 'Math.sqrt';
-function Trunc(const A: Double): NativeInt; external name 'Math.trunc'; // not on IE
+function Trunc(const A: Double): NativeInt;
 
 {*****************************************************************************
                           String functions
@@ -243,6 +243,19 @@ asm
   return A*A;
 end;
 
+function Trunc(const A: Double): NativeInt; assembler;
+asm
+  if (!Math.trunc) {
+    Math.trunc = function(v) {
+      v = +v;
+      if (!isFinite(v)) return v;
+      return (v - v % 1) || (v < 0 ? -0 : v === 0 ? v : 0);
+    };
+  }
+  $mod.Trunc = Math.trunc;
+  return Math.trunc(A);
+end;
+
 function Copy(const S: string; Index, Size: Integer): String; assembler;
 asm
   if (Index<1) Index = 1;

+ 4 - 0
packages/rtl/web.pas

@@ -1693,6 +1693,8 @@ Type
     touchend : TJSTouchEventHandler;
     touchmove : TJSTouchEventHandler;
     touchcancel : TJSTouchEventHandler;
+    procedure addEventListener(aname : string; aListener : TJSEventHandler);
+    procedure addEventListener(aname : string; aListener : JSValue);
     Procedure alert(Const Msg : String);
     Function atob(Const aValue : string) : string;
     procedure blur;
@@ -1714,6 +1716,8 @@ Type
     procedure print;
     function prompt(const aMessage : String) : String; overload;
     function prompt(const aMessage,aDefault : String) : String; overload;
+    procedure removeEventListener(aname : string; aListener : TJSEventHandler);
+    procedure removeEventListener(aname : string; aListener : JSValue);
     procedure resizeBy(aWidth,aHeight : NativeInt);
     procedure resizeTo(aWidth,aHeight : NativeInt);
     procedure scrollBy(x,y : NativeInt);