Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(831)

Side by Side Diff: fxjs/fxjs_v8.cpp

Issue 2154503002: Remove type info from CJS_Value, interrogate v8 instead (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: nit Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/javascript/global.cpp ('k') | fxjs/include/fxjs_v8.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/global.cpp ('k') | fxjs/include/fxjs_v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698