blob: e13a5095db49166e8faa8d33912aece333044a8f [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
Dan Sinclaire0345a42017-10-30 20:20:42 +00007#include "fxjs/cjs_object.h"
Dan Sinclaird808dfd2017-10-26 15:04:17 -04008
Lei Zhang70156342018-10-18 19:29:59 +00009#include "fxjs/cfxjs_engine.h"
10
Dan Sinclaird808dfd2017-10-26 15:04:17 -040011// static
12void CJS_Object::DefineConsts(CFXJS_Engine* pEngine,
13 int objId,
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000014 pdfium::span<const JSConstSpec> consts) {
15 for (const auto& item : consts) {
Dan Sinclaird808dfd2017-10-26 15:04:17 -040016 pEngine->DefineObjConst(
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000017 objId, item.pName,
18 item.eType == JSConstSpec::Number
19 ? pEngine->NewNumber(item.number).As<v8::Value>()
20 : pEngine->NewString(item.pStr).As<v8::Value>());
Dan Sinclaird808dfd2017-10-26 15:04:17 -040021 }
22}
23
24// static
25void CJS_Object::DefineProps(CFXJS_Engine* pEngine,
26 int objId,
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000027 pdfium::span<const JSPropertySpec> props) {
28 for (const auto& item : props)
29 pEngine->DefineObjProperty(objId, item.pName, item.pPropGet, item.pPropPut);
Dan Sinclaird808dfd2017-10-26 15:04:17 -040030}
31
32// static
33void CJS_Object::DefineMethods(CFXJS_Engine* pEngine,
34 int objId,
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000035 pdfium::span<const JSMethodSpec> methods) {
36 for (const auto& item : methods)
37 pEngine->DefineObjMethod(objId, item.pName, item.pMethodCall);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038}
39
Tom Sepez36aae4f2018-06-04 19:44:37 +000040CJS_Object::CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
41 : m_pIsolate(pObject->GetIsolate()),
42 m_pV8Object(GetIsolate(), pObject),
43 m_pRuntime(pRuntime) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Dan Sinclairf766ad22016-03-14 13:51:24 -040045CJS_Object::~CJS_Object() {}