OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/jsapi/include/fxjs_v8.h" | 7 #include "fpdfsdk/jsapi/include/fxjs_v8.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 : m_ObjName(sObjName), | 58 : m_ObjName(sObjName), |
59 m_ObjType(eObjType), | 59 m_ObjType(eObjType), |
60 m_pConstructor(pConstructor), | 60 m_pConstructor(pConstructor), |
61 m_pDestructor(pDestructor), | 61 m_pDestructor(pDestructor), |
62 m_pIsolate(isolate) { | 62 m_pIsolate(isolate) { |
63 v8::Isolate::Scope isolate_scope(isolate); | 63 v8::Isolate::Scope isolate_scope(isolate); |
64 v8::HandleScope handle_scope(isolate); | 64 v8::HandleScope handle_scope(isolate); |
65 | 65 |
66 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); | 66 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); |
67 fun->InstanceTemplate()->SetInternalFieldCount(2); | 67 fun->InstanceTemplate()->SetInternalFieldCount(2); |
| 68 if (eObjType == FXJSOBJTYPE_GLOBAL) { |
| 69 fun->InstanceTemplate()->Set( |
| 70 v8::Symbol::GetToStringTag(isolate), |
| 71 v8::String::NewFromUtf8(isolate, "global", v8::NewStringType::kNormal) |
| 72 .ToLocalChecked()); |
| 73 } |
68 m_FunctionTemplate.Reset(isolate, fun); | 74 m_FunctionTemplate.Reset(isolate, fun); |
69 | 75 |
70 v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun); | 76 v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun); |
71 m_Signature.Reset(isolate, sig); | 77 m_Signature.Reset(isolate, sig); |
72 } | 78 } |
73 | 79 |
74 int AssignID() { | 80 int AssignID() { |
75 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_pIsolate); | 81 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_pIsolate); |
76 pData->m_ObjectDefnArray.push_back(this); | 82 pData->m_ObjectDefnArray.push_back(this); |
77 return pData->m_ObjectDefnArray.size() - 1; | 83 return pData->m_ObjectDefnArray.size() - 1; |
(...skipping 23 matching lines...) Expand all Loading... |
101 | 107 |
102 static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate( | 108 static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate( |
103 v8::Isolate* pIsolate) { | 109 v8::Isolate* pIsolate) { |
104 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); | 110 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); |
105 for (int i = 0; i < maxID; ++i) { | 111 for (int i = 0; i < maxID; ++i) { |
106 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); | 112 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); |
107 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) | 113 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) |
108 return pObjDef->GetInstanceTemplate(); | 114 return pObjDef->GetInstanceTemplate(); |
109 } | 115 } |
110 if (!g_DefaultGlobalObjectTemplate) { | 116 if (!g_DefaultGlobalObjectTemplate) { |
111 g_DefaultGlobalObjectTemplate = new v8::Global<v8::ObjectTemplate>; | 117 v8::Local<v8::ObjectTemplate> hGlobalTemplate = |
112 g_DefaultGlobalObjectTemplate->Reset(pIsolate, | 118 v8::ObjectTemplate::New(pIsolate); |
113 v8::ObjectTemplate::New(pIsolate)); | 119 hGlobalTemplate->Set( |
| 120 v8::Symbol::GetToStringTag(pIsolate), |
| 121 v8::String::NewFromUtf8(pIsolate, "global", v8::NewStringType::kNormal) |
| 122 .ToLocalChecked()); |
| 123 g_DefaultGlobalObjectTemplate = |
| 124 new v8::Global<v8::ObjectTemplate>(pIsolate, hGlobalTemplate); |
114 } | 125 } |
115 return g_DefaultGlobalObjectTemplate->Get(pIsolate); | 126 return g_DefaultGlobalObjectTemplate->Get(pIsolate); |
116 } | 127 } |
117 | 128 |
118 void* FXJS_ArrayBufferAllocator::Allocate(size_t length) { | 129 void* FXJS_ArrayBufferAllocator::Allocate(size_t length) { |
119 return calloc(1, length); | 130 return calloc(1, length); |
120 } | 131 } |
121 | 132 |
122 void* FXJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { | 133 void* FXJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { |
123 return malloc(length); | 134 return malloc(length); |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 v8::Local<v8::Value> pValue) { | 840 v8::Local<v8::Value> pValue) { |
830 if (pValue.IsEmpty()) | 841 if (pValue.IsEmpty()) |
831 return v8::Local<v8::Array>(); | 842 return v8::Local<v8::Array>(); |
832 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 843 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
833 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 844 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
834 } | 845 } |
835 | 846 |
836 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 847 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { |
837 pTo = pFrom; | 848 pTo = pFrom; |
838 } | 849 } |
OLD | NEW |