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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 void CJS_RuntimeFactory::AddRef() { | 44 void CJS_RuntimeFactory::AddRef() { |
45 // to do.Should be implemented as atom manipulation. | 45 // to do.Should be implemented as atom manipulation. |
46 m_nRef++; | 46 m_nRef++; |
47 } | 47 } |
48 void CJS_RuntimeFactory::Release() { | 48 void CJS_RuntimeFactory::Release() { |
49 if (m_bInit) { | 49 if (m_bInit) { |
50 // to do.Should be implemented as atom manipulation. | 50 // to do.Should be implemented as atom manipulation. |
51 if (--m_nRef == 0) { | 51 if (--m_nRef == 0) { |
52 JS_Release(); | 52 JS_Release(); |
53 ReleaseGlobalData(); | |
54 m_bInit = FALSE; | 53 m_bInit = FALSE; |
55 } | 54 } |
56 } | 55 } |
57 } | 56 } |
58 | 57 |
59 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { | 58 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { |
60 delete (CJS_Runtime*)pRuntime; | 59 delete (CJS_Runtime*)pRuntime; |
61 } | 60 } |
62 | 61 |
63 CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) { | |
64 if (m_pGlobalData) { | |
65 m_nGlobalDataCount++; | |
66 return m_pGlobalData; | |
67 } | |
68 m_nGlobalDataCount = 1; | |
69 m_pGlobalData = new CJS_GlobalData(pApp); | |
70 return m_pGlobalData; | |
71 } | |
72 | |
73 void CJS_RuntimeFactory::ReleaseGlobalData() { | |
74 m_nGlobalDataCount--; | |
75 | |
76 if (m_nGlobalDataCount <= 0) { | |
77 delete m_pGlobalData; | |
78 m_pGlobalData = NULL; | |
79 } | |
80 } | |
81 | |
82 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { | 62 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { |
83 return calloc(1, length); | 63 return calloc(1, length); |
84 } | 64 } |
85 | 65 |
86 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { | 66 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { |
87 return malloc(length); | 67 return malloc(length); |
88 } | 68 } |
89 | 69 |
90 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { | 70 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { |
91 free(data); | 71 free(data); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 285 |
306 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 286 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
307 return v8::Local<v8::Context>::New(m_isolate, m_context); | 287 return v8::Local<v8::Context>::New(m_isolate, m_context); |
308 } | 288 } |
309 | 289 |
310 CFX_WideString ChangeObjName(const CFX_WideString& str) { | 290 CFX_WideString ChangeObjName(const CFX_WideString& str) { |
311 CFX_WideString sRet = str; | 291 CFX_WideString sRet = str; |
312 sRet.Replace(L"_", L"."); | 292 sRet.Replace(L"_", L"."); |
313 return sRet; | 293 return sRet; |
314 } | 294 } |
OLD | NEW |