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 <optional>
11
12#include "fxjs/js_resources.h"
13#include "v8/include/v8-forward.h"
14
16 public:
17 // Wrap constructors with static methods so we can apply [[nodiscard]],
18 // otherwise we can't catch places where someone mistakenly writes:
19 //
20 // if (error)
21 // CJS_Result(JS_ERROR_CODE);
22 //
23 // instead of
24 //
25 // if (error)
26 // return CJS_Result(JS_ERROR_CODE);
27 //
28 [[nodiscard]] static CJS_Result Success() { return CJS_Result(); }
29 [[nodiscard]] static CJS_Result Success(v8::Local<v8::Value> value) {
30 return CJS_Result(value);
31 }
32 [[nodiscard]] static CJS_Result Failure(const WideString& str) {
33 return CJS_Result(str);
34 }
36 return CJS_Result(id);
37 }
38
41
42 bool HasError() const { return error_.has_value(); }
43 const WideString& Error() const { return error_.value(); }
44
45 bool HasReturn() const { return !return_.IsEmpty(); }
46 v8::Local<v8::Value> Return() const { return return_; }
47
48 private:
49 CJS_Result(); // Successful but empty return.
50 explicit CJS_Result(v8::Local<v8::Value>); // Successful return with value.
51 explicit CJS_Result(const WideString&); // Error with custom message.
52 explicit CJS_Result(JSMessage id); // Error with stock message.
53
54 std::optional<WideString> error_;
55 v8::Local<v8::Value> return_;
56};
57
58#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
bool HasReturn() const
Definition cjs_result.h:45
v8::Local< v8::Value > Return() const
Definition cjs_result.h:46
static CJS_Result Success()
Definition cjs_result.h:28
CJS_Result(const CJS_Result &)
bool HasError() const
Definition cjs_result.h:42
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:35
static CJS_Result Success(v8::Local< v8::Value > value)
Definition cjs_result.h:29
const WideString & Error() const
Definition cjs_result.h:43
static CJS_Result Failure(const WideString &str)
Definition cjs_result.h:32
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:94
void JSDestructor(v8::Local< v8::Object > obj)
Definition js_define.cpp:26
v8::LocalVector< v8::Value > ExpandKeywordParams(CJS_Runtime *pRuntime, pdfium::span< v8::Local< v8::Value > > originals, size_t nKeywords,...)
Definition js_define.cpp:62
void JSPropSetter(const char *prop_name_string, const char *class_name_string, v8::Local< v8::Name > property, v8::Local< v8::Value > value, const v8::PropertyCallbackInfo< void > &info)
Definition js_define.h:97
void JSPropGetter(const char *prop_name_string, const char *class_name_string, v8::Local< v8::Name > property, const v8::PropertyCallbackInfo< v8::Value > &info)
Definition js_define.h:73
void JSMethod(const char *method_name_string, const char *class_name_string, const v8::FunctionCallbackInfo< v8::Value > &info)
Definition js_define.h:119
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:30
#define JS_STATIC_PROP(err_name, prop_name, class_name)
Definition js_define.h:145
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
fxcrt::WideString WideString
Definition widestring.h:207