| 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 "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
| 8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
| 9 #include "../../include/javascript/JS_EventHandler.h" | 9 #include "../../include/javascript/JS_EventHandler.h" |
| 10 #include "../../include/javascript/JS_Runtime.h" | 10 #include "../../include/javascript/JS_Runtime.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "../../include/javascript/report.h" | 24 #include "../../include/javascript/report.h" |
| 25 #include "../../include/javascript/util.h" | 25 #include "../../include/javascript/util.h" |
| 26 #include "../../include/javascript/JS_GlobalData.h" | 26 #include "../../include/javascript/JS_GlobalData.h" |
| 27 #include "../../include/javascript/global.h" | 27 #include "../../include/javascript/global.h" |
| 28 #include "../../include/javascript/console.h" | 28 #include "../../include/javascript/console.h" |
| 29 | 29 |
| 30 CJS_RuntimeFactory::~CJS_RuntimeFactory() | 30 CJS_RuntimeFactory::~CJS_RuntimeFactory() |
| 31 { | 31 { |
| 32 } | 32 } |
| 33 | 33 |
| 34 IFXJS_Runtime*» » » » » CJS_RuntimeFactory::NewJSRuntime
(CPDFDoc_Environment* pApp) | 34 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environ
ment* pApp) |
| 35 { | 35 { |
| 36 » if (!m_bInit) | 36 if (!m_bInit) |
| 37 » { | 37 { |
| 38 » » unsigned int embedderDataSlot = 0; | 38 unsigned int embedderDataSlot = 0; |
| 39 » » if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 39 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
| 40 » » » embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatfor
m->m_v8EmbedderSlot; | 40 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8Embed
derSlot; |
| 41 } | 41 } |
| 42 » » JS_Initial(embedderDataSlot); | 42 JS_Initial(embedderDataSlot); |
| 43 » » m_bInit = TRUE; | 43 m_bInit = TRUE; |
| 44 » } | 44 } |
| 45 » return new CJS_Runtime(pApp); | 45 return new CJS_Runtime(pApp); |
| 46 } | 46 } |
| 47 void» » » » » » » CJS_RuntimeFactory::AddR
ef() | 47 void CJS_RuntimeFactory::AddRef() |
| 48 { | 48 { |
| 49 » //to do.Should be implemented as atom manipulation. | 49 //to do.Should be implemented as atom manipulation. |
| 50 » m_nRef++; | 50 m_nRef++; |
| 51 } | 51 } |
| 52 void» » » » » » » CJS_RuntimeFactory::Rele
ase() | 52 void CJS_RuntimeFactory::Release() |
| 53 { | 53 { |
| 54 » if(m_bInit) | 54 if(m_bInit) |
| 55 » { | 55 { |
| 56 » » //to do.Should be implemented as atom manipulation. | 56 //to do.Should be implemented as atom manipulation. |
| 57 » » if (--m_nRef == 0) | 57 if (--m_nRef == 0) |
| 58 » » { | 58 { |
| 59 » » » JS_Release(); | 59 JS_Release(); |
| 60 » » » ReleaseGlobalData(); | 60 ReleaseGlobalData(); |
| 61 » » » m_bInit = FALSE; | 61 m_bInit = FALSE; |
| 62 » » } | 62 } |
| 63 » } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void» » » » » » » CJS_RuntimeFactory::Dele
teJSRuntime(IFXJS_Runtime* pRuntime) | 66 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtim
e* pRuntime) |
| 67 { | 67 { |
| 68 delete (CJS_Runtime*)pRuntime; | 68 delete (CJS_Runtime*)pRuntime; |
| 69 } | 69 } |
| 70 | 70 |
| 71 CJS_GlobalData*»CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) | 71 CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) |
| 72 { | 72 { |
| 73 » if (m_pGlobalData) | 73 if (m_pGlobalData) |
| 74 » { | 74 { |
| 75 » » m_nGlobalDataCount++; | 75 m_nGlobalDataCount++; |
| 76 » » return m_pGlobalData; | 76 return m_pGlobalData; |
| 77 » } | 77 } |
| 78 » else | 78 m_nGlobalDataCount = 1; |
| 79 » { | 79 m_pGlobalData = new CJS_GlobalData(pApp); |
| 80 » » m_nGlobalDataCount = 1; | 80 return m_pGlobalData; |
| 81 » » m_pGlobalData = new CJS_GlobalData(pApp); | |
| 82 » » return m_pGlobalData; | |
| 83 » } | |
| 84 } | 81 } |
| 85 | 82 |
| 86 void CJS_RuntimeFactory::ReleaseGlobalData() | 83 void CJS_RuntimeFactory::ReleaseGlobalData() |
| 87 { | 84 { |
| 88 » m_nGlobalDataCount--; | 85 m_nGlobalDataCount--; |
| 89 | 86 |
| 90 » if (m_nGlobalDataCount <= 0) | 87 if (m_nGlobalDataCount <= 0) |
| 91 » { | 88 { |
| 92 » » delete m_pGlobalData; | 89 delete m_pGlobalData; |
| 93 » » m_pGlobalData = NULL; | 90 m_pGlobalData = NULL; |
| 94 » } | 91 } |
| 95 } | 92 } |
| 96 | 93 |
| 97 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { | 94 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { |
| 98 return calloc(1, length); | 95 return calloc(1, length); |
| 99 } | 96 } |
| 100 | 97 |
| 101 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { | 98 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { |
| 102 return malloc(length); | 99 return malloc(length); |
| 103 } | 100 } |
| 104 | 101 |
| 105 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { | 102 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { |
| 106 free(data); | 103 free(data); |
| 107 } | 104 } |
| 108 | 105 |
| 109 /* ------------------------------ CJS_Runtime ------------------------------ */ | 106 /* ------------------------------ CJS_Runtime ------------------------------ */ |
| 110 | 107 |
| 111 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : | 108 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : |
| 112 m_pApp(pApp), | 109 m_pApp(pApp), |
| 113 m_pDocument(NULL), | 110 m_pDocument(NULL), |
| 114 m_bBlocking(FALSE), | 111 m_bBlocking(FALSE), |
| 115 m_pFieldEventPath(NULL), | 112 m_pFieldEventPath(NULL), |
| 116 m_isolate(NULL) | 113 m_isolate(NULL) |
| 117 { | 114 { |
| 118 » if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 115 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
| 119 » » m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillIn
fo()->m_pJsPlatform->m_isolate); | 116 m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_
pJsPlatform->m_isolate); |
| 120 » } | 117 } |
| 121 » if (!m_isolate) { | 118 if (!m_isolate) { |
| 122 » » m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); | 119 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); |
| 123 | 120 |
| 124 » » v8::Isolate::CreateParams params; | 121 v8::Isolate::CreateParams params; |
| 125 » » params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 122 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
| 126 » » m_isolate = v8::Isolate::New(params); | 123 m_isolate = v8::Isolate::New(params); |
| 127 } | 124 } |
| 128 | 125 |
| 129 » InitJSObjects(); | 126 InitJSObjects(); |
| 130 | 127 |
| 131 » CJS_Context * pContext = (CJS_Context*)NewContext(); | 128 CJS_Context * pContext = (CJS_Context*)NewContext(); |
| 132 » JS_InitialRuntime(*this, this, pContext, m_context); | 129 JS_InitialRuntime(*this, this, pContext, m_context); |
| 133 » ReleaseContext(pContext); | 130 ReleaseContext(pContext); |
| 134 } | 131 } |
| 135 | 132 |
| 136 CJS_Runtime::~CJS_Runtime() | 133 CJS_Runtime::~CJS_Runtime() |
| 137 { | 134 { |
| 138 » for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++) | 135 for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++) |
| 139 » » delete m_ContextArray.GetAt(i); | 136 delete m_ContextArray.GetAt(i); |
| 140 | 137 |
| 141 » m_ContextArray.RemoveAll(); | 138 m_ContextArray.RemoveAll(); |
| 142 | 139 |
| 143 » JS_ReleaseRuntime(*this, m_context); | 140 JS_ReleaseRuntime(*this, m_context); |
| 144 | 141 |
| 145 » RemoveEventsInLoop(m_pFieldEventPath); | 142 RemoveEventsInLoop(m_pFieldEventPath); |
| 146 | 143 |
| 147 » m_pApp = NULL; | 144 m_pApp = NULL; |
| 148 » m_pDocument = NULL; | 145 m_pDocument = NULL; |
| 149 » m_pFieldEventPath = NULL; | 146 m_pFieldEventPath = NULL; |
| 150 » m_context.Reset(); | 147 m_context.Reset(); |
| 151 | 148 |
| 152 » //m_isolate->Exit(); | 149 //m_isolate->Exit(); |
| 153 » m_isolate->Dispose(); | 150 m_isolate->Dispose(); |
| 154 } | 151 } |
| 155 | 152 |
| 156 FX_BOOL CJS_Runtime::InitJSObjects() | 153 FX_BOOL CJS_Runtime::InitJSObjects() |
| 157 { | 154 { |
| 158 » v8::Isolate::Scope isolate_scope(GetIsolate()); | 155 v8::Isolate::Scope isolate_scope(GetIsolate()); |
| 159 » v8::HandleScope handle_scope(GetIsolate()); | 156 v8::HandleScope handle_scope(GetIsolate()); |
| 160 » v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); | 157 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); |
| 161 » v8::Context::Scope context_scope(context); | 158 v8::Context::Scope context_scope(context); |
| 162 » //0 - 8 | 159 //0 - 8 |
| 163 » if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE; | 160 if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE; |
| 164 » if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE; | 161 if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE; |
| 165 » if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE; | 162 if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE; |
| 166 » if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE; | 163 if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE; |
| 167 » if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE; | 164 if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE; |
| 168 » if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE; | 165 if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE; |
| 169 » if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE; | 166 if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE; |
| 170 » if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE; | 167 if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE; |
| 171 » if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE; | 168 if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE; |
| 172 | 169 |
| 173 » //9 - 11 | 170 //9 - 11 |
| 174 » if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE; | 171 if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE; |
| 175 » if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE; | 172 if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE; |
| 176 » if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE; | 173 if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE; |
| 177 | 174 |
| 178 » //12 - 14 | 175 //12 - 14 |
| 179 » if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 176 if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE; |
| 180 » if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE; | 177 if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE; |
| 181 » if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 178 if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE; |
| 182 | 179 |
| 183 » //15 - 17 | 180 //15 - 17 |
| 184 » if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE; | 181 if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE; |
| 185 » if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 182 if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE; |
| 186 » if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE; | 183 if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE; |
| 187 | 184 |
| 188 » if (CJS_PublicMethods::Init(*this) < 0) return FALSE; | 185 if (CJS_PublicMethods::Init(*this) < 0) return FALSE; |
| 189 » if (CJS_GlobalConsts::Init(*this) < 0) return FALSE; | 186 if (CJS_GlobalConsts::Init(*this) < 0) return FALSE; |
| 190 » if (CJS_GlobalArrays::Init(*this) < 0) return FALSE; | 187 if (CJS_GlobalArrays::Init(*this) < 0) return FALSE; |
| 191 | 188 |
| 192 » if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 189 if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE; |
| 193 » if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE; | 190 if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE; |
| 194 | 191 |
| 195 » return TRUE; | 192 return TRUE; |
| 196 } | 193 } |
| 197 | 194 |
| 198 IFXJS_Context* CJS_Runtime::NewContext() | 195 IFXJS_Context* CJS_Runtime::NewContext() |
| 199 { | 196 { |
| 200 » CJS_Context * p = new CJS_Context(this); | 197 CJS_Context * p = new CJS_Context(this); |
| 201 » m_ContextArray.Add(p); | 198 m_ContextArray.Add(p); |
| 202 » return p; | 199 return p; |
| 203 } | 200 } |
| 204 | 201 |
| 205 void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext) | 202 void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext) |
| 206 { | 203 { |
| 207 » CJS_Context* pJSContext = (CJS_Context*)pContext; | 204 CJS_Context* pJSContext = (CJS_Context*)pContext; |
| 208 | 205 |
| 209 » for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++) | 206 for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++) |
| 210 » { | 207 { |
| 211 » » if (pJSContext == m_ContextArray.GetAt(i)) | 208 if (pJSContext == m_ContextArray.GetAt(i)) |
| 212 » » { | 209 { |
| 213 » » » delete pJSContext; | 210 delete pJSContext; |
| 214 » » » m_ContextArray.RemoveAt(i); | 211 m_ContextArray.RemoveAt(i); |
| 215 » » » break; | 212 break; |
| 216 » » } | 213 } |
| 217 » } | 214 } |
| 218 } | 215 } |
| 219 | 216 |
| 220 IFXJS_Context*» CJS_Runtime::GetCurrentContext() | 217 IFXJS_Context* CJS_Runtime::GetCurrentContext() |
| 221 { | 218 { |
| 222 » if(!m_ContextArray.GetSize()) | 219 if(!m_ContextArray.GetSize()) |
| 223 » » return NULL; | 220 return NULL; |
| 224 » return m_ContextArray.GetAt(m_ContextArray.GetSize()-1); | 221 return m_ContextArray.GetAt(m_ContextArray.GetSize()-1); |
| 225 } | 222 } |
| 226 | 223 |
| 227 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) | 224 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) |
| 228 { | 225 { |
| 229 » if (m_pDocument != pReaderDoc) | 226 if (m_pDocument != pReaderDoc) |
| 230 » { | 227 { |
| 231 » » v8::Isolate::Scope isolate_scope(m_isolate); | 228 v8::Isolate::Scope isolate_scope(m_isolate); |
| 232 » » v8::HandleScope handle_scope(m_isolate); | 229 v8::HandleScope handle_scope(m_isolate); |
| 233 » » v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_is
olate, m_context); | 230 v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m
_context); |
| 234 » » v8::Context::Scope context_scope(context); | 231 v8::Context::Scope context_scope(context); |
| 235 | 232 |
| 236 » » m_pDocument = pReaderDoc; | 233 m_pDocument = pReaderDoc; |
| 237 | 234 |
| 238 » » if (pReaderDoc) | 235 if (pReaderDoc) |
| 239 » » { | 236 { |
| 240 » » » JSObject pThis = JS_GetThisObj(*this); | 237 JSObject pThis = JS_GetThisObj(*this); |
| 241 » » » if(!pThis.IsEmpty()) | 238 if(!pThis.IsEmpty()) |
| 242 » » » { | 239 { |
| 243 » » » » if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*t
his, L"Document")) | 240 if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document"
)) |
| 244 » » » » { | 241 { |
| 245 » » » » » if (CJS_Document* pJSDocument = (CJS_Doc
ument*)JS_GetPrivate(pThis)) | 242 if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate
(pThis)) |
| 246 » » » » » { | 243 { |
| 247 » » » » » » if (Document * pDocument = (Docu
ment*)pJSDocument->GetEmbedObject()) | 244 if (Document * pDocument = (Document*)pJSDocument->GetEm
bedObject()) |
| 248 » » » » » » » pDocument->AttachDoc(pRe
aderDoc); | 245 pDocument->AttachDoc(pReaderDoc); |
| 249 » » » » » } | 246 } |
| 250 » » » » } | 247 } |
| 251 » » » } | 248 } |
| 252 » » » JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document")
); | 249 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document")); |
| 253 » » } | 250 } |
| 254 » » else | 251 else |
| 255 » » { | 252 { |
| 256 » » » JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app")); | 253 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app")); |
| 257 » » } | 254 } |
| 258 » } | 255 } |
| 259 } | 256 } |
| 260 | 257 |
| 261 FX_BOOL»CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) | 258 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) |
| 262 { | 259 { |
| 263 » if (m_pFieldEventPath == NULL) | 260 if (m_pFieldEventPath == NULL) |
| 264 » { | 261 { |
| 265 » » m_pFieldEventPath = new CJS_FieldEvent; | 262 m_pFieldEventPath = new CJS_FieldEvent; |
| 266 » » m_pFieldEventPath->sTargetName = sTargetName; | 263 m_pFieldEventPath->sTargetName = sTargetName; |
| 267 » » m_pFieldEventPath->eEventType = eEventType; | 264 m_pFieldEventPath->eEventType = eEventType; |
| 268 » » m_pFieldEventPath->pNext = NULL; | 265 m_pFieldEventPath->pNext = NULL; |
| 269 | 266 |
| 270 » » return TRUE; | 267 return TRUE; |
| 271 » } | 268 } |
| 272 | 269 |
| 273 » //to search | 270 //to search |
| 274 » CJS_FieldEvent* p = m_pFieldEventPath; | 271 CJS_FieldEvent* p = m_pFieldEventPath; |
| 275 » CJS_FieldEvent* pLast = m_pFieldEventPath; | 272 CJS_FieldEvent* pLast = m_pFieldEventPath; |
| 276 » while (p) | 273 while (p) |
| 277 » { | 274 { |
| 278 » » if (p->eEventType == eEventType && p->sTargetName == sTargetName
) | 275 if (p->eEventType == eEventType && p->sTargetName == sTargetName) |
| 279 » » » return FALSE; | 276 return FALSE; |
| 280 | 277 |
| 281 » » pLast = p; | 278 pLast = p; |
| 282 » » p = p->pNext; | 279 p = p->pNext; |
| 283 » } | 280 } |
| 284 | 281 |
| 285 » //to add | 282 //to add |
| 286 » CJS_FieldEvent* pNew = new CJS_FieldEvent; | 283 CJS_FieldEvent* pNew = new CJS_FieldEvent; |
| 287 » pNew->sTargetName = sTargetName; | 284 pNew->sTargetName = sTargetName; |
| 288 » pNew->eEventType = eEventType; | 285 pNew->eEventType = eEventType; |
| 289 » pNew->pNext = NULL; | 286 pNew->pNext = NULL; |
| 290 | 287 |
| 291 » pLast->pNext = pNew; | 288 pLast->pNext = pNew; |
| 292 | 289 |
| 293 » return TRUE; | 290 return TRUE; |
| 294 } | 291 } |
| 295 | 292 |
| 296 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) | 293 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) |
| 297 { | 294 { |
| 298 » FX_BOOL bFind = FALSE; | 295 FX_BOOL bFind = FALSE; |
| 299 | 296 |
| 300 » CJS_FieldEvent* p = m_pFieldEventPath; | 297 CJS_FieldEvent* p = m_pFieldEventPath; |
| 301 » CJS_FieldEvent* pLast = NULL; | 298 CJS_FieldEvent* pLast = NULL; |
| 302 » while (p) | 299 while (p) |
| 303 » { | 300 { |
| 304 » » if (p->eEventType == eEventType && p->sTargetName == sTargetName
) | 301 if (p->eEventType == eEventType && p->sTargetName == sTargetName) |
| 305 » » { | 302 { |
| 306 » » » bFind = TRUE; | 303 bFind = TRUE; |
| 307 » » » break; | 304 break; |
| 308 » » } | 305 } |
| 309 | 306 |
| 310 » » pLast = p; | 307 pLast = p; |
| 311 » » p = p->pNext; | 308 p = p->pNext; |
| 312 » } | 309 } |
| 313 | 310 |
| 314 » if (bFind) | 311 if (bFind) |
| 315 » { | 312 { |
| 316 » » RemoveEventsInLoop(p); | 313 RemoveEventsInLoop(p); |
| 317 | 314 |
| 318 » » if (p == m_pFieldEventPath) | 315 if (p == m_pFieldEventPath) |
| 319 » » » m_pFieldEventPath = NULL; | 316 m_pFieldEventPath = NULL; |
| 320 | 317 |
| 321 » » if (pLast) | 318 if (pLast) |
| 322 » » » pLast->pNext = NULL; | 319 pLast->pNext = NULL; |
| 323 » } | 320 } |
| 324 } | 321 } |
| 325 | 322 |
| 326 void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart) | 323 void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart) |
| 327 { | 324 { |
| 328 » CJS_FieldEvent* p = pStart; | 325 CJS_FieldEvent* p = pStart; |
| 329 | 326 |
| 330 » while (p) | 327 while (p) |
| 331 » { | 328 { |
| 332 » » CJS_FieldEvent* pOld = p; | 329 CJS_FieldEvent* pOld = p; |
| 333 » » p = pOld->pNext; | 330 p = pOld->pNext; |
| 334 | 331 |
| 335 » » delete pOld; | 332 delete pOld; |
| 336 » } | 333 } |
| 337 } | 334 } |
| 338 | 335 |
| 339 v8::Local<v8::Context>» CJS_Runtime::NewJSContext() | 336 v8::Local<v8::Context> CJS_Runtime::NewJSContext() |
| 340 { | 337 { |
| 341 » return v8::Local<v8::Context>::New(m_isolate, m_context); | 338 return v8::Local<v8::Context>::New(m_isolate, m_context); |
| 342 } | 339 } |
| 343 | 340 |
| 344 CFX_WideString ChangeObjName(const CFX_WideString& str) | 341 CFX_WideString ChangeObjName(const CFX_WideString& str) |
| 345 { | 342 { |
| 346 » CFX_WideString sRet = str; | 343 CFX_WideString sRet = str; |
| 347 » sRet.Replace(L"_", L"."); | 344 sRet.Replace(L"_", L"."); |
| 348 » return sRet; | 345 return sRet; |
| 349 } | 346 } |
| OLD | NEW |