7#ifndef FXJS_JS_DEFINE_H_
8#define FXJS_JS_DEFINE_H_
12#include "core/fxcrt/unowned_ptr.h"
13#include "fxjs/cfxjs_engine.h"
14#include "fxjs/cjs_result.h"
15#include "fxjs/cjs_runtime.h"
16#include "fxjs/js_resources.h"
17#include "third_party/base/containers/span.h"
18#include "v8/include/v8-local-handle.h"
22double JS_DateParse(v8::Isolate* pIsolate,
const WideString& str);
31 CJS_Runtime* pRuntime,
47 v8::Local<v8::Object> obj,
48 v8::Local<v8::Object> proxy) {
49 pEngine->SetObjectPrivate(
50 obj,
std::make_unique<T>(proxy,
static_cast<CJS_Runtime*>(pEngine)));
58 if (CFXJS_Engine::GetObjDefnID(obj) != C::GetObjDefnID())
61 CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(isolate, obj);
65 return UnownedPtr<C>(
static_cast<C*>(pJSObj));
68template <
class C,
CJS_Result (C::*M)(CJS_Runtime*)>
70 const char* class_name_string,
71 v8::Local<v8::String> property,
72 const v8::PropertyCallbackInfo<v8::Value>& info) {
73 auto pObj = JSGetObject<C>(info.GetIsolate(), info.Holder());
77 CJS_Runtime* pRuntime = pObj->GetRuntime();
81 CJS_Result result = (pObj.get()->*M)(pRuntime);
89 info.GetReturnValue().Set(result.Return());
92template <
class C,
CJS_Result (C::*M)(CJS_Runtime*, v8::Local<v8::Value>)>
94 const char* class_name_string,
95 v8::Local<v8::String> property,
96 v8::Local<v8::Value> value,
97 const v8::PropertyCallbackInfo<
void>& info) {
98 auto pObj = JSGetObject<C>(info.GetIsolate(), info.Holder());
102 CJS_Runtime* pRuntime = pObj->GetRuntime();
106 CJS_Result result = (pObj.get()->*M)(pRuntime, value);
114 CJS_Result (C::*M)(CJS_Runtime*, pdfium::span<v8::Local<v8::Value>>)>
116 const char* class_name_string,
117 const v8::FunctionCallbackInfo<v8::Value>& info) {
118 auto pObj = JSGetObject<C>(info.GetIsolate(), info.Holder());
122 CJS_Runtime* pRuntime = pObj->GetRuntime();
126 v8::LocalVector<v8::Value> parameters(info.GetIsolate());
127 for (
unsigned int i = 0; i < (
unsigned int)info.Length(); i++)
128 parameters.push_back(info[i]);
130 CJS_Result result = (pObj.get()->*M)(pRuntime, parameters);
138 info.GetReturnValue().Set(result.Return());
141#define JS_STATIC_PROP(err_name, prop_name, class_name)
142 static void get_##prop_name##_static(
143 v8::Local<v8::String> property,
144 const v8::PropertyCallbackInfo<v8::Value>& info) {
145 JSPropGetter<class_name, &class_name::get_##prop_name>(
146 #err_name, class_name::kName, property, info);
148 static void set_##prop_name##_static(
149 v8::Local<v8::String> property, v8::Local<v8::Value> value,
150 const v8::PropertyCallbackInfo<void>& info) {
151 JSPropSetter<class_name, &class_name::set_##prop_name>(
152 #err_name, class_name::kName, property, value, info);
155#define JS_STATIC_METHOD(method_name, class_name)
156 static void method_name##_static(
157 const v8::FunctionCallbackInfo<v8::Value>& info) {
158 JSMethod<class_name, &class_name::method_name>(#method_name,
159 class_name::kName, info);
void Error(const WideString &message)
static uint32_t GetObjDefnID()
static void DefineJSObjects(CFXJS_Engine *pEngine)
void SetSDKAnnot(CPDFSDK_BAAnnot *annot)
CJS_Annot(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
static void DefineProps(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSPropertySpec > consts)
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
const WideString & Error() const
WideString GetAnnotName() const
void SetAnnotName(const WideString &sName)
CPDF_Annot::Subtype GetAnnotSubtype() const override
void SetFlags(uint32_t nFlags)
uint32_t GetFlags() const
static ByteString AnnotSubtypeToString(Subtype nSubtype)
bool IsExpandedParamKnown(v8::Local< v8::Value > value)
void JSDestructor(v8::Local< v8::Object > obj)
v8::LocalVector< v8::Value > ExpandKeywordParams(CJS_Runtime *pRuntime, pdfium::span< v8::Local< v8::Value > > originals, size_t nKeywords,...)
void JSPropGetter(const char *prop_name_string, const char *class_name_string, v8::Local< v8::String > property, const v8::PropertyCallbackInfo< v8::Value > &info)
void JSPropSetter(const char *prop_name_string, const char *class_name_string, v8::Local< v8::String > property, v8::Local< v8::Value > value, const v8::PropertyCallbackInfo< void > &info)
void JSMethod(const char *method_name_string, const char *class_name_string, const v8::FunctionCallbackInfo< v8::Value > &info)
UnownedPtr< C > JSGetObject(v8::Isolate *isolate, v8::Local< v8::Object > obj)
double JS_DateParse(v8::Isolate *pIsolate, const WideString &str)
#define JS_STATIC_PROP(err_name, prop_name, class_name)
static void JSConstructor(CFXJS_Engine *pEngine, v8::Local< v8::Object > obj, v8::Local< v8::Object > proxy)
WideString JSFormatErrorString(const char *class_name, const char *property_name, const WideString &details)
constexpr uint32_t kNoView
constexpr uint32_t kHidden
constexpr uint32_t kPrint
constexpr uint32_t kInvisible