Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjs_result.h
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef FXJS_CJS_RESULT_H_
8#define FXJS_CJS_RESULT_H_
9
10#include "fxjs/js_resources.h"
11#include "third_party/abseil-cpp/absl/types/optional.h"
12#include "v8/include/v8-forward.h"
13
15 public:
16 // Wrap constructors with static methods so we can apply [[nodiscard]],
17 // otherwise we can't catch places where someone mistakenly writes:
18 //
19 // if (error)
20 // CJS_Result(JS_ERROR_CODE);
21 //
22 // instead of
23 //
24 // if (error)
25 // return CJS_Result(JS_ERROR_CODE);
26 //
27 [[nodiscard]] static CJS_Result Success() { return CJS_Result(); }
28 [[nodiscard]] static CJS_Result Success(v8::Local<v8::Value> value) {
29 return CJS_Result(value);
30 }
31 [[nodiscard]] static CJS_Result Failure(const WideString& str) {
32 return CJS_Result(str);
33 }
35 return CJS_Result(id);
36 }
37
40
41 bool HasError() const { return error_.has_value(); }
42 const WideString& Error() const { return error_.value(); }
43
44 bool HasReturn() const { return !return_.IsEmpty(); }
45 v8::Local<v8::Value> Return() const { return return_; }
46
47 private:
48 CJS_Result(); // Successful but empty return.
49 explicit CJS_Result(v8::Local<v8::Value>); // Successful return with value.
50 explicit CJS_Result(const WideString&); // Error with custom message.
51 explicit CJS_Result(JSMessage id); // Error with stock message.
52
53 absl::optional<WideString> error_;
54 v8::Local<v8::Value> return_;
55};
56
57#endif // FXJS_CJS_RESULT_H_
@ FXJSOBJTYPE_DYNAMIC
void Error(const WideString &message)
static uint32_t GetObjDefnID()
Definition cjs_annot.cpp:25
~CJS_Annot() override
static void DefineJSObjects(CFXJS_Engine *pEngine)
Definition cjs_annot.cpp:30
void SetSDKAnnot(CPDFSDK_BAAnnot *annot)
Definition cjs_annot.cpp:41
CJS_Annot(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
Definition cjs_annot.cpp:36
static void DefineProps(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSPropertySpec > consts)
bool HasReturn() const
Definition cjs_result.h:44
v8::Local< v8::Value > Return() const
Definition cjs_result.h:45
static CJS_Result Success()
Definition cjs_result.h:27
CJS_Result(const CJS_Result &)
bool HasError() const
Definition cjs_result.h:41
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
static CJS_Result Success(v8::Local< v8::Value > value)
Definition cjs_result.h:28
const WideString & Error() const
Definition cjs_result.h:42
static CJS_Result Failure(const WideString &str)
Definition cjs_result.h:31
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 IsHidden() const
bool IsExpandedParamKnown(v8::Local< v8::Value > value)
Definition js_define.cpp:95
void JSDestructor(v8::Local< v8::Object > obj)
Definition js_define.cpp:27
v8::LocalVector< v8::Value > ExpandKeywordParams(CJS_Runtime *pRuntime, pdfium::span< v8::Local< v8::Value > > originals, size_t nKeywords,...)
Definition js_define.cpp:63
void JSPropGetter(const char *prop_name_string, const char *class_name_string, v8::Local< v8::String > property, const v8::PropertyCallbackInfo< v8::Value > &info)
Definition js_define.h:69
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)
Definition js_define.h:93
void JSMethod(const char *method_name_string, const char *class_name_string, const v8::FunctionCallbackInfo< v8::Value > &info)
Definition js_define.h:115
UnownedPtr< C > JSGetObject(v8::Isolate *isolate, v8::Local< v8::Object > obj)
Definition js_define.h:57
double JS_DateParse(v8::Isolate *pIsolate, const WideString &str)
Definition js_define.cpp:31
#define JS_STATIC_PROP(err_name, prop_name, class_name)
Definition js_define.h:141
static void JSConstructor(CFXJS_Engine *pEngine, v8::Local< v8::Object > obj, v8::Local< v8::Object > proxy)
Definition js_define.h:46
JSMessage
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