-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHtmlScript.cpp
More file actions
116 lines (106 loc) · 2.81 KB
/
Copy pathHtmlScript.cpp
File metadata and controls
116 lines (106 loc) · 2.81 KB
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
#include "stdafx.h"
#include "HtmlScript.h"
IMPLEMENT_CUSTOM_CLASS(HtmlScript, HtmlEventTarget)
HtmlScript::HtmlScript()
{
}
HtmlScript::~HtmlScript()
{
}
bool HtmlScript::InitClass(const HandleContext&context)
{
if (HtmlEventTarget::GetPrototype_s().IsNull())
{
HtmlEventTarget::InitClass(context);
}
return InitClass_s(context, "HtmlScriptElement", HtmlEventTarget::GetPrototype_s());
}
bool HtmlScript::OnConstructor(IFunctionCallbackArgs&args)
{
bool re = HtmlEventTarget::OnConstructor(args);
CustomClassAutoThisObj cc(this, args, true);
SetTagName(args.getContext(), "script");
return re;
}
bool HtmlScript::OnGetProperty(GetPropertyArgs&args)
{
const char*name = args.GetName();
if (!PROPCMP(name, "src"))
{
args.SetRetValue(LocalValue(args.GetContext()).SetString(args.GetContext(), m_src.c_str()));
return true;
}
return HtmlEventTarget::OnGetProperty(args);
}
bool HtmlScript::OnSetProperty(SetPropertyArgs&args)
{
CustomClassAutoThisObj cc(this, args);
const char*name = args.GetName();
if (!PROPCMP(name, "src"))
{
m_src = args.GetValue().GetString(args.GetContext());
m_src = JSVM::GetInstance()->GetFullPath(m_src);
std::string &&szAsync = args.GetThisObject().GetProperty(args.GetContext(), "async").GetString(args.GetContext());
LoadScript(args.GetContext(), m_src, true, false);
return true;
}
else if (!PROPCMP(name, "innerText"))
{
std::string &&text = args.GetValue().GetString(args.GetContext());
LoadScript(args.GetContext(), text, true, true);
}
return HtmlEventTarget::OnSetProperty(args);
}
bool HtmlScript::LoadScript(const HandleContext&context, const std::string& name, bool bAsync,bool bIsText)
{
m_src = name;
// if (name == "./frameworks/cocos2d-html5/cocos2d/labels/CCLabelBMFont.js")
// {
// int ddd = 3;
// }
if (!bAsync)
{
if (!bIsText)
{
JSVM::GetInstance()->runScript(name.c_str());
}
else
{
JSVM::GetInstance()->RunScriptText(name.c_str(), name.c_str());
}
ExecEventListener(context, "load");
}
else
{
if (!bIsText)
{
JSVM::GetInstance()->runScriptAsync(name.c_str(), GetJsObject());
}
else
{
JSVM::GetInstance()->RunScriptTextAsync(name.c_str(), name.c_str(), GetJsObject());
}
}
return true;
// HttpRequestInterface*pHttp = JSVM::GetInstance()->GetHttpRequestInterface();
// int8_t *pData = nullptr;
// int nLen = 0;
// int nRet = pHttp->SendGetRequest(name.c_str(), nullptr, pData, nLen);
// if (nRet != 200)return false;
// if (!bAsync)
// {
// JSVM::GetInstance()->RunScriptText((char*)pData, name.c_str());
// }
// else
// {
// JSVM::GetInstance()->RunScriptTextAsync((char*)pData, name.c_str());
// }
return true;
}
void HtmlScript::OnFinalize(FinalizeArgs&args)
{
// OutputDebugStringA("OnFinalize:");
// OutputDebugStringA(m_src.c_str());
// OutputDebugStringA("\n");
HtmlEventTarget::OnFinalize(args);
}