1 // 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.
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,int objId,pdfium::span<const JSConstSpec> consts)12 void CJS_Object::DefineConsts(CFXJS_Engine* pEngine,
13 int objId,
14 pdfium::span<const JSConstSpec> consts) {
15 for (const auto& item : consts) {
16 pEngine->DefineObjConst(
17 objId, 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,int objId,pdfium::span<const JSPropertySpec> props)25 void CJS_Object::DefineProps(CFXJS_Engine* pEngine,
26 int objId,
27 pdfium::span<const JSPropertySpec> props) {
28 for (const auto& item : props)
29 pEngine->DefineObjProperty(objId, item.pName, item.pPropGet, item.pPropPut);
30 }
31
32 // static
DefineMethods(CFXJS_Engine * pEngine,int objId,pdfium::span<const JSMethodSpec> methods)33 void CJS_Object::DefineMethods(CFXJS_Engine* pEngine,
34 int objId,
35 pdfium::span<const JSMethodSpec> methods) {
36 for (const auto& item : methods)
37 pEngine->DefineObjMethod(objId, item.pName, item.pMethodCall);
38 }
39
CJS_Object(v8::Local<v8::Object> pObject,CJS_Runtime * pRuntime)40 CJS_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) {}
44
~CJS_Object()45 CJS_Object::~CJS_Object() {}
46