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