xref: /aosp_15_r20/external/pdfium/fxjs/cjs_event.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2014 The PDFium Authors
2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file.
4*3ac0a46fSAndroid Build Coastguard Worker 
5*3ac0a46fSAndroid Build Coastguard Worker // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6*3ac0a46fSAndroid Build Coastguard Worker 
7*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/cjs_event.h"
8*3ac0a46fSAndroid Build Coastguard Worker 
9*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/cjs_event_context.h"
10*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/cjs_field.h"
11*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/cjs_object.h"
12*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/js_define.h"
13*3ac0a46fSAndroid Build Coastguard Worker 
14*3ac0a46fSAndroid Build Coastguard Worker const JSPropertySpec CJS_Event::PropertySpecs[] = {
15*3ac0a46fSAndroid Build Coastguard Worker     {"change", get_change_static, set_change_static},
16*3ac0a46fSAndroid Build Coastguard Worker     {"changeEx", get_change_ex_static, set_change_ex_static},
17*3ac0a46fSAndroid Build Coastguard Worker     {"commitKey", get_commit_key_static, set_commit_key_static},
18*3ac0a46fSAndroid Build Coastguard Worker     {"fieldFull", get_field_full_static, set_field_full_static},
19*3ac0a46fSAndroid Build Coastguard Worker     {"keyDown", get_key_down_static, set_key_down_static},
20*3ac0a46fSAndroid Build Coastguard Worker     {"modifier", get_modifier_static, set_modifier_static},
21*3ac0a46fSAndroid Build Coastguard Worker     {"name", get_name_static, set_name_static},
22*3ac0a46fSAndroid Build Coastguard Worker     {"rc", get_rc_static, set_rc_static},
23*3ac0a46fSAndroid Build Coastguard Worker     {"richChange", get_rich_change_static, set_rich_change_static},
24*3ac0a46fSAndroid Build Coastguard Worker     {"richChangeEx", get_rich_change_ex_static, set_rich_change_ex_static},
25*3ac0a46fSAndroid Build Coastguard Worker     {"richValue", get_rich_value_static, set_rich_value_static},
26*3ac0a46fSAndroid Build Coastguard Worker     {"selEnd", get_sel_end_static, set_sel_end_static},
27*3ac0a46fSAndroid Build Coastguard Worker     {"selStart", get_sel_start_static, set_sel_start_static},
28*3ac0a46fSAndroid Build Coastguard Worker     {"shift", get_shift_static, set_shift_static},
29*3ac0a46fSAndroid Build Coastguard Worker     {"source", get_source_static, set_source_static},
30*3ac0a46fSAndroid Build Coastguard Worker     {"target", get_target_static, set_target_static},
31*3ac0a46fSAndroid Build Coastguard Worker     {"targetName", get_target_name_static, set_target_name_static},
32*3ac0a46fSAndroid Build Coastguard Worker     {"type", get_type_static, set_type_static},
33*3ac0a46fSAndroid Build Coastguard Worker     {"value", get_value_static, set_value_static},
34*3ac0a46fSAndroid Build Coastguard Worker     {"willCommit", get_will_commit_static, set_will_commit_static}};
35*3ac0a46fSAndroid Build Coastguard Worker 
36*3ac0a46fSAndroid Build Coastguard Worker uint32_t CJS_Event::ObjDefnID = 0;
37*3ac0a46fSAndroid Build Coastguard Worker const char CJS_Event::kName[] = "event";
38*3ac0a46fSAndroid Build Coastguard Worker 
39*3ac0a46fSAndroid Build Coastguard Worker // static
GetObjDefnID()40*3ac0a46fSAndroid Build Coastguard Worker uint32_t CJS_Event::GetObjDefnID() {
41*3ac0a46fSAndroid Build Coastguard Worker   return ObjDefnID;
42*3ac0a46fSAndroid Build Coastguard Worker }
43*3ac0a46fSAndroid Build Coastguard Worker 
44*3ac0a46fSAndroid Build Coastguard Worker // static
DefineJSObjects(CFXJS_Engine * pEngine)45*3ac0a46fSAndroid Build Coastguard Worker void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) {
46*3ac0a46fSAndroid Build Coastguard Worker   ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC,
47*3ac0a46fSAndroid Build Coastguard Worker                                  JSConstructor<CJS_Event>, JSDestructor);
48*3ac0a46fSAndroid Build Coastguard Worker   DefineProps(pEngine, ObjDefnID, PropertySpecs);
49*3ac0a46fSAndroid Build Coastguard Worker }
50*3ac0a46fSAndroid Build Coastguard Worker 
CJS_Event(v8::Local<v8::Object> pObject,CJS_Runtime * pRuntime)51*3ac0a46fSAndroid Build Coastguard Worker CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
52*3ac0a46fSAndroid Build Coastguard Worker     : CJS_Object(pObject, pRuntime) {}
53*3ac0a46fSAndroid Build Coastguard Worker 
54*3ac0a46fSAndroid Build Coastguard Worker CJS_Event::~CJS_Event() = default;
55*3ac0a46fSAndroid Build Coastguard Worker 
get_change(CJS_Runtime * pRuntime)56*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_change(CJS_Runtime* pRuntime) {
57*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
58*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(
59*3ac0a46fSAndroid Build Coastguard Worker       pRuntime->NewString(pEvent->Change().AsStringView()));
60*3ac0a46fSAndroid Build Coastguard Worker }
61*3ac0a46fSAndroid Build Coastguard Worker 
set_change(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)62*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_change(CJS_Runtime* pRuntime,
63*3ac0a46fSAndroid Build Coastguard Worker                                  v8::Local<v8::Value> vp) {
64*3ac0a46fSAndroid Build Coastguard Worker   if (vp->IsString()) {
65*3ac0a46fSAndroid Build Coastguard Worker     CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
66*3ac0a46fSAndroid Build Coastguard Worker     pEvent->Change() = pRuntime->ToWideString(vp);
67*3ac0a46fSAndroid Build Coastguard Worker   }
68*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
69*3ac0a46fSAndroid Build Coastguard Worker }
70*3ac0a46fSAndroid Build Coastguard Worker 
get_change_ex(CJS_Runtime * pRuntime)71*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_change_ex(CJS_Runtime* pRuntime) {
72*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
73*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(
74*3ac0a46fSAndroid Build Coastguard Worker       pRuntime->NewString(pEvent->ChangeEx().AsStringView()));
75*3ac0a46fSAndroid Build Coastguard Worker }
76*3ac0a46fSAndroid Build Coastguard Worker 
set_change_ex(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)77*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_change_ex(CJS_Runtime* pRuntime,
78*3ac0a46fSAndroid Build Coastguard Worker                                     v8::Local<v8::Value> vp) {
79*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
80*3ac0a46fSAndroid Build Coastguard Worker }
81*3ac0a46fSAndroid Build Coastguard Worker 
get_commit_key(CJS_Runtime * pRuntime)82*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_commit_key(CJS_Runtime* pRuntime) {
83*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
84*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewNumber(pEvent->CommitKey()));
85*3ac0a46fSAndroid Build Coastguard Worker }
86*3ac0a46fSAndroid Build Coastguard Worker 
set_commit_key(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)87*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_commit_key(CJS_Runtime* pRuntime,
88*3ac0a46fSAndroid Build Coastguard Worker                                      v8::Local<v8::Value> vp) {
89*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
90*3ac0a46fSAndroid Build Coastguard Worker }
91*3ac0a46fSAndroid Build Coastguard Worker 
get_field_full(CJS_Runtime * pRuntime)92*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_field_full(CJS_Runtime* pRuntime) {
93*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
94*3ac0a46fSAndroid Build Coastguard Worker   if (pEvent->Name() != "Keystroke")
95*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(L"unrecognized event");
96*3ac0a46fSAndroid Build Coastguard Worker 
97*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewBoolean(pEvent->FieldFull()));
98*3ac0a46fSAndroid Build Coastguard Worker }
99*3ac0a46fSAndroid Build Coastguard Worker 
set_field_full(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)100*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_field_full(CJS_Runtime* pRuntime,
101*3ac0a46fSAndroid Build Coastguard Worker                                      v8::Local<v8::Value> vp) {
102*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
103*3ac0a46fSAndroid Build Coastguard Worker }
104*3ac0a46fSAndroid Build Coastguard Worker 
get_key_down(CJS_Runtime * pRuntime)105*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_key_down(CJS_Runtime* pRuntime) {
106*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
107*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewBoolean(pEvent->KeyDown()));
108*3ac0a46fSAndroid Build Coastguard Worker }
109*3ac0a46fSAndroid Build Coastguard Worker 
set_key_down(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)110*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_key_down(CJS_Runtime* pRuntime,
111*3ac0a46fSAndroid Build Coastguard Worker                                    v8::Local<v8::Value> vp) {
112*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
113*3ac0a46fSAndroid Build Coastguard Worker }
114*3ac0a46fSAndroid Build Coastguard Worker 
get_modifier(CJS_Runtime * pRuntime)115*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_modifier(CJS_Runtime* pRuntime) {
116*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
117*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Modifier()));
118*3ac0a46fSAndroid Build Coastguard Worker }
119*3ac0a46fSAndroid Build Coastguard Worker 
set_modifier(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)120*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_modifier(CJS_Runtime* pRuntime,
121*3ac0a46fSAndroid Build Coastguard Worker                                    v8::Local<v8::Value> vp) {
122*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
123*3ac0a46fSAndroid Build Coastguard Worker }
124*3ac0a46fSAndroid Build Coastguard Worker 
get_name(CJS_Runtime * pRuntime)125*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_name(CJS_Runtime* pRuntime) {
126*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
127*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewString(pEvent->Name()));
128*3ac0a46fSAndroid Build Coastguard Worker }
129*3ac0a46fSAndroid Build Coastguard Worker 
set_name(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)130*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
131*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
132*3ac0a46fSAndroid Build Coastguard Worker }
133*3ac0a46fSAndroid Build Coastguard Worker 
get_rc(CJS_Runtime * pRuntime)134*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_rc(CJS_Runtime* pRuntime) {
135*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
136*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Rc()));
137*3ac0a46fSAndroid Build Coastguard Worker }
138*3ac0a46fSAndroid Build Coastguard Worker 
set_rc(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)139*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
140*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
141*3ac0a46fSAndroid Build Coastguard Worker   pEvent->Rc() = pRuntime->ToBoolean(vp);
142*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
143*3ac0a46fSAndroid Build Coastguard Worker }
144*3ac0a46fSAndroid Build Coastguard Worker 
get_rich_change(CJS_Runtime * pRuntime)145*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_rich_change(CJS_Runtime* pRuntime) {
146*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
147*3ac0a46fSAndroid Build Coastguard Worker }
148*3ac0a46fSAndroid Build Coastguard Worker 
set_rich_change(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)149*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_rich_change(CJS_Runtime* pRuntime,
150*3ac0a46fSAndroid Build Coastguard Worker                                       v8::Local<v8::Value> vp) {
151*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
152*3ac0a46fSAndroid Build Coastguard Worker }
153*3ac0a46fSAndroid Build Coastguard Worker 
get_rich_change_ex(CJS_Runtime * pRuntime)154*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_rich_change_ex(CJS_Runtime* pRuntime) {
155*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
156*3ac0a46fSAndroid Build Coastguard Worker }
157*3ac0a46fSAndroid Build Coastguard Worker 
set_rich_change_ex(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)158*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_rich_change_ex(CJS_Runtime* pRuntime,
159*3ac0a46fSAndroid Build Coastguard Worker                                          v8::Local<v8::Value> vp) {
160*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
161*3ac0a46fSAndroid Build Coastguard Worker }
162*3ac0a46fSAndroid Build Coastguard Worker 
get_rich_value(CJS_Runtime * pRuntime)163*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_rich_value(CJS_Runtime* pRuntime) {
164*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
165*3ac0a46fSAndroid Build Coastguard Worker }
166*3ac0a46fSAndroid Build Coastguard Worker 
set_rich_value(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)167*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_rich_value(CJS_Runtime* pRuntime,
168*3ac0a46fSAndroid Build Coastguard Worker                                      v8::Local<v8::Value> vp) {
169*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
170*3ac0a46fSAndroid Build Coastguard Worker }
171*3ac0a46fSAndroid Build Coastguard Worker 
get_sel_end(CJS_Runtime * pRuntime)172*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_sel_end(CJS_Runtime* pRuntime) {
173*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
174*3ac0a46fSAndroid Build Coastguard Worker   if (pEvent->Name() != "Keystroke")
175*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Success();
176*3ac0a46fSAndroid Build Coastguard Worker 
177*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelEnd()));
178*3ac0a46fSAndroid Build Coastguard Worker }
179*3ac0a46fSAndroid Build Coastguard Worker 
set_sel_end(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)180*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_sel_end(CJS_Runtime* pRuntime,
181*3ac0a46fSAndroid Build Coastguard Worker                                   v8::Local<v8::Value> vp) {
182*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
183*3ac0a46fSAndroid Build Coastguard Worker   if (pEvent->Name() == "Keystroke")
184*3ac0a46fSAndroid Build Coastguard Worker     pEvent->SetSelEnd(pRuntime->ToInt32(vp));
185*3ac0a46fSAndroid Build Coastguard Worker 
186*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
187*3ac0a46fSAndroid Build Coastguard Worker }
188*3ac0a46fSAndroid Build Coastguard Worker 
get_sel_start(CJS_Runtime * pRuntime)189*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_sel_start(CJS_Runtime* pRuntime) {
190*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
191*3ac0a46fSAndroid Build Coastguard Worker   if (pEvent->Name() != "Keystroke")
192*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Success();
193*3ac0a46fSAndroid Build Coastguard Worker 
194*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelStart()));
195*3ac0a46fSAndroid Build Coastguard Worker }
196*3ac0a46fSAndroid Build Coastguard Worker 
set_sel_start(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)197*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_sel_start(CJS_Runtime* pRuntime,
198*3ac0a46fSAndroid Build Coastguard Worker                                     v8::Local<v8::Value> vp) {
199*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
200*3ac0a46fSAndroid Build Coastguard Worker   if (pEvent->Name() == "Keystroke")
201*3ac0a46fSAndroid Build Coastguard Worker     pEvent->SetSelStart(pRuntime->ToInt32(vp));
202*3ac0a46fSAndroid Build Coastguard Worker 
203*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
204*3ac0a46fSAndroid Build Coastguard Worker }
205*3ac0a46fSAndroid Build Coastguard Worker 
get_shift(CJS_Runtime * pRuntime)206*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_shift(CJS_Runtime* pRuntime) {
207*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
208*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Shift()));
209*3ac0a46fSAndroid Build Coastguard Worker }
210*3ac0a46fSAndroid Build Coastguard Worker 
set_shift(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)211*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_shift(CJS_Runtime* pRuntime,
212*3ac0a46fSAndroid Build Coastguard Worker                                 v8::Local<v8::Value> vp) {
213*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
214*3ac0a46fSAndroid Build Coastguard Worker }
215*3ac0a46fSAndroid Build Coastguard Worker 
get_source(CJS_Runtime * pRuntime)216*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_source(CJS_Runtime* pRuntime) {
217*3ac0a46fSAndroid Build Coastguard Worker   CJS_Field* pField = pRuntime->GetCurrentEventContext()->SourceField();
218*3ac0a46fSAndroid Build Coastguard Worker   if (!pField)
219*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(JSMessage::kBadObjectError);
220*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pField->ToV8Object());
221*3ac0a46fSAndroid Build Coastguard Worker }
222*3ac0a46fSAndroid Build Coastguard Worker 
set_source(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)223*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_source(CJS_Runtime* pRuntime,
224*3ac0a46fSAndroid Build Coastguard Worker                                  v8::Local<v8::Value> vp) {
225*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
226*3ac0a46fSAndroid Build Coastguard Worker }
227*3ac0a46fSAndroid Build Coastguard Worker 
get_target(CJS_Runtime * pRuntime)228*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_target(CJS_Runtime* pRuntime) {
229*3ac0a46fSAndroid Build Coastguard Worker   CJS_Field* pField = pRuntime->GetCurrentEventContext()->TargetField();
230*3ac0a46fSAndroid Build Coastguard Worker   if (!pField)
231*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(JSMessage::kBadObjectError);
232*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pField->ToV8Object());
233*3ac0a46fSAndroid Build Coastguard Worker }
234*3ac0a46fSAndroid Build Coastguard Worker 
set_target(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)235*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_target(CJS_Runtime* pRuntime,
236*3ac0a46fSAndroid Build Coastguard Worker                                  v8::Local<v8::Value> vp) {
237*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
238*3ac0a46fSAndroid Build Coastguard Worker }
239*3ac0a46fSAndroid Build Coastguard Worker 
get_target_name(CJS_Runtime * pRuntime)240*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_target_name(CJS_Runtime* pRuntime) {
241*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
242*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(
243*3ac0a46fSAndroid Build Coastguard Worker       pRuntime->NewString(pEvent->TargetName().AsStringView()));
244*3ac0a46fSAndroid Build Coastguard Worker }
245*3ac0a46fSAndroid Build Coastguard Worker 
set_target_name(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)246*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_target_name(CJS_Runtime* pRuntime,
247*3ac0a46fSAndroid Build Coastguard Worker                                       v8::Local<v8::Value> vp) {
248*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
249*3ac0a46fSAndroid Build Coastguard Worker }
250*3ac0a46fSAndroid Build Coastguard Worker 
get_type(CJS_Runtime * pRuntime)251*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_type(CJS_Runtime* pRuntime) {
252*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
253*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewString(pEvent->Type()));
254*3ac0a46fSAndroid Build Coastguard Worker }
255*3ac0a46fSAndroid Build Coastguard Worker 
set_type(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)256*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
257*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
258*3ac0a46fSAndroid Build Coastguard Worker }
259*3ac0a46fSAndroid Build Coastguard Worker 
get_value(CJS_Runtime * pRuntime)260*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_value(CJS_Runtime* pRuntime) {
261*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
262*3ac0a46fSAndroid Build Coastguard Worker   if (pEvent->Type() != "Field")
263*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(L"Bad event type.");
264*3ac0a46fSAndroid Build Coastguard Worker 
265*3ac0a46fSAndroid Build Coastguard Worker   if (!pEvent->HasValue())
266*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(JSMessage::kBadObjectError);
267*3ac0a46fSAndroid Build Coastguard Worker 
268*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(
269*3ac0a46fSAndroid Build Coastguard Worker       pRuntime->NewString(pEvent->Value().AsStringView()));
270*3ac0a46fSAndroid Build Coastguard Worker }
271*3ac0a46fSAndroid Build Coastguard Worker 
set_value(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)272*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_value(CJS_Runtime* pRuntime,
273*3ac0a46fSAndroid Build Coastguard Worker                                 v8::Local<v8::Value> vp) {
274*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
275*3ac0a46fSAndroid Build Coastguard Worker   if (pEvent->Type() != "Field")
276*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(L"Bad event type.");
277*3ac0a46fSAndroid Build Coastguard Worker 
278*3ac0a46fSAndroid Build Coastguard Worker   if (!pEvent->HasValue())
279*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(JSMessage::kBadObjectError);
280*3ac0a46fSAndroid Build Coastguard Worker 
281*3ac0a46fSAndroid Build Coastguard Worker   if (vp.IsEmpty())
282*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(JSMessage::kBadObjectError);
283*3ac0a46fSAndroid Build Coastguard Worker 
284*3ac0a46fSAndroid Build Coastguard Worker   if (vp->IsNullOrUndefined() || vp->IsBoolean())
285*3ac0a46fSAndroid Build Coastguard Worker     return CJS_Result::Failure(JSMessage::kInvalidSetError);
286*3ac0a46fSAndroid Build Coastguard Worker 
287*3ac0a46fSAndroid Build Coastguard Worker   pEvent->Value() = pRuntime->ToWideString(vp);
288*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success();
289*3ac0a46fSAndroid Build Coastguard Worker }
290*3ac0a46fSAndroid Build Coastguard Worker 
get_will_commit(CJS_Runtime * pRuntime)291*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::get_will_commit(CJS_Runtime* pRuntime) {
292*3ac0a46fSAndroid Build Coastguard Worker   CJS_EventContext* pEvent = pRuntime->GetCurrentEventContext();
293*3ac0a46fSAndroid Build Coastguard Worker 
294*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Success(pRuntime->NewBoolean(pEvent->WillCommit()));
295*3ac0a46fSAndroid Build Coastguard Worker }
296*3ac0a46fSAndroid Build Coastguard Worker 
set_will_commit(CJS_Runtime * pRuntime,v8::Local<v8::Value> vp)297*3ac0a46fSAndroid Build Coastguard Worker CJS_Result CJS_Event::set_will_commit(CJS_Runtime* pRuntime,
298*3ac0a46fSAndroid Build Coastguard Worker                                       v8::Local<v8::Value> vp) {
299*3ac0a46fSAndroid Build Coastguard Worker   return CJS_Result::Failure(JSMessage::kNotSupportedError);
300*3ac0a46fSAndroid Build Coastguard Worker }
301