OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/parser/xfa_script_imp.h" | 7 #include "xfa/fxfa/parser/xfa_script_imp.h" |
8 | 8 |
9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
10 #include "xfa/fxfa/app/xfa_ffnotify.h" | 10 #include "xfa/fxfa/app/xfa_ffnotify.h" |
11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
12 #include "xfa/fxfa/parser/xfa_doclayout.h" | 12 #include "xfa/fxfa/parser/xfa_doclayout.h" |
13 #include "xfa/fxfa/parser/xfa_document.h" | 13 #include "xfa/fxfa/parser/xfa_document.h" |
14 #include "xfa/fxfa/parser/xfa_localemgr.h" | 14 #include "xfa/fxfa/parser/xfa_localemgr.h" |
15 #include "xfa/fxfa/parser/xfa_object.h" | 15 #include "xfa/fxfa/parser/xfa_object.h" |
16 #include "xfa/fxfa/parser/xfa_parser.h" | 16 #include "xfa/fxfa/parser/xfa_parser.h" |
17 #include "xfa/fxfa/parser/xfa_script.h" | 17 #include "xfa/fxfa/parser/xfa_script.h" |
18 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" | 18 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" |
19 #include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" | 19 #include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" |
20 #include "xfa/fxfa/parser/xfa_utils.h" | 20 #include "xfa/fxfa/parser/xfa_utils.h" |
21 #include "xfa/fxjse/cfxjse_arguments.h" | 21 #include "xfa/fxjse/cfxjse_arguments.h" |
22 | 22 |
23 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) | 23 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) |
24 : m_pDocument(pDocument), | 24 : m_pDocument(pDocument), |
25 m_hJsContext(nullptr), | 25 m_pJsContext(nullptr), |
26 m_pIsolate(nullptr), | 26 m_pIsolate(nullptr), |
27 m_hJsClass(nullptr), | 27 m_hJsClass(nullptr), |
28 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), | 28 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), |
29 m_pScriptNodeArray(nullptr), | 29 m_pScriptNodeArray(nullptr), |
30 m_pResolveProcessor(nullptr), | 30 m_pResolveProcessor(nullptr), |
31 m_hFM2JSContext(nullptr), | 31 m_hFM2JSContext(nullptr), |
32 m_pThisObject(nullptr), | 32 m_pThisObject(nullptr), |
33 m_dwBuiltInInFlags(0), | 33 m_dwBuiltInInFlags(0), |
34 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) { | 34 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) { |
35 FXSYS_memset(&m_JsGlobalClass, 0, sizeof(FXJSE_CLASS)); | 35 FXSYS_memset(&m_JsGlobalClass, 0, sizeof(FXJSE_CLASS)); |
36 FXSYS_memset(&m_JsNormalClass, 0, sizeof(FXJSE_CLASS)); | 36 FXSYS_memset(&m_JsNormalClass, 0, sizeof(FXJSE_CLASS)); |
37 } | 37 } |
38 CXFA_ScriptContext::~CXFA_ScriptContext() { | 38 CXFA_ScriptContext::~CXFA_ScriptContext() { |
39 FX_POSITION ps = m_mapXFAToHValue.GetStartPosition(); | 39 FX_POSITION ps = m_mapXFAToHValue.GetStartPosition(); |
40 while (ps) { | 40 while (ps) { |
41 CXFA_Object* pXFAObj; | 41 CXFA_Object* pXFAObj; |
42 FXJSE_HVALUE pValue; | 42 FXJSE_HVALUE pValue; |
43 m_mapXFAToHValue.GetNextAssoc(ps, pXFAObj, pValue); | 43 m_mapXFAToHValue.GetNextAssoc(ps, pXFAObj, pValue); |
44 FXJSE_Value_Release(pValue); | 44 FXJSE_Value_Release(pValue); |
45 } | 45 } |
46 m_mapXFAToHValue.RemoveAll(); | 46 m_mapXFAToHValue.RemoveAll(); |
47 ReleaseVariablesMap(); | 47 ReleaseVariablesMap(); |
48 if (m_hFM2JSContext) { | 48 if (m_hFM2JSContext) { |
49 XFA_FM2JS_ContextRelease(m_hFM2JSContext); | 49 XFA_FM2JS_ContextRelease(m_hFM2JSContext); |
50 m_hFM2JSContext = NULL; | 50 m_hFM2JSContext = NULL; |
51 } | 51 } |
52 if (m_hJsContext) { | 52 if (m_pJsContext) { |
53 FXJSE_Context_Release(m_hJsContext); | 53 FXJSE_Context_Release(m_pJsContext); |
54 m_hJsContext = NULL; | 54 m_pJsContext = NULL; |
55 } | 55 } |
56 delete m_pResolveProcessor; | 56 delete m_pResolveProcessor; |
57 m_upObjectArray.RemoveAll(); | 57 m_upObjectArray.RemoveAll(); |
58 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) | 58 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) |
59 delete m_CacheListArray[i]; | 59 delete m_CacheListArray[i]; |
60 } | 60 } |
61 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { | 61 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { |
62 m_pIsolate = pIsolate; | 62 m_pIsolate = pIsolate; |
63 DefineJsContext(); | 63 DefineJsContext(); |
64 DefineJsClass(); | 64 DefineJsClass(); |
65 m_pResolveProcessor = new CXFA_ResolveProcessor; | 65 m_pResolveProcessor = new CXFA_ResolveProcessor; |
66 } | 66 } |
67 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, | 67 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, |
68 const CFX_WideStringC& wsScript, | 68 const CFX_WideStringC& wsScript, |
69 FXJSE_HVALUE hRetValue, | 69 FXJSE_HVALUE hRetValue, |
70 CXFA_Object* pThisObject) { | 70 CXFA_Object* pThisObject) { |
71 CFX_ByteString btScript; | 71 CFX_ByteString btScript; |
72 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; | 72 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; |
73 m_eScriptType = eScriptType; | 73 m_eScriptType = eScriptType; |
74 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { | 74 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { |
75 if (!m_hFM2JSContext) { | 75 if (!m_hFM2JSContext) { |
76 m_hFM2JSContext = XFA_FM2JS_ContextCreate(); | 76 m_hFM2JSContext = XFA_FM2JS_ContextCreate(); |
77 XFA_FM2JS_ContextInitialize(m_hFM2JSContext, m_pIsolate, m_hJsContext, | 77 XFA_FM2JS_ContextInitialize(m_hFM2JSContext, m_pIsolate, m_pJsContext, |
78 m_pDocument); | 78 m_pDocument); |
79 } | 79 } |
80 CFX_WideTextBuf wsJavaScript; | 80 CFX_WideTextBuf wsJavaScript; |
81 CFX_WideString wsErrorInfo; | 81 CFX_WideString wsErrorInfo; |
82 int32_t iFlags = XFA_FM2JS_Translate(wsScript, wsJavaScript, wsErrorInfo); | 82 int32_t iFlags = XFA_FM2JS_Translate(wsScript, wsJavaScript, wsErrorInfo); |
83 if (iFlags) { | 83 if (iFlags) { |
84 FXJSE_Value_SetUndefined(hRetValue); | 84 FXJSE_Value_SetUndefined(hRetValue); |
85 return FALSE; | 85 return FALSE; |
86 } | 86 } |
87 btScript = | 87 btScript = |
88 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); | 88 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); |
89 } else { | 89 } else { |
90 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 90 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
91 } | 91 } |
92 CXFA_Object* pOriginalObject = m_pThisObject; | 92 CXFA_Object* pOriginalObject = m_pThisObject; |
93 m_pThisObject = pThisObject; | 93 m_pThisObject = pThisObject; |
94 FXJSE_HVALUE pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; | 94 FXJSE_HVALUE pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; |
95 FX_BOOL bRet = | 95 FX_BOOL bRet = |
96 FXJSE_ExecuteScript(m_hJsContext, btScript.c_str(), hRetValue, pValue); | 96 FXJSE_ExecuteScript(m_pJsContext, btScript.c_str(), hRetValue, pValue); |
97 m_pThisObject = pOriginalObject; | 97 m_pThisObject = pOriginalObject; |
98 m_eScriptType = eSaveType; | 98 m_eScriptType = eSaveType; |
99 return bRet; | 99 return bRet; |
100 } | 100 } |
101 void CXFA_ScriptContext::GlobalPropertySetter(FXJSE_HOBJECT hObject, | 101 void CXFA_ScriptContext::GlobalPropertySetter(FXJSE_HOBJECT hObject, |
102 const CFX_ByteStringC& szPropName, | 102 const CFX_ByteStringC& szPropName, |
103 FXJSE_HVALUE hValue) { | 103 FXJSE_HVALUE hValue) { |
104 CXFA_Object* lpOrginalNode = | 104 CXFA_Object* lpOrginalNode = |
105 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 105 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
106 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); | 106 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 m_JsGlobalClass.name = "Root"; | 377 m_JsGlobalClass.name = "Root"; |
378 m_JsGlobalClass.propNum = 0; | 378 m_JsGlobalClass.propNum = 0; |
379 m_JsGlobalClass.properties = NULL; | 379 m_JsGlobalClass.properties = NULL; |
380 m_JsGlobalClass.methNum = 0; | 380 m_JsGlobalClass.methNum = 0; |
381 m_JsGlobalClass.methods = NULL; | 381 m_JsGlobalClass.methods = NULL; |
382 m_JsGlobalClass.dynPropGetter = CXFA_ScriptContext::GlobalPropertyGetter; | 382 m_JsGlobalClass.dynPropGetter = CXFA_ScriptContext::GlobalPropertyGetter; |
383 m_JsGlobalClass.dynPropSetter = CXFA_ScriptContext::GlobalPropertySetter; | 383 m_JsGlobalClass.dynPropSetter = CXFA_ScriptContext::GlobalPropertySetter; |
384 m_JsGlobalClass.dynPropTypeGetter = CXFA_ScriptContext::GlobalPropTypeGetter; | 384 m_JsGlobalClass.dynPropTypeGetter = CXFA_ScriptContext::GlobalPropTypeGetter; |
385 m_JsGlobalClass.dynPropDeleter = NULL; | 385 m_JsGlobalClass.dynPropDeleter = NULL; |
386 m_JsGlobalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; | 386 m_JsGlobalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; |
387 m_hJsContext = FXJSE_Context_Create(m_pIsolate, &m_JsGlobalClass, | 387 m_pJsContext = FXJSE_Context_Create(m_pIsolate, &m_JsGlobalClass, |
388 m_pDocument->GetRoot()); | 388 m_pDocument->GetRoot()); |
389 RemoveBuiltInObjs(m_hJsContext); | 389 RemoveBuiltInObjs(m_pJsContext); |
390 FXJSE_Context_EnableCompatibleMode( | 390 FXJSE_Context_EnableCompatibleMode( |
391 m_hJsContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS); | 391 m_pJsContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS); |
392 } | 392 } |
393 FXJSE_HCONTEXT CXFA_ScriptContext::CreateVariablesContext( | 393 CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext( |
394 CXFA_Node* pScriptNode, | 394 CXFA_Node* pScriptNode, |
395 CXFA_Node* pSubform) { | 395 CXFA_Node* pSubform) { |
396 if (!pScriptNode || !pSubform) | 396 if (!pScriptNode || !pSubform) |
397 return nullptr; | 397 return nullptr; |
398 | 398 |
399 if (m_mapVariableToHValue.GetCount() == 0) { | 399 if (m_mapVariableToContext.GetCount() == 0) { |
400 m_JsGlobalVariablesClass.constructor = nullptr; | 400 m_JsGlobalVariablesClass.constructor = nullptr; |
401 m_JsGlobalVariablesClass.name = "XFAScriptObject"; | 401 m_JsGlobalVariablesClass.name = "XFAScriptObject"; |
402 m_JsGlobalVariablesClass.propNum = 0; | 402 m_JsGlobalVariablesClass.propNum = 0; |
403 m_JsGlobalVariablesClass.properties = nullptr; | 403 m_JsGlobalVariablesClass.properties = nullptr; |
404 m_JsGlobalVariablesClass.methNum = 0; | 404 m_JsGlobalVariablesClass.methNum = 0; |
405 m_JsGlobalVariablesClass.methods = nullptr; | 405 m_JsGlobalVariablesClass.methods = nullptr; |
406 m_JsGlobalVariablesClass.dynPropGetter = | 406 m_JsGlobalVariablesClass.dynPropGetter = |
407 CXFA_ScriptContext::GlobalPropertyGetter; | 407 CXFA_ScriptContext::GlobalPropertyGetter; |
408 m_JsGlobalVariablesClass.dynPropSetter = | 408 m_JsGlobalVariablesClass.dynPropSetter = |
409 CXFA_ScriptContext::GlobalPropertySetter; | 409 CXFA_ScriptContext::GlobalPropertySetter; |
410 m_JsGlobalVariablesClass.dynPropTypeGetter = | 410 m_JsGlobalVariablesClass.dynPropTypeGetter = |
411 CXFA_ScriptContext::NormalPropTypeGetter; | 411 CXFA_ScriptContext::NormalPropTypeGetter; |
412 m_JsGlobalVariablesClass.dynPropDeleter = nullptr; | 412 m_JsGlobalVariablesClass.dynPropDeleter = nullptr; |
413 m_JsGlobalVariablesClass.dynMethodCall = | 413 m_JsGlobalVariablesClass.dynMethodCall = |
414 CXFA_ScriptContext::NormalMethodCall; | 414 CXFA_ScriptContext::NormalMethodCall; |
415 } | 415 } |
416 FXJSE_HCONTEXT hVariablesContext = | 416 CFXJSE_Context* pVariablesContext = |
417 FXJSE_Context_Create(m_pIsolate, &m_JsGlobalVariablesClass, | 417 FXJSE_Context_Create(m_pIsolate, &m_JsGlobalVariablesClass, |
418 new CXFA_ThisProxy(pSubform, pScriptNode)); | 418 new CXFA_ThisProxy(pSubform, pScriptNode)); |
419 RemoveBuiltInObjs(hVariablesContext); | 419 RemoveBuiltInObjs(pVariablesContext); |
420 FXJSE_Context_EnableCompatibleMode( | 420 FXJSE_Context_EnableCompatibleMode( |
421 hVariablesContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS); | 421 pVariablesContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS); |
422 m_mapVariableToHValue.SetAt(pScriptNode, hVariablesContext); | 422 m_mapVariableToContext.SetAt(pScriptNode, pVariablesContext); |
423 return hVariablesContext; | 423 return pVariablesContext; |
424 } | 424 } |
425 CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject, | 425 CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject, |
426 FX_BOOL bScriptNode) { | 426 FX_BOOL bScriptNode) { |
427 if (pObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 427 if (pObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
428 return bScriptNode ? ((CXFA_ThisProxy*)pObject)->GetScriptNode() | 428 return bScriptNode ? ((CXFA_ThisProxy*)pObject)->GetScriptNode() |
429 : ((CXFA_ThisProxy*)pObject)->GetThisNode(); | 429 : ((CXFA_ThisProxy*)pObject)->GetThisNode(); |
430 } | 430 } |
431 return pObject; | 431 return pObject; |
432 } | 432 } |
433 | 433 |
434 FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { | 434 FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { |
435 if (!pScriptNode) | 435 if (!pScriptNode) |
436 return FALSE; | 436 return FALSE; |
437 | 437 |
438 if (pScriptNode->GetClassID() != XFA_ELEMENT_Script) | 438 if (pScriptNode->GetClassID() != XFA_ELEMENT_Script) |
439 return TRUE; | 439 return TRUE; |
440 | 440 |
441 CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 441 CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
442 if (!pParent || pParent->GetClassID() != XFA_ELEMENT_Variables) | 442 if (!pParent || pParent->GetClassID() != XFA_ELEMENT_Variables) |
443 return FALSE; | 443 return FALSE; |
444 | 444 |
445 if (m_mapVariableToHValue.GetValueAt(pScriptNode)) | 445 if (m_mapVariableToContext.GetValueAt(pScriptNode)) |
446 return TRUE; | 446 return TRUE; |
447 | 447 |
448 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 448 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
449 if (!pTextNode) | 449 if (!pTextNode) |
450 return FALSE; | 450 return FALSE; |
451 | 451 |
452 CFX_WideStringC wsScript; | 452 CFX_WideStringC wsScript; |
453 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) | 453 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) |
454 return FALSE; | 454 return FALSE; |
455 | 455 |
456 CFX_ByteString btScript = | 456 CFX_ByteString btScript = |
457 FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 457 FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
458 FXJSE_HVALUE hRetValue = FXJSE_Value_Create(m_pIsolate); | 458 FXJSE_HVALUE hRetValue = FXJSE_Value_Create(m_pIsolate); |
459 CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); | 459 CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
460 FXJSE_HCONTEXT hVariablesContext = | 460 CFXJSE_Context* pVariablesContext = |
461 CreateVariablesContext(pScriptNode, pThisObject); | 461 CreateVariablesContext(pScriptNode, pThisObject); |
462 CXFA_Object* pOriginalObject = m_pThisObject; | 462 CXFA_Object* pOriginalObject = m_pThisObject; |
463 m_pThisObject = pThisObject; | 463 m_pThisObject = pThisObject; |
464 FX_BOOL bRet = | 464 FX_BOOL bRet = |
465 FXJSE_ExecuteScript(hVariablesContext, btScript.c_str(), hRetValue); | 465 FXJSE_ExecuteScript(pVariablesContext, btScript.c_str(), hRetValue); |
466 m_pThisObject = pOriginalObject; | 466 m_pThisObject = pOriginalObject; |
467 FXJSE_Value_Release(hRetValue); | 467 FXJSE_Value_Release(hRetValue); |
468 return bRet; | 468 return bRet; |
469 } | 469 } |
470 | 470 |
471 FX_BOOL CXFA_ScriptContext::QueryVariableHValue( | 471 FX_BOOL CXFA_ScriptContext::QueryVariableHValue( |
472 CXFA_Node* pScriptNode, | 472 CXFA_Node* pScriptNode, |
473 const CFX_ByteStringC& szPropName, | 473 const CFX_ByteStringC& szPropName, |
474 FXJSE_HVALUE hValue, | 474 FXJSE_HVALUE hValue, |
475 FX_BOOL bGetter) { | 475 FX_BOOL bGetter) { |
476 if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) | 476 if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) |
477 return FALSE; | 477 return FALSE; |
478 | 478 |
479 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 479 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
480 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) | 480 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) |
481 return FALSE; | 481 return FALSE; |
482 | 482 |
483 void* lpVariables = m_mapVariableToHValue.GetValueAt(pScriptNode); | 483 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); |
484 if (!lpVariables) | 484 if (!lpVariables) |
485 return FALSE; | 485 return FALSE; |
486 | 486 |
487 FX_BOOL bRes = FALSE; | 487 FX_BOOL bRes = FALSE; |
488 FXJSE_HCONTEXT hVariableContext = (FXJSE_HCONTEXT)lpVariables; | 488 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); |
489 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(hVariableContext); | 489 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pVariableContext); |
490 FXJSE_HVALUE hVariableValue = FXJSE_Value_Create(m_pIsolate); | 490 FXJSE_HVALUE hVariableValue = FXJSE_Value_Create(m_pIsolate); |
491 if (!bGetter) { | 491 if (!bGetter) { |
492 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); | 492 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); |
493 bRes = TRUE; | 493 bRes = TRUE; |
494 } else if (FXJSE_Value_ObjectHasOwnProp(hObject, szPropName, FALSE)) { | 494 } else if (FXJSE_Value_ObjectHasOwnProp(hObject, szPropName, FALSE)) { |
495 FXJSE_Value_GetObjectProp(hObject, szPropName, hVariableValue); | 495 FXJSE_Value_GetObjectProp(hObject, szPropName, hVariableValue); |
496 if (FXJSE_Value_IsFunction(hVariableValue)) | 496 if (FXJSE_Value_IsFunction(hVariableValue)) |
497 FXJSE_Value_SetFunctionBind(hValue, hVariableValue, hObject); | 497 FXJSE_Value_SetFunctionBind(hValue, hVariableValue, hObject); |
498 else if (bGetter) | 498 else if (bGetter) |
499 FXJSE_Value_Set(hValue, hVariableValue); | 499 FXJSE_Value_Set(hValue, hVariableValue); |
500 else | 500 else |
501 FXJSE_Value_Set(hVariableValue, hValue); | 501 FXJSE_Value_Set(hVariableValue, hValue); |
502 bRes = TRUE; | 502 bRes = TRUE; |
503 } | 503 } |
504 FXJSE_Value_Release(hVariableValue); | 504 FXJSE_Value_Release(hVariableValue); |
505 FXJSE_Value_Release(hObject); | 505 FXJSE_Value_Release(hObject); |
506 return bRes; | 506 return bRes; |
507 } | 507 } |
508 | 508 |
509 void CXFA_ScriptContext::ReleaseVariablesMap() { | 509 void CXFA_ScriptContext::ReleaseVariablesMap() { |
510 FX_POSITION ps = m_mapVariableToHValue.GetStartPosition(); | 510 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); |
511 while (ps) { | 511 while (ps) { |
512 CXFA_Object* pScriptNode; | 512 CXFA_Object* pScriptNode; |
513 FXJSE_HCONTEXT hVariableContext = nullptr; | 513 CFXJSE_Context* pVariableContext = nullptr; |
514 m_mapVariableToHValue.GetNextAssoc(ps, pScriptNode, hVariableContext); | 514 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); |
515 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(hVariableContext); | 515 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pVariableContext); |
516 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(hObject, nullptr)); | 516 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(hObject, nullptr)); |
517 FXJSE_Value_Release(hObject); | 517 FXJSE_Value_Release(hObject); |
518 FXJSE_Context_Release(hVariableContext); | 518 FXJSE_Context_Release(pVariableContext); |
519 } | 519 } |
520 m_mapVariableToHValue.RemoveAll(); | 520 m_mapVariableToContext.RemoveAll(); |
521 } | 521 } |
522 | 522 |
523 void CXFA_ScriptContext::DefineJsClass() { | 523 void CXFA_ScriptContext::DefineJsClass() { |
524 m_JsNormalClass.constructor = NULL; | 524 m_JsNormalClass.constructor = NULL; |
525 m_JsNormalClass.name = "XFAObject"; | 525 m_JsNormalClass.name = "XFAObject"; |
526 m_JsNormalClass.propNum = 0; | 526 m_JsNormalClass.propNum = 0; |
527 m_JsNormalClass.properties = NULL; | 527 m_JsNormalClass.properties = NULL; |
528 m_JsNormalClass.methNum = 0; | 528 m_JsNormalClass.methNum = 0; |
529 m_JsNormalClass.methods = NULL; | 529 m_JsNormalClass.methods = NULL; |
530 m_JsNormalClass.dynPropGetter = CXFA_ScriptContext::NormalPropertyGetter; | 530 m_JsNormalClass.dynPropGetter = CXFA_ScriptContext::NormalPropertyGetter; |
531 m_JsNormalClass.dynPropSetter = CXFA_ScriptContext::NormalPropertySetter; | 531 m_JsNormalClass.dynPropSetter = CXFA_ScriptContext::NormalPropertySetter; |
532 m_JsNormalClass.dynPropTypeGetter = CXFA_ScriptContext::NormalPropTypeGetter; | 532 m_JsNormalClass.dynPropTypeGetter = CXFA_ScriptContext::NormalPropTypeGetter; |
533 m_JsNormalClass.dynPropDeleter = NULL; | 533 m_JsNormalClass.dynPropDeleter = NULL; |
534 m_JsNormalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; | 534 m_JsNormalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; |
535 m_hJsClass = FXJSE_DefineClass(m_hJsContext, &m_JsNormalClass); | 535 m_hJsClass = FXJSE_DefineClass(m_pJsContext, &m_JsNormalClass); |
536 } | 536 } |
537 void CXFA_ScriptContext::RemoveBuiltInObjs(FXJSE_HCONTEXT jsContext) const { | 537 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { |
538 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; | 538 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; |
539 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(jsContext); | 539 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pContext); |
540 FXJSE_HVALUE hProp = FXJSE_Value_Create(m_pIsolate); | 540 FXJSE_HVALUE hProp = FXJSE_Value_Create(m_pIsolate); |
541 for (int i = 0; i < 2; ++i) { | 541 for (int i = 0; i < 2; ++i) { |
542 if (FXJSE_Value_GetObjectProp(hObject, OBJ_NAME[i], hProp)) | 542 if (FXJSE_Value_GetObjectProp(hObject, OBJ_NAME[i], hProp)) |
543 FXJSE_Value_DeleteObjectProp(hObject, OBJ_NAME[i]); | 543 FXJSE_Value_DeleteObjectProp(hObject, OBJ_NAME[i]); |
544 } | 544 } |
545 FXJSE_Value_Release(hProp); | 545 FXJSE_Value_Release(hProp); |
546 FXJSE_Value_Release(hObject); | 546 FXJSE_Value_Release(hObject); |
547 } | 547 } |
548 FXJSE_HCLASS CXFA_ScriptContext::GetJseNormalClass() { | 548 FXJSE_HCLASS CXFA_ScriptContext::GetJseNormalClass() { |
549 return m_hJsClass; | 549 return m_hJsClass; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 } | 758 } |
759 } | 759 } |
760 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 760 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
761 if (!m_pScriptNodeArray) { | 761 if (!m_pScriptNodeArray) { |
762 return; | 762 return; |
763 } | 763 } |
764 if (m_pScriptNodeArray->Find(pNode) == -1) { | 764 if (m_pScriptNodeArray->Find(pNode) == -1) { |
765 m_pScriptNodeArray->Add(pNode); | 765 m_pScriptNodeArray->Add(pNode); |
766 } | 766 } |
767 } | 767 } |
OLD | NEW |