-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathv8napi.pas
1380 lines (1192 loc) · 35.7 KB
/
v8napi.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit v8napi;
//////////////////////////
// 1CNativeLib //
// Alexander Solomatin //
// [email protected] //
//////////////////////////
//04.04.2011 èñïðàâëåíà îøèáêà ñ äàòàìè
interface
uses SysUtils, Windows;
type
V8TYPEVAR = longword;
const
VTYPE_EMPTY = $000;
VTYPE_NULL = $001;
VTYPE_I2 = $002; //int16_t
VTYPE_I4 = $003; //int32_t
VTYPE_R4 = $004; //float
VTYPE_R8 = $005; //double
VTYPE_DATE = $006; //DATE (double)
VTYPE_TM = $007; //struct tm
VTYPE_PSTR = $008; //struct str string
VTYPE_INTERFACE = $009; //struct iface
VTYPE_ERROR = $00A; //int32_t errCode
VTYPE_BOOL = $00B; //bool
VTYPE_VARIANT = $00C; //struct V8Variant *
VTYPE_I1 = $00D; //int8_t
VTYPE_UI1 = $00E; //uint8_t
VTYPE_UI2 = $00F; //uint16_t
VTYPE_UI4 = $010; //uint32_t
VTYPE_I8 = $011; //int64_t
VTYPE_UI8 = $012; //uint64_t
VTYPE_INT = $013; //int Depends on architecture
VTYPE_UINT = $014; //unsigned int Depends on architecture 20
VTYPE_HRESULT = $015; //long hRes 21
VTYPE_PWSTR = $016; //struct wstr 22
VTYPE_BLOB = $017; //means in struct str binary data contain 23
VTYPE_CLSID = $018; //UUID 24
VTYPE_STR_BLOB = $0FFF;
VTYPE_VECTOR = $1000;
VTYPE_ARRAY = $2000;
VTYPE_BYREF = $4000; //Only with struct V8Variant *
VTYPE_RESERVED = $8000;
VTYPE_ILLEGAL = $FFFF;
VTYPE_ILLEGALMASKED = $0FFF;
VTYPE_TYPEMASK = $FFF;
type
TV8InterfaceVarRec = packed record
pInterfaceVal: pointer;
InterfaceID: TGUID;
end; //*iface*/;
TV8StringVarRec = packed record
pstrVal: PAnsiChar;
strLen: LongWord; //count of bytes
end; //*str*/;
TV8WideStringVarRec = packed record
pwstrVal: PWideChar;
wstrLen: LongWord; //count of symbol
end; //*wstr*/
PV8tm = ^TV8tm;
TV8tm = record
tm_sec: Integer; // seconds after the minute (from 0)
tm_min: Integer; // minutes after the hour (from 0)
tm_hour: Integer; // hour of the day (from 0)
tm_mday: Integer; // day of the month (from 1)
tm_mon: Integer; // month of the year (from 0)
tm_year: Integer; // years since 1900 (from 0)
tm_wday: Integer; // days since Sunday (from 0)
tm_yday: Integer; // day of the year (from 0)
tm_isdst: Integer; // Daylight Saving Time flag
end;
TVarEnum = record
case byte of
1: (i8Val: byte);
2: (shortVal: ShortInt);
3: (lVal: Integer);
4: (intVal: Integer);
5: (uintVal: LongWord);
6: (llVal: int64);
7: (ui8Val: byte);
8: (ushortVal: Word);
9: (ulVal: LongWord);
10: (ullVal: Int64);
11: (errCode: Integer);
12: (hRes: LongWord);
13: (fltVal: Single);
14: (dblVal: double);
15: (bVal: boolean);
16: (chVal: char);
17: (wchVal: WideChar);
18: (date: TDateTime);
19: (IDVal: TGUID);
20: (pvarVal: pointer);
21: (tmVal: TV8tm);
22: (vtRecInterface: TV8InterfaceVarRec);
23: (vtRecString: TV8StringVarRec);
24: (vtRecWideString: TV8WideStringVarRec);
end;
PV8Variant = ^V8Variant;
V8Variant = packed record
VarEnum: TVarEnum;
cbElements: LongWord; //Dimension for an one-dimensional array in pvarVal
vt: V8TYPEVAR;
end;
type
TV8MemoryManager = class //IMemoryManager ñì. äîêóìåíòàöèþ îò 1Ñ
public
procedure Destroy1; virtual; abstract;
function AllocMemory(pMemory: PPointer; ulCountByte: longword): boolean; virtual; stdcall; abstract;
procedure FreeMemory(pMemory: PPointer); virtual; stdcall; abstract;
end;
type
TV8AddInDefBase = class //IAddInDefBase ñì. äîêóìåíòàöèþ îò 1Ñ
public
procedure Destroy1; virtual; abstract;
function AddError(wcode: word; const source: PWideChar;
const descr: PWideChar;
scode: integer): boolean; virtual; stdcall; abstract;
function Read(wszPropName: PWideChar;
pVal: PV8Variant;
pErrCode: PInteger;
errDescriptor: PPWideChar): boolean; virtual; stdcall; abstract;
function Write(wszPropName: PWideChar;
pVar: PV8Variant): boolean; virtual; stdcall; abstract;
function RegisterProfileAs(wszProfileName: PWideChar): boolean; virtual; stdcall; abstract;
function SetEventBufferDepth(lDepth: integer): boolean; virtual; stdcall; abstract;
function GetEventBufferDepth: integer; virtual; stdcall; abstract;
function ExternalEvent(wszSource, wszMessage, wszData: PWideChar): boolean; virtual; stdcall; abstract;
procedure CleanEventBuffer; virtual; stdcall; abstract;
function SetStatusLine(wszStatusLine: PWideChar): boolean; virtual; stdcall; abstract;
procedure ResetStatusLine; virtual; stdcall; abstract;
end;
type
TV8ParamArray = array[1..255] of V8Variant;
PV8ParamArray = ^TV8ParamArray;
TV8CallAsProc = function(Params: PV8ParamArray;
const ParamCount: integer): boolean;
TV8CallAsFunc = function(RetValue: PV8Variant; Params: PV8ParamArray;
const ParamCount: integer): boolean;
TV8PropertyGetSet = function(propValue: PV8Variant; Get: boolean): boolean;
PV8CallAsProc = ^TV8CallAsProc;
PV8CallAsFunc = ^TV8CallAsFunc;
PV8PropertyGetSet = ^TV8PropertyGetSet;
type
TDefParamValue = record
Num: integer;
Value: V8Variant;
end;
TDefParamValueArray = array of TDefParamValue;
PDefParamValueArray = TDefParamValueArray;
TDefParamList = class
ValueCount: integer;
Values: TDefParamValueArray;
TempParam: PV8Variant;
function AddParam(Num: integer): PV8Variant;
procedure AddInt(V: integer; ParamNum: integer);
procedure AddDouble(V: double; ParamNum: integer);
procedure AddBool(V: boolean; ParamNum: integer);
procedure AddWString(const V: PWideChar; ParamNum: integer);
procedure AddAString(const V: PAnsiChar; ParamNum: integer);
procedure AddDate(V: TDateTime; ParamNum: integer);
destructor Destroy; override;
end;
TMethReg = class
MethName: WideString;
MethNameLoc: WideString;
IsFunction: boolean;
ParamCount: integer;
DefParams: TDefParamList;
Execute: pointer;
constructor Create;
destructor Destroy; override;
end;
TPropReg = class
PropName: WideString;
PropNameLoc: WideString;
IsReadable: boolean;
IsWritable: boolean;
PropGetSet: pointer;
end;
TPropRegArray = array of TPropReg;
PPropRegArray = ^TPropRegArray;
TMethRegArray = array of TMethReg;
PMethRegArray = ^TMethRegArray;
TClassReg = class
UserClass: TClass;
RegisterExtensionAs: WideString;
NatApiClassName: WideString;
PropCount: integer;
MethCount: integer;
PropList: TPropRegArray;
MethList: TMethRegArray;
function AddMethod(MethName, MethNameLoc: WideString; IsFunction: boolean;
ExecuteProc: pointer; ParamCount: integer = 0): TMethReg;
function AddProc(MethName, MethNameLoc: WideString;
ExecuteProc: PV8CallAsProc; ParamCount: integer = 0): TMethReg;
function AddFunc(MethName, MethNameLoc: WideString;
ExecuteProc: PV8CallAsFunc; ParamCount: integer = 0): TMethReg;
procedure AddProp(PropName, PropNameLoc: WideString; IsReadable: boolean;
IsWritable: boolean; PropGetSet: PV8PropertyGetSet);
destructor Destroy; override;
end;
TClassRegArray = array of TClassReg;
PClassRegArray = ^TClassRegArray;
TClassRegList = class
ClassCount: integer;
ClassList: TClassRegArray;
function RegisterClass(UserClass: TClass;
RegisterExtensionAs, NatApiClassName: WideString): TClassReg;
destructor Destroy; override;
end;
TV8UserObject = class
public
ClassReg: TClassReg;
V8MM: TV8MemoryManager;
V8: TV8AddInDefBase;
locale: WideString;
//Î÷èùàåò ïåðåìåííóþ V8Variant
//Åñëè ïåðåìåííàÿ V8Variant èìåëà äëèííîå çíà÷åíèå (ñòðîêà èëè blob), òî
//ïàìÿòü, çàíÿòàÿ ýòîé ïåðåìåííîé îñâîáîæäàåòñÿ ìåíåäæåðîì ïàìÿòè 1Ñ
procedure V8ClearVar(V: PV8Variant);
//Ôóíêöèè óñòàíàâëèâàþò çíà÷åíèÿ êîðîòêèõ òèïîâ ïåðåìåííîé V8Variant.
//Ïåðåä óñòàíîâêîé çíà÷åíèÿ ïåðåìåííàÿ V8Variant î÷èùàåòñÿ.
//Åñëè ïåðåìåííàÿ V8Variant èìåëà äëèííîå çíà÷åíèå (ñòðîêà èëè blob), òî
//ïàìÿòü, çàíÿòàÿ ýòîé ïåðåìåííîé îñâîáîæäàåòñÿ ìåíåäæåðîì ïàìÿòè 1Ñ.
procedure V8SetBool(V: PV8Variant; Value: boolean);
procedure V8SetDate(V: PV8Variant; Value: TDateTime);
procedure V8SetInt(V: PV8Variant; Value: integer);
procedure V8SetDouble(V: PV8Variant; Value: double);
//Ôóíêöèè ñòàíàâëèâàþò çíà÷åíèå ïåðåìåííîé V8Variant ñòðîêîâîãî òèïà èëè blob
//Ïåðåä óñòàíîâêîé çíà÷åíèÿ ïåðåìåííàÿ V8Variant î÷èùàåòñÿ.
//Åñëè ïåðåìåííàÿ V8Variant èìåëà äëèííîå çíà÷åíèå (ñòðîêà èëè blob), òî
//ïàìÿòü, çàíÿòàÿ ýòîé ïåðåìåííîé, îñâîáîæäàåòñÿ ìåíåäæåðîì ïàìÿòè 1Ñ.
//Ïàìÿòü ïîä çíà÷åíèå ïåðåìåííîé âûäåëÿåòñÿ ìåíåäæåðîì ïàìÿòè 1Ñ.
function V8SetWString(V: PV8Variant; Value: WideString): boolean;
function V8SetString(V: PV8Variant; Value: AnsiString): boolean;
function V8SetPChar(V: PV8Variant; Value: PAnsiChar): boolean;
function V8SetBlob(V: PV8Variant; Value: PByte; Length: integer): boolean;
function Init: boolean; virtual; // ìîæíî override âûçûâàåòñÿ èç v8wrap
function GetInfo: integer; virtual; // ìîæíî override âûçûâàåòñÿ èç v8wrap
procedure SetLocale; virtual; // ìîæíî override âûçûâàåòñÿ èç v8wrap
procedure Done; virtual; // ìîæíî override âûçûâàåòñÿ èç v8wrap
function SetMemManager: boolean; virtual; //ìîæíî override âûçûâàåòñÿ èç v8wrap
constructor Create; virtual; // ìîæíî override
destructor Destroy; override; // ìîæíî override
end;
TV8UserClass = class of TV8UserObject;
function GetClassObject(const name: PWideChar; var pIntf: pointer): integer; cdecl;
function GetClassNames: PWideChar; cdecl;
function DestroyObject(var pIntf: pointer): integer; cdecl;
function _WideSameStr(const S1, S2: WideString): boolean;
function AsInteger(V: PV8Variant): integer;
function AsDouble(V: PV8Variant): double;
//Ôóíêöèè ãðóïïû V8is ïðîâåðÿþò ïåðåìåííóþ òèïà V8Variant
//íà ñîîòâåòñòâèå îïðåäåëåííîìó òèïó
function V8isEmpty(V: PV8Variant): boolean; //Ïåðåìåííàÿ ïóñòà
function V8isNULL(V: PV8Variant): boolean; //Ïåðåìåííàÿ NULL
function V8isNumber(V: PV8Variant): boolean; //öåëîå èëè âåùåñòâåííîå ÷èñëî, êîä îøèáêè
function V8isString(V: PV8Variant): boolean;
function V8isWString(V: PV8Variant): boolean; //WideString
function V8isAString(V: PV8Variant): boolean; //AnsiString
function V8isBlob(V: PV8Variant): boolean;
function V8isDate(V: PV8Variant): boolean; //ÄàòàÂðåìÿ (VTYPE_DATE èëè VTYPE_TM)
function V8isBool(V: PV8Variant): boolean;
//Âîçâðàùàåò çíà÷åíèå èç V8Variant,
//åñëè çíà÷åíèå íå ñîîòâåòñòâóåò òèïó, âîçâðàùàåò íîëü
function V8AsInt(V: PV8Variant): integer; //òèï Double âîçâðàùàåòñÿ êàê öåëàÿ ÷àñòü
function V8AsDouble(V: PV8Variant): double; //òèï integer âîçâðàùàåòñÿ êàê Double
//Âîçâðàùàåò çíà÷åíèå òèïà ÄàòàÂðåìÿ èç V8Variant òèïà
// äàòà (VTYPE_DATE,VTYPE_TM) èëè Double
//åñëè çíà÷åíèå íå ñîîòâåòñòâóåò òèïó, âîçâðàùàåò íîëü
function V8AsDate(V: PV8Variant): TDateTime;
//Âîçâðàùàåò çíà÷åíèå òèïà boolean èç V8Variant,
//åñëè çíà÷åíèå íå ñîîòâåòñòâóåò òèïó, âîçâðàùàåò False
function V8AsBool(V: PV8Variant): boolean;
//Âîçâðàùàåò óêàçàòåëè íà çíà÷åíèÿ òèïîâ Blob, AnsiChar, WideChar èç V8Variant,
//åñëè çíà÷åíèå íå ñîîòâåòñòâóåò òèïó, âîçâðàùàåò nil
function V8AsPWideChar(V: PV8Variant): PWideChar;
function V8AsWString(V: PV8Variant): WideString;
function V8AsPChar(V: PV8Variant): PAnsiChar;
function V8AsBlob(V: PV8Variant): PByte;
//Âîçâðàùàåò çíà÷åíèÿ òèïîâ AnsiString è WideString èç V8Variant
//â âèäå ñòðîêè AnsiString
function V8AsAString(V: PV8Variant): AnsiString;
//Äëèíà ïåðåìåííîé äëÿ òèïîâ Blob, AnsiString, WideString
function V8StrLen(V: PV8Variant): integer;
//Âîçâðàùàåò, â âèäå ñòðîêè, òèï çíà÷åíèÿ ïåðåìåííîé V8Variant
function V8VarTypeStr(V: PV8Variant): AnsiString;
var
ClassRegList: TClassRegList;
ClassNamesString: WideString;
implementation
type
PV8ObjectRec = ^TV8ObjectRec;
TV8ObjectRec = packed record
I1: pointer;
I2: pointer;
I3: pointer;
I4: pointer;
RelObj1: TV8UserObject;
RelObj2: TV8UserObject;
RelObj3: TV8UserObject;
end;
type
_V8CP = function(Obj: TObject; paParams: PV8ParamArray;
const lSizeArray: integer; var v8: TV8AddInDefBase): boolean;
_V8CF = function(Obj: TObject; pvarRetValue: PV8Variant;
paParams: PV8ParamArray; const lSizeArray: integer; var v8: TV8AddInDefBase): boolean;
_V8PGS = function(Obj: TObject; propValue: PV8Variant; Get: boolean; var v8: TV8AddInDefBase): boolean;
type
TV8ProcRec = packed record
Destroy1: integer;
Init: pointer;
setMemManager: pointer;
GetInfo: pointer;
Done: pointer;
Destroy2: integer;
RegisterExtensionAs: pointer;
GetNProps: pointer;
FindProp: pointer;
GetPropName: pointer;
GetPropVal: pointer;
SetPropVal: pointer;
IsPropReadable: pointer;
IsPropWritable: pointer;
GetNMethods: pointer;
FindMethod: pointer;
GetMethodName: pointer;
GetNParams: pointer;
GetParamDefValue: pointer;
HasRetVal: pointer;
CallAsProc: pointer;
CallAsFunc: pointer;
Destroy3: integer;
SetLocale: pointer;
end;
var
_ProcRec: TV8ProcRec;
function _StrLen(const V: PAnsiChar): integer;
asm
MOV EDX,EDI
MOV EDI,EAX
MOV ECX,0FFFFFFFFH
XOR AL,AL
REPNE SCASB
MOV EAX,0FFFFFFFEH
SUB EAX,ECX
MOV EDI,EDX
end;
function _V8String(V8MM: TV8MemoryManager; W: WideString): PWideChar;
var
L: integer;
begin
result := nil;
L := Length(W);
L := L + L + 2;
if V8MM <> nil then
if V8MM.AllocMemory(@result, L) then
begin
Move(W[1], result^, L);
end;
end;
function GetClassObject(const name: PWideChar; var pIntf: pointer): integer;
cdecl;
var
i: integer;
obj: TV8UserObject;
begin
result := 0;
obj := nil;
for i := 0 to ClassRegList.ClassCount - 1 do
begin
if ClassRegList.ClassList[i].NatApiClassName = name then
begin
try
obj := TV8UserClass(ClassRegList.ClassList[i].UserClass).Create;
except
Break;
end;
GetMem(pIntf, sizeof(TV8ObjectRec));
FillChar(pIntf^, sizeof(TV8ObjectRec), 0);
PV8ObjectRec(pIntf).I1 := @(_ProcRec.Destroy1);
PV8ObjectRec(pIntf).I2 := @(_ProcRec.Destroy2);
PV8ObjectRec(pIntf).I3 := @(_ProcRec.Destroy3);
PV8ObjectRec(pIntf).I4 := nil;
PV8ObjectRec(pIntf).RelObj1 := obj;
PV8ObjectRec(pIntf).RelObj2 := obj;
PV8ObjectRec(pIntf).RelObj3 := obj;
PV8ObjectRec(pIntf).RelObj1.ClassReg := ClassRegList.ClassList[i];
result := 1;
Break;
end;
end;
end;
function GetClassNames: PWideChar; cdecl;
begin
result := @ClassNamesString[1];
end;
function DestroyObject(var pIntf: pointer): integer; cdecl;
begin
if pIntf <> nil then
begin
try
PV8ObjectRec(pIntf).RelObj1.Free;
finally
FreeMem(pIntf, sizeof(TV8ObjectRec));
end;
end;
result := 0;
end;
function _CallAsFunc(Obj: PV8ObjectRec; const lMethodNum: integer;
pvarRetValue, paParams: PV8Variant; const lSizeArray: integer): boolean;
stdcall;
var err: WideString;
begin
try
result := _V8CF(Obj.RelObj1.ClassReg.MethList[lMethodNum].Execute)
(Obj.RelObj1, pvarRetValue, PV8ParamArray(paParams), lSizeArray, Obj.RelObj1.v8);
except
on e: Exception do begin
err:=e.Message;
Obj.RelObj1.V8.addError(1006, 'Âíåøíÿÿ êîìïîíåíòà', pWideChar(err), E_FAIL);
result := false;
end;
end;
end;
function _CallAsProc(Obj: PV8ObjectRec; const lMethodNum: integer;
paParams: PV8Variant; const lSizeArray: integer): boolean; stdcall;
var err: WideString;
begin
try
result := _V8CP(Obj.RelObj1.ClassReg.MethList[lMethodNum].Execute)
(Obj.RelObj1, PV8ParamArray(paParams), lSizeArray, Obj.RelObj1.v8);
except
on e: Exception do begin
err:=e.Message;
Obj.RelObj1.V8.addError(1006, 'Âíåøíÿÿ êîìïîíåíòà', pWideChar(err), E_FAIL);
result := false;
end;
end;
end;
procedure _Done(Obj: PV8ObjectRec); stdcall;
begin
Obj.RelObj1.Done;
end;
function _FindMethod(Obj: PV8ObjectRec; const wsMethodName: PWideChar)
: integer; stdcall;
var
i: integer;
begin
result := -1;
for i := 0 to Obj.RelObj1.ClassReg.MethCount - 1 do
if (_WideSameStr(Obj.RelObj1.ClassReg.MethList[i].MethNameLoc,
wsMethodName)) or
(_WideSameStr(Obj.RelObj1.ClassReg.MethList[i].MethName, wsMethodName))
then
begin
result := i;
Break;
end;
end;
function _FindProp(Obj: PV8ObjectRec; const wsPropName: PWideChar): integer;
stdcall;
var
i: integer;
begin
result := -1;
for i := 0 to Obj.RelObj1.ClassReg.PropCount - 1 do
if (_WideSameStr(Obj.RelObj1.ClassReg.PropList[i].PropNameLoc, wsPropName))
or (_WideSameStr(Obj.RelObj1.ClassReg.PropList[i].PropName, wsPropName))
then
begin
result := i;
Break;
end;
end;
function _GetInfo(Obj: PV8ObjectRec): integer; stdcall;
begin
result := Obj.RelObj1.GetInfo;
end;
function _GetMethodName(Obj: PV8ObjectRec; const lMethodNum,
lMethodAlias: integer): PWideChar; stdcall;
begin
if lMethodAlias = 0 then
begin
result := _V8String(Obj.RelObj1.V8MM,
Obj.RelObj1.ClassReg.MethList[lMethodNum].MethName);
end
else
begin
result := _V8String(Obj.RelObj1.V8MM,
Obj.RelObj1.ClassReg.MethList[lMethodNum].MethNameLoc);
end;
end;
function _GetNMethods(Obj: PV8ObjectRec): integer; stdcall;
begin
result := Obj.RelObj1.ClassReg.MethCount;
end;
function _GetNParams(Obj: PV8ObjectRec; const lMethodNum: integer): integer;
stdcall;
begin
result := Obj.RelObj1.ClassReg.MethList[lMethodNum].ParamCount;
end;
function _GetNProps(Obj: PV8ObjectRec): integer; stdcall;
begin
result := Obj.RelObj1.ClassReg.PropCount;
end;
function _GetParamDefValue(Obj: PV8ObjectRec; const lMethodNum,
lParamNum: integer; pvarParamDefValue: PV8Variant): boolean; stdcall;
begin
result := False;
if Obj.RelObj1.ClassReg.MethList[lMethodNum].DefParams <> nil then
begin
pvarParamDefValue^ := Obj.RelObj1.ClassReg.MethList[lMethodNum]
.DefParams.Values[lParamNum].Value;
result := True;
end;
end;
function _GetPropName(Obj: PV8ObjectRec; lPropNum, lPropAlias: integer)
: PWideChar; stdcall;
begin
if lPropAlias = 0 then
result := _V8String(Obj.RelObj1.V8MM,
Obj.RelObj1.ClassReg.PropList[lPropNum].PropName)
else
result := _V8String(Obj.RelObj1.V8MM,
Obj.RelObj1.ClassReg.PropList[lPropNum].PropNameLoc);
end;
function _GetPropVal(Obj: PV8ObjectRec; const lPropNum: integer;
pvarPropVal: PV8Variant): boolean; stdcall;
var err: WideString;
begin
try
result := False;
if @(Obj.RelObj1.ClassReg.PropList[lPropNum].PropGetSet) <> nil then
result := _V8PGS(Obj.RelObj1.ClassReg.PropList[lPropNum].PropGetSet)
(Obj.RelObj1, pvarPropVal, True, Obj.RelObj1.v8);
except
on e: Exception do begin
err:=e.Message;
Obj.RelObj1.V8.addError(1006, 'Âíåøíÿÿ êîìïîíåíòà', pWideChar(err), E_FAIL);
result := false;
end;
end;
end;
function _HasRetVal(Obj: PV8ObjectRec; const lMethodNum: integer): boolean;
stdcall;
begin
result := Obj.RelObj1.ClassReg.MethList[lMethodNum].IsFunction;
end;
function _Init(Obj: PV8ObjectRec; disp: pointer): boolean; stdcall;
begin
Obj.RelObj1.V8 := disp;
result := Obj.RelObj1.Init;
end;
function _IsPropReadable(Obj: PV8ObjectRec; const lPropNum: integer): boolean;
stdcall;
begin
result := Obj.RelObj1.ClassReg.PropList[lPropNum].IsReadable;
end;
function _IsPropWritable(Obj: PV8ObjectRec; const lPropNum: integer): boolean;
stdcall;
begin
result := Obj.RelObj1.ClassReg.PropList[lPropNum].IsWritable;
end;
function _RegisterExtensionAs(Obj: PV8ObjectRec;
wsExtensionName: PPWideChar): boolean; stdcall;
begin
wsExtensionName^ := _V8String(Obj.RelObj1.V8MM,
Obj.RelObj1.ClassReg.RegisterExtensionAs);
result := True;
end;
procedure _SetLocale(Obj: PV8ObjectRec; const loc: PWideChar); stdcall;
begin
Obj.RelObj1.locale := loc;
Obj.RelObj1.SetLocale;
end;
function _setMemManager(Obj: PV8ObjectRec; mem: pointer): boolean; stdcall;
begin
Obj.RelObj1.V8MM := mem;
result := Obj.RelObj1.SetMemManager;
end;
function _SetPropVal(Obj: PV8ObjectRec; const lPropNum: integer;
pvarPropVal: PV8Variant): boolean; stdcall;
var err: WideString;
begin
try
result := False;
if @Obj.RelObj1.ClassReg.PropList[lPropNum].PropGetSet <> nil then
result := _V8PGS(Obj.RelObj1.ClassReg.PropList[lPropNum].PropGetSet)
(Obj.RelObj1, pvarPropVal, False, Obj.RelObj1.v8);
except
on e: Exception do begin
err:=e.Message;
Obj.RelObj1.V8.addError(1006, 'Âíåøíÿÿ êîìïîíåíòà', pWideChar(err), E_FAIL);
result := false;
end;
end;
end;
{ TDefParamList }
function TDefParamList.AddParam(Num: integer): PV8Variant;
var
L: integer;
begin
inc(ValueCount);
L := ValueCount - 1;
SetLength(Values, ValueCount);
Values[L].Num := Num - 1;
result := @(Values[L].Value);
end;
procedure TDefParamList.AddAString(const V: PAnsiChar; ParamNum: integer);
var
L: integer;
begin
L := _StrLen(V);
TempParam := AddParam(ParamNum);
TempParam.vt := VTYPE_PSTR;
TempParam.VarEnum.vtRecString.strLen := L;
TempParam.VarEnum.vtRecString.pstrVal := V;
end;
procedure TDefParamList.AddBool(V: boolean; ParamNum: integer);
begin
TempParam := AddParam(ParamNum);
TempParam.vt := VTYPE_BOOL;
TempParam.VarEnum.bVal := V;
end;
procedure TDefParamList.AddDate(V: TDateTime; ParamNum: integer);
begin
TempParam := AddParam(ParamNum);
TempParam.vt := VTYPE_DATE;
TempParam.VarEnum.date := V;
end;
procedure TDefParamList.AddDouble(V: double; ParamNum: integer);
begin
TempParam := AddParam(ParamNum);
TempParam.vt := VTYPE_R8;
TempParam.VarEnum.dblVal := V;
end;
procedure TDefParamList.AddInt(V, ParamNum: integer);
begin
TempParam := AddParam(ParamNum);
TempParam.vt := VTYPE_I4;
TempParam.VarEnum.intVal := V;
end;
procedure TDefParamList.AddWString(const V: PWideChar; ParamNum: integer);
var
L: integer;
begin
L := Length(V);
TempParam := AddParam(ParamNum);
TempParam.vt := VTYPE_PWSTR;
TempParam.VarEnum.vtRecWideString.wstrLen := L;
TempParam.VarEnum.vtRecWideString.pwstrVal := PWideChar(V);
end;
destructor TDefParamList.Destroy;
begin
SetLength(Values, 0);
inherited Destroy;
end;
{ TMethReg }
constructor TMethReg.Create;
begin
DefParams := TDefParamList.Create;
end;
destructor TMethReg.Destroy;
begin
DefParams.Free;
inherited Destroy;
end;
{ TClassReg }
function TClassReg.AddFunc(MethName, MethNameLoc: WideString;
ExecuteProc: PV8CallAsFunc; ParamCount: integer): TMethReg;
begin
result := AddMethod(MethName, MethNameLoc, True, ExecuteProc, ParamCount);
end;
function TClassReg.AddProc(MethName, MethNameLoc: WideString;
ExecuteProc: PV8CallAsProc; ParamCount: integer): TMethReg;
begin
result := AddMethod(MethName, MethNameLoc, False, pointer(ExecuteProc),
ParamCount);
end;
function TClassReg.AddMethod(MethName, MethNameLoc: WideString;
IsFunction: boolean; ExecuteProc: pointer;
ParamCount: integer = 0): TMethReg;
var
L: integer;
begin
inc(MethCount);
L := MethCount - 1;
SetLength(MethList, MethCount);
MethList[L] := TMethReg.Create;
MethList[L].MethName := MethName;
MethList[L].MethNameLoc := MethNameLoc;
MethList[L].IsFunction := IsFunction;
MethList[L].ParamCount := ParamCount;
MethList[L].Execute := ExecuteProc;
result := MethList[L];
end;
procedure TClassReg.AddProp(PropName, PropNameLoc: WideString;
IsReadable: boolean; IsWritable: boolean; PropGetSet: PV8PropertyGetSet);
var
L: integer;
begin
inc(PropCount);
L := PropCount - 1;
SetLength(PropList, PropCount);
PropList[L] := TPropReg.Create;
PropList[L].PropName := PropName;
PropList[L].PropNameLoc := PropNameLoc;
PropList[L].IsReadable := IsReadable;
PropList[L].IsWritable := IsWritable;
PropList[L].PropGetSet := pointer(PropGetSet);
end;
destructor TClassReg.Destroy;
var
i: integer;
begin
for i := 0 to PropCount - 1 do
begin
PropList[i].Free;
PropList[i] := nil;
end;
for i := 0 to MethCount - 1 do
begin
MethList[i].Free;
MethList[i] := nil;
end;
SetLength(PropList, 0);
SetLength(MethList, 0);
inherited Destroy;
end;
{ TClassRegList }
destructor TClassRegList.Destroy;
var
i: integer;
begin
for i := 0 to ClassCount - 1 do
begin
ClassList[i].Free;
ClassList[i] := nil;
end;
SetLength(ClassList, 0);
inherited Destroy;
end;
function TClassRegList.RegisterClass(UserClass: TClass;
RegisterExtensionAs, NatApiClassName: WideString): TClassReg;
var
L: integer;
begin
inc(ClassCount);
L := ClassCount - 1;
SetLength(ClassList, ClassCount);
ClassList[L] := TClassReg.Create;
ClassList[L].UserClass := UserClass;
ClassList[L].RegisterExtensionAs := RegisterExtensionAs;
ClassList[L].NatApiClassName := NatApiClassName;
result := ClassList[L];
if Length(ClassNamesString) > 0 then
ClassNamesString := ClassNamesString + '|';
ClassNamesString := ClassNamesString + NatApiClassName;
end;
{ TV8UserObject }
constructor TV8UserObject.Create;
begin
//
end;
destructor TV8UserObject.Destroy;
begin
inherited Destroy;
end;
procedure TV8UserObject.Done;
begin
//
end;
function TV8UserObject.GetInfo: integer;
begin
result := 2000;
end;
function TV8UserObject.Init: boolean;
begin
result := True;
end;
procedure TV8UserObject.SetLocale;
begin
end;
function TV8UserObject.SetMemManager: boolean;
begin
result := True;
end;
function TV8UserObject.V8SetString(V: PV8Variant; Value: AnsiString): boolean;
begin
result := V8SetPChar(V, PAnsiChar(Value));
end;
function TV8UserObject.V8SetWString(V: PV8Variant;
Value: WideString): boolean;
var
L, SZ: longword;
begin
result := (PWideChar(Value) = nil);
if result then
Exit;
V8ClearVar(V);
V.vt := VTYPE_PWSTR;
L := Length(Value);
SZ := L + L + 2;
result := V8MM.AllocMemory(@(V.VarEnum.vtRecWideString.pwstrVal), SZ);
if result then
begin
Move(Value[1], V.VarEnum.vtRecWideString.pwstrVal^, SZ);
V.VarEnum.vtRecWideString.wstrLen := L;
end;
end;
function TV8UserObject.V8SetPChar(V: PV8Variant; Value: PAnsiChar): boolean;
var
L: longword;
begin
result := (Value = nil);
if result then
Exit;
V8ClearVar(V);
V.vt := VTYPE_PSTR;
L := _StrLen(Value);
result := V8MM.AllocMemory(@(V.VarEnum.vtRecString.pstrVal), L + 1);
if result then
begin
Move(Value^, V.VarEnum.vtRecString.pstrVal^, L + 1);
V.VarEnum.vtRecString.strLen := L;
end;
end;
procedure TV8UserObject.V8ClearVar(V: PV8Variant);
begin
if (V.vt and VTYPE_TYPEMASK) in [VTYPE_BLOB, VTYPE_PSTR, VTYPE_PWSTR,
VTYPE_INTERFACE] then
begin
case (V.vt and VTYPE_TYPEMASK) of
VTYPE_BLOB:
if V.VarEnum.vtRecString.pstrVal <> nil then
V8MM.FreeMemory(@(V.VarEnum.vtRecString.pstrVal));
VTYPE_PSTR:
if V.VarEnum.vtRecString.pstrVal <> nil then
V8MM.FreeMemory(@(V.VarEnum.vtRecString.pstrVal));
VTYPE_PWSTR:
if V.VarEnum.vtRecWideString.pwstrVal <> nil then
V8MM.FreeMemory(@(V.VarEnum.vtRecWideString.pwstrVal));
VTYPE_INTERFACE:
IInterface(V.VarEnum.vtRecInterface.pInterfaceVal) := nil;
end;
end;
FillChar(V^, sizeof(V8Variant), 0);
end;
function TV8UserObject.V8SetBlob(V: PV8Variant; Value: PByte;
Length: integer): boolean;
begin
result := (Value = nil);