| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxjse/value.h" | 7 #include "xfa/fxjse/value.h" |
| 8 | 8 |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 | 10 |
| 11 #include "xfa/fxjse/class.h" | 11 #include "xfa/fxjse/class.h" |
| 12 #include "xfa/fxjse/context.h" | 12 #include "xfa/fxjse/context.h" |
| 13 | 13 |
| 14 FX_BOOL FXJSE_Value_IsUndefined(CFXJSE_Value* pValue) { | 14 void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Message) { |
| 15 return pValue && pValue->IsUndefined(); | |
| 16 } | |
| 17 | |
| 18 FX_BOOL FXJSE_Value_IsNull(CFXJSE_Value* pValue) { | |
| 19 return pValue && pValue->IsNull(); | |
| 20 } | |
| 21 | |
| 22 FX_BOOL FXJSE_Value_IsBoolean(CFXJSE_Value* pValue) { | |
| 23 return pValue && pValue->IsBoolean(); | |
| 24 } | |
| 25 | |
| 26 FX_BOOL FXJSE_Value_IsUTF8String(CFXJSE_Value* pValue) { | |
| 27 return pValue && pValue->IsString(); | |
| 28 } | |
| 29 | |
| 30 FX_BOOL FXJSE_Value_IsNumber(CFXJSE_Value* pValue) { | |
| 31 return pValue && pValue->IsNumber(); | |
| 32 } | |
| 33 | |
| 34 FX_BOOL FXJSE_Value_IsObject(CFXJSE_Value* pValue) { | |
| 35 return pValue && pValue->IsObject(); | |
| 36 } | |
| 37 | |
| 38 FX_BOOL FXJSE_Value_IsArray(CFXJSE_Value* pValue) { | |
| 39 return pValue && pValue->IsArray(); | |
| 40 } | |
| 41 | |
| 42 FX_BOOL FXJSE_Value_IsFunction(CFXJSE_Value* pValue) { | |
| 43 return pValue && pValue->IsFunction(); | |
| 44 } | |
| 45 | |
| 46 void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, | |
| 47 const CFX_ByteStringC& utf8Message) { | |
| 48 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); | 15 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
| 49 ASSERT(pIsolate); | 16 ASSERT(pIsolate); |
| 50 | 17 |
| 51 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); | 18 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); |
| 52 v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( | 19 v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( |
| 53 pIsolate, utf8Message.c_str(), v8::String::kNormalString, | 20 pIsolate, utf8Message.c_str(), v8::String::kNormalString, |
| 54 utf8Message.GetLength()); | 21 utf8Message.GetLength()); |
| 55 v8::Local<v8::Value> hError; | 22 v8::Local<v8::Value> hError = v8::Exception::Error(hMessage); |
| 56 | |
| 57 if (utf8Name == "RangeError") { | |
| 58 hError = v8::Exception::RangeError(hMessage); | |
| 59 } else if (utf8Name == "ReferenceError") { | |
| 60 hError = v8::Exception::ReferenceError(hMessage); | |
| 61 } else if (utf8Name == "SyntaxError") { | |
| 62 hError = v8::Exception::SyntaxError(hMessage); | |
| 63 } else if (utf8Name == "TypeError") { | |
| 64 hError = v8::Exception::TypeError(hMessage); | |
| 65 } else { | |
| 66 hError = v8::Exception::Error(hMessage); | |
| 67 if (utf8Name != "Error" && !utf8Name.IsEmpty()) { | |
| 68 hError.As<v8::Object>()->Set( | |
| 69 v8::String::NewFromUtf8(pIsolate, "name"), | |
| 70 v8::String::NewFromUtf8(pIsolate, utf8Name.c_str(), | |
| 71 v8::String::kNormalString, | |
| 72 utf8Name.GetLength())); | |
| 73 } | |
| 74 } | |
| 75 pIsolate->ThrowException(hError); | 23 pIsolate->ThrowException(hError); |
| 76 } | 24 } |
| 77 | 25 |
| 78 CFXJSE_HostObject* CFXJSE_Value::ToHostObject(CFXJSE_Class* lpClass) const { | 26 CFXJSE_HostObject* CFXJSE_Value::ToHostObject(CFXJSE_Class* lpClass) const { |
| 79 ASSERT(!m_hValue.IsEmpty()); | 27 ASSERT(!m_hValue.IsEmpty()); |
| 80 | 28 |
| 81 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 29 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
| 82 v8::Local<v8::Value> pValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 30 v8::Local<v8::Value> pValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
| 83 ASSERT(!pValue.IsEmpty()); | 31 ASSERT(!pValue.IsEmpty()); |
| 84 | 32 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 if (lpRetValue) | 288 if (lpRetValue) |
| 341 lpRetValue->ForceSetValue(hReturnValue); | 289 lpRetValue->ForceSetValue(hReturnValue); |
| 342 | 290 |
| 343 if (lpLocalArgs) { | 291 if (lpLocalArgs) { |
| 344 for (uint32_t i = 0; i < nArgCount; i++) | 292 for (uint32_t i = 0; i < nArgCount; i++) |
| 345 lpLocalArgs[i].~Local(); | 293 lpLocalArgs[i].~Local(); |
| 346 FX_Free(lpLocalArgs); | 294 FX_Free(lpLocalArgs); |
| 347 } | 295 } |
| 348 return bRetValue; | 296 return bRetValue; |
| 349 } | 297 } |
| OLD | NEW |