Add some missing const in CFXJSE_Context These were declared non-const since there is likely a missing const in the v8 API that these are used in. Reduces a small amount of global writable data. -- rename to k-style names while at it. Change-Id: I800cea0a8f23fd319bf4c5f70b78465e151f7e9d Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/74831 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/README b/fxjs/README index a1cfe32..fb49f59 100644 --- a/fxjs/README +++ b/fxjs/README
@@ -20,8 +20,8 @@ objects, regardless of the FXJS/FXJSE distinction. Slot 0 is the tag and contains either: kPerObjectDataTag for FXJS objects, or - g_FXJSEHostObjectTag for FXJSE Host objects, or - g_FXJSEProxyObjectTag for a global proxy object under FXJSE, or + kFXJSEHostObjectTag for FXJSE Host objects, or + kFXJSEProxyObjectTag for a global proxy object under FXJSE, or One of 4 specific FXJSE_CLASS_DESCRIPTOR globals for FXJSE classes: GlobalClassDescriptor NormalClassDescriptor @@ -30,10 +30,10 @@ Slot 1's contents are determined by these tags: kPerObjectDataTag means an aligned pointer to CFXJS_PerObjectData. - g_FXJSEHostObjectTag means an aligned pointer to CFXJSE_HostObject. - g_FXJSEProxyObjectTag means nullptr, and to check the prototype instead. + kFXJSEHostObjectTag means an aligned pointer to CFXJSE_HostObject. + kFXJSEProxyObjectTag means nullptr, and to check the prototype instead. A FXJSE_CLASS_DESCRIPTOR pointer means to expect an actual v8 function - object (or a string naming that function), and not an aligned pointer. + object (or a string naming that function), and not an aligned pointer. Because PDFium uses V8 for various unrelated purposes, there may be up to four v8::Contexts (JS Global Objects) associated with each document. One is
diff --git a/fxjs/xfa/cfxjse_context.cpp b/fxjs/xfa/cfxjse_context.cpp index 26a07e9..3ea9a18 100644 --- a/fxjs/xfa/cfxjse_context.cpp +++ b/fxjs/xfa/cfxjse_context.cpp
@@ -55,8 +55,8 @@ "};"; // Only address matters, values are for humans debuging here. -char g_FXJSEHostObjectTag[] = "FXJSE Host Object"; -char g_FXJSEProxyObjectTag[] = "FXJSE Proxy Object"; +const char kFXJSEHostObjectTag[] = "FXJSE Host Object"; +const char kFXJSEProxyObjectTag[] = "FXJSE Proxy Object"; v8::Local<v8::Object> CreateReturnValue(v8::Isolate* pIsolate, v8::TryCatch* trycatch) { @@ -127,7 +127,8 @@ void FXJSE_UpdateProxyBinding(v8::Local<v8::Object> hObject) { ASSERT(!hObject.IsEmpty()); ASSERT(hObject->InternalFieldCount() == 2); - hObject->SetAlignedPointerInInternalField(0, g_FXJSEProxyObjectTag); + hObject->SetAlignedPointerInInternalField( + 0, const_cast<char*>(kFXJSEProxyObjectTag)); hObject->SetAlignedPointerInInternalField(1, nullptr); } @@ -137,7 +138,8 @@ CFXJSE_HostObject* lpNewBinding) { ASSERT(!hObject.IsEmpty()); ASSERT(hObject->InternalFieldCount() == 2); - hObject->SetAlignedPointerInInternalField(0, g_FXJSEHostObjectTag); + hObject->SetAlignedPointerInInternalField( + 0, const_cast<char*>(kFXJSEHostObjectTag)); hObject->SetAlignedPointerInInternalField(1, lpNewBinding); } @@ -156,7 +158,7 @@ v8::Local<v8::Object> hObject = hJSObject; if (hObject->InternalFieldCount() != 2 || - hObject->GetAlignedPointerFromInternalField(0) == g_FXJSEProxyObjectTag) { + hObject->GetAlignedPointerFromInternalField(0) == kFXJSEProxyObjectTag) { v8::Local<v8::Value> hProtoObject = hObject->GetPrototype(); if (hProtoObject.IsEmpty() || !hProtoObject->IsObject()) return nullptr; @@ -165,7 +167,7 @@ if (hObject->InternalFieldCount() != 2) return nullptr; } - if (hObject->GetAlignedPointerFromInternalField(0) != g_FXJSEHostObjectTag) + if (hObject->GetAlignedPointerFromInternalField(0) != kFXJSEHostObjectTag) return nullptr; return static_cast<CFXJSE_HostObject*>(