summaryrefslogtreecommitdiff
path: root/fxjs/cjs_v8.h
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-12-06 03:12:09 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-06 03:12:09 +0000
commit4bd2ad8cf901134cabae0c56524a05a542c118fd (patch)
tree08414ce353909c495b004c78fa3fca22132a65f9 /fxjs/cjs_v8.h
parent6eda94d78313f18a8f0708c4492d0962649fa709 (diff)
downloadpdfium-4bd2ad8cf901134cabae0c56524a05a542c118fd.tar.xz
Move V8 helper methods to their own class.
This CL extracts the V8 helper methods from the CFXJS_Engine and places them in a CJS_V8 class which the engine inherits from. This will allow inheriting the CJS_V8 class into CFXJSE_Engine to share the helper methods. Change-Id: I58a7cd7ebac3af303ecbeee84c6940186a0f1dc6 Reviewed-on: https://pdfium-review.googlesource.com/20470 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cjs_v8.h')
-rw-r--r--fxjs/cjs_v8.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/fxjs/cjs_v8.h b/fxjs/cjs_v8.h
new file mode 100644
index 0000000000..9060f019ab
--- /dev/null
+++ b/fxjs/cjs_v8.h
@@ -0,0 +1,82 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJS_CJS_V8_H_
+#define FXJS_CJS_V8_H_
+
+#include <v8-util.h>
+#include <v8.h>
+
+#include <map>
+#include <vector>
+
+#include "core/fxcrt/bytestring.h"
+#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/widestring.h"
+
+class CJS_V8 {
+ public:
+ explicit CJS_V8(v8::Isolate* pIsolate);
+ virtual ~CJS_V8();
+
+ v8::Isolate* GetIsolate() const { return m_isolate; }
+
+ v8::Local<v8::Context> NewLocalContext();
+ v8::Local<v8::Context> GetPersistentContext();
+
+ v8::Local<v8::Value> NewNull();
+ v8::Local<v8::Value> NewUndefined();
+ v8::Local<v8::Array> NewArray();
+ v8::Local<v8::Number> NewNumber(int number);
+ v8::Local<v8::Number> NewNumber(double number);
+ v8::Local<v8::Number> NewNumber(float number);
+ v8::Local<v8::Boolean> NewBoolean(bool b);
+ v8::Local<v8::String> NewString(const ByteStringView& str);
+ v8::Local<v8::String> NewString(const WideStringView& str);
+ v8::Local<v8::Date> NewDate(double d);
+
+ int ToInt32(v8::Local<v8::Value> pValue);
+ bool ToBoolean(v8::Local<v8::Value> pValue);
+ double ToDouble(v8::Local<v8::Value> pValue);
+ WideString ToWideString(v8::Local<v8::Value> pValue);
+ v8::Local<v8::Object> ToObject(v8::Local<v8::Value> pValue);
+ v8::Local<v8::Array> ToArray(v8::Local<v8::Value> pValue);
+
+ // Arrays.
+ unsigned GetArrayLength(v8::Local<v8::Array> pArray);
+ v8::Local<v8::Value> GetArrayElement(v8::Local<v8::Array> pArray,
+ unsigned index);
+ unsigned PutArrayElement(v8::Local<v8::Array> pArray,
+ unsigned index,
+ v8::Local<v8::Value> pValue);
+
+ void SetConstArray(const WideString& name, v8::Local<v8::Array> array);
+ v8::Local<v8::Array> GetConstArray(const WideString& name);
+
+ // Objects.
+ std::vector<WideString> GetObjectPropertyNames(v8::Local<v8::Object> pObj);
+ v8::Local<v8::Value> GetObjectProperty(v8::Local<v8::Object> pObj,
+ const WideString& PropertyName);
+ void PutObjectProperty(v8::Local<v8::Object> pObj,
+ const WideString& PropertyName,
+ v8::Local<v8::Value> pValue);
+
+ protected:
+ void SetIsolate(v8::Isolate* pIsolate) { m_isolate = pIsolate; }
+ void ClearConstArray() { m_ConstArrays.clear(); }
+
+ void ResetPersistentContext(v8::Local<v8::Context> context) {
+ m_V8PersistentContext.Reset(m_isolate, context);
+ }
+ void ReleasePersistentContext() { m_V8PersistentContext.Reset(); }
+
+ private:
+ v8::Isolate* m_isolate;
+ std::map<WideString, v8::Global<v8::Array>> m_ConstArrays;
+ v8::Global<v8::Context> m_V8PersistentContext;
+};
+
+#endif // FXJS_CJS_V8_H_