-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqxsrunner.cpp
103 lines (75 loc) · 2.18 KB
/
qxsrunner.cpp
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
#include <QDebug>
#include "qxsrunner.h"
#include "xsall.h"
#include "xs.h"
#include "prebuild_js.xs.h"
#include "litehtml/include/litehtml.h"
extern "C" {
void fxRunModule(txMachine* the, const char* path)
{
mxPushStringC((txString)path);
fxRequireModule(the, XS_NO_ID, the->stack);
the->stack++;
}
int modTimersExecute(void);
void fxRunLoop(txMachine* /*the*/)
{
while( modTimersExecute() ) {
}
}
txPreparation* xsPreparation();
void xsDebugLog( txString message )
{
qDebug( ) << message;
}
}
QXsRunner::QXsRunner( litehtml::document* doc )
{
m_document = doc;
}
void QXsRunner::run()
{
fxInitializeSharedCluster();
txPreparation* preparation = xsPreparation();
txMachine root;
c_memset(&root, 0, sizeof(txMachine));
root.machine_data = m_document;
root.preparation = preparation;
root.archive = NULL;
root.keyArray = preparation->keys;
root.keyCount = (txID)preparation->keyCount + (txID)preparation->creation.keyCount;
root.keyIndex = (txID)preparation->keyCount;
root.nameModulo = preparation->nameModulo;
root.nameTable = preparation->names;
root.symbolModulo = preparation->symbolModulo;
root.symbolTable = preparation->symbols;
root.stack = &preparation->stack[0];
root.stackBottom = &preparation->stack[0];
root.stackTop = &preparation->stack[preparation->stackCount];
root.firstHeap = &preparation->heap[0];
root.freeHeap = &preparation->heap[preparation->heapCount - 1];
root.aliasCount = (txID)preparation->aliasCount;
xsMachine* machine = fxCloneMachine( &preparation->creation, &root, (char*)"xs", NULL );
xsBeginHost(machine);
{
xsTry {
//xsVars(1);
//xsVar(0) = xsNewHostObject( NULL );
//xsSetHostData(xsVar(0), m_document );
//xsVar(1) = xsNewHostFunction(dom_document_create_element, 0);
//xsDefine( xsVar(0), xsID_createElement, xsVar(1), xsDefault );
//xsSet(xsGlobal, fxID(the,"document"), xsVar(0));
//xsStartProfiling();
fxRunModule(the, "C:\\Qt\\Projects\\PhotonBoard3\\test.js");
//xsStopProfiling();
fxRunLoop(the);
}
xsCatch {
xsStringValue message = xsToString(xsException);
qDebug() << message;
}
}
xsEndHost(the);
xsDeleteMachine(machine);
fxTerminateSharedCluster();
}