Ensure functions in FXJS_V8 are prefixed by FXJS_.
authorTom Sepez <tsepez@chromium.org>
Wed, 16 Sep 2015 17:42:08 +0000 (10:42 -0700)
committerTom Sepez <tsepez@chromium.org>
Wed, 16 Sep 2015 17:42:08 +0000 (10:42 -0700)
Currently, its hard to tell which functions come from the JS_
layer at fpdfsdk/include/javascript vs. which functions come
from the FXJS_V8 layer at fpdfsdk/include/jsapi.  Until we
take up the task of using namespaces, at least make the
prefix consistent.

Move objects out of FXJS_V8 that are really part of JS_.

R=thestig@chromium.org

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

19 files changed:
fpdfsdk/include/javascript/JS_Define.h
fpdfsdk/include/javascript/JS_Runtime.h
fpdfsdk/include/javascript/JS_Value.h
fpdfsdk/include/jsapi/fxjs_v8.h
fpdfsdk/src/javascript/Consts.cpp
fpdfsdk/src/javascript/Document.cpp
fpdfsdk/src/javascript/Field.cpp
fpdfsdk/src/javascript/JS_Context.cpp
fpdfsdk/src/javascript/JS_EventHandler.cpp
fpdfsdk/src/javascript/JS_Object.cpp
fpdfsdk/src/javascript/JS_Runtime.cpp
fpdfsdk/src/javascript/JS_Value.cpp
fpdfsdk/src/javascript/PublicMethods.cpp
fpdfsdk/src/javascript/app.cpp
fpdfsdk/src/javascript/event.cpp
fpdfsdk/src/javascript/global.cpp
fpdfsdk/src/javascript/util.cpp
fpdfsdk/src/jsapi/fxjs_v8.cpp
fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp

index 4b1b224..04f5ece 100644 (file)
@@ -88,14 +88,14 @@ void JSPropGetter(const char* prop_name_string,
   v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
   IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
   IFXJS_Context* pContext = pRuntime->GetCurrentContext();
-  CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder());
+  CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
   C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
   CFX_WideString sError;
   CJS_PropValue value(isolate);
   value.StartGetting();
   if (!(pObj->*M)(pContext, value, sError)) {
-    JS_Error(isolate,
-             JSFormatErrorString(class_name_string, prop_name_string, sError));
+    FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
+                                            sError));
     return;
   }
   info.GetReturnValue().Set((v8::Local<v8::Value>)value);
@@ -118,14 +118,14 @@ void JSPropSetter(const char* prop_name_string,
   v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
   IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
   IFXJS_Context* pContext = pRuntime->GetCurrentContext();
-  CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder());
+  CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
   C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
   CFX_WideString sError;
-  CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown));
+  CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
   propValue.StartSetting();
   if (!(pObj->*M)(pContext, propValue, sError)) {
-    JS_Error(isolate,
-             JSFormatErrorString(class_name_string, prop_name_string, sError));
+    FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
+                                            sError));
   }
 }
 
@@ -164,15 +164,15 @@ void JSMethod(const char* method_name_string,
   IFXJS_Context* cc = pRuntime->GetCurrentContext();
   CJS_Parameters parameters;
   for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
-    parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
+    parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
   }
   CJS_Value valueRes(isolate);
-  CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder());
+  CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
   C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
   CFX_WideString sError;
   if (!(pObj->*M)(cc, parameters, valueRes, sError)) {
-    JS_Error(isolate, JSFormatErrorString(class_name_string, method_name_string,
-                                          sError));
+    FXJS_Error(isolate, JSFormatErrorString(class_name_string,
+                                            method_name_string, sError));
     return;
   }
   info.GetReturnValue().Set(valueRes.ToV8Value());
@@ -205,36 +205,36 @@ void JSMethod(const char* method_name_string,
   static JSMethodSpec JS_Class_Methods[];                                   \
   static const wchar_t* m_pClassName
 
-#define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name)    \
-  const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);      \
-  void js_class_name::JSConstructor(IFXJS_Context* cc,                         \
-                                    v8::Local<v8::Object> obj,                 \
-                                    v8::Local<v8::Object> global) {            \
-    CJS_Object* pObj = new js_class_name(obj);                                 \
-    pObj->SetEmbedObject(new class_alternate(pObj));                           \
-    JS_SetPrivate(NULL, obj, (void*)pObj);                                     \
-    pObj->InitInstance(cc);                                                    \
-  }                                                                            \
-                                                                               \
-  void js_class_name::JSDestructor(v8::Local<v8::Object> obj) {                \
-    js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj);            \
-    pObj->ExitInstance();                                                      \
-    delete pObj;                                                               \
-  }                                                                            \
-                                                                               \
-  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                   \
-                                      FXJSOBJTYPE eObjType) {                  \
-    int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName,       \
-                                  eObjType, JSConstructor, JSDestructor);      \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) {          \
-      JS_DefineObjProperty(pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \
-                           JS_Class_Properties[i].pPropGet,                    \
-                           JS_Class_Properties[i].pPropPut);                   \
-    }                                                                          \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) {             \
-      JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName,      \
-                         JS_Class_Methods[i].pMethodCall);                     \
-    }                                                                          \
+#define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name)  \
+  const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);    \
+  void js_class_name::JSConstructor(IFXJS_Context* cc,                       \
+                                    v8::Local<v8::Object> obj,               \
+                                    v8::Local<v8::Object> global) {          \
+    CJS_Object* pObj = new js_class_name(obj);                               \
+    pObj->SetEmbedObject(new class_alternate(pObj));                         \
+    FXJS_SetPrivate(NULL, obj, (void*)pObj);                                 \
+    pObj->InitInstance(cc);                                                  \
+  }                                                                          \
+                                                                             \
+  void js_class_name::JSDestructor(v8::Local<v8::Object> obj) {              \
+    js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj);        \
+    pObj->ExitInstance();                                                    \
+    delete pObj;                                                             \
+  }                                                                          \
+                                                                             \
+  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                 \
+                                      FXJSOBJTYPE eObjType) {                \
+    int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName,   \
+                                    eObjType, JSConstructor, JSDestructor);  \
+    for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) {        \
+      FXJS_DefineObjProperty(                                                \
+          pIsolate, nObjDefnID, JS_Class_Properties[i].pName,                \
+          JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \
+    }                                                                        \
+    for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) {           \
+      FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName,  \
+                           JS_Class_Methods[i].pMethodCall);                 \
+    }                                                                        \
   }
 
 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \
@@ -248,19 +248,19 @@ void JSMethod(const char* method_name_string,
   static JSConstSpec JS_Class_Consts[];                                     \
   static const wchar_t* m_pClassName
 
-#define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name)               \
-  const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \
-  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,              \
-                                      FXJSOBJTYPE eObjType) {             \
-    int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName,  \
-                                  eObjType, NULL, NULL);                  \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) {         \
-      JS_DefineObjConst(                                                  \
-          pIsolate, nObjDefnID, JS_Class_Consts[i].pName,                 \
-          JS_Class_Consts[i].t == 0                                       \
-              ? JS_NewNumber(pIsolate, JS_Class_Consts[i].number)         \
-              : JS_NewString(pIsolate, JS_Class_Consts[i].string));       \
-    }                                                                     \
+#define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name)                \
+  const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);  \
+  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,               \
+                                      FXJSOBJTYPE eObjType) {              \
+    int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \
+                                    eObjType, NULL, NULL);                 \
+    for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) {          \
+      FXJS_DefineObjConst(                                                 \
+          pIsolate, nObjDefnID, JS_Class_Consts[i].pName,                  \
+          JS_Class_Consts[i].t == 0                                        \
+              ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number)        \
+              : FXJS_NewString(pIsolate, JS_Class_Consts[i].string));      \
+    }                                                                      \
   }
 
 /* ===================================== SPECIAL JS CLASS
@@ -275,7 +275,7 @@ void JSSpecialPropQuery(const char*,
   CFX_WideString propname =
       CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
   CJS_Object* pJSObj =
-      reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+      reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
   FX_BOOL bRet = pObj->QueryProperty(propname.c_str());
   info.GetReturnValue().Set(bRet ? 4 : 0);
@@ -294,7 +294,7 @@ void JSSpecialPropGet(const char* class_name,
   IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
   IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
   CJS_Object* pJSObj =
-      reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+      reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
   v8::String::Utf8Value utf8_value(property);
   CFX_WideString propname =
@@ -303,7 +303,7 @@ void JSSpecialPropGet(const char* class_name,
   CJS_PropValue value(isolate);
   value.StartGetting();
   if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
-    JS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
+    FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
     return;
   }
   info.GetReturnValue().Set((v8::Local<v8::Value>)value);
@@ -323,16 +323,16 @@ void JSSpecialPropPut(const char* class_name,
   IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
   IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
   CJS_Object* pJSObj =
-      reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+      reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
   v8::String::Utf8Value utf8_value(property);
   CFX_WideString propname =
       CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
   CFX_WideString sError;
-  CJS_PropValue PropValue(CJS_Value(isolate, value, VT_unknown));
+  CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
   PropValue.StartSetting();
   if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
-    JS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
+    FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
   }
 }
 
@@ -349,7 +349,7 @@ void JSSpecialPropDel(const char* class_name,
   IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
   IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
   CJS_Object* pJSObj =
-      reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+      reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
   v8::String::Utf8Value utf8_value(property);
   CFX_WideString propname =
@@ -358,7 +358,7 @@ void JSSpecialPropDel(const char* class_name,
   if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
     CFX_ByteString cbName;
     cbName.Format("%s.%s", class_name, "DelProperty");
-    // Probably a missing call to JS_Error().
+    // Probably a missing call to JSFX_Error().
   }
 }
 
@@ -411,12 +411,12 @@ void JSSpecialPropDel(const char* class_name,
                                     v8::Local<v8::Object> global) {            \
     CJS_Object* pObj = new js_class_name(obj);                                 \
     pObj->SetEmbedObject(new class_alternate(pObj));                           \
-    JS_SetPrivate(NULL, obj, (void*)pObj);                                     \
+    FXJS_SetPrivate(NULL, obj, (void*)pObj);                                   \
     pObj->InitInstance(cc);                                                    \
   }                                                                            \
                                                                                \
   void js_class_name::JSDestructor(v8::Local<v8::Object> obj) {                \
-    js_class_name* pObj = (js_class_name*)JS_GetPrivate(NULL, obj);            \
+    js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj);          \
     ASSERT(pObj != NULL);                                                      \
     pObj->ExitInstance();                                                      \
     delete pObj;                                                               \
@@ -424,19 +424,19 @@ void JSSpecialPropDel(const char* class_name,
                                                                                \
   void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                   \
                                       FXJSOBJTYPE eObjType) {                  \
-    int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName,       \
-                                  eObjType, JSConstructor, JSDestructor);      \
+    int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName,     \
+                                    eObjType, JSConstructor, JSDestructor);    \
     for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) {          \
-      JS_DefineObjProperty(pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \
-                           JS_Class_Properties[i].pPropGet,                    \
-                           JS_Class_Properties[i].pPropPut);                   \
+      FXJS_DefineObjProperty(                                                  \
+          pIsolate, nObjDefnID, JS_Class_Properties[i].pName,                  \
+          JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut);   \
     }                                                                          \
                                                                                \
     for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) {             \
-      JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName,      \
-                         JS_Class_Methods[i].pMethodCall);                     \
+      FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName,    \
+                           JS_Class_Methods[i].pMethodCall);                   \
     }                                                                          \
-    JS_DefineObjAllProperties(                                                 \
+    FXJS_DefineObjAllProperties(                                               \
         pIsolate, nObjDefnID,                                                  \
         js_class_name::queryprop_##js_class_name##_static,                     \
         js_class_name::getprop_##js_class_name##_static,                       \
@@ -463,12 +463,12 @@ void JSGlobalFunc(const char* func_name_string,
   IFXJS_Context* cc = pRuntime->GetCurrentContext();
   CJS_Parameters parameters;
   for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
-    parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
+    parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
   }
   CJS_Value valueRes(isolate);
   CFX_WideString sError;
   if (!(*F)(cc, parameters, valueRes, sError)) {
-    JS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
+    FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
     return;
   }
   info.GetReturnValue().Set(valueRes.ToV8Value());
@@ -491,14 +491,15 @@ void JSGlobalFunc(const char* func_name_string,
 
 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD()
 
-#define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name)                         \
-  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) {                \
-    for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) {              \
-      JS_DefineGlobalMethod(pIsolate, js_class_name::global_methods[i].pName, \
-                            js_class_name::global_methods[i].pMethodCall);    \
-    }                                                                         \
+#define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name)                        \
+  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) {               \
+    for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) {             \
+      FXJS_DefineGlobalMethod(pIsolate,                                      \
+                              js_class_name::global_methods[i].pName,        \
+                              js_class_name::global_methods[i].pMethodCall); \
+    }                                                                        \
   }
 
-FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p);
+CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p);
 
 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
index 9d1927f..a5d6954 100644 (file)
@@ -59,7 +59,7 @@ class CJS_Runtime : public IFXJS_Runtime {
   CJS_FieldEvent* m_pFieldEventPath;
   v8::Isolate* m_isolate;
   bool m_isolateManaged;
-  nonstd::unique_ptr<JS_ArrayBufferAllocator> m_pArrayBufferAllocator;
+  nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator;
   v8::Global<v8::Context> m_context;
 };
 
index 771214d..384e772 100644 (file)
@@ -17,8 +17,20 @@ class CJS_Object;
 
 class CJS_Value {
  public:
+  enum Type {
+    VT_unknown,
+    VT_string,
+    VT_number,
+    VT_boolean,
+    VT_date,
+    VT_object,
+    VT_fxobject,
+    VT_null,
+    VT_undefined
+  };
+
   CJS_Value(v8::Isolate* isolate);
-  CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, FXJSVALUETYPE t);
+  CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t);
   CJS_Value(v8::Isolate* isolate, const int& iValue);
   CJS_Value(v8::Isolate* isolate, const double& dValue);
   CJS_Value(v8::Isolate* isolate, const float& fValue);
@@ -33,10 +45,11 @@ class CJS_Value {
   ~CJS_Value();
 
   void SetNull();
-  void Attach(v8::Local<v8::Value> pValue, FXJSVALUETYPE t);
+  void Attach(v8::Local<v8::Value> pValue, Type t);
   void Attach(CJS_Value* pValue);
   void Detach();
 
+  Type GetType() const;
   int ToInt() const;
   bool ToBool() const;
   double ToDouble() const;
@@ -63,16 +76,14 @@ class CJS_Value {
 
   FX_BOOL IsArrayObject() const;
   FX_BOOL IsDateObject() const;
-  FXJSVALUETYPE GetType() const;
-
   FX_BOOL ConvertToArray(CJS_Array&) const;
   FX_BOOL ConvertToDate(CJS_Date&) const;
 
   v8::Isolate* GetIsolate() { return m_isolate; }
 
  protected:
+  Type m_eType;
   v8::Local<v8::Value> m_pValue;
-  FXJSVALUETYPE m_eType;
   v8::Isolate* m_isolate;
 };
 
@@ -190,4 +201,18 @@ class CJS_Date {
   v8::Isolate* m_isolate;
 };
 
+double JS_GetDateTime();
+int JS_GetYearFromTime(double dt);
+int JS_GetMonthFromTime(double dt);
+int JS_GetDayFromTime(double dt);
+int JS_GetHourFromTime(double dt);
+int JS_GetMinFromTime(double dt);
+int JS_GetSecFromTime(double dt);
+double JS_DateParse(const wchar_t* string);
+double JS_MakeDay(int nYear, int nMonth, int nDay);
+double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
+double JS_MakeDate(double day, double time);
+bool JS_PortIsNan(double d);
+double JS_LocalTime(double d);
+
 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_
index 6e4fc6f..e455bfc 100644 (file)
 #include "../../../core/include/fxcrt/fx_string.h"  // For CFX_WideString
 
 enum FXJSOBJTYPE {
-  JS_DYNAMIC = 0,
-  JS_STATIC = 1,
-};
-
-enum FXJSVALUETYPE {
-  VT_unknown,
-  VT_string,
-  VT_number,
-  VT_boolean,
-  VT_date,
-  VT_object,
-  VT_fxobject,
-  VT_null,
-  VT_undefined
+  FXJS_DYNAMIC = 0,
+  FXJS_STATIC = 1,
 };
 
 struct FXJSErr {
@@ -46,20 +34,28 @@ extern const wchar_t kFXJSValueNameNull[];
 extern const wchar_t kFXJSValueNameUndefined[];
 
 // FXJS_V8 places no interpretation on these two classes; it merely
-// passes them on to the caller-provided LP_CONSTRUCTORs.
+// passes them on to the caller-provided FXJS_CONSTRUCTORs.
 class IFXJS_Context;
 class IFXJS_Runtime;
 
-class JS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
+class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
   void* Allocate(size_t length) override;
   void* AllocateUninitialized(size_t length) override;
   void Free(void* data, size_t length) override;
 };
 
-typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc,
-                               v8::Local<v8::Object> obj,
-                               v8::Local<v8::Object> global);
-typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj);
+using FXJS_CONSTRUCTOR = void (*)(IFXJS_Context* cc,
+                                  v8::Local<v8::Object> obj,
+                                  v8::Local<v8::Object> global);
+using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> obj);
+
+// Call before making FXJS_PrepareIsolate call.
+void FXJS_Initialize(unsigned int embedderDataSlot);
+void FXJS_Release();
+
+// Call before making FXJS_Define* calls. Resources allocated here are cleared
+// as part of FXJS_ReleaseRuntime().
+void FXJS_PrepareIsolate(v8::Isolate* pIsolate);
 
 // Call before making JS_PrepareIsolate call.
 void JS_Initialize(unsigned int embedderDataSlot);
@@ -70,156 +66,146 @@ void JS_Release();
 void JS_PrepareIsolate(v8::Isolate* pIsolate);
 
 // Always returns a valid, newly-created objDefnID.
-int JS_DefineObj(v8::Isolate* pIsolate,
-                 const wchar_t* sObjName,
-                 FXJSOBJTYPE eObjType,
-                 LP_CONSTRUCTOR pConstructor,
-                 LP_DESTRUCTOR pDestructor);
-
-void JS_DefineObjMethod(v8::Isolate* pIsolate,
-                        int nObjDefnID,
-                        const wchar_t* sMethodName,
-                        v8::FunctionCallback pMethodCall);
-void JS_DefineObjProperty(v8::Isolate* pIsolate,
+int FXJS_DefineObj(v8::Isolate* pIsolate,
+                   const wchar_t* sObjName,
+                   FXJSOBJTYPE eObjType,
+                   FXJS_CONSTRUCTOR pConstructor,
+                   FXJS_DESTRUCTOR pDestructor);
+
+void FXJS_DefineObjMethod(v8::Isolate* pIsolate,
                           int nObjDefnID,
-                          const wchar_t* sPropName,
-                          v8::AccessorGetterCallback pPropGet,
-                          v8::AccessorSetterCallback pPropPut);
-void JS_DefineObjAllProperties(v8::Isolate* pIsolate,
-                               int nObjDefnID,
-                               v8::NamedPropertyQueryCallback pPropQurey,
-                               v8::NamedPropertyGetterCallback pPropGet,
-                               v8::NamedPropertySetterCallback pPropPut,
-                               v8::NamedPropertyDeleterCallback pPropDel);
-void JS_DefineObjConst(v8::Isolate* pIsolate,
-                       int nObjDefnID,
-                       const wchar_t* sConstName,
-                       v8::Local<v8::Value> pDefault);
-void JS_DefineGlobalMethod(v8::Isolate* pIsolate,
-                           const wchar_t* sMethodName,
-                           v8::FunctionCallback pMethodCall);
-void JS_DefineGlobalConst(v8::Isolate* pIsolate,
-                          const wchar_t* sConstName,
-                          v8::Local<v8::Value> pDefault);
-
-// Called after JS_Define* calls made.
-void JS_InitializeRuntime(v8::Isolate* pIsolate,
-                          IFXJS_Runtime* pFXRuntime,
-                          IFXJS_Context* context,
-                          v8::Global<v8::Context>& v8PersistentContext);
-void JS_ReleaseRuntime(v8::Isolate* pIsolate,
-                       v8::Global<v8::Context>& v8PersistentContext);
-
-// Called after JS_InitializeRuntime call made.
-int JS_Execute(v8::Isolate* pIsolate,
-               IFXJS_Context* pJSContext,
-               const wchar_t* script,
-               long length,
-               FXJSErr* perror);
-
-v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
-                                         IFXJS_Context* pJSContext,
-                                         int nObjDefnID);
-v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID);
-v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate);
-int JS_GetObjDefnID(v8::Local<v8::Object> pObj);
-v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj);
-int JS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName);
-void JS_Error(v8::Isolate* isolate, const CFX_WideString& message);
-unsigned JS_CalcHash(const wchar_t* main, unsigned nLen);
-unsigned JS_CalcHash(const wchar_t* main);
-const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj);
-void JS_SetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, void* p);
-void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj);
-void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p);
-void* JS_GetPrivate(v8::Local<v8::Object> pObj);
-void JS_FreePrivate(void* p);
-void JS_FreePrivate(v8::Local<v8::Object> pObj);
-v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj);
-v8::Local<v8::Value> JS_GetObjectElement(v8::Isolate* pIsolate,
-                                         v8::Local<v8::Object> pObj,
-                                         const wchar_t* PropertyName);
-v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate,
-                                              v8::Local<v8::Object> pObj);
-void JS_PutObjectString(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        const wchar_t* sValue);
-void JS_PutObjectNumber(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        int nValue);
-void JS_PutObjectNumber(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        float fValue);
-void JS_PutObjectNumber(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        double dValue);
-void JS_PutObjectBoolean(v8::Isolate* pIsolate,
-                         v8::Local<v8::Object> pObj,
-                         const wchar_t* PropertyName,
-                         bool bValue);
-void JS_PutObjectObject(v8::Isolate* pIsolate,
+                          const wchar_t* sMethodName,
+                          v8::FunctionCallback pMethodCall);
+void FXJS_DefineObjProperty(v8::Isolate* pIsolate,
+                            int nObjDefnID,
+                            const wchar_t* sPropName,
+                            v8::AccessorGetterCallback pPropGet,
+                            v8::AccessorSetterCallback pPropPut);
+void FXJS_DefineObjAllProperties(v8::Isolate* pIsolate,
+                                 int nObjDefnID,
+                                 v8::NamedPropertyQueryCallback pPropQurey,
+                                 v8::NamedPropertyGetterCallback pPropGet,
+                                 v8::NamedPropertySetterCallback pPropPut,
+                                 v8::NamedPropertyDeleterCallback pPropDel);
+void FXJS_DefineObjConst(v8::Isolate* pIsolate,
+                         int nObjDefnID,
+                         const wchar_t* sConstName,
+                         v8::Local<v8::Value> pDefault);
+void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate,
+                             const wchar_t* sMethodName,
+                             v8::FunctionCallback pMethodCall);
+void FXJS_DefineGlobalConst(v8::Isolate* pIsolate,
+                            const wchar_t* sConstName,
+                            v8::Local<v8::Value> pDefault);
+
+// Called after FXJS_Define* calls made.
+void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
+                            IFXJS_Runtime* pFXRuntime,
+                            IFXJS_Context* context,
+                            v8::Global<v8::Context>& v8PersistentContext);
+void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
+                         v8::Global<v8::Context>& v8PersistentContext);
+
+// Called after FXJS_InitializeRuntime call made.
+int FXJS_Execute(v8::Isolate* pIsolate,
+                 IFXJS_Context* pJSContext,
+                 const wchar_t* script,
+                 long length,
+                 FXJSErr* perror);
+
+v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate,
+                                           IFXJS_Context* pJSContext,
+                                           int nObjDefnID);
+v8::Local<v8::Object> FXJS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID);
+v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate);
+int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj);
+v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj);
+int FXJS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName);
+void FXJS_Error(v8::Isolate* isolate, const CFX_WideString& message);
+const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj);
+void FXJS_SetPrivate(v8::Isolate* pIsolate,
+                     v8::Local<v8::Object> pObj,
+                     void* p);
+void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj);
+void FXJS_SetPrivate(v8::Local<v8::Object> pObj, void* p);
+void* FXJS_GetPrivate(v8::Local<v8::Object> pObj);
+void FXJS_FreePrivate(void* p);
+void FXJS_FreePrivate(v8::Local<v8::Object> pObj);
+v8::Local<v8::String> FXJS_WSToJSString(v8::Isolate* pIsolate,
+                                        const wchar_t* PropertyName,
+                                        int Len = -1);
+v8::Local<v8::Value> FXJS_GetObjectValue(v8::Local<v8::Object> pObj);
+v8::Local<v8::Value> FXJS_GetObjectElement(v8::Isolate* pIsolate,
+                                           v8::Local<v8::Object> pObj,
+                                           const wchar_t* PropertyName);
+v8::Local<v8::Array> FXJS_GetObjectElementNames(v8::Isolate* pIsolate,
+                                                v8::Local<v8::Object> pObj);
+void FXJS_PutObjectString(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          const wchar_t* sValue);
+void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          int nValue);
+void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          float fValue);
+void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          double dValue);
+void FXJS_PutObjectBoolean(v8::Isolate* pIsolate,
+                           v8::Local<v8::Object> pObj,
+                           const wchar_t* PropertyName,
+                           bool bValue);
+void FXJS_PutObjectObject(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          v8::Local<v8::Object> pPut);
+void FXJS_PutObjectNull(v8::Isolate* pIsolate,
                         v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        v8::Local<v8::Object> pPut);
-void JS_PutObjectNull(v8::Isolate* pIsolate,
-                      v8::Local<v8::Object> pObj,
-                      const wchar_t* PropertyName);
-unsigned JS_PutArrayElement(v8::Isolate* pIsolate,
-                            v8::Local<v8::Array> pArray,
-                            unsigned index,
-                            v8::Local<v8::Value> pValue,
-                            FXJSVALUETYPE eType);
-v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate,
-                                        v8::Local<v8::Array> pArray,
-                                        unsigned index);
-unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray);
-v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate,
-                                     v8::Local<v8::Value> pList,
-                                     int index);
-
-v8::Local<v8::Array> JS_NewArray(v8::Isolate* pIsolate);
-v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, int number);
-v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, double number);
-v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, float number);
-v8::Local<v8::Value> JS_NewBoolean(v8::Isolate* pIsolate, bool b);
-v8::Local<v8::Value> JS_NewObject(v8::Isolate* pIsolate,
-                                  v8::Local<v8::Object> pObj);
-v8::Local<v8::Value> JS_NewObject2(v8::Isolate* pIsolate,
-                                   v8::Local<v8::Array> pObj);
-v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate, const wchar_t* string);
-v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
-                                  const wchar_t* string,
-                                  unsigned nLen);
-v8::Local<v8::Value> JS_NewNull();
-v8::Local<v8::Value> JS_NewDate(v8::Isolate* pIsolate, double d);
-v8::Local<v8::Value> JS_NewValue(v8::Isolate* pIsolate);
-
-int JS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
-bool JS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
-double JS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
-v8::Local<v8::Object> JS_ToObject(v8::Isolate* pIsolate,
+                        const wchar_t* PropertyName);
+unsigned FXJS_PutArrayElement(v8::Isolate* pIsolate,
+                              v8::Local<v8::Array> pArray,
+                              unsigned index,
+                              v8::Local<v8::Value> pValue);
+v8::Local<v8::Value> FXJS_GetArrayElement(v8::Isolate* pIsolate,
+                                          v8::Local<v8::Array> pArray,
+                                          unsigned index);
+unsigned FXJS_GetArrayLength(v8::Local<v8::Array> pArray);
+v8::Local<v8::Value> FXJS_GetListValue(v8::Isolate* pIsolate,
+                                       v8::Local<v8::Value> pList,
+                                       int index);
+
+v8::Local<v8::Array> FXJS_NewArray(v8::Isolate* pIsolate);
+v8::Local<v8::Value> FXJS_NewNumber(v8::Isolate* pIsolate, int number);
+v8::Local<v8::Value> FXJS_NewNumber(v8::Isolate* pIsolate, double number);
+v8::Local<v8::Value> FXJS_NewNumber(v8::Isolate* pIsolate, float number);
+v8::Local<v8::Value> FXJS_NewBoolean(v8::Isolate* pIsolate, bool b);
+v8::Local<v8::Value> FXJS_NewObject(v8::Isolate* pIsolate,
+                                    v8::Local<v8::Object> pObj);
+v8::Local<v8::Value> FXJS_NewObject2(v8::Isolate* pIsolate,
+                                     v8::Local<v8::Array> pObj);
+v8::Local<v8::Value> FXJS_NewString(v8::Isolate* pIsolate,
+                                    const wchar_t* string);
+v8::Local<v8::Value> FXJS_NewString(v8::Isolate* pIsolate,
+                                    const wchar_t* string,
+                                    unsigned nLen);
+v8::Local<v8::Value> FXJS_NewNull();
+v8::Local<v8::Value> FXJS_NewDate(v8::Isolate* pIsolate, double d);
+v8::Local<v8::Value> FXJS_NewValue(v8::Isolate* pIsolate);
+
+int FXJS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
+bool FXJS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
+double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
+v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate,
+                                    v8::Local<v8::Value> pValue);
+CFX_WideString FXJS_ToString(v8::Isolate* pIsolate,
+                             v8::Local<v8::Value> pValue);
+v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate,
                                   v8::Local<v8::Value> pValue);
-CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
-v8::Local<v8::Array> JS_ToArray(v8::Isolate* pIsolate,
-                                v8::Local<v8::Value> pValue);
-void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
-
-double JS_GetDateTime();
-int JS_GetYearFromTime(double dt);
-int JS_GetMonthFromTime(double dt);
-int JS_GetDayFromTime(double dt);
-int JS_GetHourFromTime(double dt);
-int JS_GetMinFromTime(double dt);
-int JS_GetSecFromTime(double dt);
-double JS_DateParse(const wchar_t* string);
-double JS_MakeDay(int nYear, int nMonth, int nDay);
-double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
-double JS_MakeDate(double day, double time);
-bool JS_PortIsNan(double d);
-double JS_LocalTime(double d);
+void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
 
 #endif  // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_
index 9574c44..acb4966 100644 (file)
@@ -132,7 +132,8 @@ IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype)
 static void DefineGlobalConstString(v8::Isolate* pIsolate,
                                     const wchar_t* pConstName,
                                     const wchar_t* pValue) {
-  JS_DefineGlobalConst(pIsolate, pConstName, JS_NewString(pIsolate, pValue));
+  FXJS_DefineGlobalConst(pIsolate, pConstName,
+                         FXJS_NewString(pIsolate, pValue));
 }
 
 void CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) {
@@ -176,7 +177,7 @@ void DefineGlobalConstStringArray(v8::Isolate* pIsolate,
   }
   CJS_PropValue prop(pIsolate);
   prop << array;
-  JS_DefineGlobalConst(pIsolate, sConstName, prop.ToV8Value());
+  FXJS_DefineGlobalConst(pIsolate, sConstName, prop.ToV8Value());
 }
 
 void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
index a8a4ebc..27a3971 100644 (file)
@@ -326,11 +326,11 @@ FX_BOOL Document::getField(IFXJS_Context* cc,
 
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
   v8::Local<v8::Object> pFieldObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
+      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
+                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
 
   v8::Isolate* isolate = GetIsolate(cc);
-  CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate, pFieldObj);
+  CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj);
   Field* pField = (Field*)pJSField->GetEmbedObject();
   pField->AttachField(this, wideName);
 
@@ -457,11 +457,11 @@ FX_BOOL Document::print(IFXJS_Context* cc,
 
   int nlength = params.size();
   if (nlength == 9) {
-    if (params[8].GetType() == VT_fxobject) {
+    if (params[8].GetType() == CJS_Value::VT_fxobject) {
       v8::Local<v8::Object> pObj = params[8].ToV8Object();
       {
-        if (JS_GetObjDefnID(pObj) ==
-            JS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj")) {
+        if (FXJS_GetObjDefnID(pObj) ==
+            FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj")) {
           if (CJS_Object* pJSObj = params[8].ToCJSObject()) {
             if (PrintParamsObj* pprintparamsObj =
                     (PrintParamsObj*)pJSObj->GetEmbedObject()) {
@@ -595,7 +595,7 @@ FX_BOOL Document::resetForm(IFXJS_Context* cc,
       default:
         aName.Attach(params[0].ToV8Array());
         break;
-      case VT_string:
+      case CJS_Value::VT_string:
         aName.SetElement(0, params[0]);
         break;
     }
@@ -651,7 +651,7 @@ FX_BOOL Document::submitForm(IFXJS_Context* cc,
   CJS_Array aFields(isolate);
 
   CJS_Value v = params[0];
-  if (v.GetType() == VT_string) {
+  if (v.GetType() == CJS_Value::VT_string) {
     strURL = params[0].ToCFXWideString();
     if (nSize > 1)
       bFDF = params[1].ToBool();
@@ -659,17 +659,17 @@ FX_BOOL Document::submitForm(IFXJS_Context* cc,
       bEmpty = params[2].ToBool();
     if (nSize > 3)
       aFields.Attach(params[3].ToV8Array());
-  } else if (v.GetType() == VT_object) {
+  } else if (v.GetType() == CJS_Value::VT_object) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
-    v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cURL");
+    v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL");
     if (!pValue.IsEmpty())
       strURL =
           CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
-    pValue = JS_GetObjectElement(isolate, pObj, L"bFDF");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF");
     bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
-    pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty");
     bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
-    pValue = JS_GetObjectElement(isolate, pObj, L"aFields");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields");
     aFields.Attach(
         CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
   }
@@ -766,26 +766,26 @@ FX_BOOL Document::mailDoc(IFXJS_Context* cc,
 
   v8::Isolate* isolate = GetIsolate(cc);
 
-  if (params.size() >= 1 && params[0].GetType() == VT_object) {
+  if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
 
-    v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI");
+    v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
     bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
     cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cCc");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
     cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cBcc");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
     cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cSubject");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
     cSubject =
         CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
     cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
   }
 
@@ -851,16 +851,17 @@ FX_BOOL Document::info(IFXJS_Context* cc,
     CJS_Context* pContext = (CJS_Context*)cc;
     CJS_Runtime* pRuntime = pContext->GetJSRuntime();
     v8::Local<v8::Object> pObj =
-        JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, -1);
-    JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
-    JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
-    JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
-    JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
-    JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
-    JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
-    JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str());
-    JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
-    JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
+        FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext, -1);
+    FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"CreationDate",
+                         cwCreationDate.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
 
     // It's to be compatible to non-standard info dictionary.
     FX_POSITION pos = pDictionary->GetStartPos();
@@ -870,14 +871,14 @@ FX_BOOL Document::info(IFXJS_Context* cc,
       CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
       if ((pValueObj->GetType() == PDFOBJ_STRING) ||
           (pValueObj->GetType() == PDFOBJ_NAME))
-        JS_PutObjectString(isolate, pObj, wsKey.c_str(),
-                           pValueObj->GetUnicodeText().c_str());
+        FXJS_PutObjectString(isolate, pObj, wsKey.c_str(),
+                             pValueObj->GetUnicodeText().c_str());
       if (pValueObj->GetType() == PDFOBJ_NUMBER)
-        JS_PutObjectNumber(isolate, pObj, wsKey.c_str(),
-                           (float)pValueObj->GetNumber());
+        FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(),
+                             (float)pValueObj->GetNumber());
       if (pValueObj->GetType() == PDFOBJ_BOOLEAN)
-        JS_PutObjectBoolean(isolate, pObj, wsKey.c_str(),
-                            (bool)pValueObj->GetInteger());
+        FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(),
+                              (bool)pValueObj->GetInteger());
     }
     vp << pObj;
   }
@@ -1287,7 +1288,7 @@ FX_BOOL Document::getAnnots3D(IFXJS_Context* cc,
                               const CJS_Parameters& params,
                               CJS_Value& vRet,
                               CFX_WideString& sError) {
-  vRet = VT_undefined;
+  vRet = CJS_Value::VT_undefined;
   return TRUE;
 }
 
@@ -1366,15 +1367,15 @@ FX_BOOL Document::addIcon(IFXJS_Context* cc,
   }
   CFX_WideString swIconName = params[0].ToCFXWideString();
 
-  if (params[1].GetType() != VT_object) {
+  if (params[1].GetType() != CJS_Value::VT_object) {
     sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
     return FALSE;
   }
   v8::Local<v8::Object> pJSIcon = params[1].ToV8Object();
 
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  if (JS_GetObjDefnID(pJSIcon) !=
-      JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")) {
+  if (FXJS_GetObjDefnID(pJSIcon) !=
+      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")) {
     sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
     return FALSE;
   }
@@ -1421,13 +1422,13 @@ FX_BOOL Document::icons(IFXJS_Context* cc,
   for (int i = 0; i < iIconTreeLength; i++) {
     pIconElement = (*m_pIconTree)[i];
 
-    v8::Local<v8::Object> pObj =
-        JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                           JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
+    v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
+        pRuntime->GetIsolate(), pContext,
+        FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
     if (pObj.IsEmpty())
       return FALSE;
 
-    CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
+    CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pObj);
     if (!pJS_Icon)
       return FALSE;
 
@@ -1465,13 +1466,13 @@ FX_BOOL Document::getIcon(IFXJS_Context* cc,
     if ((*m_pIconTree)[i]->IconName == swIconName) {
       Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
 
-      v8::Local<v8::Object> pObj =
-          JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                             JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
+      v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
+          pRuntime->GetIsolate(), pContext,
+          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
       if (pObj.IsEmpty())
         return FALSE;
 
-      CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
+      CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pObj);
       if (!pJS_Icon)
         return FALSE;
 
@@ -1662,9 +1663,9 @@ FX_BOOL Document::getPrintParams(IFXJS_Context* cc,
                                  CFX_WideString& sError) {
   CJS_Context* pContext = (CJS_Context*)cc;
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  v8::Local<v8::Object> pRetObj = JS_NewFxDynamicObj(
+  v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
       pRuntime->GetIsolate(), pContext,
-      JS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj"));
+      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj"));
 
   // Not implemented yet.
 
index a0570cb..66a9601 100644 (file)
@@ -1038,7 +1038,7 @@ FX_BOOL Field::currentValueIndices(IFXJS_Context* cc,
 
     CFX_DWordArray array;
 
-    if (vp.GetType() == VT_number) {
+    if (vp.GetType() == CJS_Value::VT_number) {
       int iSelecting = 0;
       vp >> iSelecting;
       array.Add(iSelecting);
@@ -3316,15 +3316,12 @@ FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc,
   ASSERT(pRuntime != NULL);
 
   v8::Local<v8::Object> pObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
+      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
+                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
   ASSERT(pObj.IsEmpty() == FALSE);
 
-  CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
-  ASSERT(pJS_Icon != NULL);
-
+  CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pObj);
   Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
-  ASSERT(pIcon != NULL);
 
   CPDF_Stream* pIconStream = NULL;
   if (nface == 0)
@@ -3531,17 +3528,13 @@ FX_BOOL Field::getArray(IFXJS_Context* cc,
   for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) {
     CFX_WideString* pStr = swSort.GetAt(j);
 
-    v8::Local<v8::Object> pObj =
-        JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                           JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
+    v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
+        pRuntime->GetIsolate(), pContext,
+        FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
     ASSERT(pObj.IsEmpty() == FALSE);
 
-    CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pObj);
-    ASSERT(pJSField != NULL);
-
+    CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(pObj);
     Field* pField = (Field*)pJSField->GetEmbedObject();
-    ASSERT(pField != NULL);
-
     pField->AttachField(m_pJSDoc, *pStr);
 
     CJS_Value FormFieldValue(m_isolate);
index 2bee913..41146ed 100644 (file)
@@ -55,8 +55,8 @@ FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
   FXJSErr error = {NULL, NULL, 0};
   int nRet = 0;
   if (script.GetLength() > 0) {
-    nRet = JS_Execute(m_pRuntime->GetIsolate(), this, script.c_str(),
-                      script.GetLength(), &error);
+    nRet = FXJS_Execute(m_pRuntime->GetIsolate(), this, script.c_str(),
+                        script.GetLength(), &error);
   }
 
   if (nRet < 0) {
index acaacf2..bd762b4 100644 (file)
@@ -615,19 +615,17 @@ Field* CJS_EventHandler::Source() {
 
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
 
-  v8::Local<v8::Object> pDocObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
+  v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext,
+      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
   ASSERT(pDocObj.IsEmpty() == FALSE);
   v8::Local<v8::Object> pFieldObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
+      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
+                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
   ASSERT(pFieldObj.IsEmpty() == FALSE);
 
-  CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
-  ASSERT(pJSDocument != NULL);
+  CJS_Document* pJSDocument = (CJS_Document*)FXJS_GetPrivate(pDocObj);
   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
-  ASSERT(pDocument != NULL);
   if (m_pTargetDoc != NULL)
     pDocument->AttachDoc(m_pTargetDoc);
   else
@@ -639,7 +637,7 @@ Field* CJS_EventHandler::Source() {
   // CPDF_FormField* pFormField = pWidget->GetFormField();
   // ASSERT(pFormField);
   // CFX_WideString csFieldName = pFormField->GetFullName();
-  CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
+  CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(pFieldObj);
   ASSERT(pJSField != NULL);
   Field* pField = (Field*)pJSField->GetEmbedObject();
   ASSERT(pField != NULL);
@@ -652,25 +650,23 @@ Field* CJS_EventHandler::Target_Field() {
 
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
 
-  v8::Local<v8::Object> pDocObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
+  v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext,
+      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
   ASSERT(pDocObj.IsEmpty() == FALSE);
   v8::Local<v8::Object> pFieldObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
+      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
+                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
   ASSERT(pFieldObj.IsEmpty() == FALSE);
 
-  CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
-  ASSERT(pJSDocument != NULL);
+  CJS_Document* pJSDocument = (CJS_Document*)FXJS_GetPrivate(pDocObj);
   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
-  ASSERT(pDocument != NULL);
   if (m_pTargetDoc != NULL)
     pDocument->AttachDoc(m_pTargetDoc);
   else
     pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
 
-  CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
+  CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(pFieldObj);
   ASSERT(pJSField != NULL);
 
   Field* pField = (Field*)pJSField->GetEmbedObject();
index 17e987d..6891e6f 100644 (file)
@@ -74,7 +74,7 @@ void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) {
   CJS_Object* pJSObj = data.GetParameter();
   pJSObj->ExitInstance();
   delete pJSObj;
-  JS_FreePrivate(data.GetInternalField(0));
+  FXJS_FreePrivate(data.GetInternalField(0));
 }
 
 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) {
index 37b0d35..81f9462 100644 (file)
@@ -39,7 +39,7 @@ void CJS_RuntimeFactory::AddRef() {
 void CJS_RuntimeFactory::Release() {
   if (m_bInit) {
     if (--m_nRef == 0) {
-      JS_Release();
+      FXJS_Release();
       m_bInit = FALSE;
     }
   }
@@ -65,7 +65,7 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
     embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
   }
   if (!m_isolate) {
-    m_pArrayBufferAllocator.reset(new JS_ArrayBufferAllocator());
+    m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator());
 
     v8::Isolate::CreateParams params;
     params.array_buffer_allocator = m_pArrayBufferAllocator.get();
@@ -73,11 +73,11 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
     m_isolateManaged = true;
   }
 
-  JS_Initialize(embedderDataSlot);
+  FXJS_Initialize(embedderDataSlot);
   DefineJSObjects();
 
   CJS_Context* pContext = (CJS_Context*)NewContext();
-  JS_InitializeRuntime(GetIsolate(), this, pContext, m_context);
+  FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context);
   ReleaseContext(pContext);
 }
 
@@ -86,7 +86,7 @@ CJS_Runtime::~CJS_Runtime() {
     delete m_ContextArray.GetAt(i);
 
   m_ContextArray.RemoveAll();
-  JS_ReleaseRuntime(GetIsolate(), m_context);
+  FXJS_ReleaseRuntime(GetIsolate(), m_context);
   RemoveEventsInLoop(m_pFieldEventPath);
 
   m_pApp = NULL;
@@ -106,34 +106,34 @@ void CJS_Runtime::DefineJSObjects() {
 
   // The call order determines the "ObjDefID" assigned to each class.
   // ObjDefIDs 0 - 2
-  CJS_Border::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Display::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Font::DefineJSObjects(GetIsolate(), JS_STATIC);
+  CJS_Border::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Display::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Font::DefineJSObjects(GetIsolate(), FXJS_STATIC);
 
   // ObjDefIDs 3 - 5
-  CJS_Highlight::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Position::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_ScaleHow::DefineJSObjects(GetIsolate(), JS_STATIC);
+  CJS_Highlight::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Position::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJS_STATIC);
 
   // ObjDefIDs 6 - 8
-  CJS_ScaleWhen::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Style::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Zoomtype::DefineJSObjects(GetIsolate(), JS_STATIC);
+  CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Style::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJS_STATIC);
 
   // ObjDefIDs 9 - 11
-  CJS_App::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Color::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Console::DefineJSObjects(GetIsolate(), JS_STATIC);
+  CJS_App::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Color::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Console::DefineJSObjects(GetIsolate(), FXJS_STATIC);
 
   // ObjDefIDs 12 - 14
-  CJS_Document::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
-  CJS_Event::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Field::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
+  CJS_Document::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
+  CJS_Event::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Field::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
 
   // ObjDefIDs 15 - 17
-  CJS_Global::DefineJSObjects(GetIsolate(), JS_STATIC);
-  CJS_Icon::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
-  CJS_Util::DefineJSObjects(GetIsolate(), JS_STATIC);
+  CJS_Global::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Icon::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
+  CJS_Util::DefineJSObjects(GetIsolate(), FXJS_STATIC);
 
   // ObjDefIDs 18 - 20 (these can't fail, return void).
   CJS_PublicMethods::DefineJSObjects(GetIsolate());
@@ -141,8 +141,8 @@ void CJS_Runtime::DefineJSObjects() {
   CJS_GlobalArrays::DefineJSObjects(GetIsolate());
 
   // ObjDefIDs 21 - 22.
-  CJS_TimerObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
-  CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
+  CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
+  CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
 }
 
 IFXJS_Context* CJS_Runtime::NewContext() {
@@ -179,11 +179,12 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
 
     m_pDocument = pReaderDoc;
     if (pReaderDoc) {
-      v8::Local<v8::Object> pThis = JS_GetThisObj(GetIsolate());
+      v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate());
       if (!pThis.IsEmpty()) {
-        if (JS_GetObjDefnID(pThis) ==
-            JS_GetObjDefnID(GetIsolate(), L"Document")) {
-          if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis)) {
+        if (FXJS_GetObjDefnID(pThis) ==
+            FXJS_GetObjDefnID(GetIsolate(), L"Document")) {
+          if (CJS_Document* pJSDocument =
+                  (CJS_Document*)FXJS_GetPrivate(pThis)) {
             if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
               pDocument->AttachDoc(pReaderDoc);
           }
index 7fb2116..3b8f597 100644 (file)
 #include "../../include/javascript/JS_Value.h"
 #include "../../include/javascript/Document.h"
 
+static const FX_DWORD g_nan[2] = {0, 0x7FF80000};
+static double GetNan() {
+  return *(double*)g_nan;
+}
+
 /* ---------------------------- CJS_Value ---------------------------- */
 
 CJS_Value::CJS_Value(v8::Isolate* isolate)
     : m_eType(VT_unknown), m_isolate(isolate) {}
-CJS_Value::CJS_Value(v8::Isolate* isolate,
-                     v8::Local<v8::Value> pValue,
-                     FXJSVALUETYPE t)
-    : m_pValue(pValue), m_eType(t), m_isolate(isolate) {}
+CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t)
+    : m_eType(t), m_pValue(pValue), m_isolate(isolate) {
+}
 
 CJS_Value::CJS_Value(v8::Isolate* isolate, const int& iValue)
     : m_isolate(isolate) {
@@ -73,7 +77,7 @@ CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array)
 
 CJS_Value::~CJS_Value() {}
 
-void CJS_Value::Attach(v8::Local<v8::Value> pValue, FXJSVALUETYPE t) {
+void CJS_Value::Attach(v8::Local<v8::Value> pValue, Type t) {
   m_pValue = pValue;
   m_eType = t;
 }
@@ -92,15 +96,15 @@ void CJS_Value::Detach() {
  */
 
 int CJS_Value::ToInt() const {
-  return JS_ToInt32(m_isolate, m_pValue);
+  return FXJS_ToInt32(m_isolate, m_pValue);
 }
 
 bool CJS_Value::ToBool() const {
-  return JS_ToBoolean(m_isolate, m_pValue);
+  return FXJS_ToBoolean(m_isolate, m_pValue);
 }
 
 double CJS_Value::ToDouble() const {
-  return JS_ToNumber(m_isolate, m_pValue);
+  return FXJS_ToNumber(m_isolate, m_pValue);
 }
 
 float CJS_Value::ToFloat() const {
@@ -108,16 +112,16 @@ float CJS_Value::ToFloat() const {
 }
 
 CJS_Object* CJS_Value::ToCJSObject() const {
-  v8::Local<v8::Object> pObj = JS_ToObject(m_isolate, m_pValue);
-  return (CJS_Object*)JS_GetPrivate(m_isolate, pObj);
+  v8::Local<v8::Object> pObj = FXJS_ToObject(m_isolate, m_pValue);
+  return (CJS_Object*)FXJS_GetPrivate(m_isolate, pObj);
 }
 
 v8::Local<v8::Object> CJS_Value::ToV8Object() const {
-  return JS_ToObject(m_isolate, m_pValue);
+  return FXJS_ToObject(m_isolate, m_pValue);
 }
 
 CFX_WideString CJS_Value::ToCFXWideString() const {
-  return JS_ToString(m_isolate, m_pValue);
+  return FXJS_ToString(m_isolate, m_pValue);
 }
 
 CFX_ByteString CJS_Value::ToCFXByteString() const {
@@ -130,7 +134,7 @@ v8::Local<v8::Value> CJS_Value::ToV8Value() const {
 
 v8::Local<v8::Array> CJS_Value::ToV8Array() const {
   if (IsArrayObject())
-    return v8::Local<v8::Array>::Cast(JS_ToObject(m_isolate, m_pValue));
+    return v8::Local<v8::Array>::Cast(FXJS_ToObject(m_isolate, m_pValue));
   return v8::Local<v8::Array>();
 }
 
@@ -138,31 +142,27 @@ v8::Local<v8::Array> CJS_Value::ToV8Array() const {
  */
 
 void CJS_Value::operator=(int iValue) {
-  m_pValue = JS_NewNumber(m_isolate, iValue);
-
+  m_pValue = FXJS_NewNumber(m_isolate, iValue);
   m_eType = VT_number;
 }
 
 void CJS_Value::operator=(bool bValue) {
-  m_pValue = JS_NewBoolean(m_isolate, bValue);
-
+  m_pValue = FXJS_NewBoolean(m_isolate, bValue);
   m_eType = VT_boolean;
 }
 
 void CJS_Value::operator=(double dValue) {
-  m_pValue = JS_NewNumber(m_isolate, dValue);
-
+  m_pValue = FXJS_NewNumber(m_isolate, dValue);
   m_eType = VT_number;
 }
 
 void CJS_Value::operator=(float fValue) {
-  m_pValue = JS_NewNumber(m_isolate, fValue);
+  m_pValue = FXJS_NewNumber(m_isolate, fValue);
   m_eType = VT_number;
 }
 
 void CJS_Value::operator=(v8::Local<v8::Object> pObj) {
-  m_pValue = JS_NewObject(m_isolate, pObj);
-
+  m_pValue = FXJS_NewObject(m_isolate, pObj);
   m_eType = VT_fxobject;
 }
 
@@ -179,14 +179,12 @@ void CJS_Value::operator=(CJS_Document* pJsDoc) {
 }
 
 void CJS_Value::operator=(const FX_WCHAR* pWstr) {
-  m_pValue = JS_NewString(m_isolate, (wchar_t*)pWstr);
-
+  m_pValue = FXJS_NewString(m_isolate, (wchar_t*)pWstr);
   m_eType = VT_string;
 }
 
 void CJS_Value::SetNull() {
-  m_pValue = JS_NewNull();
-
+  m_pValue = FXJS_NewNull();
   m_eType = VT_null;
 }
 
@@ -195,20 +193,17 @@ void CJS_Value::operator=(const FX_CHAR* pStr) {
 }
 
 void CJS_Value::operator=(CJS_Array& array) {
-  m_pValue = JS_NewObject2(m_isolate, (v8::Local<v8::Array>)array);
-
+  m_pValue = FXJS_NewObject2(m_isolate, (v8::Local<v8::Array>)array);
   m_eType = VT_object;
 }
 
 void CJS_Value::operator=(CJS_Date& date) {
-  m_pValue = JS_NewDate(m_isolate, (double)date);
-
+  m_pValue = FXJS_NewDate(m_isolate, (double)date);
   m_eType = VT_date;
 }
 
 void CJS_Value::operator=(CJS_Value value) {
   m_pValue = value.ToV8Value();
-
   m_eType = value.m_eType;
   m_isolate = value.m_isolate;
 }
@@ -216,7 +211,7 @@ void CJS_Value::operator=(CJS_Value value) {
 /* ----------------------------------------------------------------------------------------
  */
 
-FXJSVALUETYPE CJS_Value::GetType() const {
+CJS_Value::Type CJS_Value::GetType() const {
   if (m_pValue.IsEmpty())
     return VT_unknown;
   if (m_pValue->IsString())
@@ -251,7 +246,7 @@ FX_BOOL CJS_Value::IsDateObject() const {
 // CJS_Value::operator CJS_Array()
 FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const {
   if (IsArrayObject()) {
-    array.Attach(JS_ToArray(m_isolate, m_pValue));
+    array.Attach(FXJS_ToArray(m_isolate, m_pValue));
     return TRUE;
   }
 
@@ -424,27 +419,26 @@ FX_BOOL CJS_Array::IsAttached() {
 void CJS_Array::GetElement(unsigned index, CJS_Value& value) {
   if (m_pArray.IsEmpty())
     return;
-  v8::Local<v8::Value> p = JS_GetArrayElement(m_isolate, m_pArray, index);
-  value.Attach(p, VT_object);
+  v8::Local<v8::Value> p = FXJS_GetArrayElement(m_isolate, m_pArray, index);
+  value.Attach(p, CJS_Value::VT_object);
 }
 
 void CJS_Array::SetElement(unsigned index, CJS_Value value) {
   if (m_pArray.IsEmpty())
-    m_pArray = JS_NewArray(m_isolate);
+    m_pArray = FXJS_NewArray(m_isolate);
 
-  JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(),
-                     value.GetType());
+  FXJS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value());
 }
 
 int CJS_Array::GetLength() {
   if (m_pArray.IsEmpty())
     return 0;
-  return JS_GetArrayLength(m_pArray);
+  return FXJS_GetArrayLength(m_pArray);
 }
 
 CJS_Array::operator v8::Local<v8::Array>() {
   if (m_pArray.IsEmpty())
-    m_pArray = JS_NewArray(m_isolate);
+    m_pArray = FXJS_NewArray(m_isolate);
 
   return m_pArray;
 }
@@ -456,7 +450,7 @@ CJS_Date::CJS_Date(v8::Isolate* isolate) : m_isolate(isolate) {}
 
 CJS_Date::CJS_Date(v8::Isolate* isolate, double dMsec_time) {
   m_isolate = isolate;
-  m_pDate = JS_NewDate(isolate, dMsec_time);
+  m_pDate = FXJS_NewDate(isolate, dMsec_time);
 }
 
 CJS_Date::CJS_Date(v8::Isolate* isolate,
@@ -467,7 +461,7 @@ CJS_Date::CJS_Date(v8::Isolate* isolate,
                    int min,
                    int sec) {
   m_isolate = isolate;
-  m_pDate = JS_NewDate(isolate, MakeDate(year, mon, day, hour, min, sec, 0));
+  m_pDate = FXJS_NewDate(isolate, MakeDate(year, mon, day, hour, min, sec, 0));
 }
 
 double CJS_Date::MakeDate(int year,
@@ -486,7 +480,7 @@ CJS_Date::~CJS_Date() {}
 FX_BOOL CJS_Date::IsValidDate() {
   if (m_pDate.IsEmpty())
     return FALSE;
-  return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate));
+  return !JS_PortIsNan(FXJS_ToNumber(m_isolate, m_pDate));
 }
 
 void CJS_Date::Attach(v8::Local<v8::Value> pDate) {
@@ -495,7 +489,7 @@ void CJS_Date::Attach(v8::Local<v8::Value> pDate) {
 
 int CJS_Date::GetYear() {
   if (IsValidDate())
-    return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate)));
+    return JS_GetYearFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
 
   return 0;
 }
@@ -503,12 +497,12 @@ int CJS_Date::GetYear() {
 void CJS_Date::SetYear(int iYear) {
   double date = MakeDate(iYear, GetMonth(), GetDay(), GetHours(), GetMinutes(),
                          GetSeconds(), 0);
-  JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date));
+  FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
 }
 
 int CJS_Date::GetMonth() {
   if (IsValidDate())
-    return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate)));
+    return JS_GetMonthFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
 
   return 0;
 }
@@ -516,12 +510,12 @@ int CJS_Date::GetMonth() {
 void CJS_Date::SetMonth(int iMonth) {
   double date = MakeDate(GetYear(), iMonth, GetDay(), GetHours(), GetMinutes(),
                          GetSeconds(), 0);
-  JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date));
+  FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
 }
 
 int CJS_Date::GetDay() {
   if (IsValidDate())
-    return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate)));
+    return JS_GetDayFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
 
   return 0;
 }
@@ -529,12 +523,12 @@ int CJS_Date::GetDay() {
 void CJS_Date::SetDay(int iDay) {
   double date = MakeDate(GetYear(), GetMonth(), iDay, GetHours(), GetMinutes(),
                          GetSeconds(), 0);
-  JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date));
+  FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
 }
 
 int CJS_Date::GetHours() {
   if (IsValidDate())
-    return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate)));
+    return JS_GetHourFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
 
   return 0;
 }
@@ -542,12 +536,12 @@ int CJS_Date::GetHours() {
 void CJS_Date::SetHours(int iHours) {
   double date = MakeDate(GetYear(), GetMonth(), GetDay(), iHours, GetMinutes(),
                          GetSeconds(), 0);
-  JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date));
+  FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
 }
 
 int CJS_Date::GetMinutes() {
   if (IsValidDate())
-    return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate)));
+    return JS_GetMinFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
 
   return 0;
 }
@@ -555,12 +549,12 @@ int CJS_Date::GetMinutes() {
 void CJS_Date::SetMinutes(int minutes) {
   double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(), minutes,
                          GetSeconds(), 0);
-  JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date));
+  FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
 }
 
 int CJS_Date::GetSeconds() {
   if (IsValidDate())
-    return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate)));
+    return JS_GetSecFromTime(JS_LocalTime(FXJS_ToNumber(m_isolate, m_pDate)));
 
   return 0;
 }
@@ -568,7 +562,7 @@ int CJS_Date::GetSeconds() {
 void CJS_Date::SetSeconds(int seconds) {
   double date = MakeDate(GetYear(), GetMonth(), GetDay(), GetHours(),
                          GetMinutes(), seconds, 0);
-  JS_ValueCopy(m_pDate, JS_NewDate(m_isolate, date));
+  FXJS_ValueCopy(m_pDate, FXJS_NewDate(m_isolate, date));
 }
 
 CJS_Date::operator v8::Local<v8::Value>() {
@@ -578,11 +572,291 @@ CJS_Date::operator v8::Local<v8::Value>() {
 CJS_Date::operator double() const {
   if (m_pDate.IsEmpty())
     return 0.0;
-  return JS_ToNumber(m_isolate, m_pDate);
+  return FXJS_ToNumber(m_isolate, m_pDate);
 }
 
 CFX_WideString CJS_Date::ToString() const {
   if (m_pDate.IsEmpty())
     return L"";
-  return JS_ToString(m_isolate, m_pDate);
+  return FXJS_ToString(m_isolate, m_pDate);
+}
+
+double _getLocalTZA() {
+  if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
+    return 0;
+  time_t t = 0;
+  time(&t);
+  localtime(&t);
+#if _MSC_VER >= 1900
+  // In gcc and in Visual Studio prior to VS 2015 'timezone' is a global
+  // variable declared in time.h. That variable was deprecated and in VS 2015
+  // is removed, with _get_timezone replacing it.
+  long timezone = 0;
+  _get_timezone(&timezone);
+#endif
+  return (double)(-(timezone * 1000));
+}
+
+int _getDaylightSavingTA(double d) {
+  if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
+    return 0;
+  time_t t = (time_t)(d / 1000);
+  struct tm* tmp = localtime(&t);
+  if (tmp == NULL)
+    return 0;
+  if (tmp->tm_isdst > 0)
+    // One hour.
+    return (int)60 * 60 * 1000;
+  return 0;
+}
+
+double _Mod(double x, double y) {
+  double r = fmod(x, y);
+  if (r < 0)
+    r += y;
+  return r;
+}
+
+int _isfinite(double v) {
+#if _MSC_VER
+  return ::_finite(v);
+#else
+  return std::fabs(v) < std::numeric_limits<double>::max();
+#endif
+}
+
+double _toInteger(double n) {
+  return (n >= 0) ? FXSYS_floor(n) : -FXSYS_floor(-n);
+}
+
+bool _isLeapYear(int year) {
+  return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0));
+}
+
+int _DayFromYear(int y) {
+  return (int)(365 * (y - 1970.0) + FXSYS_floor((y - 1969.0) / 4) -
+               FXSYS_floor((y - 1901.0) / 100) +
+               FXSYS_floor((y - 1601.0) / 400));
+}
+
+double _TimeFromYear(int y) {
+  return ((double)86400000) * _DayFromYear(y);
+}
+
+double _TimeFromYearMonth(int y, int m) {
+  static int daysMonth[12] = {
+      0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
+  static int leapDaysMonth[12] = {
+      0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
+  int* pMonth = daysMonth;
+  if (_isLeapYear(y))
+    pMonth = leapDaysMonth;
+  return _TimeFromYear(y) + ((double)pMonth[m]) * 86400000;
+}
+
+int _Day(double t) {
+  return (int)FXSYS_floor(t / 86400000);
+}
+
+int _YearFromTime(double t) {
+  // estimate the time.
+  int y = 1970 + (int)(t / (365.0 * 86400000));
+  if (_TimeFromYear(y) <= t) {
+    while (_TimeFromYear(y + 1) <= t)
+      y++;
+  } else
+    while (_TimeFromYear(y - 1) > t)
+      y--;
+  return y;
+}
+
+int _DayWithinYear(double t) {
+  int year = _YearFromTime(t);
+  int day = _Day(t);
+  return day - _DayFromYear(year);
+}
+
+int _MonthFromTime(double t) {
+  int day = _DayWithinYear(t);
+  int year = _YearFromTime(t);
+  if (0 <= day && day < 31)
+    return 0;
+  if (31 <= day && day < 59 + _isLeapYear(year))
+    return 1;
+  if ((59 + _isLeapYear(year)) <= day && day < (90 + _isLeapYear(year)))
+    return 2;
+  if ((90 + _isLeapYear(year)) <= day && day < (120 + _isLeapYear(year)))
+    return 3;
+  if ((120 + _isLeapYear(year)) <= day && day < (151 + _isLeapYear(year)))
+    return 4;
+  if ((151 + _isLeapYear(year)) <= day && day < (181 + _isLeapYear(year)))
+    return 5;
+  if ((181 + _isLeapYear(year)) <= day && day < (212 + _isLeapYear(year)))
+    return 6;
+  if ((212 + _isLeapYear(year)) <= day && day < (243 + _isLeapYear(year)))
+    return 7;
+  if ((243 + _isLeapYear(year)) <= day && day < (273 + _isLeapYear(year)))
+    return 8;
+  if ((273 + _isLeapYear(year)) <= day && day < (304 + _isLeapYear(year)))
+    return 9;
+  if ((304 + _isLeapYear(year)) <= day && day < (334 + _isLeapYear(year)))
+    return 10;
+  if ((334 + _isLeapYear(year)) <= day && day < (365 + _isLeapYear(year)))
+    return 11;
+
+  return -1;
+}
+
+int _DateFromTime(double t) {
+  int day = _DayWithinYear(t);
+  int year = _YearFromTime(t);
+  bool leap = _isLeapYear(year);
+  int month = _MonthFromTime(t);
+  switch (month) {
+    case 0:
+      return day + 1;
+    case 1:
+      return day - 30;
+    case 2:
+      return day - 58 - leap;
+    case 3:
+      return day - 89 - leap;
+    case 4:
+      return day - 119 - leap;
+    case 5:
+      return day - 150 - leap;
+    case 6:
+      return day - 180 - leap;
+    case 7:
+      return day - 211 - leap;
+    case 8:
+      return day - 242 - leap;
+    case 9:
+      return day - 272 - leap;
+    case 10:
+      return day - 303 - leap;
+    case 11:
+      return day - 333 - leap;
+    default:
+      return 0;
+  }
+}
+
+double JS_GetDateTime() {
+  if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
+    return 0;
+  time_t t = time(NULL);
+  struct tm* pTm = localtime(&t);
+
+  int year = pTm->tm_year + 1900;
+  double t1 = _TimeFromYear(year);
+
+  return t1 + pTm->tm_yday * 86400000.0 + pTm->tm_hour * 3600000.0 +
+         pTm->tm_min * 60000.0 + pTm->tm_sec * 1000.0;
+}
+
+int JS_GetYearFromTime(double dt) {
+  return _YearFromTime(dt);
+}
+
+int JS_GetMonthFromTime(double dt) {
+  return _MonthFromTime(dt);
+}
+
+int JS_GetDayFromTime(double dt) {
+  return _DateFromTime(dt);
+}
+
+int JS_GetHourFromTime(double dt) {
+  return (int)_Mod(FXSYS_floor((double)(dt / (60 * 60 * 1000))), 24);
+}
+
+int JS_GetMinFromTime(double dt) {
+  return (int)_Mod(FXSYS_floor((double)(dt / (60 * 1000))), 60);
+}
+
+int JS_GetSecFromTime(double dt) {
+  return (int)_Mod(FXSYS_floor((double)(dt / 1000)), 60);
+}
+
+double JS_DateParse(const wchar_t* string) {
+  v8::Isolate* pIsolate = v8::Isolate::GetCurrent();
+  v8::Isolate::Scope isolate_scope(pIsolate);
+  v8::HandleScope scope(pIsolate);
+
+  v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
+
+  // Use the built-in object method.
+  v8::Local<v8::Value> v =
+      context->Global()
+          ->Get(context, v8::String::NewFromUtf8(pIsolate, "Date",
+                                                 v8::NewStringType::kNormal)
+                             .ToLocalChecked())
+          .ToLocalChecked();
+  if (v->IsObject()) {
+    v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked();
+    v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse",
+                                                v8::NewStringType::kNormal)
+                            .ToLocalChecked()).ToLocalChecked();
+    if (v->IsFunction()) {
+      v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v);
+
+      const int argc = 1;
+      v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, string);
+      v8::Local<v8::Value> argv[argc] = {timeStr};
+      v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked();
+      if (v->IsNumber()) {
+        double date = v->ToNumber(context).ToLocalChecked()->Value();
+        if (!_isfinite(date))
+          return date;
+        return date + _getLocalTZA() + _getDaylightSavingTA(date);
+      }
+    }
+  }
+  return 0;
+}
+
+double JS_MakeDay(int nYear, int nMonth, int nDate) {
+  if (!_isfinite(nYear) || !_isfinite(nMonth) || !_isfinite(nDate))
+    return GetNan();
+  double y = _toInteger(nYear);
+  double m = _toInteger(nMonth);
+  double dt = _toInteger(nDate);
+  double ym = y + FXSYS_floor((double)m / 12);
+  double mn = _Mod(m, 12);
+
+  double t = _TimeFromYearMonth((int)ym, (int)mn);
+
+  if (_YearFromTime(t) != ym || _MonthFromTime(t) != mn ||
+      _DateFromTime(t) != 1)
+    return GetNan();
+  return _Day(t) + dt - 1;
+}
+
+double JS_MakeTime(int nHour, int nMin, int nSec, int nMs) {
+  if (!_isfinite(nHour) || !_isfinite(nMin) || !_isfinite(nSec) ||
+      !_isfinite(nMs))
+    return GetNan();
+
+  double h = _toInteger(nHour);
+  double m = _toInteger(nMin);
+  double s = _toInteger(nSec);
+  double milli = _toInteger(nMs);
+
+  return h * 3600000 + m * 60000 + s * 1000 + milli;
+}
+
+double JS_MakeDate(double day, double time) {
+  if (!_isfinite(day) || !_isfinite(time))
+    return GetNan();
+
+  return day * 86400000 + time;
+}
+
+bool JS_PortIsNan(double d) {
+  return d != d;
+}
+
+double JS_LocalTime(double d) {
+  return JS_GetDateTime() + _getDaylightSavingTA(d);
 }
index 1722d0f..ef745b7 100644 (file)
@@ -1934,7 +1934,7 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc,
 
   CJS_Value params1 = params[1];
 
-  if (!params1.IsArrayObject() && params1.GetType() != VT_string) {
+  if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) {
     sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
     return FALSE;
   }
index a679451..9d4fa9c 100644 (file)
@@ -122,16 +122,17 @@ FX_BOOL app::activeDocs(IFXJS_Context* cc,
   if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
     CJS_Document* pJSDocument = NULL;
     if (pDoc == pCurDoc) {
-      v8::Local<v8::Object> pObj = JS_GetThisObj(pRuntime->GetIsolate());
-      if (JS_GetObjDefnID(pObj) ==
-          JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"))
+      v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
+      if (FXJS_GetObjDefnID(pObj) ==
+          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"))
         pJSDocument =
-            (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj);
+            (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
     } else {
-      v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(
+      v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
           pRuntime->GetIsolate(), pContext,
-          JS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
-      pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj);
+          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
+      pJSDocument =
+          (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
       ASSERT(pJSDocument != NULL);
     }
     aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument));
@@ -269,21 +270,23 @@ FX_BOOL app::alert(IFXJS_Context* cc,
   v8::Isolate* isolate = GetIsolate(cc);
 
   if (iSize == 1) {
-    if (params[0].GetType() == VT_object) {
+    if (params[0].GetType() == CJS_Value::VT_object) {
       v8::Local<v8::Object> pObj = params[0].ToV8Object();
       {
         v8::Local<v8::Value> pValue =
-            JS_GetObjectElement(isolate, pObj, L"cMsg");
-        swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
+            FXJS_GetObjectElement(isolate, pObj, L"cMsg");
+        swMsg =
+            CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString();
 
-        pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
-        swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
+        pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
+        swTitle =
+            CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString();
 
-        pValue = JS_GetObjectElement(isolate, pObj, L"nIcon");
-        iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt();
+        pValue = FXJS_GetObjectElement(isolate, pObj, L"nIcon");
+        iIcon = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt();
 
-        pValue = JS_GetObjectElement(isolate, pObj, L"nType");
-        iType = CJS_Value(isolate, pValue, VT_unknown).ToInt();
+        pValue = FXJS_GetObjectElement(isolate, pObj, L"nType");
+        iType = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt();
       }
 
       if (swMsg == L"") {
@@ -304,7 +307,7 @@ FX_BOOL app::alert(IFXJS_Context* cc,
 
       if (swTitle == L"")
         swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
-    } else if (params[0].GetType() == VT_boolean) {
+    } else if (params[0].GetType() == CJS_Value::VT_boolean) {
       FX_BOOL bGet = params[0].ToBool();
       if (bGet)
         swMsg = L"true";
@@ -317,7 +320,7 @@ FX_BOOL app::alert(IFXJS_Context* cc,
       swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
     }
   } else {
-    if (params[0].GetType() == VT_boolean) {
+    if (params[0].GetType() == CJS_Value::VT_boolean) {
       FX_BOOL bGet = params[0].ToBool();
       if (bGet)
         swMsg = L"true";
@@ -415,12 +418,12 @@ FX_BOOL app::setInterval(IFXJS_Context* cc,
   //   pTimer->SetStartTime(GetTickCount());
   pTimer->SetJSTimer(dwInterval);
 
-  v8::Local<v8::Object> pRetObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
+  v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pContext,
+      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
 
   CJS_TimerObj* pJS_TimerObj =
-      (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
+      (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
   ASSERT(pJS_TimerObj != NULL);
 
   TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
@@ -468,12 +471,12 @@ FX_BOOL app::setTimeOut(IFXJS_Context* cc,
   pTimer->SetTimeOut(dwTimeOut);
   pTimer->SetJSTimer(dwTimeOut);
 
-  v8::Local<v8::Object> pRetObj =
-      JS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                         JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
+  v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pContext,
+      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
 
   CJS_TimerObj* pJS_TimerObj =
-      (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
+      (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
   ASSERT(pJS_TimerObj != NULL);
 
   TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
@@ -500,11 +503,11 @@ FX_BOOL app::clearTimeOut(IFXJS_Context* cc,
     return FALSE;
   }
 
-  if (params[0].GetType() == VT_fxobject) {
+  if (params[0].GetType() == CJS_Value::VT_fxobject) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
     {
-      if (JS_GetObjDefnID(pObj) ==
-          JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
+      if (FXJS_GetObjDefnID(pObj) ==
+          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
         if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
           if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
             if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
@@ -543,11 +546,11 @@ FX_BOOL app::clearInterval(IFXJS_Context* cc,
     return FALSE;
   }
 
-  if (params[0].GetType() == VT_fxobject) {
+  if (params[0].GetType() == CJS_Value::VT_fxobject) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
     {
-      if (JS_GetObjDefnID(pObj) ==
-          JS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
+      if (FXJS_GetObjDefnID(pObj) ==
+          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
         if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
           if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
             if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
@@ -641,26 +644,26 @@ FX_BOOL app::mailMsg(IFXJS_Context* cc,
   if (params.size() < 1)
     return FALSE;
 
-  if (params[0].GetType() == VT_object) {
+  if (params[0].GetType() == CJS_Value::VT_object) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
 
-    v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI");
+    v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
     bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
     cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cCc");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
     cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cBcc");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
     cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cSubject");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
     cSubject =
         CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
     cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
   } else {
     if (params.size() < 2)
@@ -779,26 +782,26 @@ FX_BOOL app::response(IFXJS_Context* cc,
   v8::Isolate* isolate = GetIsolate(cc);
 
   int iLength = params.size();
-  if (iLength > 0 && params[0].GetType() == VT_object) {
+  if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
     v8::Local<v8::Value> pValue =
-        JS_GetObjectElement(isolate, pObj, L"cQuestion");
+        FXJS_GetObjectElement(isolate, pObj, L"cQuestion");
     swQuestion =
         CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
     swTitle =
         CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cDefault");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cDefault");
     swDefault =
         CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"cLabel");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cLabel");
     swLabel =
         CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
 
-    pValue = JS_GetObjectElement(isolate, pObj, L"bPassword");
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword");
     bPassWord = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
   } else {
     switch (iLength) {
index 492f225..751705a 100644 (file)
@@ -63,7 +63,7 @@ FX_BOOL event::change(IFXJS_Context* cc,
 
   CFX_WideString& wChange = pEvent->Change();
   if (vp.IsSetting()) {
-    if (vp.GetType() == VT_string)
+    if (vp.GetType() == CJS_Value::VT_string)
       vp >> wChange;
   } else {
     vp << wChange;
index e75dbd5..af517c0 100644 (file)
@@ -4,6 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include "../../../core/include/fxcrt/fx_ext.h"
 #include "../../include/javascript/IJavaScript.h"
 #include "../../include/javascript/JS_Context.h"
 #include "../../include/javascript/JS_Define.h"
@@ -52,6 +53,10 @@ const unsigned int JSCONST_nNullHash = CHash<'n', 'u', 'l', 'l'>::value;
 const unsigned int JSCONST_nUndefHash =
     CHash<'u', 'n', 'd', 'e', 'f', 'i', 'n', 'e', 'd'>::value;
 
+static unsigned JS_CalcHash(const wchar_t* main) {
+  return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main));
+}
+
 #ifdef _DEBUG
 class HashVerify {
  public:
@@ -59,22 +64,14 @@ class HashVerify {
 } g_hashVerify;
 
 HashVerify::HashVerify() {
-  ASSERT(JSCONST_nStringHash ==
-         JS_CalcHash(kFXJSValueNameString, wcslen(kFXJSValueNameString)));
-  ASSERT(JSCONST_nNumberHash ==
-         JS_CalcHash(kFXJSValueNameNumber, wcslen(kFXJSValueNameNumber)));
-  ASSERT(JSCONST_nBoolHash ==
-         JS_CalcHash(kFXJSValueNameBoolean, wcslen(kFXJSValueNameBoolean)));
-  ASSERT(JSCONST_nDateHash ==
-         JS_CalcHash(kFXJSValueNameDate, wcslen(kFXJSValueNameDate)));
-  ASSERT(JSCONST_nObjectHash ==
-         JS_CalcHash(kFXJSValueNameObject, wcslen(kFXJSValueNameObject)));
-  ASSERT(JSCONST_nFXobjHash ==
-         JS_CalcHash(kFXJSValueNameFxobj, wcslen(kFXJSValueNameFxobj)));
-  ASSERT(JSCONST_nNullHash ==
-         JS_CalcHash(kFXJSValueNameNull, wcslen(kFXJSValueNameNull)));
-  ASSERT(JSCONST_nUndefHash ==
-         JS_CalcHash(kFXJSValueNameUndefined, wcslen(kFXJSValueNameUndefined)));
+  ASSERT(JSCONST_nStringHash == JS_CalcHash(kFXJSValueNameString));
+  ASSERT(JSCONST_nNumberHash == JS_CalcHash(kFXJSValueNameNumber));
+  ASSERT(JSCONST_nBoolHash == JS_CalcHash(kFXJSValueNameBoolean));
+  ASSERT(JSCONST_nDateHash == JS_CalcHash(kFXJSValueNameDate));
+  ASSERT(JSCONST_nObjectHash == JS_CalcHash(kFXJSValueNameObject));
+  ASSERT(JSCONST_nFXobjHash == JS_CalcHash(kFXJSValueNameFxobj));
+  ASSERT(JSCONST_nNullHash == JS_CalcHash(kFXJSValueNameNull));
+  ASSERT(JSCONST_nUndefHash == JS_CalcHash(kFXJSValueNameUndefined);
 }
 #endif
 
@@ -139,35 +136,35 @@ FX_BOOL JSGlobalAlternate::DoProperty(IFXJS_Context* cc,
   if (vp.IsSetting()) {
     CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
     switch (vp.GetType()) {
-      case VT_number: {
+      case CJS_Value::VT_number: {
         double dData;
         vp >> dData;
         return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData,
                                   false, "", v8::Local<v8::Object>(), FALSE);
       }
-      case VT_boolean: {
+      case CJS_Value::VT_boolean: {
         bool bData;
         vp >> bData;
         return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0,
                                   bData, "", v8::Local<v8::Object>(), FALSE);
       }
-      case VT_string: {
+      case CJS_Value::VT_string: {
         CFX_ByteString sData;
         vp >> sData;
         return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0,
                                   false, sData, v8::Local<v8::Object>(), FALSE);
       }
-      case VT_object: {
+      case CJS_Value::VT_object: {
         v8::Local<v8::Object> pData;
         vp >> pData;
         return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0,
                                   false, "", pData, FALSE);
       }
-      case VT_null: {
+      case CJS_Value::VT_null: {
         return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false,
                                   "", v8::Local<v8::Object>(), FALSE);
       }
-      case VT_undefined: {
+      case CJS_Value::VT_undefined: {
         DelProperty(cc, propname, sError);
         return TRUE;
       }
@@ -246,46 +243,46 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER,
                            pData->data.dData, false, "",
                            v8::Local<v8::Object>(), pData->bPersistent == 1);
-        JS_PutObjectNumber(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
-                           pData->data.sKey.UTF8Decode().c_str(),
-                           pData->data.dData);
+        FXJS_PutObjectNumber(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+                             pData->data.sKey.UTF8Decode().c_str(),
+                             pData->data.dData);
         break;
       case JS_GLOBALDATA_TYPE_BOOLEAN:
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0,
                            (bool)(pData->data.bData == 1), "",
                            v8::Local<v8::Object>(), pData->bPersistent == 1);
-        JS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
-                            pData->data.sKey.UTF8Decode().c_str(),
-                            (bool)(pData->data.bData == 1));
+        FXJS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+                              pData->data.sKey.UTF8Decode().c_str(),
+                              (bool)(pData->data.bData == 1));
         break;
       case JS_GLOBALDATA_TYPE_STRING:
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0,
                            false, pData->data.sData, v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
-        JS_PutObjectString(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
-                           pData->data.sKey.UTF8Decode().c_str(),
-                           pData->data.sData.UTF8Decode().c_str());
+        FXJS_PutObjectString(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+                             pData->data.sKey.UTF8Decode().c_str(),
+                             pData->data.sData.UTF8Decode().c_str());
         break;
       case JS_GLOBALDATA_TYPE_OBJECT: {
         v8::Isolate* pRuntime =
-            JS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
-        v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+            FXJS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
+        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);
-        JS_PutObjectObject(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
-                           pData->data.sKey.UTF8Decode().c_str(),
-                           (v8::Local<v8::Object>)pObj);
+        FXJS_PutObjectObject(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+                             pData->data.sKey.UTF8Decode().c_str(),
+                             (v8::Local<v8::Object>)pObj);
       } break;
       case JS_GLOBALDATA_TYPE_NULL:
         SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false,
                            "", v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
-        JS_PutObjectNull(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
-                         pData->data.sKey.UTF8Decode().c_str());
+        FXJS_PutObjectNull(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
+                           pData->data.sKey.UTF8Decode().c_str());
         break;
     }
   }
@@ -337,48 +334,47 @@ void JSGlobalAlternate::ObjectToArray(v8::Local<v8::Object> pObj,
                                       CJS_GlobalVariableArray& array) {
   v8::Local<v8::Context> context = pObj->CreationContext();
   v8::Isolate* isolate = context->GetIsolate();
-  v8::Local<v8::Array> pKeyList = JS_GetObjectElementNames(isolate, pObj);
+  v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj);
   int nObjElements = pKeyList->Length();
 
   for (int i = 0; i < nObjElements; i++) {
     CFX_WideString ws =
-        JS_ToString(isolate, JS_GetArrayElement(isolate, pKeyList, i));
+        FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i));
     CFX_ByteString sKey = ws.UTF8Encode();
 
-    v8::Local<v8::Value> v = JS_GetObjectElement(isolate, pObj, ws.c_str());
-    FXJSVALUETYPE vt = GET_VALUE_TYPE(v);
-    switch (vt) {
-      case VT_number: {
+    v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws.c_str());
+    switch (GET_VALUE_TYPE(v)) {
+      case CJS_Value::VT_number: {
         CJS_KeyValue* pObjElement = new CJS_KeyValue;
         pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER;
         pObjElement->sKey = sKey;
-        pObjElement->dData = JS_ToNumber(isolate, v);
+        pObjElement->dData = FXJS_ToNumber(isolate, v);
         array.Add(pObjElement);
       } break;
-      case VT_boolean: {
+      case CJS_Value::VT_boolean: {
         CJS_KeyValue* pObjElement = new CJS_KeyValue;
         pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
         pObjElement->sKey = sKey;
-        pObjElement->dData = JS_ToBoolean(isolate, v);
+        pObjElement->dData = FXJS_ToBoolean(isolate, v);
         array.Add(pObjElement);
       } break;
-      case VT_string: {
+      case CJS_Value::VT_string: {
         CFX_ByteString sValue =
-            CJS_Value(isolate, v, VT_string).ToCFXByteString();
+            CJS_Value(isolate, v, CJS_Value::VT_string).ToCFXByteString();
         CJS_KeyValue* pObjElement = new CJS_KeyValue;
         pObjElement->nType = JS_GLOBALDATA_TYPE_STRING;
         pObjElement->sKey = sKey;
         pObjElement->sData = sValue;
         array.Add(pObjElement);
       } break;
-      case VT_object: {
+      case CJS_Value::VT_object: {
         CJS_KeyValue* pObjElement = new CJS_KeyValue;
         pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT;
         pObjElement->sKey = sKey;
-        ObjectToArray(JS_ToObject(isolate, v), pObjElement->objData);
+        ObjectToArray(FXJS_ToObject(isolate, v), pObjElement->objData);
         array.Add(pObjElement);
       } break;
-      case VT_null: {
+      case CJS_Value::VT_null: {
         CJS_KeyValue* pObjElement = new CJS_KeyValue;
         pObjElement->nType = JS_GLOBALDATA_TYPE_NULL;
         pObjElement->sKey = sKey;
@@ -400,32 +396,33 @@ void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj,
 
     switch (pObjData->nType) {
       case JS_GLOBALDATA_TYPE_NUMBER:
-        JS_PutObjectNumber(NULL, (v8::Local<v8::Object>)pObj,
-                           pObjData->sKey.UTF8Decode().c_str(),
-                           pObjData->dData);
+        FXJS_PutObjectNumber(NULL, (v8::Local<v8::Object>)pObj,
+                             pObjData->sKey.UTF8Decode().c_str(),
+                             pObjData->dData);
         break;
       case JS_GLOBALDATA_TYPE_BOOLEAN:
-        JS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)pObj,
-                            pObjData->sKey.UTF8Decode().c_str(),
-                            (bool)(pObjData->bData == 1));
+        FXJS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)pObj,
+                              pObjData->sKey.UTF8Decode().c_str(),
+                              (bool)(pObjData->bData == 1));
         break;
       case JS_GLOBALDATA_TYPE_STRING:
-        JS_PutObjectString(NULL, (v8::Local<v8::Object>)pObj,
-                           pObjData->sKey.UTF8Decode().c_str(),
-                           pObjData->sData.UTF8Decode().c_str());
+        FXJS_PutObjectString(NULL, (v8::Local<v8::Object>)pObj,
+                             pObjData->sKey.UTF8Decode().c_str(),
+                             pObjData->sData.UTF8Decode().c_str());
         break;
       case JS_GLOBALDATA_TYPE_OBJECT: {
         v8::Isolate* pRuntime =
-            JS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
-        v8::Local<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+            FXJS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
+        v8::Local<v8::Object> pNewObj =
+            FXJS_NewFxDynamicObj(pRuntime, NULL, -1);
         PutObjectProperty(pNewObj, pObjData);
-        JS_PutObjectObject(NULL, (v8::Local<v8::Object>)pObj,
-                           pObjData->sKey.UTF8Decode().c_str(),
-                           (v8::Local<v8::Object>)pNewObj);
+        FXJS_PutObjectObject(NULL, (v8::Local<v8::Object>)pObj,
+                             pObjData->sKey.UTF8Decode().c_str(),
+                             (v8::Local<v8::Object>)pNewObj);
       } break;
       case JS_GLOBALDATA_TYPE_NULL:
-        JS_PutObjectNull(NULL, (v8::Local<v8::Object>)pObj,
-                         pObjData->sKey.UTF8Decode().c_str());
+        FXJS_PutObjectNull(NULL, (v8::Local<v8::Object>)pObj,
+                           pObjData->sKey.UTF8Decode().c_str());
         break;
     }
   }
@@ -470,7 +467,7 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname,
         pTemp->sData = sData;
       } break;
       case JS_GLOBALDATA_TYPE_OBJECT: {
-        pTemp->pData.Reset(JS_GetRuntime(pData), pData);
+        pTemp->pData.Reset(FXJS_GetRuntime(pData), pData);
       } break;
       case JS_GLOBALDATA_TYPE_NULL:
         break;
@@ -504,7 +501,7 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname,
     case JS_GLOBALDATA_TYPE_OBJECT: {
       pNewData = new JSGlobalData;
       pNewData->nType = JS_GLOBALDATA_TYPE_OBJECT;
-      pNewData->pData.Reset(JS_GetRuntime(pData), pData);
+      pNewData->pData.Reset(FXJS_GetRuntime(pData), pData);
       pNewData->bPersistent = bDefaultPersistent;
     } break;
     case JS_GLOBALDATA_TYPE_NULL: {
@@ -520,25 +517,25 @@ FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname,
   return TRUE;
 }
 
-FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p) {
-  const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p));
+CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p) {
+  const unsigned int nHash = JS_CalcHash(FXJS_GetTypeof(p));
 
   if (nHash == JSCONST_nUndefHash)
-    return VT_undefined;
+    return CJS_Value::VT_undefined;
   if (nHash == JSCONST_nNullHash)
-    return VT_null;
+    return CJS_Value::VT_null;
   if (nHash == JSCONST_nStringHash)
-    return VT_string;
+    return CJS_Value::VT_string;
   if (nHash == JSCONST_nNumberHash)
-    return VT_number;
+    return CJS_Value::VT_number;
   if (nHash == JSCONST_nBoolHash)
-    return VT_boolean;
+    return CJS_Value::VT_boolean;
   if (nHash == JSCONST_nDateHash)
-    return VT_date;
+    return CJS_Value::VT_date;
   if (nHash == JSCONST_nObjectHash)
-    return VT_object;
+    return CJS_Value::VT_object;
   if (nHash == JSCONST_nFXobjHash)
-    return VT_fxobject;
+    return CJS_Value::VT_fxobject;
 
-  return VT_unknown;
+  return CJS_Value::VT_unknown;
 }
index 85092da..c1b7b4e 100644 (file)
@@ -212,7 +212,7 @@ FX_BOOL util::printd(IFXJS_Context* cc,
     return FALSE;
   }
 
-  if (p1.GetType() == VT_number) {
+  if (p1.GetType() == CJS_Value::VT_number) {
     int nFormat = p1.ToInt();
     CFX_WideString swResult;
 
@@ -242,7 +242,7 @@ FX_BOOL util::printd(IFXJS_Context* cc,
     vRet = swResult.c_str();
     return TRUE;
   }
-  if (p1.GetType() == VT_string) {
+  if (p1.GetType() == CJS_Value::VT_string) {
     std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str();
 
     bool bXFAPicture = false;
index c516645..2fe6e44 100644 (file)
@@ -4,14 +4,14 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "../../../core/include/fxcrt/fx_basic.h"
-#include "../../../core/include/fxcrt/fx_ext.h"
-#include "../../include/jsapi/fxjs_v8.h"
-#include "../../include/fsdk_define.h"
-#include "time.h"
+#include <time.h>
 #include <cmath>
 #include <limits>
 
+#include "../../../core/include/fxcrt/fx_basic.h"
+#include "../../include/fsdk_define.h"
+#include "../../include/jsapi/fxjs_v8.h"
+
 const wchar_t kFXJSValueNameString[] = L"string";
 const wchar_t kFXJSValueNameNumber[] = L"number";
 const wchar_t kFXJSValueNameBoolean[] = L"boolean";
@@ -21,26 +21,22 @@ const wchar_t kFXJSValueNameFxobj[] = L"fxobj";
 const wchar_t kFXJSValueNameNull[] = L"null";
 const wchar_t kFXJSValueNameUndefined[] = L"undefined";
 
-const static FX_DWORD g_nan[2] = {0, 0x7FF80000};
-static double GetNan() {
-  return *(double*)g_nan;
-}
 static unsigned int g_embedderDataSlot = 0u;
 
-class CJS_PrivateData {
+class CFXJS_PrivateData {
  public:
-  CJS_PrivateData() : ObjDefID(-1), pPrivate(NULL) {}
+  CFXJS_PrivateData() : ObjDefID(-1), pPrivate(NULL) {}
   int ObjDefID;
   void* pPrivate;
 };
 
-class CJS_ObjDefintion {
+class CFXJS_ObjDefintion {
  public:
-  CJS_ObjDefintion(v8::Isolate* isolate,
-                   const wchar_t* sObjName,
-                   FXJSOBJTYPE eObjType,
-                   LP_CONSTRUCTOR pConstructor,
-                   LP_DESTRUCTOR pDestructor)
+  CFXJS_ObjDefintion(v8::Isolate* isolate,
+                     const wchar_t* sObjName,
+                     FXJSOBJTYPE eObjType,
+                     FXJS_CONSTRUCTOR pConstructor,
+                     FXJS_DESTRUCTOR pDestructor)
       : objName(sObjName),
         objType(eObjType),
         m_pConstructor(pConstructor),
@@ -59,7 +55,7 @@ class CJS_ObjDefintion {
       m_bSetAsGlobalObject = TRUE;
     }
   }
-  ~CJS_ObjDefintion() {
+  ~CFXJS_ObjDefintion() {
     m_objTemplate.Reset();
     m_StaticObj.Reset();
   }
@@ -67,51 +63,51 @@ class CJS_ObjDefintion {
  public:
   const wchar_t* objName;
   FXJSOBJTYPE objType;
-  LP_CONSTRUCTOR m_pConstructor;
-  LP_DESTRUCTOR m_pDestructor;
+  FXJS_CONSTRUCTOR m_pConstructor;
+  FXJS_DESTRUCTOR m_pDestructor;
   FX_BOOL m_bSetAsGlobalObject;
 
   v8::Global<v8::ObjectTemplate> m_objTemplate;
   v8::Global<v8::Object> m_StaticObj;
 };
 
-void* JS_ArrayBufferAllocator::Allocate(size_t length) {
+void* FXJS_ArrayBufferAllocator::Allocate(size_t length) {
   return calloc(1, length);
 }
 
-void* JS_ArrayBufferAllocator::AllocateUninitialized(size_t length) {
+void* FXJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) {
   return malloc(length);
 }
 
-void JS_ArrayBufferAllocator::Free(void* data, size_t length) {
+void FXJS_ArrayBufferAllocator::Free(void* data, size_t length) {
   free(data);
 }
 
-void JS_PrepareIsolate(v8::Isolate* pIsolate) {
+void FXJS_PrepareIsolate(v8::Isolate* pIsolate) {
   if (!pIsolate->GetData(g_embedderDataSlot))
     pIsolate->SetData(g_embedderDataSlot, new CFX_PtrArray());
 }
 
-int JS_DefineObj(v8::Isolate* pIsolate,
-                 const wchar_t* sObjName,
-                 FXJSOBJTYPE eObjType,
-                 LP_CONSTRUCTOR pConstructor,
-                 LP_DESTRUCTOR pDestructor) {
+int FXJS_DefineObj(v8::Isolate* pIsolate,
+                   const wchar_t* sObjName,
+                   FXJSOBJTYPE eObjType,
+                   FXJS_CONSTRUCTOR pConstructor,
+                   FXJS_DESTRUCTOR pDestructor) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
 
-  JS_PrepareIsolate(pIsolate);
+  FXJS_PrepareIsolate(pIsolate);
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
-  CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(pIsolate, sObjName, eObjType,
-                                                   pConstructor, pDestructor);
+  CFXJS_ObjDefintion* pObjDef = new CFXJS_ObjDefintion(
+      pIsolate, sObjName, eObjType, pConstructor, pDestructor);
   pArray->Add(pObjDef);
   return pArray->GetSize() - 1;
 }
 
-void JS_DefineObjMethod(v8::Isolate* pIsolate,
-                        int nObjDefnID,
-                        const wchar_t* sMethodName,
-                        v8::FunctionCallback pMethodCall) {
+void FXJS_DefineObjMethod(v8::Isolate* pIsolate,
+                          int nObjDefnID,
+                          const wchar_t* sMethodName,
+                          v8::FunctionCallback pMethodCall) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
 
@@ -120,7 +116,7 @@ void JS_DefineObjMethod(v8::Isolate* pIsolate,
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
 
   // Note: GetAt() halts if out-of-range even in release builds.
-  CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
+  CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
   v8::Local<v8::ObjectTemplate> objTemp =
       v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
   objTemp->Set(
@@ -130,11 +126,11 @@ void JS_DefineObjMethod(v8::Isolate* pIsolate,
   pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
 }
 
-void JS_DefineObjProperty(v8::Isolate* pIsolate,
-                          int nObjDefnID,
-                          const wchar_t* sPropName,
-                          v8::AccessorGetterCallback pPropGet,
-                          v8::AccessorSetterCallback pPropPut) {
+void FXJS_DefineObjProperty(v8::Isolate* pIsolate,
+                            int nObjDefnID,
+                            const wchar_t* sPropName,
+                            v8::AccessorGetterCallback pPropGet,
+                            v8::AccessorSetterCallback pPropPut) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
 
@@ -143,7 +139,7 @@ void JS_DefineObjProperty(v8::Isolate* pIsolate,
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
 
   // Note: GetAt() halts if out-of-range even in release builds.
-  CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
+  CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
   v8::Local<v8::ObjectTemplate> objTemp =
       v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
   objTemp->SetAccessor(
@@ -153,28 +149,28 @@ void JS_DefineObjProperty(v8::Isolate* pIsolate,
   pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
 }
 
-void JS_DefineObjAllProperties(v8::Isolate* pIsolate,
-                               int nObjDefnID,
-                               v8::NamedPropertyQueryCallback pPropQurey,
-                               v8::NamedPropertyGetterCallback pPropGet,
-                               v8::NamedPropertySetterCallback pPropPut,
-                               v8::NamedPropertyDeleterCallback pPropDel) {
+void FXJS_DefineObjAllProperties(v8::Isolate* pIsolate,
+                                 int nObjDefnID,
+                                 v8::NamedPropertyQueryCallback pPropQurey,
+                                 v8::NamedPropertyGetterCallback pPropGet,
+                                 v8::NamedPropertySetterCallback pPropPut,
+                                 v8::NamedPropertyDeleterCallback pPropDel) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
 
   // Note: GetAt() halts if out-of-range even in release builds.
-  CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
+  CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
   v8::Local<v8::ObjectTemplate> objTemp =
       v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
   objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDel);
   pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
 }
 
-void JS_DefineObjConst(v8::Isolate* pIsolate,
-                       int nObjDefnID,
-                       const wchar_t* sConstName,
-                       v8::Local<v8::Value> pDefault) {
+void FXJS_DefineObjConst(v8::Isolate* pIsolate,
+                         int nObjDefnID,
+                         const wchar_t* sConstName,
+                         v8::Local<v8::Value> pDefault) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
 
@@ -183,7 +179,7 @@ void JS_DefineObjConst(v8::Isolate* pIsolate,
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
 
   // Note: GetAt() halts if out-of-range even in release builds.
-  CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
+  CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
   v8::Local<v8::ObjectTemplate> objTemp =
       v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
   objTemp->Set(pIsolate, bsConstName.c_str(), pDefault);
@@ -198,7 +194,7 @@ static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
   ASSERT(pArray != NULL);
   for (int i = 0; i < pArray->GetSize(); i++) {
-    CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
+    CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(i);
     if (pObjDef->m_bSetAsGlobalObject)
       return pObjDef->m_objTemplate;
   }
@@ -206,9 +202,9 @@ static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(
   return gloabalObjectTemplate;
 }
 
-void JS_DefineGlobalMethod(v8::Isolate* pIsolate,
-                           const wchar_t* sMethodName,
-                           v8::FunctionCallback pMethodCall) {
+void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate,
+                             const wchar_t* sMethodName,
+                             v8::FunctionCallback pMethodCall) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
 
@@ -233,9 +229,9 @@ void JS_DefineGlobalMethod(v8::Isolate* pIsolate,
   globalObjTemp.Reset(pIsolate, objTemp);
 }
 
-void JS_DefineGlobalConst(v8::Isolate* pIsolate,
-                          const wchar_t* sConstName,
-                          v8::Local<v8::Value> pDefault) {
+void FXJS_DefineGlobalConst(v8::Isolate* pIsolate,
+                            const wchar_t* sConstName,
+                            v8::Local<v8::Value> pDefault) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
 
@@ -258,10 +254,10 @@ void JS_DefineGlobalConst(v8::Isolate* pIsolate,
   globalObjTemp.Reset(pIsolate, objTemp);
 }
 
-void JS_InitializeRuntime(v8::Isolate* pIsolate,
-                          IFXJS_Runtime* pFXRuntime,
-                          IFXJS_Context* context,
-                          v8::Global<v8::Context>& v8PersistentContext) {
+void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
+                            IFXJS_Runtime* pFXRuntime,
+                            IFXJS_Context* context,
+                            v8::Global<v8::Context>& v8PersistentContext) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
 
@@ -280,7 +276,7 @@ void JS_InitializeRuntime(v8::Isolate* pIsolate,
     return;
 
   for (int i = 0; i < pArray->GetSize(); i++) {
-    CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
+    CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(i);
     CFX_WideString ws = CFX_WideString(pObjDef->objName);
     CFX_ByteString bs = ws.UTF8Encode();
     v8::Local<v8::String> objName =
@@ -288,10 +284,10 @@ void JS_InitializeRuntime(v8::Isolate* pIsolate,
                                 v8::NewStringType::kNormal,
                                 bs.GetLength()).ToLocalChecked();
 
-    if (pObjDef->objType == JS_DYNAMIC) {
+    if (pObjDef->objType == FXJS_DYNAMIC) {
       // Document is set as global object, need to construct it first.
       if (ws.Equal(L"Document")) {
-        CJS_PrivateData* pPrivateData = new CJS_PrivateData;
+        CFXJS_PrivateData* pPrivateData = new CFXJS_PrivateData;
         pPrivateData->ObjDefID = i;
 
         v8Context->Global()
@@ -311,7 +307,7 @@ void JS_InitializeRuntime(v8::Isolate* pIsolate,
                                       .ToLocalChecked());
       }
     } else {
-      v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pIsolate, context, i);
+      v8::Local<v8::Object> obj = FXJS_NewFxDynamicObj(pIsolate, context, i);
       v8Context->Global()->Set(v8Context, objName, obj).FromJust();
       pObjDef->m_StaticObj.Reset(pIsolate, obj);
     }
@@ -319,8 +315,8 @@ void JS_InitializeRuntime(v8::Isolate* pIsolate,
   v8PersistentContext.Reset(pIsolate, v8Context);
 }
 
-void JS_ReleaseRuntime(v8::Isolate* pIsolate,
-                       v8::Global<v8::Context>& v8PersistentContext) {
+void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
+                         v8::Global<v8::Context>& v8PersistentContext) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::HandleScope handle_scope(pIsolate);
   v8::Local<v8::Context> context =
@@ -332,13 +328,13 @@ void JS_ReleaseRuntime(v8::Isolate* pIsolate,
     return;
 
   for (int i = 0; i < pArray->GetSize(); i++) {
-    CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
+    CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(i);
     if (!pObjDef->m_StaticObj.IsEmpty()) {
       v8::Local<v8::Object> pObj =
           v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
       if (pObjDef->m_pDestructor)
         pObjDef->m_pDestructor(pObj);
-      JS_FreePrivate(pObj);
+      FXJS_FreePrivate(pObj);
     }
     delete pObjDef;
   }
@@ -346,18 +342,18 @@ void JS_ReleaseRuntime(v8::Isolate* pIsolate,
   pIsolate->SetData(g_embedderDataSlot, NULL);
 }
 
-void JS_Initialize(unsigned int embedderDataSlot) {
+void FXJS_Initialize(unsigned int embedderDataSlot) {
   g_embedderDataSlot = embedderDataSlot;
 }
 
-void JS_Release() {
+void FXJS_Release() {
 }
 
-int JS_Execute(v8::Isolate* pIsolate,
-               IFXJS_Context* pJSContext,
-               const wchar_t* script,
-               long length,
-               FXJSErr* perror) {
+int FXJS_Execute(v8::Isolate* pIsolate,
+                 IFXJS_Context* pJSContext,
+                 const wchar_t* script,
+                 long length,
+                 FXJSErr* pError) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::TryCatch try_catch(pIsolate);
 
@@ -372,20 +368,22 @@ int JS_Execute(v8::Isolate* pIsolate,
                         bsScript.GetLength()).ToLocalChecked())
            .ToLocal(&compiled_script)) {
     v8::String::Utf8Value error(try_catch.Exception());
+    // TODO(tsepez): return error via pError->message.
     return -1;
   }
 
   v8::Local<v8::Value> result;
   if (!compiled_script->Run(context).ToLocal(&result)) {
     v8::String::Utf8Value error(try_catch.Exception());
+    // TODO(tsepez): return error via pError->message.
     return -1;
   }
   return 0;
 }
 
-v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
-                                         IFXJS_Context* pJSContext,
-                                         int nObjDefnID) {
+v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate,
+                                           IFXJS_Context* pJSContext,
+                                           int nObjDefnID) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   if (-1 == nObjDefnID) {
@@ -402,7 +400,7 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
 
   if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
     return v8::Local<v8::Object>();
-  CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
+  CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
 
   v8::Local<v8::ObjectTemplate> objTemp =
       v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
@@ -410,7 +408,7 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
   if (!objTemp->NewInstance(context).ToLocal(&obj))
     return v8::Local<v8::Object>();
 
-  CJS_PrivateData* pPrivateData = new CJS_PrivateData;
+  CFXJS_PrivateData* pPrivateData = new CFXJS_PrivateData;
   pPrivateData->ObjDefID = nObjDefnID;
 
   obj->SetAlignedPointerInInternalField(0, pPrivateData);
@@ -422,7 +420,7 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
   return obj;
 }
 
-v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID) {
+v8::Local<v8::Object> FXJS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
   if (!pArray)
@@ -430,13 +428,13 @@ v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID) {
 
   if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
     return v8::Local<v8::Object>();
-  CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
+  CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
   v8::Local<v8::Object> obj =
       v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj);
   return obj;
 }
 
-v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate) {
+v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate) {
   // Return the global object.
   v8::Isolate::Scope isolate_scope(pIsolate);
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
@@ -447,17 +445,17 @@ v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate) {
   return context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
 }
 
-int JS_GetObjDefnID(v8::Local<v8::Object> pObj) {
+int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj) {
   if (pObj.IsEmpty() || !pObj->InternalFieldCount())
     return -1;
-  CJS_PrivateData* pPrivateData =
-      (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
+  CFXJS_PrivateData* pPrivateData =
+      (CFXJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
   if (pPrivateData)
     return pPrivateData->ObjDefID;
   return -1;
 }
 
-v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj) {
+v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj) {
   if (pObj.IsEmpty())
     return NULL;
   v8::Local<v8::Context> context = pObj->CreationContext();
@@ -466,21 +464,21 @@ v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj) {
   return context->GetIsolate();
 }
 
-int JS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName) {
+int FXJS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName) {
   v8::Isolate::Scope isolate_scope(pIsolate);
   CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
   if (!pArray)
     return -1;
 
   for (int i = 0; i < pArray->GetSize(); i++) {
-    CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
+    CFXJS_ObjDefintion* pObjDef = (CFXJS_ObjDefintion*)pArray->GetAt(i);
     if (FXSYS_wcscmp(pObjDef->objName, pObjName) == 0)
       return i;
   }
   return -1;
 }
 
-void JS_Error(v8::Isolate* pIsolate, const CFX_WideString& message) {
+void FXJS_Error(v8::Isolate* pIsolate, const CFX_WideString& message) {
   // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t
   // wide-strings isn't handled by v8, so use UTF8 as a common
   // intermediate format.
@@ -490,14 +488,7 @@ void JS_Error(v8::Isolate* pIsolate, const CFX_WideString& message) {
                               v8::NewStringType::kNormal).ToLocalChecked());
 }
 
-unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) {
-  return (unsigned)FX_HashCode_String_GetW(main, nLen);
-}
-
-unsigned JS_CalcHash(const wchar_t* main) {
-  return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main));
-}
-const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj) {
+const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj) {
   if (pObj.IsEmpty())
     return NULL;
   if (pObj->IsString())
@@ -516,38 +507,40 @@ const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj) {
     return kFXJSValueNameUndefined;
   return NULL;
 }
-void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) {
-  JS_SetPrivate(NULL, pObj, p);
+void FXJS_SetPrivate(v8::Local<v8::Object> pObj, void* p) {
+  FXJS_SetPrivate(NULL, pObj, p);
 }
 
-void* JS_GetPrivate(v8::Local<v8::Object> pObj) {
-  return JS_GetPrivate(NULL, pObj);
+void* FXJS_GetPrivate(v8::Local<v8::Object> pObj) {
+  return FXJS_GetPrivate(NULL, pObj);
 }
 
-void JS_SetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, void* p) {
+void FXJS_SetPrivate(v8::Isolate* pIsolate,
+                     v8::Local<v8::Object> pObj,
+                     void* p) {
   if (pObj.IsEmpty() || !pObj->InternalFieldCount())
     return;
-  CJS_PrivateData* pPrivateData =
-      (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
+  CFXJS_PrivateData* pPrivateData =
+      (CFXJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
   if (!pPrivateData)
     return;
   pPrivateData->pPrivate = p;
 }
 
-void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) {
+void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) {
   if (pObj.IsEmpty())
     return NULL;
-  CJS_PrivateData* pPrivateData = NULL;
+  CFXJS_PrivateData* pPrivateData = NULL;
   if (pObj->InternalFieldCount())
     pPrivateData =
-        (CJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
+        (CFXJS_PrivateData*)pObj->GetAlignedPointerFromInternalField(0);
   else {
     // It could be a global proxy object.
     v8::Local<v8::Value> v = pObj->GetPrototype();
     v8::Isolate* isolate = (v8::Isolate*)pIsolate;
     v8::Local<v8::Context> context = isolate->GetCurrentContext();
     if (v->IsObject())
-      pPrivateData = (CJS_PrivateData*)v->ToObject(context)
+      pPrivateData = (CFXJS_PrivateData*)v->ToObject(context)
                          .ToLocalChecked()
                          ->GetAlignedPointerFromInternalField(0);
   }
@@ -556,24 +549,20 @@ void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj) {
   return pPrivateData->pPrivate;
 }
 
-void JS_FreePrivate(void* pPrivateData) {
-  delete (CJS_PrivateData*)pPrivateData;
+void FXJS_FreePrivate(void* pPrivateData) {
+  delete (CFXJS_PrivateData*)pPrivateData;
 }
 
-void JS_FreePrivate(v8::Local<v8::Object> pObj) {
+void FXJS_FreePrivate(v8::Local<v8::Object> pObj) {
   if (pObj.IsEmpty() || !pObj->InternalFieldCount())
     return;
-  JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0));
+  FXJS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0));
   pObj->SetAlignedPointerInInternalField(0, NULL);
 }
 
-v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) {
-  return pObj;
-}
-
-v8::Local<v8::String> WSToJSString(v8::Isolate* pIsolate,
-                                   const wchar_t* PropertyName,
-                                   int Len = -1) {
+v8::Local<v8::String> FXJS_WSToJSString(v8::Isolate* pIsolate,
+                                        const wchar_t* PropertyName,
+                                        int Len) {
   CFX_WideString ws = CFX_WideString(PropertyName, Len);
   CFX_ByteString bs = ws.UTF8Encode();
   if (!pIsolate)
@@ -582,20 +571,24 @@ v8::Local<v8::String> WSToJSString(v8::Isolate* pIsolate,
                                  v8::NewStringType::kNormal).ToLocalChecked();
 }
 
-v8::Local<v8::Value> JS_GetObjectElement(v8::Isolate* pIsolate,
-                                         v8::Local<v8::Object> pObj,
-                                         const wchar_t* PropertyName) {
+v8::Local<v8::Value> FXJS_GetObjectValue(v8::Local<v8::Object> pObj) {
+  return pObj;
+}
+
+v8::Local<v8::Value> FXJS_GetObjectElement(v8::Isolate* pIsolate,
+                                           v8::Local<v8::Object> pObj,
+                                           const wchar_t* PropertyName) {
   if (pObj.IsEmpty())
     return v8::Local<v8::Value>();
   v8::Local<v8::Value> val;
   if (!pObj->Get(pIsolate->GetCurrentContext(),
-                 WSToJSString(pIsolate, PropertyName)).ToLocal(&val))
+                 FXJS_WSToJSString(pIsolate, PropertyName)).ToLocal(&val))
     return v8::Local<v8::Value>();
   return val;
 }
 
-v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate,
-                                              v8::Local<v8::Object> pObj) {
+v8::Local<v8::Array> FXJS_GetObjectElementNames(v8::Isolate* pIsolate,
+                                                v8::Local<v8::Object> pObj) {
   if (pObj.IsEmpty())
     return v8::Local<v8::Array>();
   v8::Local<v8::Array> val;
@@ -604,85 +597,90 @@ v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate,
   return val;
 }
 
-void JS_PutObjectString(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        const wchar_t* sValue)  // VT_string
+void FXJS_PutObjectString(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          const wchar_t* sValue)  // VT_string
 {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
-            WSToJSString(pIsolate, sValue)).FromJust();
+  pObj->Set(pIsolate->GetCurrentContext(),
+            FXJS_WSToJSString(pIsolate, PropertyName),
+            FXJS_WSToJSString(pIsolate, sValue)).FromJust();
 }
 
-void JS_PutObjectNumber(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        int nValue) {
+void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          int nValue) {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
+  pObj->Set(pIsolate->GetCurrentContext(),
+            FXJS_WSToJSString(pIsolate, PropertyName),
             v8::Int32::New(pIsolate, nValue)).FromJust();
 }
 
-void JS_PutObjectNumber(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        float fValue) {
+void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          float fValue) {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
+  pObj->Set(pIsolate->GetCurrentContext(),
+            FXJS_WSToJSString(pIsolate, PropertyName),
             v8::Number::New(pIsolate, (double)fValue)).FromJust();
 }
 
-void JS_PutObjectNumber(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        double dValue) {
+void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          double dValue) {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
+  pObj->Set(pIsolate->GetCurrentContext(),
+            FXJS_WSToJSString(pIsolate, PropertyName),
             v8::Number::New(pIsolate, (double)dValue)).FromJust();
 }
 
-void JS_PutObjectBoolean(v8::Isolate* pIsolate,
-                         v8::Local<v8::Object> pObj,
-                         const wchar_t* PropertyName,
-                         bool bValue) {
+void FXJS_PutObjectBoolean(v8::Isolate* pIsolate,
+                           v8::Local<v8::Object> pObj,
+                           const wchar_t* PropertyName,
+                           bool bValue) {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
+  pObj->Set(pIsolate->GetCurrentContext(),
+            FXJS_WSToJSString(pIsolate, PropertyName),
             v8::Boolean::New(pIsolate, bValue)).FromJust();
 }
 
-void JS_PutObjectObject(v8::Isolate* pIsolate,
-                        v8::Local<v8::Object> pObj,
-                        const wchar_t* PropertyName,
-                        v8::Local<v8::Object> pPut) {
+void FXJS_PutObjectObject(v8::Isolate* pIsolate,
+                          v8::Local<v8::Object> pObj,
+                          const wchar_t* PropertyName,
+                          v8::Local<v8::Object> pPut) {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
-            pPut).FromJust();
+  pObj->Set(pIsolate->GetCurrentContext(),
+            FXJS_WSToJSString(pIsolate, PropertyName), pPut).FromJust();
 }
 
-void JS_PutObjectNull(v8::Isolate* pIsolate,
-                      v8::Local<v8::Object> pObj,
-                      const wchar_t* PropertyName) {
+void FXJS_PutObjectNull(v8::Isolate* pIsolate,
+                        v8::Local<v8::Object> pObj,
+                        const wchar_t* PropertyName) {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(pIsolate->GetCurrentContext(), WSToJSString(pIsolate, PropertyName),
+  pObj->Set(pIsolate->GetCurrentContext(),
+            FXJS_WSToJSString(pIsolate, PropertyName),
             v8::Local<v8::Object>()).FromJust();
 }
 
-v8::Local<v8::Array> JS_NewArray(v8::Isolate* pIsolate) {
+v8::Local<v8::Array> FXJS_NewArray(v8::Isolate* pIsolate) {
   return v8::Array::New(pIsolate);
 }
 
-unsigned JS_PutArrayElement(v8::Isolate* pIsolate,
-                            v8::Local<v8::Array> pArray,
-                            unsigned index,
-                            v8::Local<v8::Value> pValue,
-                            FXJSVALUETYPE eType) {
+unsigned FXJS_PutArrayElement(v8::Isolate* pIsolate,
+                              v8::Local<v8::Array> pArray,
+                              unsigned index,
+                              v8::Local<v8::Value> pValue) {
   if (pArray.IsEmpty())
     return 0;
   if (pArray->Set(pIsolate->GetCurrentContext(), index, pValue).IsNothing())
@@ -690,9 +688,9 @@ unsigned JS_PutArrayElement(v8::Isolate* pIsolate,
   return 1;
 }
 
-v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate,
-                                        v8::Local<v8::Array> pArray,
-                                        unsigned index) {
+v8::Local<v8::Value> FXJS_GetArrayElement(v8::Isolate* pIsolate,
+                                          v8::Local<v8::Array> pArray,
+                                          unsigned index) {
   if (pArray.IsEmpty())
     return v8::Local<v8::Value>();
   v8::Local<v8::Value> val;
@@ -701,68 +699,68 @@ v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate,
   return val;
 }
 
-unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) {
+unsigned FXJS_GetArrayLength(v8::Local<v8::Array> pArray) {
   if (pArray.IsEmpty())
     return 0;
   return pArray->Length();
 }
 
-v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, int number) {
+v8::Local<v8::Value> FXJS_NewNumber(v8::Isolate* pIsolate, int number) {
   return v8::Int32::New(pIsolate, number);
 }
 
-v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, double number) {
+v8::Local<v8::Value> FXJS_NewNumber(v8::Isolate* pIsolate, double number) {
   return v8::Number::New(pIsolate, number);
 }
 
-v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, float number) {
+v8::Local<v8::Value> FXJS_NewNumber(v8::Isolate* pIsolate, float number) {
   return v8::Number::New(pIsolate, (float)number);
 }
 
-v8::Local<v8::Value> JS_NewBoolean(v8::Isolate* pIsolate, bool b) {
+v8::Local<v8::Value> FXJS_NewBoolean(v8::Isolate* pIsolate, bool b) {
   return v8::Boolean::New(pIsolate, b);
 }
 
-v8::Local<v8::Value> JS_NewObject(v8::Isolate* pIsolate,
-                                  v8::Local<v8::Object> pObj) {
+v8::Local<v8::Value> FXJS_NewObject(v8::Isolate* pIsolate,
+                                    v8::Local<v8::Object> pObj) {
   if (pObj.IsEmpty())
     return v8::Local<v8::Value>();
   return pObj->Clone();
 }
 
-v8::Local<v8::Value> JS_NewObject2(v8::Isolate* pIsolate,
-                                   v8::Local<v8::Array> pObj) {
+v8::Local<v8::Value> FXJS_NewObject2(v8::Isolate* pIsolate,
+                                     v8::Local<v8::Array> pObj) {
   if (pObj.IsEmpty())
     return v8::Local<v8::Value>();
   return pObj->Clone();
 }
 
-v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
-                                  const wchar_t* string) {
-  return WSToJSString(pIsolate, string);
+v8::Local<v8::Value> FXJS_NewString(v8::Isolate* pIsolate,
+                                    const wchar_t* string) {
+  return FXJS_WSToJSString(pIsolate, string);
 }
 
-v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
-                                  const wchar_t* string,
-                                  unsigned nLen) {
-  return WSToJSString(pIsolate, string, nLen);
+v8::Local<v8::Value> FXJS_NewString(v8::Isolate* pIsolate,
+                                    const wchar_t* string,
+                                    unsigned nLen) {
+  return FXJS_WSToJSString(pIsolate, string, nLen);
 }
 
-v8::Local<v8::Value> JS_NewNull() {
+v8::Local<v8::Value> FXJS_NewNull() {
   return v8::Local<v8::Value>();
 }
 
-v8::Local<v8::Value> JS_NewDate(v8::Isolate* pIsolate, double d) {
+v8::Local<v8::Value> FXJS_NewDate(v8::Isolate* pIsolate, double d) {
   return v8::Date::New(pIsolate->GetCurrentContext(), d).ToLocalChecked();
 }
 
-v8::Local<v8::Value> JS_NewValue(v8::Isolate* pIsolate) {
+v8::Local<v8::Value> FXJS_NewValue(v8::Isolate* pIsolate) {
   return v8::Local<v8::Value>();
 }
 
-v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate,
-                                     v8::Local<v8::Value> pList,
-                                     int index) {
+v8::Local<v8::Value> FXJS_GetListValue(v8::Isolate* pIsolate,
+                                       v8::Local<v8::Value> pList,
+                                       int index) {
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   if (!pList.IsEmpty() && pList->IsObject()) {
     v8::Local<v8::Object> obj;
@@ -775,36 +773,37 @@ v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate,
   return v8::Local<v8::Value>();
 }
 
-int JS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
+int FXJS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return 0;
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   return pValue->ToInt32(context).ToLocalChecked()->Value();
 }
 
-bool JS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
+bool FXJS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return false;
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   return pValue->ToBoolean(context).ToLocalChecked()->Value();
 }
 
-double JS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
+double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return 0.0;
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   return pValue->ToNumber(context).ToLocalChecked()->Value();
 }
 
-v8::Local<v8::Object> JS_ToObject(v8::Isolate* pIsolate,
-                                  v8::Local<v8::Value> pValue) {
+v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate,
+                                    v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return v8::Local<v8::Object>();
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   return pValue->ToObject(context).ToLocalChecked();
 }
 
-CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
+CFX_WideString FXJS_ToString(v8::Isolate* pIsolate,
+                             v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return L"";
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
@@ -812,299 +811,16 @@ CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
   return CFX_WideString::FromUTF8(*s, s.length());
 }
 
-v8::Local<v8::Array> JS_ToArray(v8::Isolate* pIsolate,
-                                v8::Local<v8::Value> pValue) {
+v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate,
+                                  v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return v8::Local<v8::Array>();
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
 }
 
-void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
+void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
   pTo = pFrom;
 }
 
-// JavaScript time implement begin.
-
-double _getLocalTZA() {
-  if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
-    return 0;
-  time_t t = 0;
-  time(&t);
-  localtime(&t);
-#if _MSC_VER >= 1900
-  // In gcc and in Visual Studio prior to VS 2015 'timezone' is a global
-  // variable declared in time.h. That variable was deprecated and in VS 2015
-  // is removed, with _get_timezone replacing it.
-  long timezone = 0;
-  _get_timezone(&timezone);
-#endif
-  return (double)(-(timezone * 1000));
-}
-
-int _getDaylightSavingTA(double d) {
-  if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
-    return 0;
-  time_t t = (time_t)(d / 1000);
-  struct tm* tmp = localtime(&t);
-  if (tmp == NULL)
-    return 0;
-  if (tmp->tm_isdst > 0)
-    // One hour.
-    return (int)60 * 60 * 1000;
-  return 0;
-}
-
-double _Mod(double x, double y) {
-  double r = fmod(x, y);
-  if (r < 0)
-    r += y;
-  return r;
-}
-
-int _isfinite(double v) {
-#if _MSC_VER
-  return ::_finite(v);
-#else
-  return std::fabs(v) < std::numeric_limits<double>::max();
-#endif
-}
-
-double _toInteger(double n) {
-  return (n >= 0) ? FXSYS_floor(n) : -FXSYS_floor(-n);
-}
-
-bool _isLeapYear(int year) {
-  return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0));
-}
-
-int _DayFromYear(int y) {
-  return (int)(365 * (y - 1970.0) + FXSYS_floor((y - 1969.0) / 4) -
-               FXSYS_floor((y - 1901.0) / 100) +
-               FXSYS_floor((y - 1601.0) / 400));
-}
-
-double _TimeFromYear(int y) {
-  return ((double)86400000) * _DayFromYear(y);
-}
-
-double _TimeFromYearMonth(int y, int m) {
-  static int daysMonth[12] = {0,   31,  59,  90,  120, 151,
-                              181, 212, 243, 273, 304, 334};
-  static int leapDaysMonth[12] = {0,   31,  60,  91,  121, 152,
-                                  182, 213, 244, 274, 305, 335};
-  int* pMonth = daysMonth;
-  if (_isLeapYear(y))
-    pMonth = leapDaysMonth;
-  return _TimeFromYear(y) + ((double)pMonth[m]) * 86400000;
-}
-
-int _Day(double t) {
-  return (int)FXSYS_floor(t / 86400000);
-}
-
-int _YearFromTime(double t) {
-  // estimate the time.
-  int y = 1970 + (int)(t / (365.0 * 86400000));
-  if (_TimeFromYear(y) <= t) {
-    while (_TimeFromYear(y + 1) <= t)
-      y++;
-  } else
-    while (_TimeFromYear(y - 1) > t)
-      y--;
-  return y;
-}
-
-int _DayWithinYear(double t) {
-  int year = _YearFromTime(t);
-  int day = _Day(t);
-  return day - _DayFromYear(year);
-}
-
-int _MonthFromTime(double t) {
-  int day = _DayWithinYear(t);
-  int year = _YearFromTime(t);
-  if (0 <= day && day < 31)
-    return 0;
-  if (31 <= day && day < 59 + _isLeapYear(year))
-    return 1;
-  if ((59 + _isLeapYear(year)) <= day && day < (90 + _isLeapYear(year)))
-    return 2;
-  if ((90 + _isLeapYear(year)) <= day && day < (120 + _isLeapYear(year)))
-    return 3;
-  if ((120 + _isLeapYear(year)) <= day && day < (151 + _isLeapYear(year)))
-    return 4;
-  if ((151 + _isLeapYear(year)) <= day && day < (181 + _isLeapYear(year)))
-    return 5;
-  if ((181 + _isLeapYear(year)) <= day && day < (212 + _isLeapYear(year)))
-    return 6;
-  if ((212 + _isLeapYear(year)) <= day && day < (243 + _isLeapYear(year)))
-    return 7;
-  if ((243 + _isLeapYear(year)) <= day && day < (273 + _isLeapYear(year)))
-    return 8;
-  if ((273 + _isLeapYear(year)) <= day && day < (304 + _isLeapYear(year)))
-    return 9;
-  if ((304 + _isLeapYear(year)) <= day && day < (334 + _isLeapYear(year)))
-    return 10;
-  if ((334 + _isLeapYear(year)) <= day && day < (365 + _isLeapYear(year)))
-    return 11;
-
-  return -1;
-}
-
-int _DateFromTime(double t) {
-  int day = _DayWithinYear(t);
-  int year = _YearFromTime(t);
-  bool leap = _isLeapYear(year);
-  int month = _MonthFromTime(t);
-  switch (month) {
-    case 0:
-      return day + 1;
-    case 1:
-      return day - 30;
-    case 2:
-      return day - 58 - leap;
-    case 3:
-      return day - 89 - leap;
-    case 4:
-      return day - 119 - leap;
-    case 5:
-      return day - 150 - leap;
-    case 6:
-      return day - 180 - leap;
-    case 7:
-      return day - 211 - leap;
-    case 8:
-      return day - 242 - leap;
-    case 9:
-      return day - 272 - leap;
-    case 10:
-      return day - 303 - leap;
-    case 11:
-      return day - 333 - leap;
-    default:
-      return 0;
-  }
-}
-
-double JS_GetDateTime() {
-  if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
-    return 0;
-  time_t t = time(NULL);
-  struct tm* pTm = localtime(&t);
-
-  int year = pTm->tm_year + 1900;
-  double t1 = _TimeFromYear(year);
-
-  return t1 + pTm->tm_yday * 86400000.0 + pTm->tm_hour * 3600000.0 +
-         pTm->tm_min * 60000.0 + pTm->tm_sec * 1000.0;
-}
-
-int JS_GetYearFromTime(double dt) {
-  return _YearFromTime(dt);
-}
-
-int JS_GetMonthFromTime(double dt) {
-  return _MonthFromTime(dt);
-}
-
-int JS_GetDayFromTime(double dt) {
-  return _DateFromTime(dt);
-}
-
-int JS_GetHourFromTime(double dt) {
-  return (int)_Mod(FXSYS_floor((double)(dt / (60 * 60 * 1000))), 24);
-}
-
-int JS_GetMinFromTime(double dt) {
-  return (int)_Mod(FXSYS_floor((double)(dt / (60 * 1000))), 60);
-}
-
-int JS_GetSecFromTime(double dt) {
-  return (int)_Mod(FXSYS_floor((double)(dt / 1000)), 60);
-}
-
-double JS_DateParse(const wchar_t* string) {
-  v8::Isolate* pIsolate = v8::Isolate::GetCurrent();
-  v8::Isolate::Scope isolate_scope(pIsolate);
-  v8::HandleScope scope(pIsolate);
-
-  v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
-
-  // Use the built-in object method.
-  v8::Local<v8::Value> v =
-      context->Global()
-          ->Get(context, v8::String::NewFromUtf8(pIsolate, "Date",
-                                                 v8::NewStringType::kNormal)
-                             .ToLocalChecked())
-          .ToLocalChecked();
-  if (v->IsObject()) {
-    v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked();
-    v = o->Get(context, v8::String::NewFromUtf8(pIsolate, "parse",
-                                                v8::NewStringType::kNormal)
-                            .ToLocalChecked())
-            .ToLocalChecked();
-    if (v->IsFunction()) {
-      v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v);
-
-      const int argc = 1;
-      v8::Local<v8::String> timeStr = WSToJSString(pIsolate, string);
-      v8::Local<v8::Value> argv[argc] = {timeStr};
-      v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked();
-      if (v->IsNumber()) {
-        double date = v->ToNumber(context).ToLocalChecked()->Value();
-        if (!_isfinite(date))
-          return date;
-        return date + _getLocalTZA() + _getDaylightSavingTA(date);
-      }
-    }
-  }
-  return 0;
-}
-
-double JS_MakeDay(int nYear, int nMonth, int nDate) {
-  if (!_isfinite(nYear) || !_isfinite(nMonth) || !_isfinite(nDate))
-    return GetNan();
-  double y = _toInteger(nYear);
-  double m = _toInteger(nMonth);
-  double dt = _toInteger(nDate);
-  double ym = y + FXSYS_floor((double)m / 12);
-  double mn = _Mod(m, 12);
-
-  double t = _TimeFromYearMonth((int)ym, (int)mn);
-
-  if (_YearFromTime(t) != ym || _MonthFromTime(t) != mn ||
-      _DateFromTime(t) != 1)
-    return GetNan();
-  return _Day(t) + dt - 1;
-}
-
-double JS_MakeTime(int nHour, int nMin, int nSec, int nMs) {
-  if (!_isfinite(nHour) || !_isfinite(nMin) || !_isfinite(nSec) ||
-      !_isfinite(nMs))
-    return GetNan();
-
-  double h = _toInteger(nHour);
-  double m = _toInteger(nMin);
-  double s = _toInteger(nSec);
-  double milli = _toInteger(nMs);
-
-  return h * 3600000 + m * 60000 + s * 1000 + milli;
-}
-
-double JS_MakeDate(double day, double time) {
-  if (!_isfinite(day) || !_isfinite(time))
-    return GetNan();
-
-  return day * 86400000 + time;
-}
-
-bool JS_PortIsNan(double d) {
-  return d != d;
-}
-
-double JS_LocalTime(double d) {
-  return JS_GetDateTime() + _getDaylightSavingTA(d);
-}
 
-// JavaScript time implement End.
index bddf301..2671a91 100644 (file)
@@ -22,7 +22,7 @@ class FXJSV8Embeddertest : public EmbedderTest {
 
   void SetUp() override {
     EmbedderTest::SetUp();
-    m_pAllocator.reset(new JS_ArrayBufferAllocator());
+    m_pAllocator.reset(new FXJS_ArrayBufferAllocator());
 
     v8::Isolate::CreateParams params;
     params.array_buffer_allocator = m_pAllocator.get();
@@ -30,14 +30,14 @@ class FXJSV8Embeddertest : public EmbedderTest {
 
     v8::Isolate::Scope isolate_scope(m_pIsolate);
     v8::HandleScope handle_scope(m_pIsolate);
-    JS_Initialize(0);
-    JS_PrepareIsolate(m_pIsolate);
-    JS_InitializeRuntime(m_pIsolate, nullptr, nullptr, m_pPersistentContext);
+    FXJS_Initialize(0);
+    FXJS_PrepareIsolate(m_pIsolate);
+    FXJS_InitializeRuntime(m_pIsolate, nullptr, nullptr, m_pPersistentContext);
   }
 
   void TearDown() override {
-    JS_ReleaseRuntime(m_pIsolate, m_pPersistentContext);
-    JS_Release();
+    FXJS_ReleaseRuntime(m_pIsolate, m_pPersistentContext);
+    FXJS_Release();
     EmbedderTest::TearDown();
   }
 
@@ -60,10 +60,10 @@ TEST_F(FXJSV8Embeddertest, Getters) {
   FXJSErr error;
   CFX_WideString wsInfo;
   CFX_WideString wsScript(kScript);
-  int sts = JS_Execute(isolate(), nullptr, kScript, wcslen(kScript), &error);
+  int sts = FXJS_Execute(isolate(), nullptr, kScript, wcslen(kScript), &error);
   EXPECT_EQ(0, sts);
 
-  v8::Local<v8::Object> This = JS_GetThisObj(isolate());
-  v8::Local<v8::Value> fred = JS_GetObjectElement(isolate(), This, L"fred");
+  v8::Local<v8::Object> This = FXJS_GetThisObj(isolate());
+  v8::Local<v8::Value> fred = FXJS_GetObjectElement(isolate(), This, L"fred");
   EXPECT_TRUE(fred->IsNumber());
 }