blob: c8a4451ef0175af4b66f0486ed104c4ffe5f7e40 [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.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
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#ifndef FXJS_CJS_OBJECT_H_
8#define FXJS_CJS_OBJECT_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez36aae4f2018-06-04 19:44:37 +000010#include "core/fxcrt/unowned_ptr.h"
Dan Sinclair00d47a62018-03-28 18:39:04 +000011#include "fpdfsdk/cpdfsdk_helpers.h"
Tom Sepezb7c7df62018-02-09 19:08:59 +000012#include "fxjs/cfxjs_engine.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000013#include "fxjs/cjs_runtime.h"
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000014#include "third_party/base/span.h"
Tom Sepez3a832662015-03-02 12:59:05 -080015
Dan Sinclaird808dfd2017-10-26 15:04:17 -040016struct JSConstSpec {
17 enum Type { Number = 0, String = 1 };
18
19 const char* pName;
20 Type eType;
21 double number;
22 const char* pStr;
23};
24
25struct JSPropertySpec {
26 const char* pName;
27 v8::AccessorGetterCallback pPropGet;
28 v8::AccessorSetterCallback pPropPut;
29};
30
31struct JSMethodSpec {
32 const char* pName;
33 v8::FunctionCallback pMethodCall;
34};
35
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036class CJS_Object {
37 public:
Dan Sinclaird808dfd2017-10-26 15:04:17 -040038 static void DefineConsts(CFXJS_Engine* pEngine,
39 int objId,
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000040 pdfium::span<const JSConstSpec> consts);
Dan Sinclaird808dfd2017-10-26 15:04:17 -040041 static void DefineProps(CFXJS_Engine* pEngine,
42 int objId,
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000043 pdfium::span<const JSPropertySpec> consts);
Dan Sinclaird808dfd2017-10-26 15:04:17 -040044 static void DefineMethods(CFXJS_Engine* pEngine,
45 int objId,
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000046 pdfium::span<const JSMethodSpec> consts);
Dan Sinclaird808dfd2017-10-26 15:04:17 -040047
Tom Sepez36aae4f2018-06-04 19:44:37 +000048 CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
Lei Zhang2b1a2d52015-08-14 22:16:22 -070049 virtual ~CJS_Object();
Tom Sepezc6ab1722015-02-05 15:27:25 -080050
Tom Sepez36aae4f2018-06-04 19:44:37 +000051 v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(GetIsolate()); }
52 v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); }
53 CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054
Tom Sepez36aae4f2018-06-04 19:44:37 +000055 private:
56 UnownedPtr<v8::Isolate> m_pIsolate;
Tom Sepez116e4ad2015-09-21 09:22:05 -070057 v8::Global<v8::Object> m_pV8Object;
Tom Sepez36aae4f2018-06-04 19:44:37 +000058 CJS_Runtime::ObservedPtr m_pRuntime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059};
60
Dan Sinclaire0345a42017-10-30 20:20:42 +000061#endif // FXJS_CJS_OBJECT_H_