-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathJSContext.cpp
More file actions
142 lines (112 loc) · 2.82 KB
/
JSContext.cpp
File metadata and controls
142 lines (112 loc) · 2.82 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
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
#include "stdafx.h"
#include "JSCoreMarshal.h"
#include "JSValue.h"
#include "JSObject.h"
#include "JSContext.h"
JSContext::JSContext()
{
_context = JSGlobalContextCreate(NULL);
_contextCreated = true;
}
JSContext::JSContext(JSContextRef context)
: _context(context)
{
}
JSContext::JSContext(IntPtr context)
: _context((JSContextRef) context.ToPointer())
{
}
JSContext::JSContext(WebKit::Interop::IWebFrame ^ webFrame)
{
::IWebFrame * unmgdFrame = (::IWebFrame *) Marshal::GetComInterfaceForObject(webFrame,
WebKit::Interop::IWebFrame::typeid).ToPointer();
_context = unmgdFrame->globalContext();
}
JSContext::~JSContext()
{
if(_contextCreated)
{
JSGlobalContextRelease((JSGlobalContextRef)_context);
}
// TODO: clean up
}
JSValue ^ JSContext::EvaluateScript(String ^ script)
{
return EvaluateScript(script, nullptr, nullptr, 0);
}
JSValue ^ JSContext::EvaluateScript(String ^ script, Object ^ thisObject)
{
return EvaluateScript(script, thisObject, nullptr, 0);
}
JSValue ^ JSContext::EvaluateScript(String ^ script, Object ^ thisObject,
String ^ sourceUrl, int startingLineNumber)
{
// TODO: lets not worry about exceptions just yet...
JSStringRef jsScript = JSCoreMarshal::StringToJSString(script);
// TODO: marshal thisObject to JSObject
JSObjectRef jsObj = NULL;
// TODO: handle nulls and stuff
JSStringRef jsSrc = JSCoreMarshal::StringToJSString(sourceUrl);
JSValueRef exception = NULL;
JSValueRef result = JSEvaluateScript(_context, jsScript, jsObj, jsSrc, 0, &exception);
JSValue ^ retval = result != NULL ? gcnew JSValue(this, result) : nullptr;
// clean up
if (jsScript != NULL)
JSStringRelease(jsScript);
if (jsSrc != NULL)
JSStringRelease(jsSrc);
return retval;
}
bool JSContext::CheckScriptSyntax(String ^ script)
{
return false;
}
bool JSContext::CheckScriptSyntax(String ^ script, Object ^ thisObject)
{
return false;
}
bool JSContext::CheckScriptSyntax(String ^ script, Object ^ thisObject,
String ^ sourceUrl, int startingLineNumber)
{
return false;
}
void JSContext::GarbageCollect()
{
JSGarbageCollect(_context);
}
JSValue ^ JSContext::MakeUndefined()
{
return nullptr;
}
JSValue ^ JSContext::MakeNull()
{
return nullptr;
}
JSValue ^ JSContext::MakeBoolean(bool boolean)
{
return nullptr;
}
JSValue ^ JSContext::MakeNumber(double number)
{
return nullptr;
}
JSValue ^ JSContext::MakeString(String ^ string)
{
return nullptr;
}
JSValue ^ JSContext::MakeValueFromJSONString(String ^ jsonString)
{
return nullptr;
}
JSObject ^ JSContext::MakeObject(Object ^ object)
{
return nullptr;
}
JSContextRef JSContext::context()
{
return _context;
}
JSObject ^ JSContext::GetGlobalObject()
{
return gcnew JSObject(this, ::JSContextGetGlobalObject(_context));
}