// Copyright 2020 The PDFium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #ifndef FXJS_FXV8_H_ #define FXJS_FXV8_H_ #include #include #include "core/fxcrt/fx_string.h" #include "third_party/base/containers/span.h" #include "v8/include/v8-forward.h" // The fxv8 functions soften up the interface to the V8 API. In particular, // PDFium uses size_t for sizes and indices, but V8 mostly uses ints, so // these routines perform checked conversions. namespace fxv8 { // These first check for empty locals. bool IsUndefined(v8::Local value); bool IsNull(v8::Local value); bool IsBoolean(v8::Local value); bool IsString(v8::Local value); bool IsNumber(v8::Local value); bool IsInteger(v8::Local value); bool IsObject(v8::Local value); bool IsArray(v8::Local value); bool IsDate(v8::Local value); bool IsFunction(v8::Local value); v8::Local NewNullHelper(v8::Isolate* pIsolate); v8::Local NewUndefinedHelper(v8::Isolate* pIsolate); v8::Local NewNumberHelper(v8::Isolate* pIsolate, int number); v8::Local NewNumberHelper(v8::Isolate* pIsolate, double number); v8::Local NewNumberHelper(v8::Isolate* pIsolate, float number); v8::Local NewBooleanHelper(v8::Isolate* pIsolate, bool b); v8::Local NewStringHelper(v8::Isolate* pIsolate, ByteStringView str); v8::Local NewStringHelper(v8::Isolate* pIsolate, WideStringView str); v8::Local NewArrayHelper(v8::Isolate* pIsolate); v8::Local NewArrayHelper(v8::Isolate* pIsolate, pdfium::span> values); v8::Local NewObjectHelper(v8::Isolate* pIsolate); v8::Local NewDateHelper(v8::Isolate* pIsolate, double d); // Conversion to PDFium type without re-entry from known v8 type. WideString ToWideString(v8::Isolate* pIsolate, v8::Local pValue); ByteString ToByteString(v8::Isolate* pIsolate, v8::Local pValue); // Conversion to PDFium type with possible re-entry for coercion. int32_t ReentrantToInt32Helper(v8::Isolate* pIsolate, v8::Local pValue); bool ReentrantToBooleanHelper(v8::Isolate* pIsolate, v8::Local pValue); float ReentrantToFloatHelper(v8::Isolate* pIsolate, v8::Local pValue); double ReentrantToDoubleHelper(v8::Isolate* pIsolate, v8::Local pValue); WideString ReentrantToWideStringHelper(v8::Isolate* pIsolate, v8::Local pValue); ByteString ReentrantToByteStringHelper(v8::Isolate* pIsolate, v8::Local pValue); v8::Local ReentrantToObjectHelper(v8::Isolate* pIsolate, v8::Local pValue); v8::Local ReentrantToArrayHelper(v8::Isolate* pIsolate, v8::Local pValue); v8::Local ReentrantGetObjectPropertyHelper( v8::Isolate* pIsolate, v8::Local pObj, ByteStringView bsUTF8PropertyName); std::vector ReentrantGetObjectPropertyNamesHelper( v8::Isolate* pIsolate, v8::Local pObj); bool ReentrantHasObjectOwnPropertyHelper(v8::Isolate* pIsolate, v8::Local pObj, ByteStringView bsUTF8PropertyName); bool ReentrantSetObjectOwnPropertyHelper(v8::Isolate* pIsolate, v8::Local pObj, ByteStringView bsUTF8PropertyName, v8::Local pValue); bool ReentrantPutObjectPropertyHelper(v8::Isolate* pIsolate, v8::Local pObj, ByteStringView bsUTF8PropertyName, v8::Local pPut); void ReentrantDeleteObjectPropertyHelper(v8::Isolate* pIsolate, v8::Local pObj, ByteStringView bsUTF8PropertyName); bool ReentrantPutArrayElementHelper(v8::Isolate* pIsolate, v8::Local pArray, size_t index, v8::Local pValue); v8::Local ReentrantGetArrayElementHelper(v8::Isolate* pIsolate, v8::Local pArray, size_t index); size_t GetArrayLengthHelper(v8::Local pArray); void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str); void ThrowExceptionHelper(v8::Isolate* pIsolate, WideStringView str); } // namespace fxv8 #endif // FXJS_FXV8_H_