Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjs_global.h
Go to the documentation of this file.
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#ifndef FXJS_CJS_GLOBAL_H_
8#define FXJS_CJS_GLOBAL_H_
9
10#include <map>
11#include <memory>
12#include <vector>
13
14#include "core/fxcrt/unowned_ptr.h"
15#include "fxjs/cfx_keyvalue.h"
16#include "fxjs/cjs_object.h"
17#include "fxjs/cjs_result.h"
18#include "third_party/base/containers/span.h"
19
20class CFX_GlobalData;
21
22// The CJS_Global object is not the V8 global object (i.e. it is not |this|
23// in JavaScript outside of a bound function call). It is a facility for
24// sharing data amongst documents and persisting data within a document
25// between sessions. It is only partially implemented due to security and
26// privacy concerns. It provides access via properties in the usual manner,
27// execpt that these are stored on the C++ side rather than in V8 itself.
28// It is a static object that is available as "global" property of the V8
29// global object and can be manipulated from JavaScript as |global['foo']|
30// for example.
31
32class CJS_Global final : public CJS_Object {
33 public:
34 static uint32_t GetObjDefnID();
35 static void DefineJSObjects(CFXJS_Engine* pEngine);
36 static void DefineAllProperties(CFXJS_Engine* pEngine);
37
38 static void queryprop_static(
39 v8::Local<v8::Name> property,
40 const v8::PropertyCallbackInfo<v8::Integer>& info);
41 static void getprop_static(v8::Local<v8::Name> property,
42 const v8::PropertyCallbackInfo<v8::Value>& info);
43 static void putprop_static(v8::Local<v8::Name> property,
44 v8::Local<v8::Value> value,
45 const v8::PropertyCallbackInfo<v8::Value>& info);
46 static void delprop_static(v8::Local<v8::Name> property,
47 const v8::PropertyCallbackInfo<v8::Boolean>& info);
48 static void enumprop_static(const v8::PropertyCallbackInfo<v8::Array>& info);
49
50 static void setPersistent_static(
51 const v8::FunctionCallbackInfo<v8::Value>& info);
52
53 CJS_Global(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
54 ~CJS_Global() override;
55
56 private:
57 struct JSGlobalData : public CFX_Value {
58 public:
59 JSGlobalData();
60 ~JSGlobalData();
61
62 v8::Global<v8::Object> pData;
63 bool bPersistent = false;
64 bool bDeleted = false;
65 };
66
67 static uint32_t ObjDefnID;
68 static const JSMethodSpec MethodSpecs[];
69
70 void UpdateGlobalPersistentVariables();
71 // TODO(crbug.com/pdfium/926): This method is never called.
72 void CommitGlobalPersisitentVariables();
73 void DestroyGlobalPersisitentVariables();
74 CJS_Result SetGlobalVariables(const ByteString& propname,
75 CFX_Value::DataType nType,
76 double dData,
77 bool bData,
78 const ByteString& sData,
79 v8::Local<v8::Object> pData,
80 bool bDefaultPersistent);
81 std::vector<std::unique_ptr<CFX_KeyValue>> ObjectToArray(
82 CJS_Runtime* pRuntime,
83 v8::Local<v8::Object> pObj);
84 void PutObjectProperty(v8::Local<v8::Object> obj, CFX_KeyValue* pData);
85 CJS_Result setPersistent(CJS_Runtime* pRuntime,
86 pdfium::span<v8::Local<v8::Value>> params);
87 bool HasProperty(const ByteString& propname);
88 bool DelProperty(const ByteString& propname);
89 CJS_Result GetProperty(CJS_Runtime* pRuntime, const ByteString& propname);
90 CJS_Result SetProperty(CJS_Runtime* pRuntime,
91 const ByteString& propname,
92 v8::Local<v8::Value> vp);
93 void EnumProperties(CJS_Runtime* pRuntime,
94 const v8::PropertyCallbackInfo<v8::Array>& info);
95
96 std::map<ByteString, std::unique_ptr<JSGlobalData>> m_MapGlobal;
97 UnownedPtr<CFX_GlobalData> m_pGlobalData;
98};
99
100#endif // FXJS_CJS_GLOBAL_H_
@ FXJSOBJTYPE_STATIC
double dData
DataType nType
CJS_Global(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
static void delprop_static(v8::Local< v8::Name > property, const v8::PropertyCallbackInfo< v8::Boolean > &info)
static void enumprop_static(const v8::PropertyCallbackInfo< v8::Array > &info)
static void setPersistent_static(const v8::FunctionCallbackInfo< v8::Value > &info)
static void getprop_static(v8::Local< v8::Name > property, const v8::PropertyCallbackInfo< v8::Value > &info)
static void queryprop_static(v8::Local< v8::Name > property, const v8::PropertyCallbackInfo< v8::Integer > &info)
static void DefineAllProperties(CFXJS_Engine *pEngine)
~CJS_Global() override
static uint32_t GetObjDefnID()
static void putprop_static(v8::Local< v8::Name > property, v8::Local< v8::Value > value, const v8::PropertyCallbackInfo< v8::Value > &info)
static void DefineJSObjects(CFXJS_Engine *pEngine)
CJS_Runtime * GetRuntime() const
Definition cjs_object.h:54
static void DefineMethods(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSMethodSpec > consts)
static CJS_Result Success()
Definition cjs_result.h:27
static CJS_Result Failure(JSMessage id)
Definition cjs_result.h:34
bool IsEmpty() const
Definition bytestring.h:119
JSMessage
@ kObjectTypeError
@ kGlobalNotFoundError
@ kUnknownProperty
#define CHECK(cvref)