blob: 95f392487a070e422d49f57ff1e6bc1a86ae6b12 [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
Tom Sepez37458412015-10-06 11:33:46 -07007#include "JS_Runtime.h"
8
Tom Sepez37458412015-10-06 11:33:46 -07009#include "Consts.h"
10#include "Document.h"
11#include "Field.h"
12#include "Icon.h"
13#include "JS_Context.h"
14#include "JS_Define.h"
15#include "JS_EventHandler.h"
16#include "JS_GlobalData.h"
17#include "JS_Object.h"
18#include "JS_Value.h"
19#include "PublicMethods.h"
20#include "app.h"
21#include "color.h"
22#include "console.h"
23#include "event.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080024#include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment.
25#include "fpdfsdk/include/javascript/IJavaScript.h"
Tom Sepez37458412015-10-06 11:33:46 -070026#include "global.h"
27#include "report.h"
28#include "util.h"
Lei Zhangcd2bb302015-12-22 13:49:44 -080029#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Tom Sepez40e9ff32015-11-30 12:39:54 -080031#ifdef PDF_ENABLE_XFA
Lei Zhang875b9c92016-01-08 13:51:10 -080032#include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h"
33#include "xfa/src/fxjse/src/value.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080034#endif // PDF_ENABLE_XFA
35
Tom Sepez67fd5df2015-10-08 12:24:19 -070036// static
Tom Sepez452b4f32015-10-13 09:27:27 -070037void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {
38 FXJS_Initialize(slot, reinterpret_cast<v8::Isolate*>(isolate));
39}
40
41// static
Tom Sepezba038bc2015-10-08 12:03:00 -070042IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) {
Tom Sepez37458412015-10-06 11:33:46 -070043 return new CJS_Runtime(pEnv);
44}
45
Tom Sepez67fd5df2015-10-08 12:24:19 -070046// static
47CJS_Runtime* CJS_Runtime::FromContext(const IJS_Context* cc) {
48 const CJS_Context* pContext = static_cast<const CJS_Context*>(cc);
49 return pContext->GetJSRuntime();
50}
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
53 : m_pApp(pApp),
54 m_pDocument(NULL),
55 m_bBlocking(FALSE),
Jochen Eisinger29007842015-08-05 09:02:13 +020056 m_isolate(NULL),
57 m_isolateManaged(false) {
Tom Sepez51da0932015-11-25 16:05:49 -080058#ifndef PDF_ENABLE_XFA
59 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform;
60 if (pPlatform->version <= 2) {
61 unsigned int embedderDataSlot = 0;
62 v8::Isolate* pExternalIsolate = nullptr;
63 if (pPlatform->version == 2) {
64 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
65 embedderDataSlot = pPlatform->m_v8EmbedderSlot;
66#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
68 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
69 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
Tom Sepeza72e8e22015-10-07 10:17:53 -070070 } else {
71 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform;
72 if (pPlatform->version <= 2) {
73 unsigned int embedderDataSlot = 0;
74 v8::Isolate* pExternalIsolate = nullptr;
75 if (pPlatform->version == 2) {
76 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
77 embedderDataSlot = pPlatform->m_v8EmbedderSlot;
78 }
79 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
Tom Sepez51da0932015-11-25 16:05:49 -080080#endif
Tom Sepeza72e8e22015-10-07 10:17:53 -070081 }
Tom Sepez51da0932015-11-25 16:05:49 -080082#ifndef PDF_ENABLE_XFA
83 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
84#else
Tom Sepeza72e8e22015-10-07 10:17:53 -070085 m_isolateManaged = FXJS_GetIsolate(&m_isolate);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 }
Tom Sepezd2cc1b92015-04-30 15:19:03 -070087
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 v8::Isolate* isolate = m_isolate;
89 v8::Isolate::Scope isolate_scope(isolate);
90 v8::Locker locker(isolate);
91 v8::HandleScope handle_scope(isolate);
Tom Sepezed7b2b52015-09-22 08:36:17 -070092 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 CJS_Context* pContext = (CJS_Context*)NewContext();
Tom Sepez4237aed2015-11-10 15:19:17 -080094 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070095 ReleaseContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 return;
Tom Sepez51da0932015-11-25 16:05:49 -080097#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 }
Tom Sepez51da0932015-11-25 16:05:49 -080099#ifndef PDF_ENABLE_XFA
100 m_isolateManaged = FXJS_GetIsolate(&m_isolate);
101#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102
Tom Sepez51da0932015-11-25 16:05:49 -0800103#endif
Lei Zhang3fa115b2015-10-08 12:04:47 -0700104 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
105 DefineJSObjects();
106
Tom Sepez51da0932015-11-25 16:05:49 -0800107#ifdef PDF_ENABLE_XFA
Tom Sepezed7b2b52015-09-22 08:36:17 -0700108 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109
Tom Sepez51da0932015-11-25 16:05:49 -0800110#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 CJS_Context* pContext = (CJS_Context*)NewContext();
Tom Sepez4237aed2015-11-10 15:19:17 -0800112 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114}
115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116CJS_Runtime::~CJS_Runtime() {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700117 for (auto* obs : m_observers)
118 obs->OnDestroyed();
119
Tom Sepez50d12ad2015-11-24 09:50:51 -0800120 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 delete m_ContextArray.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 m_ContextArray.RemoveAll();
Tom Sepez51da0932015-11-25 16:05:49 -0800124 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 m_pApp = NULL;
127 m_pDocument = NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 m_context.Reset();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129
Jochen Eisinger29007842015-08-05 09:02:13 +0200130 if (m_isolateManaged)
131 m_isolate->Dispose();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
Tom Sepez142165e2015-09-11 13:21:50 -0700134void CJS_Runtime::DefineJSObjects() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 v8::Isolate::Scope isolate_scope(GetIsolate());
Tom Sepez51da0932015-11-25 16:05:49 -0800136#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 v8::Locker locker(GetIsolate());
Tom Sepez51da0932015-11-25 16:05:49 -0800138#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 v8::HandleScope handle_scope(GetIsolate());
140 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
141 v8::Context::Scope context_scope(context);
Tom Sepez570875c2015-09-11 08:35:03 -0700142
143 // The call order determines the "ObjDefID" assigned to each class.
144 // ObjDefIDs 0 - 2
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700145 CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
146 CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
147 CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Tom Sepez570875c2015-09-11 08:35:03 -0700149 // ObjDefIDs 3 - 5
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700150 CJS_Highlight::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
151 CJS_Position::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
152 CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Tom Sepez570875c2015-09-11 08:35:03 -0700154 // ObjDefIDs 6 - 8
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700155 CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
156 CJS_Style::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
157 CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158
Tom Sepez570875c2015-09-11 08:35:03 -0700159 // ObjDefIDs 9 - 11
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700160 CJS_App::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
161 CJS_Color::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
162 CJS_Console::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Tom Sepez570875c2015-09-11 08:35:03 -0700164 // ObjDefIDs 12 - 14
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700165 CJS_Document::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_GLOBAL);
166 CJS_Event::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
167 CJS_Field::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168
Tom Sepez570875c2015-09-11 08:35:03 -0700169 // ObjDefIDs 15 - 17
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700170 CJS_Global::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
171 CJS_Icon::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
172 CJS_Util::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
Tom Sepez570875c2015-09-11 08:35:03 -0700173
Tom Sepez142165e2015-09-11 13:21:50 -0700174 // ObjDefIDs 18 - 20 (these can't fail, return void).
175 CJS_PublicMethods::DefineJSObjects(GetIsolate());
Tom Sepez67fd5df2015-10-08 12:24:19 -0700176 CJS_GlobalConsts::DefineJSObjects(this);
177 CJS_GlobalArrays::DefineJSObjects(this);
Tom Sepez570875c2015-09-11 08:35:03 -0700178
Tom Sepez142165e2015-09-11 13:21:50 -0700179 // ObjDefIDs 21 - 22.
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700180 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
181 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182}
183
Tom Sepezba038bc2015-10-08 12:03:00 -0700184IJS_Context* CJS_Runtime::NewContext() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 CJS_Context* p = new CJS_Context(this);
186 m_ContextArray.Add(p);
187 return p;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188}
189
Tom Sepezba038bc2015-10-08 12:03:00 -0700190void CJS_Runtime::ReleaseContext(IJS_Context* pContext) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 CJS_Context* pJSContext = (CJS_Context*)pContext;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) {
194 if (pJSContext == m_ContextArray.GetAt(i)) {
195 delete pJSContext;
196 m_ContextArray.RemoveAt(i);
197 break;
198 }
199 }
200}
201
Tom Sepezba038bc2015-10-08 12:03:00 -0700202IJS_Context* CJS_Runtime::GetCurrentContext() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 if (!m_ContextArray.GetSize())
204 return NULL;
205 return m_ContextArray.GetAt(m_ContextArray.GetSize() - 1);
206}
207
208void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
209 if (m_pDocument != pReaderDoc) {
210 v8::Isolate::Scope isolate_scope(m_isolate);
Tom Sepez51da0932015-11-25 16:05:49 -0800211#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 v8::Locker locker(m_isolate);
Tom Sepez51da0932015-11-25 16:05:49 -0800213#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 v8::HandleScope handle_scope(m_isolate);
215 v8::Local<v8::Context> context =
216 v8::Local<v8::Context>::New(m_isolate, m_context);
217 v8::Context::Scope context_scope(context);
218
219 m_pDocument = pReaderDoc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 if (pReaderDoc) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700221 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 if (!pThis.IsEmpty()) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700223 if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700224 if (CJS_Document* pJSDocument =
Tom Sepezd5a0e952015-09-17 15:40:06 -0700225 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
227 pDocument->AttachDoc(pReaderDoc);
228 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700229 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700231 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233}
234
Tom Sepez33420902015-10-13 15:00:10 -0700235int CJS_Runtime::Execute(IJS_Context* cc,
236 const wchar_t* script,
237 CFX_WideString* info) {
238 FXJSErr error = {};
239 int nRet = FXJS_Execute(m_isolate, cc, script, &error);
240 if (nRet < 0) {
241 info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
242 error.message);
243 }
244 return nRet;
245}
246
Tom Sepez5d0e8432015-09-22 15:50:03 -0700247bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
248 return m_FieldEventSet.insert(event).second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249}
250
Tom Sepez5d0e8432015-09-22 15:50:03 -0700251void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
252 m_FieldEventSet.erase(event);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253}
254
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
256 return v8::Local<v8::Context>::New(m_isolate, m_context);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700257}
258
Tom Sepez51da0932015-11-25 16:05:49 -0800259#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260CFX_WideString ChangeObjName(const CFX_WideString& str) {
261 CFX_WideString sRet = str;
262 sRet.Replace(L"_", L".");
263 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265FX_BOOL CJS_Runtime::GetHValueByName(const CFX_ByteStringC& utf8Name,
266 FXJSE_HVALUE hValue) {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700267#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 const FX_CHAR* name = utf8Name.GetCStr();
Bo Xufdc00a72014-10-28 23:03:33 -0700269
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 v8::Locker lock(GetIsolate());
271 v8::Isolate::Scope isolate_scope(GetIsolate());
272 v8::HandleScope handle_scope(GetIsolate());
Tom Sepez4f4603c2015-11-10 15:03:12 -0800273 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 v8::Local<v8::Context> context =
275 v8::Local<v8::Context>::New(GetIsolate(), m_context);
276 v8::Context::Scope context_scope(context);
Bo Xufdc00a72014-10-28 23:03:33 -0700277
Tom Sepez4f4603c2015-11-10 15:03:12 -0800278 // Caution: We're about to hand to XFA an object that in order to invoke
279 // methods will require that the current v8::Context always has a pointer
280 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates
281 // its own v8::Context which has not initialized the embedder data slot.
282 // Do so now.
283 // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's
284 // embedder data slots, and/or to always use the right context.
285 FXJS_SetRuntimeForV8Context(old_context, this);
286
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 v8::Local<v8::Value> propvalue =
288 context->Global()->Get(v8::String::NewFromUtf8(
289 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
Bo Xufdc00a72014-10-28 23:03:33 -0700290
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 if (propvalue.IsEmpty()) {
292 FXJSE_Value_SetUndefined(hValue);
293 return FALSE;
294 }
295 ((CFXJSE_Value*)hValue)->ForceSetValue(propvalue);
Tom Sepeza8a39e22015-10-12 15:47:07 -0700296#endif
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -0700299}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300FX_BOOL CJS_Runtime::SetHValueByName(const CFX_ByteStringC& utf8Name,
301 FXJSE_HVALUE hValue) {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700302#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 if (utf8Name.IsEmpty() || hValue == NULL)
304 return FALSE;
305 const FX_CHAR* name = utf8Name.GetCStr();
306 v8::Isolate* pIsolate = GetIsolate();
307 v8::Locker lock(pIsolate);
308 v8::Isolate::Scope isolate_scope(pIsolate);
309 v8::HandleScope handle_scope(pIsolate);
310 v8::Local<v8::Context> context =
311 v8::Local<v8::Context>::New(pIsolate, m_context);
312 v8::Context::Scope context_scope(context);
Bo Xufdc00a72014-10-28 23:03:33 -0700313
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 // v8::Local<v8::Context> tmpCotext =
315 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
316 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(
317 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue());
318 context->Global()->Set(
319 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
320 utf8Name.GetLength()),
321 propvalue);
Tom Sepeza8a39e22015-10-12 15:47:07 -0700322#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -0700324}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700325
Tom Sepez51da0932015-11-25 16:05:49 -0800326#endif
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700327void CJS_Runtime::AddObserver(Observer* observer) {
Lei Zhangcd2bb302015-12-22 13:49:44 -0800328 ASSERT(!pdfium::ContainsKey(m_observers, observer));
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700329 m_observers.insert(observer);
330}
331
332void CJS_Runtime::RemoveObserver(Observer* observer) {
Lei Zhangcd2bb302015-12-22 13:49:44 -0800333 ASSERT(pdfium::ContainsKey(m_observers, observer));
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700334 m_observers.erase(observer);
335}