blob: 34a846e9e3ae9336e99d4bcd3c722edc5e50a948 [file] [log] [blame]
Tom Sepeza1fe7322018-04-18 22:48:22 +00001// Copyright 2018 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.
4
5#include "fxjs/ijs_runtime.h"
6
Tom Sepeza1fe7322018-04-18 22:48:22 +00007#include "fxjs/cjs_runtimestub.h"
8#include "third_party/base/ptr_util.h"
9
10#ifdef PDF_ENABLE_V8
11#include "fxjs/cfxjs_engine.h"
12#include "fxjs/cjs_runtime.h"
13#endif
14
Tom Sepez0928bc52018-08-22 17:40:12 +000015IJS_Runtime::ScopedEventContext::ScopedEventContext(IJS_Runtime* pRuntime)
16 : m_pRuntime(pRuntime), m_pContext(pRuntime->NewEventContext()) {}
17
18IJS_Runtime::ScopedEventContext::~ScopedEventContext() {
19 m_pRuntime->ReleaseEventContext(m_pContext.Release());
20}
21
Tom Sepeza1fe7322018-04-18 22:48:22 +000022// static
23void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {
24#ifdef PDF_ENABLE_V8
Tom Sepez9b8b2172018-04-25 22:12:34 +000025 FXJS_Initialize(slot, static_cast<v8::Isolate*>(isolate));
Tom Sepeza1fe7322018-04-18 22:48:22 +000026#endif
27}
28
29// static
30void IJS_Runtime::Destroy() {
31#ifdef PDF_ENABLE_V8
32 FXJS_Release();
33#endif
34}
35
36// static
37std::unique_ptr<IJS_Runtime> IJS_Runtime::Create(
38 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
39#ifdef PDF_ENABLE_V8
Tom Sepez0784c732018-04-23 18:02:57 +000040 if (pFormFillEnv->IsJSPlatformPresent())
41 return pdfium::MakeUnique<CJS_Runtime>(pFormFillEnv);
Tom Sepeza1fe7322018-04-18 22:48:22 +000042#endif
Tom Sepez0784c732018-04-23 18:02:57 +000043 return pdfium::MakeUnique<CJS_RuntimeStub>(pFormFillEnv);
Tom Sepeza1fe7322018-04-18 22:48:22 +000044}
Tom Sepez0784c732018-04-23 18:02:57 +000045
46IJS_Runtime::~IJS_Runtime() = default;
Dan Sinclairdc5d88b2018-05-17 13:53:52 +000047
48IJS_Runtime::JS_Error::JS_Error(int line,
49 int column,
50 const WideString& exception)
51 : line(line), column(column), exception(exception) {}