Ver Fonte

* Add JSClassName

Michael Van Canneyt há 8 meses atrás
pai
commit
7d4d5afb64
1 ficheiros alterados com 11 adições e 0 exclusões
  1. 11 0
      packages/rtl/src/js.pas

+ 11 - 0
packages/rtl/src/js.pas

@@ -1196,6 +1196,7 @@ function toObject(Value: JSValue): TJSObject; // If Value is not a Javascript ob
 function toArray(Value: JSValue): TJSArray; // If Value is not a Javascript array, returns Nil
 function toBoolean(Value: JSValue): Boolean; // If Value is not a Boolean, returns False
 function toString(Value: JSValue): String; // If Value is not a string, returns ''
+function JSClassName(aObj : TJSObject) : string;
 
 Type
   TJSValueType = (jvtNull,jvtBoolean,jvtInteger,jvtFloat,jvtString,jvtObject,jvtArray);
@@ -1208,6 +1209,16 @@ Const
 
 implementation
 
+function JSClassName(aObj : TJSObject) : string;
+
+begin
+  Result:='';
+  if aObj=Nil then exit;
+  asm
+    return aObj.constructor.name;
+  end;
+end;
+
 function AsNumber(v: JSValue): Double; assembler;
 asm
   return Number(v);