John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 7 | #include "fxjs/cjs_object.h" |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 8 | |
Lei Zhang | 7015634 | 2018-10-18 19:29:59 +0000 | [diff] [blame] | 9 | #include "fxjs/cfxjs_engine.h" |
| 10 | |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 11 | // static |
| 12 | void CJS_Object::DefineConsts(CFXJS_Engine* pEngine, |
| 13 | int objId, |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 14 | pdfium::span<const JSConstSpec> consts) { |
| 15 | for (const auto& item : consts) { |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 16 | pEngine->DefineObjConst( |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 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>()); |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 21 | } |
| 22 | } |
| 23 | |
| 24 | // static |
| 25 | void CJS_Object::DefineProps(CFXJS_Engine* pEngine, |
| 26 | int objId, |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 27 | pdfium::span<const JSPropertySpec> props) { |
| 28 | for (const auto& item : props) |
| 29 | pEngine->DefineObjProperty(objId, item.pName, item.pPropGet, item.pPropPut); |
Dan Sinclair | d808dfd | 2017-10-26 15:04:17 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // static |
| 33 | void CJS_Object::DefineMethods(CFXJS_Engine* pEngine, |
| 34 | int objId, |
Tom Sepez | 8b4ddeb | 2018-06-11 15:55:17 +0000 | [diff] [blame] | 35 | pdfium::span<const JSMethodSpec> methods) { |
| 36 | for (const auto& item : methods) |
| 37 | pEngine->DefineObjMethod(objId, item.pName, item.pMethodCall); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Tom Sepez | 36aae4f | 2018-06-04 19:44:37 +0000 | [diff] [blame] | 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) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 45 | CJS_Object::~CJS_Object() {} |