| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 void CJS_RuntimeFactory::AddRef() { | 46 void CJS_RuntimeFactory::AddRef() { |
| 47 // to do.Should be implemented as atom manipulation. | 47 // to do.Should be implemented as atom manipulation. |
| 48 m_nRef++; | 48 m_nRef++; |
| 49 } | 49 } |
| 50 void CJS_RuntimeFactory::Release() { | 50 void CJS_RuntimeFactory::Release() { |
| 51 if (m_bInit) { | 51 if (m_bInit) { |
| 52 // to do.Should be implemented as atom manipulation. | 52 // to do.Should be implemented as atom manipulation. |
| 53 if (--m_nRef == 0) { | 53 if (--m_nRef == 0) { |
| 54 JS_Release(); | 54 JS_Release(); |
| 55 ReleaseGlobalData(); | |
| 56 m_bInit = FALSE; | 55 m_bInit = FALSE; |
| 57 } | 56 } |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { | 60 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { |
| 62 delete (CJS_Runtime*)pRuntime; | 61 delete (CJS_Runtime*)pRuntime; |
| 63 } | 62 } |
| 64 | 63 |
| 65 CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) { | |
| 66 if (m_pGlobalData) { | |
| 67 m_nGlobalDataCount++; | |
| 68 return m_pGlobalData; | |
| 69 } | |
| 70 m_nGlobalDataCount = 1; | |
| 71 m_pGlobalData = new CJS_GlobalData(pApp); | |
| 72 return m_pGlobalData; | |
| 73 } | |
| 74 | |
| 75 void CJS_RuntimeFactory::ReleaseGlobalData() { | |
| 76 m_nGlobalDataCount--; | |
| 77 | |
| 78 if (m_nGlobalDataCount <= 0) { | |
| 79 delete m_pGlobalData; | |
| 80 m_pGlobalData = NULL; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { | 64 void* CJS_ArrayBufferAllocator::Allocate(size_t length) { |
| 85 return calloc(1, length); | 65 return calloc(1, length); |
| 86 } | 66 } |
| 87 | 67 |
| 88 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { | 68 void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { |
| 89 return malloc(length); | 69 return malloc(length); |
| 90 } | 70 } |
| 91 | 71 |
| 92 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { | 72 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { |
| 93 free(data); | 73 free(data); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // v8::Local<v8::Context>::New(GetIsolate(), m_context); | 355 // v8::Local<v8::Context>::New(GetIsolate(), m_context); |
| 376 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New( | 356 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New( |
| 377 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue()); | 357 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue()); |
| 378 context->Global()->Set( | 358 context->Global()->Set( |
| 379 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, | 359 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, |
| 380 utf8Name.GetLength()), | 360 utf8Name.GetLength()), |
| 381 propvalue); | 361 propvalue); |
| 382 | 362 |
| 383 return TRUE; | 363 return TRUE; |
| 384 } | 364 } |
| OLD | NEW |