More tidy of CJS_Object, kill implicit cast operator
authorTom Sepez <tsepez@chromium.org>
Mon, 21 Sep 2015 16:01:56 +0000 (09:01 -0700)
committerTom Sepez <tsepez@chromium.org>
Mon, 21 Sep 2015 16:01:56 +0000 (09:01 -0700)
R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1349423006 .

fpdfsdk/include/javascript/JS_Object.h
fpdfsdk/src/javascript/JS_Object.cpp
fpdfsdk/src/javascript/JS_Value.cpp
fpdfsdk/src/javascript/global.cpp

index a7772f1..c7f92ac 100644 (file)
@@ -60,9 +60,7 @@ class CJS_Object {
   virtual FX_BOOL InitInstance(IFXJS_Context* cc) { return TRUE; }
   virtual FX_BOOL ExitInstance() { return TRUE; }
 
-  operator v8::Local<v8::Object>() {
-    return v8::Local<v8::Object>::New(m_pIsolate, m_pObject);
-  }
+  v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(m_pIsolate); }
 
   // Takes ownership of |pObj|.
   void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); }
@@ -81,7 +79,7 @@ class CJS_Object {
 
  protected:
   nonstd::unique_ptr<CJS_EmbedObj> m_pEmbedObj;
-  v8::Global<v8::Object> m_pObject;
+  v8::Global<v8::Object> m_pV8Object;
   v8::Isolate* m_pIsolate;
 };
 
index 6891e6f..3cffec7 100644 (file)
@@ -83,22 +83,21 @@ void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) {
   data.SetSecondPassCallback(FreeObject);
 }
 
-CJS_Object::CJS_Object(v8::Local<v8::Object> pObject) : m_pEmbedObj(NULL) {
-  v8::Local<v8::Context> context = pObject->CreationContext();
-  m_pIsolate = context->GetIsolate();
-  m_pObject.Reset(m_pIsolate, pObject);
-};
+CJS_Object::CJS_Object(v8::Local<v8::Object> pObject) {
+  m_pIsolate = pObject->CreationContext()->GetIsolate();
+  m_pV8Object.Reset(m_pIsolate, pObject);
+}
 
 CJS_Object::~CJS_Object() {
-  m_pObject.Reset();
-};
+}
 
 void CJS_Object::MakeWeak() {
-  m_pObject.SetWeak(this, DisposeObject, v8::WeakCallbackType::kInternalFields);
+  m_pV8Object.SetWeak(this, DisposeObject,
+                      v8::WeakCallbackType::kInternalFields);
 }
 
 void CJS_Object::Dispose() {
-  m_pObject.Reset();
+  m_pV8Object.Reset();
 }
 
 CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) {
index 23def5d..a07c61f 100644 (file)
@@ -61,7 +61,7 @@ CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc)
     : m_isolate(isolate) {
   m_eType = VT_object;
   if (pJsDoc)
-    m_pValue = (v8::Local<v8::Object>)*pJsDoc;
+    m_pValue = pJsDoc->ToV8Object();
 }
 
 CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr)
@@ -172,13 +172,13 @@ void CJS_Value::operator=(v8::Local<v8::Object> pObj) {
 
 void CJS_Value::operator=(CJS_Object* pObj) {
   if (pObj)
-    operator=((v8::Local<v8::Object>)*pObj);
+    operator=(pObj->ToV8Object());
 }
 
 void CJS_Value::operator=(CJS_Document* pJsDoc) {
   m_eType = VT_object;
   if (pJsDoc) {
-    m_pValue = static_cast<v8::Local<v8::Object>>(*pJsDoc);
+    m_pValue = pJsDoc->ToV8Object();
   }
 }
 
index 51455d0..20276c3 100644 (file)
@@ -243,7 +243,7 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER,
                            pData->data.dData, false, "",
                            v8::Local<v8::Object>(), pData->bPersistent == 1);
-        FXJS_PutObjectNumber(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+        FXJS_PutObjectNumber(NULL, m_pJSObject->ToV8Object(),
                              pData->data.sKey.UTF8Decode().c_str(),
                              pData->data.dData);
         break;
@@ -251,7 +251,7 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0,
                            (bool)(pData->data.bData == 1), "",
                            v8::Local<v8::Object>(), pData->bPersistent == 1);
-        FXJS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+        FXJS_PutObjectBoolean(NULL, m_pJSObject->ToV8Object(),
                               pData->data.sKey.UTF8Decode().c_str(),
                               (bool)(pData->data.bData == 1));
         break;
@@ -259,29 +259,27 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0,
                            false, pData->data.sData, v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
-        FXJS_PutObjectString(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+        FXJS_PutObjectString(NULL, m_pJSObject->ToV8Object(),
                              pData->data.sKey.UTF8Decode().c_str(),
                              pData->data.sData.UTF8Decode().c_str());
         break;
       case JS_GLOBALDATA_TYPE_OBJECT: {
-        v8::Isolate* pRuntime =
-            FXJS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
+        v8::Isolate* pRuntime = FXJS_GetRuntime(m_pJSObject->ToV8Object());
         v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(pRuntime, NULL, -1);
 
         PutObjectProperty(pObj, &pData->data);
 
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0,
-                           false, "", (v8::Local<v8::Object>)pObj,
-                           pData->bPersistent == 1);
-        FXJS_PutObjectObject(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
-                             pData->data.sKey.UTF8Decode().c_str(),
-                             (v8::Local<v8::Object>)pObj);
+                           false, "", pObj, pData->bPersistent == 1);
+        FXJS_PutObjectObject(NULL, m_pJSObject->ToV8Object(),
+                             pData->data.sKey.UTF8Decode().c_str(), pObj);
+
       } break;
       case JS_GLOBALDATA_TYPE_NULL:
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false,
                            "", v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
-        FXJS_PutObjectNull(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+        FXJS_PutObjectNull(NULL, m_pJSObject->ToV8Object(),
                            pData->data.sKey.UTF8Decode().c_str());
         break;
     }
@@ -396,33 +394,27 @@ void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj,
 
     switch (pObjData->nType) {
       case JS_GLOBALDATA_TYPE_NUMBER:
-        FXJS_PutObjectNumber(NULL, (v8::Local<v8::Object>)pObj,
-                             pObjData->sKey.UTF8Decode().c_str(),
+        FXJS_PutObjectNumber(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
                              pObjData->dData);
         break;
       case JS_GLOBALDATA_TYPE_BOOLEAN:
-        FXJS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)pObj,
-                              pObjData->sKey.UTF8Decode().c_str(),
-                              (bool)(pObjData->bData == 1));
+        FXJS_PutObjectBoolean(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
+                              pObjData->bData == 1);
         break;
       case JS_GLOBALDATA_TYPE_STRING:
-        FXJS_PutObjectString(NULL, (v8::Local<v8::Object>)pObj,
-                             pObjData->sKey.UTF8Decode().c_str(),
+        FXJS_PutObjectString(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
                              pObjData->sData.UTF8Decode().c_str());
         break;
       case JS_GLOBALDATA_TYPE_OBJECT: {
-        v8::Isolate* pRuntime =
-            FXJS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
+        v8::Isolate* pRuntime = FXJS_GetRuntime(m_pJSObject->ToV8Object());
         v8::Local<v8::Object> pNewObj =
             FXJS_NewFxDynamicObj(pRuntime, NULL, -1);
         PutObjectProperty(pNewObj, pObjData);
-        FXJS_PutObjectObject(NULL, (v8::Local<v8::Object>)pObj,
-                             pObjData->sKey.UTF8Decode().c_str(),
-                             (v8::Local<v8::Object>)pNewObj);
+        FXJS_PutObjectObject(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
+                             pNewObj);
       } break;
       case JS_GLOBALDATA_TYPE_NULL:
-        FXJS_PutObjectNull(NULL, (v8::Local<v8::Object>)pObj,
-                           pObjData->sKey.UTF8Decode().c_str());
+        FXJS_PutObjectNull(NULL, pObj, pObjData->sKey.UTF8Decode().c_str());
         break;
     }
   }