xref: /aosp_15_r20/external/pdfium/fxjs/fxv8.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2020 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_FXV8_H_
8 #define FXJS_FXV8_H_
9 
10 #include <stddef.h>
11 
12 #include <vector>
13 
14 #include "core/fxcrt/fx_string.h"
15 #include "third_party/base/containers/span.h"
16 #include "v8/include/v8-forward.h"
17 
18 // The fxv8 functions soften up the interface to the V8 API. In particular,
19 // PDFium uses size_t for sizes and indices, but V8 mostly uses ints, so
20 // these routines perform checked conversions.
21 
22 namespace fxv8 {
23 
24 // These first check for empty locals.
25 bool IsUndefined(v8::Local<v8::Value> value);
26 bool IsNull(v8::Local<v8::Value> value);
27 bool IsBoolean(v8::Local<v8::Value> value);
28 bool IsString(v8::Local<v8::Value> value);
29 bool IsNumber(v8::Local<v8::Value> value);
30 bool IsInteger(v8::Local<v8::Value> value);
31 bool IsObject(v8::Local<v8::Value> value);
32 bool IsArray(v8::Local<v8::Value> value);
33 bool IsDate(v8::Local<v8::Value> value);
34 bool IsFunction(v8::Local<v8::Value> value);
35 
36 v8::Local<v8::Value> NewNullHelper(v8::Isolate* pIsolate);
37 v8::Local<v8::Value> NewUndefinedHelper(v8::Isolate* pIsolate);
38 v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, int number);
39 v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, double number);
40 v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, float number);
41 v8::Local<v8::Boolean> NewBooleanHelper(v8::Isolate* pIsolate, bool b);
42 v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate,
43                                       ByteStringView str);
44 v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate,
45                                       WideStringView str);
46 v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate);
47 v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate,
48                                     pdfium::span<v8::Local<v8::Value>> values);
49 v8::Local<v8::Object> NewObjectHelper(v8::Isolate* pIsolate);
50 v8::Local<v8::Date> NewDateHelper(v8::Isolate* pIsolate, double d);
51 
52 // Conversion to PDFium type without re-entry from known v8 type.
53 WideString ToWideString(v8::Isolate* pIsolate, v8::Local<v8::String> pValue);
54 ByteString ToByteString(v8::Isolate* pIsolate, v8::Local<v8::String> pValue);
55 
56 // Conversion to PDFium type with possible re-entry for coercion.
57 int32_t ReentrantToInt32Helper(v8::Isolate* pIsolate,
58                                v8::Local<v8::Value> pValue);
59 bool ReentrantToBooleanHelper(v8::Isolate* pIsolate,
60                               v8::Local<v8::Value> pValue);
61 float ReentrantToFloatHelper(v8::Isolate* pIsolate,
62                              v8::Local<v8::Value> pValue);
63 double ReentrantToDoubleHelper(v8::Isolate* pIsolate,
64                                v8::Local<v8::Value> pValue);
65 WideString ReentrantToWideStringHelper(v8::Isolate* pIsolate,
66                                        v8::Local<v8::Value> pValue);
67 ByteString ReentrantToByteStringHelper(v8::Isolate* pIsolate,
68                                        v8::Local<v8::Value> pValue);
69 v8::Local<v8::Object> ReentrantToObjectHelper(v8::Isolate* pIsolate,
70                                               v8::Local<v8::Value> pValue);
71 v8::Local<v8::Array> ReentrantToArrayHelper(v8::Isolate* pIsolate,
72                                             v8::Local<v8::Value> pValue);
73 
74 v8::Local<v8::Value> ReentrantGetObjectPropertyHelper(
75     v8::Isolate* pIsolate,
76     v8::Local<v8::Object> pObj,
77     ByteStringView bsUTF8PropertyName);
78 std::vector<WideString> ReentrantGetObjectPropertyNamesHelper(
79     v8::Isolate* pIsolate,
80     v8::Local<v8::Object> pObj);
81 bool ReentrantHasObjectOwnPropertyHelper(v8::Isolate* pIsolate,
82                                          v8::Local<v8::Object> pObj,
83                                          ByteStringView bsUTF8PropertyName);
84 bool ReentrantSetObjectOwnPropertyHelper(v8::Isolate* pIsolate,
85                                          v8::Local<v8::Object> pObj,
86                                          ByteStringView bsUTF8PropertyName,
87                                          v8::Local<v8::Value> pValue);
88 bool ReentrantPutObjectPropertyHelper(v8::Isolate* pIsolate,
89                                       v8::Local<v8::Object> pObj,
90                                       ByteStringView bsUTF8PropertyName,
91                                       v8::Local<v8::Value> pPut);
92 void ReentrantDeleteObjectPropertyHelper(v8::Isolate* pIsolate,
93                                          v8::Local<v8::Object> pObj,
94                                          ByteStringView bsUTF8PropertyName);
95 
96 bool ReentrantPutArrayElementHelper(v8::Isolate* pIsolate,
97                                     v8::Local<v8::Array> pArray,
98                                     size_t index,
99                                     v8::Local<v8::Value> pValue);
100 v8::Local<v8::Value> ReentrantGetArrayElementHelper(v8::Isolate* pIsolate,
101                                                     v8::Local<v8::Array> pArray,
102                                                     size_t index);
103 size_t GetArrayLengthHelper(v8::Local<v8::Array> pArray);
104 
105 void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str);
106 void ThrowExceptionHelper(v8::Isolate* pIsolate, WideStringView str);
107 
108 }  // namespace fxv8
109 
110 #endif  // FXJS_FXV8_H_
111