blob: f00f07c3b928362ea866efa12d70f82c0effc2ae [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"
10#include "fxjs/cjs_eventhandler.h"
11#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
Dan Sinclairf7435522018-02-05 22:27:22 +000057CJS_Return CJS_Event::get_change(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -080058 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -080059 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +000060 return CJS_Return::Success(
61 pRuntime->NewString(pEvent->Change().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -040062}
63
Dan Sinclairf7435522018-02-05 22:27:22 +000064CJS_Return CJS_Event::set_change(CJS_Runtime* pRuntime,
65 v8::Local<v8::Value> vp) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +000066 ASSERT(pRuntime->GetCurrentEventContext());
67
dan sinclaircbe23db2017-10-19 14:29:33 -040068 CJS_EventHandler* pEvent =
69 pRuntime->GetCurrentEventContext()->GetEventHandler();
70
dan sinclair80435cb2017-10-24 21:40:24 -040071 if (vp->IsString()) {
dan sinclaircbe23db2017-10-19 14:29:33 -040072 WideString& wChange = pEvent->Change();
dan sinclair80435cb2017-10-24 21:40:24 -040073 wChange = pRuntime->ToWideString(vp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 }
Tom Sepez20736f72018-08-17 16:44:50 +000075 return CJS_Return::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076}
77
Dan Sinclairf7435522018-02-05 22:27:22 +000078CJS_Return CJS_Event::get_change_ex(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -040079 CJS_EventHandler* pEvent =
80 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +000081 return CJS_Return::Success(
82 pRuntime->NewString(pEvent->ChangeEx().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -040083}
84
Dan Sinclairf7435522018-02-05 22:27:22 +000085CJS_Return CJS_Event::set_change_ex(CJS_Runtime* pRuntime,
86 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +000087 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -040088}
89
Dan Sinclairf7435522018-02-05 22:27:22 +000090CJS_Return CJS_Event::get_commit_key(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -040091 CJS_EventHandler* pEvent =
92 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +000093 return CJS_Return::Success(pRuntime->NewNumber(pEvent->CommitKey()));
dan sinclaircbe23db2017-10-19 14:29:33 -040094}
95
Dan Sinclairf7435522018-02-05 22:27:22 +000096CJS_Return CJS_Event::set_commit_key(CJS_Runtime* pRuntime,
97 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +000098 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -040099}
100
Dan Sinclairf7435522018-02-05 22:27:22 +0000101CJS_Return CJS_Event::get_field_full(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400102 CJS_EventHandler* pEvent =
103 pRuntime->GetCurrentEventContext()->GetEventHandler();
dan sinclaircbe23db2017-10-19 14:29:33 -0400104 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Tom Sepez20736f72018-08-17 16:44:50 +0000105 return CJS_Return::Failure(L"unrecognized event");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106
Tom Sepez20736f72018-08-17 16:44:50 +0000107 return CJS_Return::Success(pRuntime->NewBoolean(pEvent->FieldFull()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400108}
109
Dan Sinclairf7435522018-02-05 22:27:22 +0000110CJS_Return CJS_Event::set_field_full(CJS_Runtime* pRuntime,
111 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000112 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400113}
114
Dan Sinclairf7435522018-02-05 22:27:22 +0000115CJS_Return CJS_Event::get_key_down(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800116 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800117 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000118 return CJS_Return::Success(pRuntime->NewBoolean(pEvent->KeyDown()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119}
120
Dan Sinclairf7435522018-02-05 22:27:22 +0000121CJS_Return CJS_Event::set_key_down(CJS_Runtime* pRuntime,
122 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000123 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400124}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Dan Sinclairf7435522018-02-05 22:27:22 +0000126CJS_Return CJS_Event::get_modifier(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800127 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800128 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000129 return CJS_Return::Success(pRuntime->NewBoolean(pEvent->Modifier()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130}
131
Dan Sinclairf7435522018-02-05 22:27:22 +0000132CJS_Return CJS_Event::set_modifier(CJS_Runtime* pRuntime,
133 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000134 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400135}
136
Dan Sinclairf7435522018-02-05 22:27:22 +0000137CJS_Return CJS_Event::get_name(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800138 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800139 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000140 return CJS_Return::Success(pRuntime->NewString(pEvent->Name()));
tsepez4cf55152016-11-02 14:37:54 -0700141}
142
Dan Sinclairf7435522018-02-05 22:27:22 +0000143CJS_Return CJS_Event::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000144 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400145}
tsepez4cf55152016-11-02 14:37:54 -0700146
Dan Sinclairf7435522018-02-05 22:27:22 +0000147CJS_Return CJS_Event::get_rc(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800148 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800149 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000150 return CJS_Return::Success(pRuntime->NewBoolean(pEvent->Rc()));
tsepez4cf55152016-11-02 14:37:54 -0700151}
152
Dan Sinclairf7435522018-02-05 22:27:22 +0000153CJS_Return CJS_Event::set_rc(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800154 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800155 pRuntime->GetCurrentEventContext()->GetEventHandler();
dan sinclair80435cb2017-10-24 21:40:24 -0400156 pEvent->Rc() = pRuntime->ToBoolean(vp);
Tom Sepez20736f72018-08-17 16:44:50 +0000157 return CJS_Return::Success();
tsepez4cf55152016-11-02 14:37:54 -0700158}
159
Dan Sinclairf7435522018-02-05 22:27:22 +0000160CJS_Return CJS_Event::get_rich_change(CJS_Runtime* pRuntime) {
Tom Sepez20736f72018-08-17 16:44:50 +0000161 return CJS_Return::Success();
tsepez4cf55152016-11-02 14:37:54 -0700162}
163
Dan Sinclairf7435522018-02-05 22:27:22 +0000164CJS_Return CJS_Event::set_rich_change(CJS_Runtime* pRuntime,
165 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000166 return CJS_Return::Success();
tsepez4cf55152016-11-02 14:37:54 -0700167}
168
Dan Sinclairf7435522018-02-05 22:27:22 +0000169CJS_Return CJS_Event::get_rich_change_ex(CJS_Runtime* pRuntime) {
Tom Sepez20736f72018-08-17 16:44:50 +0000170 return CJS_Return::Success();
tsepez4cf55152016-11-02 14:37:54 -0700171}
172
Dan Sinclairf7435522018-02-05 22:27:22 +0000173CJS_Return CJS_Event::set_rich_change_ex(CJS_Runtime* pRuntime,
174 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000175 return CJS_Return::Success();
Dan Sinclairf7435522018-02-05 22:27:22 +0000176}
177
178CJS_Return CJS_Event::get_rich_value(CJS_Runtime* pRuntime) {
Tom Sepez20736f72018-08-17 16:44:50 +0000179 return CJS_Return::Success();
Dan Sinclairf7435522018-02-05 22:27:22 +0000180}
181
182CJS_Return CJS_Event::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair8f524d62017-10-25 13:30:31 -0400183 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000184 return CJS_Return::Success();
tsepez4cf55152016-11-02 14:37:54 -0700185}
186
Dan Sinclairf7435522018-02-05 22:27:22 +0000187CJS_Return CJS_Event::get_sel_end(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800188 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800189 pRuntime->GetCurrentEventContext()->GetEventHandler();
tsepez4cf55152016-11-02 14:37:54 -0700190
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800191 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Tom Sepez20736f72018-08-17 16:44:50 +0000192 return CJS_Return::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193
Tom Sepez20736f72018-08-17 16:44:50 +0000194 return CJS_Return::Success(pRuntime->NewNumber(pEvent->SelEnd()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700195}
196
Dan Sinclairf7435522018-02-05 22:27:22 +0000197CJS_Return CJS_Event::set_sel_end(CJS_Runtime* pRuntime,
198 v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800199 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800200 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
Tom Sepez20736f72018-08-17 16:44:50 +0000202 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") == 0)
203 pEvent->SetSelEnd(pRuntime->ToInt32(vp));
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800204
Tom Sepez20736f72018-08-17 16:44:50 +0000205 return CJS_Return::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700206}
207
Dan Sinclairf7435522018-02-05 22:27:22 +0000208CJS_Return CJS_Event::get_sel_start(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800209 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800210 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
dan sinclaircbe23db2017-10-19 14:29:33 -0400212 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0)
Tom Sepez20736f72018-08-17 16:44:50 +0000213 return CJS_Return::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400214
Tom Sepez20736f72018-08-17 16:44:50 +0000215 return CJS_Return::Success(pRuntime->NewNumber(pEvent->SelStart()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216}
217
Dan Sinclairf7435522018-02-05 22:27:22 +0000218CJS_Return CJS_Event::set_sel_start(CJS_Runtime* pRuntime,
219 v8::Local<v8::Value> vp) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800220 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800221 pRuntime->GetCurrentEventContext()->GetEventHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222
Tom Sepez20736f72018-08-17 16:44:50 +0000223 if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") == 0)
224 pEvent->SetSelStart(pRuntime->ToInt32(vp));
dan sinclaircbe23db2017-10-19 14:29:33 -0400225
Tom Sepez20736f72018-08-17 16:44:50 +0000226 return CJS_Return::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227}
228
Dan Sinclairf7435522018-02-05 22:27:22 +0000229CJS_Return CJS_Event::get_shift(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800230 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800231 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000232 return CJS_Return::Success(pRuntime->NewBoolean(pEvent->Shift()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233}
234
Dan Sinclairf7435522018-02-05 22:27:22 +0000235CJS_Return CJS_Event::set_shift(CJS_Runtime* pRuntime,
236 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000237 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400238}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Dan Sinclairf7435522018-02-05 22:27:22 +0000240CJS_Return CJS_Event::get_source(CJS_Runtime* pRuntime) {
Tom Sepezb1670b52017-02-16 17:01:00 -0800241 CJS_EventHandler* pEvent =
242 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000243 return CJS_Return::Success(pEvent->Source()->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244}
245
Dan Sinclairf7435522018-02-05 22:27:22 +0000246CJS_Return CJS_Event::set_source(CJS_Runtime* pRuntime,
247 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000248 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400249}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250
Dan Sinclairf7435522018-02-05 22:27:22 +0000251CJS_Return CJS_Event::get_target(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000252 ASSERT(pRuntime->GetCurrentEventContext());
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800253 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800254 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000255 return CJS_Return::Success(pEvent->Target_Field()->ToV8Object());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256}
257
Dan Sinclairf7435522018-02-05 22:27:22 +0000258CJS_Return CJS_Event::set_target(CJS_Runtime* pRuntime,
259 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000260 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400261}
262
Dan Sinclairf7435522018-02-05 22:27:22 +0000263CJS_Return CJS_Event::get_target_name(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000264 ASSERT(pRuntime->GetCurrentEventContext());
dan sinclaircbe23db2017-10-19 14:29:33 -0400265 CJS_EventHandler* pEvent =
266 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000267 return CJS_Return::Success(
268 pRuntime->NewString(pEvent->TargetName().AsStringView()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400269}
270
Dan Sinclairf7435522018-02-05 22:27:22 +0000271CJS_Return CJS_Event::set_target_name(CJS_Runtime* pRuntime,
272 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000273 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400274}
275
Dan Sinclairf7435522018-02-05 22:27:22 +0000276CJS_Return CJS_Event::get_type(CJS_Runtime* pRuntime) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400277 CJS_EventHandler* pEvent =
278 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000279 return CJS_Return::Success(pRuntime->NewString(pEvent->Type()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400280}
281
Dan Sinclairf7435522018-02-05 22:27:22 +0000282CJS_Return CJS_Event::set_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000283 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400284}
285
Dan Sinclairf7435522018-02-05 22:27:22 +0000286CJS_Return CJS_Event::get_value(CJS_Runtime* pRuntime) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800287 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800288 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
Tom Sepez20736f72018-08-17 16:44:50 +0000291 return CJS_Return::Failure(L"Bad event type.");
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800292
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 if (!pEvent->m_pValue)
Tom Sepez20736f72018-08-17 16:44:50 +0000294 return CJS_Return::Failure(JSMessage::kBadObjectError);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800295
Tom Sepez20736f72018-08-17 16:44:50 +0000296 return CJS_Return::Success(
297 pRuntime->NewString(pEvent->Value().AsStringView()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700298}
299
Dan Sinclairf7435522018-02-05 22:27:22 +0000300CJS_Return CJS_Event::set_value(CJS_Runtime* pRuntime,
301 v8::Local<v8::Value> vp) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000302 ASSERT(pRuntime->GetCurrentEventContext());
303
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800304 CJS_EventHandler* pEvent =
Tom Sepezb1670b52017-02-16 17:01:00 -0800305 pRuntime->GetCurrentEventContext()->GetEventHandler();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700306
dan sinclaircbe23db2017-10-19 14:29:33 -0400307 if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0)
Tom Sepez20736f72018-08-17 16:44:50 +0000308 return CJS_Return::Failure(L"Bad event type.");
dan sinclaircbe23db2017-10-19 14:29:33 -0400309
310 if (!pEvent->m_pValue)
Tom Sepez20736f72018-08-17 16:44:50 +0000311 return CJS_Return::Failure(JSMessage::kBadObjectError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400312
dan sinclair80435cb2017-10-24 21:40:24 -0400313 pEvent->Value() = pRuntime->ToWideString(vp);
Tom Sepez20736f72018-08-17 16:44:50 +0000314 return CJS_Return::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315}
dan sinclaircbe23db2017-10-19 14:29:33 -0400316
Dan Sinclairf7435522018-02-05 22:27:22 +0000317CJS_Return CJS_Event::get_will_commit(CJS_Runtime* pRuntime) {
Dan Sinclaire9f7db92018-06-05 18:24:12 +0000318 ASSERT(pRuntime->GetCurrentEventContext());
319
dan sinclaircbe23db2017-10-19 14:29:33 -0400320 CJS_EventHandler* pEvent =
321 pRuntime->GetCurrentEventContext()->GetEventHandler();
Tom Sepez20736f72018-08-17 16:44:50 +0000322 return CJS_Return::Success(pRuntime->NewBoolean(pEvent->WillCommit()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400323}
324
Dan Sinclairf7435522018-02-05 22:27:22 +0000325CJS_Return CJS_Event::set_will_commit(CJS_Runtime* pRuntime,
326 v8::Local<v8::Value> vp) {
Tom Sepez20736f72018-08-17 16:44:50 +0000327 return CJS_Return::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400328}