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 "fxjs/include/fxjs_v8.h" | 7 #include "fxjs/include/fxjs_v8.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "core/fxcrt/include/fx_basic.h" | 11 #include "core/fxcrt/include/fx_basic.h" |
12 | 12 |
13 const wchar_t kFXJSValueNameString[] = L"string"; | |
14 const wchar_t kFXJSValueNameNumber[] = L"number"; | |
15 const wchar_t kFXJSValueNameBoolean[] = L"boolean"; | |
16 const wchar_t kFXJSValueNameDate[] = L"date"; | |
17 const wchar_t kFXJSValueNameObject[] = L"object"; | |
18 const wchar_t kFXJSValueNameFxobj[] = L"fxobj"; | |
19 const wchar_t kFXJSValueNameNull[] = L"null"; | |
20 const wchar_t kFXJSValueNameUndefined[] = L"undefined"; | |
21 | |
22 // Keep this consistent with the values defined in gin/public/context_holder.h | 13 // Keep this consistent with the values defined in gin/public/context_holder.h |
23 // (without actually requiring a dependency on gin itself for the standalone | 14 // (without actually requiring a dependency on gin itself for the standalone |
24 // embedders of PDFIum). The value we want to use is: | 15 // embedders of PDFIum). The value we want to use is: |
25 // kPerContextDataStartIndex + kEmbedderPDFium, which is 3. | 16 // kPerContextDataStartIndex + kEmbedderPDFium, which is 3. |
26 static const unsigned int kPerContextDataIndex = 3u; | 17 static const unsigned int kPerContextDataIndex = 3u; |
27 static unsigned int g_embedderDataSlot = 1u; | 18 static unsigned int g_embedderDataSlot = 1u; |
28 static v8::Isolate* g_isolate = nullptr; | 19 static v8::Isolate* g_isolate = nullptr; |
29 static size_t g_isolate_ref_count = 0; | 20 static size_t g_isolate_ref_count = 0; |
30 static FXJS_ArrayBufferAllocator* g_arrayBufferAllocator = nullptr; | 21 static FXJS_ArrayBufferAllocator* g_arrayBufferAllocator = nullptr; |
31 static v8::Global<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr; | 22 static v8::Global<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr; |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t | 535 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t |
545 // wide-strings isn't handled by v8, so use UTF8 as a common | 536 // wide-strings isn't handled by v8, so use UTF8 as a common |
546 // intermediate format. | 537 // intermediate format. |
547 CFX_ByteString utf8_message = message.UTF8Encode(); | 538 CFX_ByteString utf8_message = message.UTF8Encode(); |
548 pIsolate->ThrowException(v8::String::NewFromUtf8(pIsolate, | 539 pIsolate->ThrowException(v8::String::NewFromUtf8(pIsolate, |
549 utf8_message.c_str(), | 540 utf8_message.c_str(), |
550 v8::NewStringType::kNormal) | 541 v8::NewStringType::kNormal) |
551 .ToLocalChecked()); | 542 .ToLocalChecked()); |
552 } | 543 } |
553 | 544 |
554 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj) { | |
555 if (pObj.IsEmpty()) | |
556 return nullptr; | |
557 if (pObj->IsString()) | |
558 return kFXJSValueNameString; | |
559 if (pObj->IsNumber()) | |
560 return kFXJSValueNameNumber; | |
561 if (pObj->IsBoolean()) | |
562 return kFXJSValueNameBoolean; | |
563 if (pObj->IsDate()) | |
564 return kFXJSValueNameDate; | |
565 if (pObj->IsObject()) | |
566 return kFXJSValueNameObject; | |
567 if (pObj->IsNull()) | |
568 return kFXJSValueNameNull; | |
569 if (pObj->IsUndefined()) | |
570 return kFXJSValueNameUndefined; | |
571 return nullptr; | |
572 } | |
573 | |
574 void FXJS_SetPrivate(v8::Isolate* pIsolate, | 545 void FXJS_SetPrivate(v8::Isolate* pIsolate, |
575 v8::Local<v8::Object> pObj, | 546 v8::Local<v8::Object> pObj, |
576 void* p) { | 547 void* p) { |
577 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) | 548 if (pObj.IsEmpty() || !pObj->InternalFieldCount()) |
578 return; | 549 return; |
579 CFXJS_PerObjectData* pPerObjectData = static_cast<CFXJS_PerObjectData*>( | 550 CFXJS_PerObjectData* pPerObjectData = static_cast<CFXJS_PerObjectData*>( |
580 pObj->GetAlignedPointerFromInternalField(0)); | 551 pObj->GetAlignedPointerFromInternalField(0)); |
581 if (!pPerObjectData) | 552 if (!pPerObjectData) |
582 return; | 553 return; |
583 pPerObjectData->m_pPrivate = p; | 554 pPerObjectData->m_pPrivate = p; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 v8::Local<v8::Value> pValue) { | 804 v8::Local<v8::Value> pValue) { |
834 if (pValue.IsEmpty()) | 805 if (pValue.IsEmpty()) |
835 return v8::Local<v8::Array>(); | 806 return v8::Local<v8::Array>(); |
836 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 807 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
837 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 808 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
838 } | 809 } |
839 | 810 |
840 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 811 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { |
841 pTo = pFrom; | 812 pTo = pFrom; |
842 } | 813 } |
OLD | NEW |