diff options
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r-- | fpdfsdk/src/javascript/Consts.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Document.cpp | 108 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Field.cpp | 23 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Context.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_EventHandler.cpp | 32 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Object.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Runtime.cpp | 60 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Value.cpp | 392 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/PublicMethods.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/app.cpp | 93 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/event.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/global.cpp | 159 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/util.cpp | 4 |
13 files changed, 577 insertions, 309 deletions
diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp index 9574c44730..acb49662b0 100644 --- a/fpdfsdk/src/javascript/Consts.cpp +++ b/fpdfsdk/src/javascript/Consts.cpp @@ -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) { diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index f25e8e0dec..bccf08b271 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -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(); } @@ -853,16 +853,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(); @@ -872,14 +873,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; @@ -1292,7 +1293,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; } @@ -1405,15 +1406,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; } @@ -1460,13 +1461,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; @@ -1504,13 +1505,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; @@ -1706,9 +1707,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. @@ -1830,13 +1831,12 @@ FX_BOOL Document::deletePages(IFXJS_Context* cc, if (iSize < 1) { } else 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"nStart"); + FXJS_GetObjectElement(isolate, pObj, L"nStart"); nStart = CJS_Value(m_isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt(); - - pValue = JS_GetObjectElement(isolate, pObj, L"nEnd"); + pValue = FXJS_GetObjectElement(isolate, pObj, L"nEnd"); nEnd = CJS_Value(m_isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt(); } else { nStart = params[0].ToInt(); diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp index 38262ce132..52f6321f4a 100644 --- a/fpdfsdk/src/javascript/Field.cpp +++ b/fpdfsdk/src/javascript/Field.cpp @@ -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); diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp index 3c9be58013..d4d1f2c877 100644 --- a/fpdfsdk/src/javascript/JS_Context.cpp +++ b/fpdfsdk/src/javascript/JS_Context.cpp @@ -56,8 +56,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) { diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp index acaacf2943..bd762b4946 100644 --- a/fpdfsdk/src/javascript/JS_EventHandler.cpp +++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp @@ -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(); diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp index 17e987d96a..6891e6fc60 100644 --- a/fpdfsdk/src/javascript/JS_Object.cpp +++ b/fpdfsdk/src/javascript/JS_Object.cpp @@ -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) { diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index a85067be1b..bbe9f6e8c8 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -41,7 +41,7 @@ void CJS_RuntimeFactory::AddRef() { void CJS_RuntimeFactory::Release() { if (m_bInit) { if (--m_nRef == 0) { - JS_Release(); + FXJS_Release(); m_bInit = FALSE; } } @@ -69,7 +69,7 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); } 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(); @@ -83,7 +83,7 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) v8::HandleScope handle_scope(isolate); if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) { CJS_Context* pContext = (CJS_Context*)NewContext(); - JS_InitializeRuntime(GetIsolate(), this, pContext, m_context); + FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); ReleaseContext(pContext); return; } @@ -91,11 +91,11 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) unsigned int embedderDataSlot = 0; if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; - 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); } @@ -105,7 +105,6 @@ CJS_Runtime::~CJS_Runtime() { delete m_ContextArray.GetAt(i); m_ContextArray.RemoveAll(); - RemoveEventsInLoop(m_pFieldEventPath); m_pApp = NULL; @@ -127,34 +126,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()); @@ -162,8 +161,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() { @@ -201,11 +200,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); } diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp index 7fb2116e1f..23def5dc9c 100644 --- a/fpdfsdk/src/javascript/JS_Value.cpp +++ b/fpdfsdk/src/javascript/JS_Value.cpp @@ -4,20 +4,28 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include <time.h> +#include <cmath> +#include <limits> + #include "../../include/javascript/JavaScript.h" #include "../../include/javascript/JS_Define.h" #include "../../include/javascript/JS_Object.h" #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 +81,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 +100,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 +116,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 +138,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 +146,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 +183,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 +197,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 +215,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 +250,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 +423,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 +454,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 +465,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 +484,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 +493,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 +501,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 +514,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 +527,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 +540,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 +553,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 +566,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 +576,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); } diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp index c1e0cfc609..17164cc3ee 100644 --- a/fpdfsdk/src/javascript/PublicMethods.cpp +++ b/fpdfsdk/src/javascript/PublicMethods.cpp @@ -1936,7 +1936,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; } diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index d81b226f96..2cdb1ad616 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -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)); @@ -275,21 +276,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"") { @@ -310,7 +313,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"; @@ -323,7 +326,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"; @@ -421,12 +424,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(); @@ -474,12 +477,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(); @@ -506,11 +509,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()) { @@ -549,11 +552,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()) { @@ -647,26 +650,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) @@ -785,26 +788,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) { diff --git a/fpdfsdk/src/javascript/event.cpp b/fpdfsdk/src/javascript/event.cpp index 492f225d18..751705aed1 100644 --- a/fpdfsdk/src/javascript/event.cpp +++ b/fpdfsdk/src/javascript/event.cpp @@ -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; diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp index e87db8c7a0..53dd731f48 100644 --- a/fpdfsdk/src/javascript/global.cpp +++ b/fpdfsdk/src/javascript/global.cpp @@ -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" @@ -53,6 +54,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: @@ -60,22 +65,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 @@ -140,35 +137,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; } @@ -247,46 +244,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; } } @@ -338,48 +335,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; @@ -401,32 +397,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; } } @@ -471,7 +468,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; @@ -505,7 +502,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: { @@ -521,25 +518,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; } diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp index 85092dab17..c1b7b4e06a 100644 --- a/fpdfsdk/src/javascript/util.cpp +++ b/fpdfsdk/src/javascript/util.cpp @@ -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; |