{ This file is part of the Pas2JS run time library. Copyright (c) 2018 by Mattias Gaertner See the file COPYING.FPC, included in this distribution, for details about the copyright. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **********************************************************************} unit RTTI; {$mode objfpc} interface uses SysUtils, Types; type TVirtualInterfaceInvokeEvent = function(const aMethodName: string; const Args: TJSValueDynArray): JSValue of object; { TVirtualInterface: A class that can implement any IInterface. Any method call is handled by the OnInvoke event. } TVirtualInterface = class(TInterfacedObject, IInterface) private FOnInvoke: TVirtualInterfaceInvokeEvent; public constructor Create(InterfaceTypeInfo: Pointer); overload; assembler; constructor Create(InterfaceTypeInfo: Pointer; const InvokeEvent: TVirtualInterfaceInvokeEvent); overload; property OnInvoke: TVirtualInterfaceInvokeEvent read FOnInvoke write FOnInvoke; end; procedure CreateVirtualCorbaInterface(InterfaceTypeInfo: Pointer; const MethodImplementation: TVirtualInterfaceInvokeEvent; out IntfVar); assembler; implementation procedure CreateVirtualCorbaInterface(InterfaceTypeInfo: Pointer; const MethodImplementation: TVirtualInterfaceInvokeEvent; out IntfVar); assembler; asm var IntfType = InterfaceTypeInfo.interface; var i = Object.create(IntfType); var o = { $name: "virtual", $fullname: "virtual" }; i.$o = o; do { var names = IntfType.$names; if (!names) break; for (var j=0; j