blob: d68b26859103eee80edd621e855a44368594b70f [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "../../include/javascript/JavaScript.h"
8#include "../../include/javascript/IJavaScript.h"
9#include "../../include/javascript/JS_EventHandler.h"
10#include "../../include/javascript/JS_Runtime.h"
11#include "../../include/javascript/JS_Context.h"
12#include "../../include/javascript/JS_Define.h"
13#include "../../include/javascript/JS_Object.h"
14#include "../../include/javascript/JS_Value.h"
15#include "../../include/javascript/Document.h"
16#include "../../include/javascript/app.h"
17#include "../../include/javascript/color.h"
18#include "../../include/javascript/Consts.h"
19#include "../../include/javascript/Document.h"
20#include "../../include/javascript/event.h"
21#include "../../include/javascript/Field.h"
22#include "../../include/javascript/Icon.h"
23#include "../../include/javascript/PublicMethods.h"
24#include "../../include/javascript/report.h"
25#include "../../include/javascript/util.h"
26#include "../../include/javascript/JS_GlobalData.h"
27#include "../../include/javascript/global.h"
28#include "../../include/javascript/console.h"
Bo Xufdc00a72014-10-28 23:03:33 -070029#include "../../include/fpdfxfa/fpdfxfa_app.h"
Bo Xufdc00a72014-10-28 23:03:33 -070030#include "../../../xfa/src/fxjse/src/value.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
32CJS_RuntimeFactory::~CJS_RuntimeFactory()
33{
34}
35
Tom Sepez2f2ffec2015-07-23 14:42:09 -070036IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037{
38 if (!m_bInit)
39 {
Jochen Eisinger06b60022015-07-30 17:44:35 +020040 unsigned int embedderDataSlot = 0;
41 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
42 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
43 }
44 JS_Initial(embedderDataSlot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045 m_bInit = TRUE;
46 }
47 return new CJS_Runtime(pApp);
48}
Tom Sepez2f2ffec2015-07-23 14:42:09 -070049void CJS_RuntimeFactory::AddRef()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070051 //to do.Should be implemented as atom manipulation.
52 m_nRef++;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053}
Tom Sepez2f2ffec2015-07-23 14:42:09 -070054void CJS_RuntimeFactory::Release()
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070055{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070056 if(m_bInit)
57 {
58 //to do.Should be implemented as atom manipulation.
59 if (--m_nRef == 0)
60 {
61 JS_Release();
62 ReleaseGlobalData();
63 m_bInit = FALSE;
64 }
65 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066}
67
Tom Sepez2f2ffec2015-07-23 14:42:09 -070068void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069{
Lei Zhang796c9082015-07-16 18:45:22 -070070 delete (CJS_Runtime*)pRuntime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
Tom Sepez2f2ffec2015-07-23 14:42:09 -070073CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070075 if (m_pGlobalData)
76 {
77 m_nGlobalDataCount++;
78 return m_pGlobalData;
79 }
80 m_nGlobalDataCount = 1;
81 m_pGlobalData = new CJS_GlobalData(pApp);
82 return m_pGlobalData;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070083}
84
85void CJS_RuntimeFactory::ReleaseGlobalData()
86{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070087 m_nGlobalDataCount--;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070088
Tom Sepez2f2ffec2015-07-23 14:42:09 -070089 if (m_nGlobalDataCount <= 0)
90 {
91 delete m_pGlobalData;
92 m_pGlobalData = NULL;
93 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070094}
95
Tom Sepezd2cc1b92015-04-30 15:19:03 -070096void* CJS_ArrayBufferAllocator::Allocate(size_t length) {
97 return calloc(1, length);
98}
99
100void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) {
101 return malloc(length);
102}
103
104void CJS_ArrayBufferAllocator::Free(void* data, size_t length) {
105 free(data);
106}
107
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108/* ------------------------------ CJS_Runtime ------------------------------ */
Jochen Eisingerdfa2c992015-05-19 00:38:00 +0200109extern v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJSRuntime);
Bo Xufdc00a72014-10-28 23:03:33 -0700110CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) :
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111 m_pApp(pApp),
112 m_pDocument(NULL),
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113 m_bBlocking(FALSE),
Jochen Eisinger06b60022015-07-30 17:44:35 +0200114 m_pFieldEventPath(NULL),
115 m_isolate(NULL)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116{
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700117 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
Jochen Eisinger06b60022015-07-30 17:44:35 +0200118 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700119 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
Jochen Eisinger06b60022015-07-30 17:44:35 +0200120 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
121 m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
122 }
123 if (!m_isolate) {
Tom Sepezd2cc1b92015-04-30 15:19:03 -0700124 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
Jochen Eisinger06b60022015-07-30 17:44:35 +0200125
Tom Sepezd2cc1b92015-04-30 15:19:03 -0700126 v8::Isolate::CreateParams params;
127 params.array_buffer_allocator = m_pArrayBufferAllocator.get();
128 m_isolate = v8::Isolate::New(params);
Jochen Eisinger06b60022015-07-30 17:44:35 +0200129 }
Tom Sepezd2cc1b92015-04-30 15:19:03 -0700130
Bo Xufdc00a72014-10-28 23:03:33 -0700131 v8::Isolate* isolate = m_isolate;
132 v8::Isolate::Scope isolate_scope(isolate);
133 v8::Locker locker(isolate);
134 v8::HandleScope handle_scope(isolate);
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700135 if (CPDFXFA_App::GetInstance()->InitRuntime(FALSE)) {
Bo Xufdc00a72014-10-28 23:03:33 -0700136 CJS_Context * pContext = (CJS_Context*)NewContext();
137 JS_InitialRuntime(*this, this, pContext, m_context);
138 ReleaseContext(pContext);
139 return;
140 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700142 InitJSObjects();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700144 CJS_Context * pContext = (CJS_Context*)NewContext();
145 JS_InitialRuntime(*this, this, pContext, m_context);
146 ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147}
148
149CJS_Runtime::~CJS_Runtime()
150{
Bo Xufdc00a72014-10-28 23:03:33 -0700151 int size = m_ContextArray.GetSize();
152 for (int i=0;i < size; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153 delete m_ContextArray.GetAt(i);
154
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700155 m_ContextArray.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700157 RemoveEventsInLoop(m_pFieldEventPath);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700159 m_pApp = NULL;
160 m_pDocument = NULL;
161 m_pFieldEventPath = NULL;
162 m_context.Reset();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Bo Xufdc00a72014-10-28 23:03:33 -0700164 m_isolate = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165}
166
167FX_BOOL CJS_Runtime::InitJSObjects()
168{
169 v8::Isolate::Scope isolate_scope(GetIsolate());
Bo Xufdc00a72014-10-28 23:03:33 -0700170 v8::Locker locker(GetIsolate());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171 v8::HandleScope handle_scope(GetIsolate());
Jochen Eisingerdfa2c992015-05-19 00:38:00 +0200172 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173 v8::Context::Scope context_scope(context);
174 //0 - 8
175 if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE;
176 if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE;
177 if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE;
178 if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE;
179 if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE;
180 if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE;
181 if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700182 if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE;
183 if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
185 //9 - 11
186 if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700187 if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188 if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE;
189
190 //12 - 14
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700191 if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE;
192 if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE;
193 if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194
195 //15 - 17
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700196 if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197 if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE;
198 if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE;
199
200 if (CJS_PublicMethods::Init(*this) < 0) return FALSE;
201 if (CJS_GlobalConsts::Init(*this) < 0) return FALSE;
202 if (CJS_GlobalArrays::Init(*this) < 0) return FALSE;
203
204 if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE;
205 if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE;
206
207 return TRUE;
208}
209
210IFXJS_Context* CJS_Runtime::NewContext()
211{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700212 CJS_Context * p = new CJS_Context(this);
213 m_ContextArray.Add(p);
214 return p;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700215}
216
217void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext)
218{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700219 CJS_Context* pJSContext = (CJS_Context*)pContext;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700221 for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
222 {
223 if (pJSContext == m_ContextArray.GetAt(i))
224 {
225 delete pJSContext;
226 m_ContextArray.RemoveAt(i);
227 break;
228 }
229 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700230}
231
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700232IFXJS_Context* CJS_Runtime::GetCurrentContext()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700234 if(!m_ContextArray.GetSize())
235 return NULL;
236 return m_ContextArray.GetAt(m_ContextArray.GetSize()-1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700237}
238
239void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc)
240{
241 if (m_pDocument != pReaderDoc)
242 {
243 v8::Isolate::Scope isolate_scope(m_isolate);
Bo Xufdc00a72014-10-28 23:03:33 -0700244 v8::Locker locker(m_isolate);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245 v8::HandleScope handle_scope(m_isolate);
246 v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m_context);
247 v8::Context::Scope context_scope(context);
248
249 m_pDocument = pReaderDoc;
250
251 if (pReaderDoc)
252 {
253 JSObject pThis = JS_GetThisObj(*this);
254 if(!pThis.IsEmpty())
255 {
256 if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document"))
257 {
258 if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis))
259 {
260 if (Document * pDocument = (Document*)pJSDocument->GetEmbedObject())
261 pDocument->AttachDoc(pReaderDoc);
262 }
263 }
264 }
265 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document"));
266 }
267 else
268 {
269 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app"));
270 }
271 }
272}
273
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700274FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700276 if (m_pFieldEventPath == NULL)
277 {
278 m_pFieldEventPath = new CJS_FieldEvent;
279 m_pFieldEventPath->sTargetName = sTargetName;
280 m_pFieldEventPath->eEventType = eEventType;
281 m_pFieldEventPath->pNext = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700283 return TRUE;
284 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700285
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700286 //to search
287 CJS_FieldEvent* p = m_pFieldEventPath;
288 CJS_FieldEvent* pLast = m_pFieldEventPath;
289 while (p)
290 {
291 if (p->eEventType == eEventType && p->sTargetName == sTargetName)
292 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700293
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700294 pLast = p;
295 p = p->pNext;
296 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700298 //to add
299 CJS_FieldEvent* pNew = new CJS_FieldEvent;
300 pNew->sTargetName = sTargetName;
301 pNew->eEventType = eEventType;
302 pNew->pNext = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700303
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700304 pLast->pNext = pNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700305
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700306 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700307}
308
309void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
310{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700311 FX_BOOL bFind = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700313 CJS_FieldEvent* p = m_pFieldEventPath;
314 CJS_FieldEvent* pLast = NULL;
315 while (p)
316 {
317 if (p->eEventType == eEventType && p->sTargetName == sTargetName)
318 {
319 bFind = TRUE;
320 break;
321 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700322
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700323 pLast = p;
324 p = p->pNext;
325 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700326
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700327 if (bFind)
328 {
329 RemoveEventsInLoop(p);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700330
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700331 if (p == m_pFieldEventPath)
332 m_pFieldEventPath = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700333
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700334 if (pLast)
335 pLast->pNext = NULL;
336 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700337}
338
339void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart)
340{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700341 CJS_FieldEvent* p = pStart;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700342
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700343 while (p)
344 {
345 CJS_FieldEvent* pOld = p;
346 p = pOld->pNext;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700348 delete pOld;
349 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350}
351
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700352v8::Local<v8::Context> CJS_Runtime::NewJSContext()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700354 return v8::Local<v8::Context>::New(m_isolate, m_context);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355}
356
357CFX_WideString ChangeObjName(const CFX_WideString& str)
358{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700359 CFX_WideString sRet = str;
360 sRet.Replace(L"_", L".");
361 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700362}
Tom Sepezca3ac5e2015-06-10 17:38:11 -0700363FX_BOOL CJS_Runtime::GetHValueByName(const CFX_ByteStringC& utf8Name, FXJSE_HVALUE hValue)
Bo Xufdc00a72014-10-28 23:03:33 -0700364{
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700365 const FX_CHAR* name = utf8Name.GetCStr();
Bo Xufdc00a72014-10-28 23:03:33 -0700366
367 v8::Locker lock(GetIsolate());
368 v8::Isolate::Scope isolate_scope(GetIsolate());
369 v8::HandleScope handle_scope(GetIsolate());
370 v8::Local<v8::Context> context =
371 v8::Local<v8::Context>::New(GetIsolate(), m_context);
372 v8::Context::Scope context_scope(context);
373
374
375 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsolate(), m_context);
376 v8::Local<v8::Value> propvalue = context->Global()->Get(v8::String::NewFromUtf8(GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700377
Bo Xufdc00a72014-10-28 23:03:33 -0700378 if (propvalue.IsEmpty()) {
379 FXJSE_Value_SetUndefined(hValue);
380 return FALSE;
381 }
382 ((CFXJSE_Value*)hValue)->ForceSetValue(propvalue);
383
384 return TRUE;
385}
Tom Sepezca3ac5e2015-06-10 17:38:11 -0700386FX_BOOL CJS_Runtime::SetHValueByName(const CFX_ByteStringC& utf8Name, FXJSE_HVALUE hValue)
Bo Xufdc00a72014-10-28 23:03:33 -0700387{
388 if (utf8Name.IsEmpty() || hValue == NULL)
389 return FALSE;
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700390 const FX_CHAR* name = utf8Name.GetCStr();
Bo Xufdc00a72014-10-28 23:03:33 -0700391 v8::Isolate* pIsolate = GetIsolate();
392 v8::Locker lock(pIsolate);
393 v8::Isolate::Scope isolate_scope(pIsolate);
394 v8::HandleScope handle_scope(pIsolate);
395 v8::Local<v8::Context> context =
396 v8::Local<v8::Context>::New(pIsolate, m_context);
397 v8::Context::Scope context_scope(context);
398
399 //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsolate(), m_context);
400 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),((CFXJSE_Value*)hValue)->DirectGetValue());
401 context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, utf8Name.GetLength()), propvalue);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700402
Bo Xufdc00a72014-10-28 23:03:33 -0700403 return TRUE;
404}