blob: a16ee6c53baa59f3b8e7cb20033fce40dc868d23 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclaire0345a42017-10-30 20:20:42 +00007#include "fxjs/cjs_event.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Dan Sinclaire0345a42017-10-30 20:20:42 +00009#include "fxjs/cjs_event_context.h"
Tom Sepez7dbb85b2019-06-11 19:49:00 +000010#include "fxjs/cjs_eventrecorder.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000011#include "fxjs/cjs_field.h"
12#include "fxjs/cjs_object.h"
Tom Sepez221f0b32018-06-04 22:11:27 +000013#include "fxjs/js_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
Dan Sinclairc94a7932017-10-26 16:48:57 -040015const JSPropertySpec CJS_Event::PropertySpecs[] = {
Tom Sepez4d5b8c52017-02-21 15:17:07 -080016 {"change", get_change_static, set_change_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040017 {"changeEx", get_change_ex_static, set_change_ex_static},
18 {"commitKey", get_commit_key_static, set_commit_key_static},
19 {"fieldFull", get_field_full_static, set_field_full_static},
20 {"keyDown", get_key_down_static, set_key_down_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080021 {"modifier", get_modifier_static, set_modifier_static},
22 {"name", get_name_static, set_name_static},
23 {"rc", get_rc_static, set_rc_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040024 {"richChange", get_rich_change_static, set_rich_change_static},
25 {"richChangeEx", get_rich_change_ex_static, set_rich_change_ex_static},
26 {"richValue", get_rich_value_static, set_rich_value_static},
27 {"selEnd", get_sel_end_static, set_sel_end_static},
28 {"selStart", get_sel_start_static, set_sel_start_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080029 {"shift", get_shift_static, set_shift_static},
30 {"source", get_source_static, set_source_static},
31 {"target", get_target_static, set_target_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040032 {"targetName", get_target_name_static, set_target_name_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080033 {"type", get_type_static, set_type_static},
34 {"value", get_value_static, set_value_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +000035 {"willCommit", get_will_commit_static, set_will_commit_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
Dan Sinclairef299532017-10-26 16:48:30 -040037int CJS_Event::ObjDefnID = -1;
Dan Sinclairf7435522018-02-05 22:27:22 +000038const char CJS_Event::kName[] = "event";
Dan Sinclair89d26c82017-10-26 12:21:28 -040039
Dan Sinclairef299532017-10-26 16:48:30 -040040// static
Lei Zhangad1f7b42018-07-11 13:04:43 +000041int CJS_Event::GetObjDefnID() {
42 return ObjDefnID;
43}
44
45// static
Dan Sinclairbef4d3e2017-10-26 16:49:38 -040046void CJS_Event::DefineJSObjects(CFXJS_Engine* pEngine) {
Dan Sinclairf7435522018-02-05 22:27:22 +000047 ObjDefnID = pEngine->DefineObj(CJS_Event::kName, FXJSOBJTYPE_STATIC,
Dan Sinclair998fee32018-02-05 21:43:19 +000048 JSConstructor<CJS_Event>, JSDestructor);
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000049 DefineProps(pEngine, ObjDefnID, PropertySpecs);
Dan Sinclair89d26c82017-10-26 12:21:28 -040050}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Tom Sepez36aae4f2018-06-04 19:44:37 +000052CJS_Event::CJS_Event(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
53 : CJS_Object(pObject, pRuntime) {}
Dan Sinclair998fee32018-02-05 21:43:19 +000054
Dan Sinclairf7435522018-02-05 22:27:22 +000055CJS_Event::~CJS_Event() = default;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056
Tom Sepez3a6d0582018-08-17 19:28:52 +000057CJS_Result CJS_Event::get_change(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +000058 CJS_EventRecorder* pEvent =
59 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +000060 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +000061 pRuntime->NewString(pEvent->Change().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -040062}
63
Tom Sepez3a6d0582018-08-17 19:28:52 +000064CJS_Result CJS_Event::set_change(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +000065 v8::Local<v8::Value> vp) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +000066 CJS_EventRecorder* pEvent =
67 pRuntime->GetCurrentEventContext()->GetEventRecorder();
dan sinclaircbe23db2017-10-19 14:29:33 -040068
dan sinclair80435cb2017-10-24 21:40:24 -040069 if (vp->IsString()) {
dan sinclaircbe23db2017-10-19 14:29:33 -040070 WideString& wChange = pEvent->Change();
dan sinclair80435cb2017-10-24 21:40:24 -040071 wChange = pRuntime->ToWideString(vp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 }
Tom Sepez3a6d0582018-08-17 19:28:52 +000073 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074}
75
Tom Sepez3a6d0582018-08-17 19:28:52 +000076CJS_Result CJS_Event::get_change_ex(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +000077 CJS_EventRecorder* pEvent =
78 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +000079 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +000080 pRuntime->NewString(pEvent->ChangeEx().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -040081}
82
Tom Sepez3a6d0582018-08-17 19:28:52 +000083CJS_Result CJS_Event::set_change_ex(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +000084 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +000085 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -040086}
87
Tom Sepez3a6d0582018-08-17 19:28:52 +000088CJS_Result CJS_Event::get_commit_key(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +000089 CJS_EventRecorder* pEvent =
90 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +000091 return CJS_Result::Success(pRuntime->NewNumber(pEvent->CommitKey()));
dan sinclaircbe23db2017-10-19 14:29:33 -040092}
93
Tom Sepez3a6d0582018-08-17 19:28:52 +000094CJS_Result CJS_Event::set_commit_key(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +000095 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +000096 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -040097}
98
Tom Sepez3a6d0582018-08-17 19:28:52 +000099CJS_Result CJS_Event::get_field_full(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000100 CJS_EventRecorder* pEvent =
101 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepezceac05a2018-11-30 23:26:58 +0000102 if (pEvent->Name() != "Keystroke")
Tom Sepez3a6d0582018-08-17 19:28:52 +0000103 return CJS_Result::Failure(L"unrecognized event");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104
Tom Sepez3a6d0582018-08-17 19:28:52 +0000105 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->FieldFull()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400106}
107
Tom Sepez3a6d0582018-08-17 19:28:52 +0000108CJS_Result CJS_Event::set_field_full(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000109 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000110 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400111}
112
Tom Sepez3a6d0582018-08-17 19:28:52 +0000113CJS_Result CJS_Event::get_key_down(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000114 CJS_EventRecorder* pEvent =
115 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000116 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->KeyDown()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117}
118
Tom Sepez3a6d0582018-08-17 19:28:52 +0000119CJS_Result CJS_Event::set_key_down(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000120 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000121 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400122}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
Tom Sepez3a6d0582018-08-17 19:28:52 +0000124CJS_Result CJS_Event::get_modifier(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000125 CJS_EventRecorder* pEvent =
126 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000127 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Modifier()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128}
129
Tom Sepez3a6d0582018-08-17 19:28:52 +0000130CJS_Result CJS_Event::set_modifier(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000131 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000132 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400133}
134
Tom Sepez3a6d0582018-08-17 19:28:52 +0000135CJS_Result CJS_Event::get_name(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000136 CJS_EventRecorder* pEvent =
137 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000138 return CJS_Result::Success(pRuntime->NewString(pEvent->Name()));
tsepez4cf55152016-11-02 14:37:54 -0700139}
140
Tom Sepez3a6d0582018-08-17 19:28:52 +0000141CJS_Result CJS_Event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
142 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400143}
tsepez4cf55152016-11-02 14:37:54 -0700144
Tom Sepez3a6d0582018-08-17 19:28:52 +0000145CJS_Result CJS_Event::get_rc(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000146 CJS_EventRecorder* pEvent =
147 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000148 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Rc()));
tsepez4cf55152016-11-02 14:37:54 -0700149}
150
Tom Sepez3a6d0582018-08-17 19:28:52 +0000151CJS_Result CJS_Event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000152 CJS_EventRecorder* pEvent =
153 pRuntime->GetCurrentEventContext()->GetEventRecorder();
dan sinclair80435cb2017-10-24 21:40:24 -0400154 pEvent->Rc() = pRuntime->ToBoolean(vp);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000155 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700156}
157
Tom Sepez3a6d0582018-08-17 19:28:52 +0000158CJS_Result CJS_Event::get_rich_change(CJS_Runtime* pRuntime) {
159 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700160}
161
Tom Sepez3a6d0582018-08-17 19:28:52 +0000162CJS_Result CJS_Event::set_rich_change(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000163 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000164 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700165}
166
Tom Sepez3a6d0582018-08-17 19:28:52 +0000167CJS_Result CJS_Event::get_rich_change_ex(CJS_Runtime* pRuntime) {
168 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700169}
170
Tom Sepez3a6d0582018-08-17 19:28:52 +0000171CJS_Result CJS_Event::set_rich_change_ex(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000172 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000173 return CJS_Result::Success();
Dan Sinclairf7435522018-02-05 22:27:22 +0000174}
175
Tom Sepez3a6d0582018-08-17 19:28:52 +0000176CJS_Result CJS_Event::get_rich_value(CJS_Runtime* pRuntime) {
177 return CJS_Result::Success();
Dan Sinclairf7435522018-02-05 22:27:22 +0000178}
179
Tom Sepez3a6d0582018-08-17 19:28:52 +0000180CJS_Result CJS_Event::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -0400181 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000182 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700183}
184
Tom Sepez3a6d0582018-08-17 19:28:52 +0000185CJS_Result CJS_Event::get_sel_end(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000186 CJS_EventRecorder* pEvent =
187 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepezceac05a2018-11-30 23:26:58 +0000188 if (pEvent->Name() != "Keystroke")
Tom Sepez3a6d0582018-08-17 19:28:52 +0000189 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190
Tom Sepez3a6d0582018-08-17 19:28:52 +0000191 return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelEnd()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192}
193
Tom Sepez3a6d0582018-08-17 19:28:52 +0000194CJS_Result CJS_Event::set_sel_end(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000195 v8::Local<v8::Value> vp) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000196 CJS_EventRecorder* pEvent =
197 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepezceac05a2018-11-30 23:26:58 +0000198 if (pEvent->Name() == "Keystroke")
Tom Sepez20736f72018-08-17 16:44:50 +0000199 pEvent->SetSelEnd(pRuntime->ToInt32(vp));
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800200
Tom Sepez3a6d0582018-08-17 19:28:52 +0000201 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202}
203
Tom Sepez3a6d0582018-08-17 19:28:52 +0000204CJS_Result CJS_Event::get_sel_start(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000205 CJS_EventRecorder* pEvent =
206 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepezceac05a2018-11-30 23:26:58 +0000207 if (pEvent->Name() != "Keystroke")
Tom Sepez3a6d0582018-08-17 19:28:52 +0000208 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400209
Tom Sepez3a6d0582018-08-17 19:28:52 +0000210 return CJS_Result::Success(pRuntime->NewNumber(pEvent->SelStart()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211}
212
Tom Sepez3a6d0582018-08-17 19:28:52 +0000213CJS_Result CJS_Event::set_sel_start(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000214 v8::Local<v8::Value> vp) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000215 CJS_EventRecorder* pEvent =
216 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepezceac05a2018-11-30 23:26:58 +0000217 if (pEvent->Name() == "Keystroke")
Tom Sepez20736f72018-08-17 16:44:50 +0000218 pEvent->SetSelStart(pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -0400219
Tom Sepez3a6d0582018-08-17 19:28:52 +0000220 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221}
222
Tom Sepez3a6d0582018-08-17 19:28:52 +0000223CJS_Result CJS_Event::get_shift(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000224 CJS_EventRecorder* pEvent =
225 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000226 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->Shift()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227}
228
Tom Sepez3a6d0582018-08-17 19:28:52 +0000229CJS_Result CJS_Event::set_shift(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000230 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000231 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400232}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233
Tom Sepez3a6d0582018-08-17 19:28:52 +0000234CJS_Result CJS_Event::get_source(CJS_Runtime* pRuntime) {
Tom Sepez796bd772019-06-11 23:43:05 +0000235 CJS_Field* pField = pRuntime->GetCurrentEventContext()->SourceField();
236 if (!pField)
237 return CJS_Result::Failure(JSMessage::kBadObjectError);
238 return CJS_Result::Success(pField->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239}
240
Tom Sepez3a6d0582018-08-17 19:28:52 +0000241CJS_Result CJS_Event::set_source(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000242 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000243 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400244}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245
Tom Sepez3a6d0582018-08-17 19:28:52 +0000246CJS_Result CJS_Event::get_target(CJS_Runtime* pRuntime) {
Tom Sepez796bd772019-06-11 23:43:05 +0000247 CJS_Field* pField = pRuntime->GetCurrentEventContext()->TargetField();
248 if (!pField)
249 return CJS_Result::Failure(JSMessage::kBadObjectError);
250 return CJS_Result::Success(pField->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700251}
252
Tom Sepez3a6d0582018-08-17 19:28:52 +0000253CJS_Result CJS_Event::set_target(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000254 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000255 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400256}
257
Tom Sepez3a6d0582018-08-17 19:28:52 +0000258CJS_Result CJS_Event::get_target_name(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000259 CJS_EventRecorder* pEvent =
260 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000261 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +0000262 pRuntime->NewString(pEvent->TargetName().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400263}
264
Tom Sepez3a6d0582018-08-17 19:28:52 +0000265CJS_Result CJS_Event::set_target_name(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000266 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000267 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400268}
269
Tom Sepez3a6d0582018-08-17 19:28:52 +0000270CJS_Result CJS_Event::get_type(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000271 CJS_EventRecorder* pEvent =
272 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000273 return CJS_Result::Success(pRuntime->NewString(pEvent->Type()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400274}
275
Tom Sepez3a6d0582018-08-17 19:28:52 +0000276CJS_Result CJS_Event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
277 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400278}
279
Tom Sepez3a6d0582018-08-17 19:28:52 +0000280CJS_Result CJS_Event::get_value(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000281 CJS_EventRecorder* pEvent =
282 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepezceac05a2018-11-30 23:26:58 +0000283 if (pEvent->Type() != "Field")
Tom Sepez3a6d0582018-08-17 19:28:52 +0000284 return CJS_Result::Failure(L"Bad event type.");
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800285
Tom Sepez88883312019-06-11 23:55:46 +0000286 if (!pEvent->HasValue())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000287 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800288
Tom Sepez3a6d0582018-08-17 19:28:52 +0000289 return CJS_Result::Success(
Tom Sepez20736f72018-08-17 16:44:50 +0000290 pRuntime->NewString(pEvent->Value().AsStringView()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291}
292
Tom Sepez3a6d0582018-08-17 19:28:52 +0000293CJS_Result CJS_Event::set_value(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000294 v8::Local<v8::Value> vp) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000295 CJS_EventRecorder* pEvent =
296 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepezceac05a2018-11-30 23:26:58 +0000297 if (pEvent->Type() != "Field")
Tom Sepez3a6d0582018-08-17 19:28:52 +0000298 return CJS_Result::Failure(L"Bad event type.");
dan sinclaircbe23db2017-10-19 14:29:33 -0400299
Tom Sepez88883312019-06-11 23:55:46 +0000300 if (!pEvent->HasValue())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000301 return CJS_Result::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400302
Lei Zhang058e2aa2018-11-09 23:49:50 +0000303 if (vp.IsEmpty())
304 return CJS_Result::Failure(JSMessage::kBadObjectError);
305
306 if (vp->IsNullOrUndefined() || vp->IsBoolean())
307 return CJS_Result::Failure(JSMessage::kInvalidSetError);
308
dan sinclair80435cb2017-10-24 21:40:24 -0400309 pEvent->Value() = pRuntime->ToWideString(vp);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000310 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311}
dan sinclaircbe23db2017-10-19 14:29:33 -0400312
Tom Sepez3a6d0582018-08-17 19:28:52 +0000313CJS_Result CJS_Event::get_will_commit(CJS_Runtime* pRuntime) {
Tom Sepez7dbb85b2019-06-11 19:49:00 +0000314 CJS_EventRecorder* pEvent =
315 pRuntime->GetCurrentEventContext()->GetEventRecorder();
Tom Sepez19757a12018-11-07 20:05:13 +0000316
Tom Sepez3a6d0582018-08-17 19:28:52 +0000317 return CJS_Result::Success(pRuntime->NewBoolean(pEvent->WillCommit()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400318}
319
Tom Sepez3a6d0582018-08-17 19:28:52 +0000320CJS_Result CJS_Event::set_will_commit(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000321 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000322 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400323}