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 | |
| 9 | // static |
| 10 | void CJS_Object::DefineConsts(CFXJS_Engine* pEngine, |
| 11 | int objId, |
| 12 | const JSConstSpec consts[]) { |
| 13 | for (size_t i = 0; consts[i].pName != 0; ++i) { |
| 14 | pEngine->DefineObjConst( |
| 15 | objId, consts[i].pName, |
| 16 | consts[i].eType == JSConstSpec::Number |
| 17 | ? pEngine->NewNumber(consts[i].number).As<v8::Value>() |
| 18 | : pEngine->NewString(consts[i].pStr).As<v8::Value>()); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | // static |
| 23 | void CJS_Object::DefineProps(CFXJS_Engine* pEngine, |
| 24 | int objId, |
| 25 | const JSPropertySpec props[]) { |
| 26 | for (size_t i = 0; props[i].pName != 0; ++i) { |
| 27 | pEngine->DefineObjProperty(objId, props[i].pName, props[i].pPropGet, |
| 28 | props[i].pPropPut); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // static |
| 33 | void CJS_Object::DefineMethods(CFXJS_Engine* pEngine, |
| 34 | int objId, |
| 35 | const JSMethodSpec methods[]) { |
| 36 | for (size_t i = 0; methods[i].pName != 0; ++i) |
| 37 | pEngine->DefineObjMethod(objId, methods[i].pName, methods[i].pMethodCall); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 40 | CJS_Object::CJS_Object(v8::Local<v8::Object> pObject) { |
Tom Sepez | 371379d | 2015-11-06 08:29:39 -0800 | [diff] [blame] | 41 | m_pIsolate = pObject->GetIsolate(); |
Tom Sepez | 116e4ad | 2015-09-21 09:22:05 -0700 | [diff] [blame] | 42 | m_pV8Object.Reset(m_pIsolate, pObject); |
| 43 | } |
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() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 47 | void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} |