Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: fpdfsdk/src/javascript/JS_Runtime.cpp

Issue 1382263002: Store object definition ID in each js_class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove lookup by name Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_EventHandler.h" 9 #include "../../include/javascript/JS_EventHandler.h"
10 #include "../../include/javascript/JS_Runtime.h" 10 #include "../../include/javascript/JS_Runtime.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 void CJS_Runtime::DefineJSObjects() { 76 void CJS_Runtime::DefineJSObjects() {
77 v8::Isolate::Scope isolate_scope(GetIsolate()); 77 v8::Isolate::Scope isolate_scope(GetIsolate());
78 v8::HandleScope handle_scope(GetIsolate()); 78 v8::HandleScope handle_scope(GetIsolate());
79 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 79 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
80 v8::Context::Scope context_scope(context); 80 v8::Context::Scope context_scope(context);
81 81
82 // The call order determines the "ObjDefID" assigned to each class. 82 // The call order determines the "ObjDefID" assigned to each class.
83 // ObjDefIDs 0 - 2 83 // ObjDefIDs 0 - 2
84 CJS_Border::DefineJSObjects(GetIsolate(), FXJS_STATIC); 84 CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
85 CJS_Display::DefineJSObjects(GetIsolate(), FXJS_STATIC); 85 CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
86 CJS_Font::DefineJSObjects(GetIsolate(), FXJS_STATIC); 86 CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
87 87
88 // ObjDefIDs 3 - 5 88 // ObjDefIDs 3 - 5
89 CJS_Highlight::DefineJSObjects(GetIsolate(), FXJS_STATIC); 89 CJS_Highlight::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
90 CJS_Position::DefineJSObjects(GetIsolate(), FXJS_STATIC); 90 CJS_Position::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
91 CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJS_STATIC); 91 CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
92 92
93 // ObjDefIDs 6 - 8 93 // ObjDefIDs 6 - 8
94 CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJS_STATIC); 94 CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
95 CJS_Style::DefineJSObjects(GetIsolate(), FXJS_STATIC); 95 CJS_Style::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
96 CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJS_STATIC); 96 CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
97 97
98 // ObjDefIDs 9 - 11 98 // ObjDefIDs 9 - 11
99 CJS_App::DefineJSObjects(GetIsolate(), FXJS_STATIC); 99 CJS_App::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
100 CJS_Color::DefineJSObjects(GetIsolate(), FXJS_STATIC); 100 CJS_Color::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
101 CJS_Console::DefineJSObjects(GetIsolate(), FXJS_STATIC); 101 CJS_Console::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
102 102
103 // ObjDefIDs 12 - 14 103 // ObjDefIDs 12 - 14
104 CJS_Document::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); 104 CJS_Document::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_GLOBAL);
105 CJS_Event::DefineJSObjects(GetIsolate(), FXJS_STATIC); 105 CJS_Event::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
106 CJS_Field::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); 106 CJS_Field::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
107 107
108 // ObjDefIDs 15 - 17 108 // ObjDefIDs 15 - 17
109 CJS_Global::DefineJSObjects(GetIsolate(), FXJS_STATIC); 109 CJS_Global::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
110 CJS_Icon::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); 110 CJS_Icon::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
111 CJS_Util::DefineJSObjects(GetIsolate(), FXJS_STATIC); 111 CJS_Util::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
112 112
113 // ObjDefIDs 18 - 20 (these can't fail, return void). 113 // ObjDefIDs 18 - 20 (these can't fail, return void).
114 CJS_PublicMethods::DefineJSObjects(GetIsolate()); 114 CJS_PublicMethods::DefineJSObjects(GetIsolate());
115 CJS_GlobalConsts::DefineJSObjects(GetIsolate()); 115 CJS_GlobalConsts::DefineJSObjects(GetIsolate());
116 CJS_GlobalArrays::DefineJSObjects(GetIsolate()); 116 CJS_GlobalArrays::DefineJSObjects(GetIsolate());
117 117
118 // ObjDefIDs 21 - 22. 118 // ObjDefIDs 21 - 22.
119 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); 119 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
120 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); 120 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
121 } 121 }
122 122
123 IFXJS_Context* CJS_Runtime::NewContext() { 123 IFXJS_Context* CJS_Runtime::NewContext() {
124 CJS_Context* p = new CJS_Context(this); 124 CJS_Context* p = new CJS_Context(this);
125 m_ContextArray.Add(p); 125 m_ContextArray.Add(p);
126 return p; 126 return p;
127 } 127 }
128 128
129 void CJS_Runtime::ReleaseContext(IFXJS_Context* pContext) { 129 void CJS_Runtime::ReleaseContext(IFXJS_Context* pContext) {
130 CJS_Context* pJSContext = (CJS_Context*)pContext; 130 CJS_Context* pJSContext = (CJS_Context*)pContext;
(...skipping 18 matching lines...) Expand all
149 v8::Isolate::Scope isolate_scope(m_isolate); 149 v8::Isolate::Scope isolate_scope(m_isolate);
150 v8::HandleScope handle_scope(m_isolate); 150 v8::HandleScope handle_scope(m_isolate);
151 v8::Local<v8::Context> context = 151 v8::Local<v8::Context> context =
152 v8::Local<v8::Context>::New(m_isolate, m_context); 152 v8::Local<v8::Context>::New(m_isolate, m_context);
153 v8::Context::Scope context_scope(context); 153 v8::Context::Scope context_scope(context);
154 154
155 m_pDocument = pReaderDoc; 155 m_pDocument = pReaderDoc;
156 if (pReaderDoc) { 156 if (pReaderDoc) {
157 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate()); 157 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate());
158 if (!pThis.IsEmpty()) { 158 if (!pThis.IsEmpty()) {
159 if (FXJS_GetObjDefnID(pThis) == 159 if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) {
160 FXJS_GetObjDefnID(GetIsolate(), L"Document")) {
161 if (CJS_Document* pJSDocument = 160 if (CJS_Document* pJSDocument =
162 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { 161 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) {
163 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) 162 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
164 pDocument->AttachDoc(pReaderDoc); 163 pDocument->AttachDoc(pReaderDoc);
165 } 164 }
166 } 165 }
167 } 166 }
168 } 167 }
169 } 168 }
170 } 169 }
171 170
172 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { 171 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
173 return m_FieldEventSet.insert(event).second; 172 return m_FieldEventSet.insert(event).second;
174 } 173 }
175 174
176 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { 175 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
177 m_FieldEventSet.erase(event); 176 m_FieldEventSet.erase(event);
178 } 177 }
179 178
180 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { 179 v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
181 return v8::Local<v8::Context>::New(m_isolate, m_context); 180 return v8::Local<v8::Context>::New(m_isolate, m_context);
182 } 181 }
183 182
184 CFX_WideString ChangeObjName(const CFX_WideString& str) { 183 CFX_WideString ChangeObjName(const CFX_WideString& str) {
185 CFX_WideString sRet = str; 184 CFX_WideString sRet = str;
186 sRet.Replace(L"_", L"."); 185 sRet.Replace(L"_", L".");
187 return sRet; 186 return sRet;
188 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698