K. Moon | 832a694 | 2022-10-31 20:11:31 +0000 | [diff] [blame] | 1 | // Copyright 2020 The PDFium Authors |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 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 | #include "fxjs/fxv8.h" |
| 8 | |
Tom Sepez | d5a7e7f | 2021-11-10 03:05:00 +0000 | [diff] [blame] | 9 | #include "third_party/base/numerics/safe_conversions.h" |
Dan Elphick | 05673a3 | 2021-09-09 15:42:55 +0000 | [diff] [blame] | 10 | #include "v8/include/v8-container.h" |
| 11 | #include "v8/include/v8-date.h" |
| 12 | #include "v8/include/v8-exception.h" |
| 13 | #include "v8/include/v8-isolate.h" |
| 14 | #include "v8/include/v8-primitive.h" |
| 15 | #include "v8/include/v8-value.h" |
| 16 | |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 17 | namespace fxv8 { |
| 18 | |
Tom Sepez | af6371f | 2020-11-02 20:13:01 +0000 | [diff] [blame] | 19 | bool IsUndefined(v8::Local<v8::Value> value) { |
| 20 | return !value.IsEmpty() && value->IsUndefined(); |
| 21 | } |
| 22 | |
| 23 | bool IsNull(v8::Local<v8::Value> value) { |
| 24 | return !value.IsEmpty() && value->IsNull(); |
| 25 | } |
| 26 | |
| 27 | bool IsBoolean(v8::Local<v8::Value> value) { |
| 28 | return !value.IsEmpty() && value->IsBoolean(); |
| 29 | } |
| 30 | |
| 31 | bool IsString(v8::Local<v8::Value> value) { |
| 32 | return !value.IsEmpty() && value->IsString(); |
| 33 | } |
| 34 | |
| 35 | bool IsNumber(v8::Local<v8::Value> value) { |
| 36 | return !value.IsEmpty() && value->IsNumber(); |
| 37 | } |
| 38 | |
| 39 | bool IsInteger(v8::Local<v8::Value> value) { |
| 40 | return !value.IsEmpty() && value->IsInt32(); |
| 41 | } |
| 42 | |
| 43 | bool IsObject(v8::Local<v8::Value> value) { |
| 44 | return !value.IsEmpty() && value->IsObject(); |
| 45 | } |
| 46 | |
| 47 | bool IsArray(v8::Local<v8::Value> value) { |
| 48 | return !value.IsEmpty() && value->IsArray(); |
| 49 | } |
| 50 | |
| 51 | bool IsDate(v8::Local<v8::Value> value) { |
| 52 | return !value.IsEmpty() && value->IsDate(); |
| 53 | } |
| 54 | |
| 55 | bool IsFunction(v8::Local<v8::Value> value) { |
| 56 | return !value.IsEmpty() && value->IsFunction(); |
| 57 | } |
| 58 | |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 59 | v8::Local<v8::Value> NewNullHelper(v8::Isolate* pIsolate) { |
| 60 | return v8::Null(pIsolate); |
| 61 | } |
| 62 | |
| 63 | v8::Local<v8::Value> NewUndefinedHelper(v8::Isolate* pIsolate) { |
| 64 | return v8::Undefined(pIsolate); |
| 65 | } |
| 66 | |
| 67 | v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, int number) { |
| 68 | return v8::Int32::New(pIsolate, number); |
| 69 | } |
| 70 | |
| 71 | v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, double number) { |
| 72 | return v8::Number::New(pIsolate, number); |
| 73 | } |
| 74 | |
| 75 | v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, float number) { |
| 76 | return v8::Number::New(pIsolate, number); |
| 77 | } |
| 78 | |
| 79 | v8::Local<v8::Boolean> NewBooleanHelper(v8::Isolate* pIsolate, bool b) { |
| 80 | return v8::Boolean::New(pIsolate, b); |
| 81 | } |
| 82 | |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 83 | v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate, |
| 84 | ByteStringView str) { |
Tom Sepez | a0de6da | 2021-11-11 01:40:23 +0000 | [diff] [blame] | 85 | return v8::String::NewFromUtf8( |
| 86 | pIsolate, str.unterminated_c_str(), v8::NewStringType::kNormal, |
| 87 | pdfium::base::checked_cast<int>(str.GetLength())) |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 88 | .ToLocalChecked(); |
| 89 | } |
| 90 | |
| 91 | v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate, |
| 92 | WideStringView str) { |
| 93 | return NewStringHelper(pIsolate, FX_UTF8Encode(str).AsStringView()); |
| 94 | } |
| 95 | |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 96 | v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate) { |
| 97 | return v8::Array::New(pIsolate); |
| 98 | } |
| 99 | |
Tom Sepez | 145e22d | 2020-11-18 00:49:06 +0000 | [diff] [blame] | 100 | v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate, |
| 101 | pdfium::span<v8::Local<v8::Value>> values) { |
| 102 | v8::Local<v8::Array> result = NewArrayHelper(pIsolate); |
| 103 | for (size_t i = 0; i < values.size(); ++i) { |
| 104 | fxv8::ReentrantPutArrayElementHelper( |
| 105 | pIsolate, result, i, |
| 106 | values[i].IsEmpty() ? fxv8::NewUndefinedHelper(pIsolate) : values[i]); |
| 107 | } |
| 108 | return result; |
| 109 | } |
| 110 | |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 111 | v8::Local<v8::Object> NewObjectHelper(v8::Isolate* pIsolate) { |
| 112 | return v8::Object::New(pIsolate); |
| 113 | } |
| 114 | |
| 115 | v8::Local<v8::Date> NewDateHelper(v8::Isolate* pIsolate, double d) { |
| 116 | return v8::Date::New(pIsolate->GetCurrentContext(), d) |
| 117 | .ToLocalChecked() |
| 118 | .As<v8::Date>(); |
| 119 | } |
| 120 | |
Tom Sepez | 494efc7 | 2020-11-30 20:50:59 +0000 | [diff] [blame] | 121 | WideString ToWideString(v8::Isolate* pIsolate, v8::Local<v8::String> pValue) { |
| 122 | v8::String::Utf8Value s(pIsolate, pValue); |
| 123 | return WideString::FromUTF8(ByteStringView(*s, s.length())); |
| 124 | } |
| 125 | |
| 126 | ByteString ToByteString(v8::Isolate* pIsolate, v8::Local<v8::String> pValue) { |
| 127 | v8::String::Utf8Value s(pIsolate, pValue); |
| 128 | return ByteString(*s, s.length()); |
| 129 | } |
| 130 | |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 131 | int ReentrantToInt32Helper(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) { |
| 132 | if (pValue.IsEmpty()) |
| 133 | return 0; |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 134 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 135 | return pValue->Int32Value(pIsolate->GetCurrentContext()).FromMaybe(0); |
| 136 | } |
| 137 | |
| 138 | bool ReentrantToBooleanHelper(v8::Isolate* pIsolate, |
| 139 | v8::Local<v8::Value> pValue) { |
| 140 | if (pValue.IsEmpty()) |
| 141 | return false; |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 142 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 143 | return pValue->BooleanValue(pIsolate); |
| 144 | } |
| 145 | |
Tom Sepez | d564b0d | 2020-11-06 18:28:10 +0000 | [diff] [blame] | 146 | float ReentrantToFloatHelper(v8::Isolate* pIsolate, |
| 147 | v8::Local<v8::Value> pValue) { |
| 148 | return static_cast<float>(ReentrantToDoubleHelper(pIsolate, pValue)); |
| 149 | } |
| 150 | |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 151 | double ReentrantToDoubleHelper(v8::Isolate* pIsolate, |
| 152 | v8::Local<v8::Value> pValue) { |
| 153 | if (pValue.IsEmpty()) |
| 154 | return 0.0; |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 155 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 156 | return pValue->NumberValue(pIsolate->GetCurrentContext()).FromMaybe(0.0); |
| 157 | } |
| 158 | |
| 159 | WideString ReentrantToWideStringHelper(v8::Isolate* pIsolate, |
| 160 | v8::Local<v8::Value> pValue) { |
| 161 | if (pValue.IsEmpty()) |
| 162 | return WideString(); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 163 | |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 164 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 165 | v8::MaybeLocal<v8::String> maybe_string = |
| 166 | pValue->ToString(pIsolate->GetCurrentContext()); |
| 167 | if (maybe_string.IsEmpty()) |
| 168 | return WideString(); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 169 | |
Tom Sepez | 494efc7 | 2020-11-30 20:50:59 +0000 | [diff] [blame] | 170 | return ToWideString(pIsolate, maybe_string.ToLocalChecked()); |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | ByteString ReentrantToByteStringHelper(v8::Isolate* pIsolate, |
| 174 | v8::Local<v8::Value> pValue) { |
| 175 | if (pValue.IsEmpty()) |
| 176 | return ByteString(); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 177 | |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 178 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 179 | v8::MaybeLocal<v8::String> maybe_string = |
| 180 | pValue->ToString(pIsolate->GetCurrentContext()); |
| 181 | if (maybe_string.IsEmpty()) |
| 182 | return ByteString(); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 183 | |
Tom Sepez | 494efc7 | 2020-11-30 20:50:59 +0000 | [diff] [blame] | 184 | return ToByteString(pIsolate, maybe_string.ToLocalChecked()); |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 187 | v8::Local<v8::Object> ReentrantToObjectHelper(v8::Isolate* pIsolate, |
| 188 | v8::Local<v8::Value> pValue) { |
Tom Sepez | af6371f | 2020-11-02 20:13:01 +0000 | [diff] [blame] | 189 | if (!fxv8::IsObject(pValue)) |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 190 | return v8::Local<v8::Object>(); |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 191 | |
| 192 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 193 | v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 194 | return pValue->ToObject(context).ToLocalChecked(); |
| 195 | } |
| 196 | |
| 197 | v8::Local<v8::Array> ReentrantToArrayHelper(v8::Isolate* pIsolate, |
| 198 | v8::Local<v8::Value> pValue) { |
Tom Sepez | af6371f | 2020-11-02 20:13:01 +0000 | [diff] [blame] | 199 | if (!fxv8::IsArray(pValue)) |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 200 | return v8::Local<v8::Array>(); |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 201 | |
| 202 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 203 | v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 204 | return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
| 205 | } |
| 206 | |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 207 | v8::Local<v8::Value> ReentrantGetObjectPropertyHelper( |
| 208 | v8::Isolate* pIsolate, |
| 209 | v8::Local<v8::Object> pObj, |
| 210 | ByteStringView bsUTF8PropertyName) { |
| 211 | if (pObj.IsEmpty()) |
| 212 | return v8::Local<v8::Value>(); |
| 213 | |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 214 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 215 | v8::Local<v8::Value> val; |
| 216 | if (!pObj->Get(pIsolate->GetCurrentContext(), |
| 217 | NewStringHelper(pIsolate, bsUTF8PropertyName)) |
| 218 | .ToLocal(&val)) { |
| 219 | return v8::Local<v8::Value>(); |
| 220 | } |
| 221 | return val; |
| 222 | } |
| 223 | |
| 224 | std::vector<WideString> ReentrantGetObjectPropertyNamesHelper( |
| 225 | v8::Isolate* pIsolate, |
| 226 | v8::Local<v8::Object> pObj) { |
| 227 | if (pObj.IsEmpty()) |
| 228 | return std::vector<WideString>(); |
| 229 | |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 230 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 231 | v8::Local<v8::Array> val; |
| 232 | v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 233 | if (!pObj->GetPropertyNames(context).ToLocal(&val)) |
| 234 | return std::vector<WideString>(); |
| 235 | |
| 236 | std::vector<WideString> result; |
| 237 | for (uint32_t i = 0; i < val->Length(); ++i) { |
| 238 | result.push_back(ReentrantToWideStringHelper( |
| 239 | pIsolate, val->Get(context, i).ToLocalChecked())); |
| 240 | } |
| 241 | return result; |
| 242 | } |
| 243 | |
Tom Sepez | f487445 | 2020-11-09 21:14:06 +0000 | [diff] [blame] | 244 | bool ReentrantHasObjectOwnPropertyHelper(v8::Isolate* pIsolate, |
| 245 | v8::Local<v8::Object> pObj, |
Tom Sepez | 47793dc | 2021-05-26 20:03:38 +0000 | [diff] [blame] | 246 | ByteStringView bsUTF8PropertyName) { |
Tom Sepez | f487445 | 2020-11-09 21:14:06 +0000 | [diff] [blame] | 247 | if (pObj.IsEmpty()) |
| 248 | return false; |
| 249 | |
| 250 | v8::TryCatch squash_exceptions(pIsolate); |
| 251 | v8::Local<v8::Context> pContext = pIsolate->GetCurrentContext(); |
| 252 | v8::Local<v8::String> hKey = |
| 253 | fxv8::NewStringHelper(pIsolate, bsUTF8PropertyName); |
Tom Sepez | 47793dc | 2021-05-26 20:03:38 +0000 | [diff] [blame] | 254 | return pObj->HasRealNamedProperty(pContext, hKey).FromJust(); |
Tom Sepez | f487445 | 2020-11-09 21:14:06 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | bool ReentrantSetObjectOwnPropertyHelper(v8::Isolate* pIsolate, |
| 258 | v8::Local<v8::Object> pObj, |
| 259 | ByteStringView bsUTF8PropertyName, |
| 260 | v8::Local<v8::Value> pValue) { |
Tom Sepez | ab436ae | 2020-11-20 19:57:20 +0000 | [diff] [blame] | 261 | if (pObj.IsEmpty() || pValue.IsEmpty()) |
Tom Sepez | f487445 | 2020-11-09 21:14:06 +0000 | [diff] [blame] | 262 | return false; |
| 263 | |
| 264 | v8::TryCatch squash_exceptions(pIsolate); |
| 265 | v8::Local<v8::String> name = NewStringHelper(pIsolate, bsUTF8PropertyName); |
| 266 | return pObj->DefineOwnProperty(pIsolate->GetCurrentContext(), name, pValue) |
| 267 | .FromMaybe(false); |
| 268 | } |
| 269 | |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 270 | bool ReentrantPutObjectPropertyHelper(v8::Isolate* pIsolate, |
| 271 | v8::Local<v8::Object> pObj, |
| 272 | ByteStringView bsUTF8PropertyName, |
| 273 | v8::Local<v8::Value> pPut) { |
Tom Sepez | ab436ae | 2020-11-20 19:57:20 +0000 | [diff] [blame] | 274 | if (pObj.IsEmpty() || pPut.IsEmpty()) |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 275 | return false; |
| 276 | |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 277 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 278 | v8::Local<v8::String> name = NewStringHelper(pIsolate, bsUTF8PropertyName); |
Tom Sepez | 2fb992d | 2020-03-20 19:45:59 +0000 | [diff] [blame] | 279 | v8::Maybe<bool> result = pObj->Set(pIsolate->GetCurrentContext(), name, pPut); |
| 280 | return result.IsJust() && result.FromJust(); |
Tom Sepez | c72e23f | 2020-03-19 18:58:17 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Tom Sepez | 4643cf6 | 2020-11-09 19:27:05 +0000 | [diff] [blame] | 283 | void ReentrantDeleteObjectPropertyHelper(v8::Isolate* pIsolate, |
| 284 | v8::Local<v8::Object> pObj, |
| 285 | ByteStringView bsUTF8PropertyName) { |
| 286 | v8::TryCatch squash_exceptions(pIsolate); |
| 287 | pObj->Delete(pIsolate->GetCurrentContext(), |
| 288 | fxv8::NewStringHelper(pIsolate, bsUTF8PropertyName)) |
| 289 | .FromJust(); |
| 290 | } |
| 291 | |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 292 | bool ReentrantPutArrayElementHelper(v8::Isolate* pIsolate, |
| 293 | v8::Local<v8::Array> pArray, |
Tom Sepez | d5a7e7f | 2021-11-10 03:05:00 +0000 | [diff] [blame] | 294 | size_t index, |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 295 | v8::Local<v8::Value> pValue) { |
| 296 | if (pArray.IsEmpty()) |
| 297 | return false; |
Tom Sepez | 2fb992d | 2020-03-20 19:45:59 +0000 | [diff] [blame] | 298 | |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 299 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 2fb992d | 2020-03-20 19:45:59 +0000 | [diff] [blame] | 300 | v8::Maybe<bool> result = |
Tom Sepez | d5a7e7f | 2021-11-10 03:05:00 +0000 | [diff] [blame] | 301 | pArray->Set(pIsolate->GetCurrentContext(), |
| 302 | pdfium::base::checked_cast<uint32_t>(index), pValue); |
Tom Sepez | 2fb992d | 2020-03-20 19:45:59 +0000 | [diff] [blame] | 303 | return result.IsJust() && result.FromJust(); |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | v8::Local<v8::Value> ReentrantGetArrayElementHelper(v8::Isolate* pIsolate, |
| 307 | v8::Local<v8::Array> pArray, |
Tom Sepez | d5a7e7f | 2021-11-10 03:05:00 +0000 | [diff] [blame] | 308 | size_t index) { |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 309 | if (pArray.IsEmpty()) |
| 310 | return v8::Local<v8::Value>(); |
Tom Sepez | 5f3e581 | 2020-08-11 22:46:10 +0000 | [diff] [blame] | 311 | |
| 312 | v8::TryCatch squash_exceptions(pIsolate); |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 313 | v8::Local<v8::Value> val; |
Tom Sepez | d5a7e7f | 2021-11-10 03:05:00 +0000 | [diff] [blame] | 314 | if (!pArray |
| 315 | ->Get(pIsolate->GetCurrentContext(), |
| 316 | pdfium::base::checked_cast<uint32_t>(index)) |
| 317 | .ToLocal(&val)) { |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 318 | return v8::Local<v8::Value>(); |
Tom Sepez | d5a7e7f | 2021-11-10 03:05:00 +0000 | [diff] [blame] | 319 | } |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 320 | return val; |
| 321 | } |
| 322 | |
Tom Sepez | d5a7e7f | 2021-11-10 03:05:00 +0000 | [diff] [blame] | 323 | size_t GetArrayLengthHelper(v8::Local<v8::Array> pArray) { |
Tom Sepez | 1512c36 | 2020-03-19 22:13:52 +0000 | [diff] [blame] | 324 | if (pArray.IsEmpty()) |
| 325 | return 0; |
| 326 | return pArray->Length(); |
| 327 | } |
| 328 | |
Tom Sepez | acc0778 | 2020-03-19 20:02:00 +0000 | [diff] [blame] | 329 | void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str) { |
| 330 | pIsolate->ThrowException(NewStringHelper(pIsolate, str)); |
| 331 | } |
| 332 | |
| 333 | void ThrowExceptionHelper(v8::Isolate* pIsolate, WideStringView str) { |
| 334 | pIsolate->ThrowException(NewStringHelper(pIsolate, str)); |
| 335 | } |
| 336 | |
Tom Sepez | 3466e27 | 2020-03-18 23:33:35 +0000 | [diff] [blame] | 337 | } // namespace fxv8 |