1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fxjs/cjs_object.h"
8
9 #include "fxjs/cfxjs_engine.h"
10
11 // static
DefineConsts(CFXJS_Engine * pEngine,uint32_t nObjDefnID,pdfium::span<const JSConstSpec> consts)12 void CJS_Object::DefineConsts(CFXJS_Engine* pEngine,
13 uint32_t nObjDefnID,
14 pdfium::span<const JSConstSpec> consts) {
15 for (const auto& item : consts) {
16 pEngine->DefineObjConst(
17 nObjDefnID, item.pName,
18 item.eType == JSConstSpec::Number
19 ? pEngine->NewNumber(item.number).As<v8::Value>()
20 : pEngine->NewString(item.pStr).As<v8::Value>());
21 }
22 }
23
24 // static
DefineProps(CFXJS_Engine * pEngine,uint32_t nObjDefnID,pdfium::span<const JSPropertySpec> props)25 void CJS_Object::DefineProps(CFXJS_Engine* pEngine,
26 uint32_t nObjDefnID,
27 pdfium::span<const JSPropertySpec> props) {
28 for (const auto& item : props)
29 pEngine->DefineObjProperty(nObjDefnID, item.pName, item.pPropGet,
30 item.pPropPut);
31 }
32
33 // static
DefineMethods(CFXJS_Engine * pEngine,uint32_t nObjDefnID,pdfium::span<const JSMethodSpec> methods)34 void CJS_Object::DefineMethods(CFXJS_Engine* pEngine,
35 uint32_t nObjDefnID,
36 pdfium::span<const JSMethodSpec> methods) {
37 for (const auto& item : methods)
38 pEngine->DefineObjMethod(nObjDefnID, item.pName, item.pMethodCall);
39 }
40
CJS_Object(v8::Local<v8::Object> pObject,CJS_Runtime * pRuntime)41 CJS_Object::CJS_Object(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
42 : m_pV8Object(pObject->GetIsolate(), pObject), m_pRuntime(pRuntime) {}
43
44 CJS_Object::~CJS_Object() = default;
45