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

Side by Side Diff: sky/engine/bindings/core/v8/V8PerIsolateData.cpp

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
(Empty)
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "sky/engine/config.h"
27 #include "sky/engine/bindings/core/v8/V8PerIsolateData.h"
28
29 #include "sky/engine/bindings/core/v8/DOMDataStore.h"
30 #include "sky/engine/bindings/core/v8/ScriptGCEvent.h"
31 #include "sky/engine/bindings/core/v8/ScriptProfiler.h"
32 #include "sky/engine/bindings/core/v8/V8Binding.h"
33 #include "sky/engine/bindings/core/v8/V8HiddenValue.h"
34 #include "sky/engine/bindings/core/v8/V8ObjectConstructor.h"
35 #include "sky/engine/bindings/core/v8/V8RecursionScope.h"
36 #include "sky/engine/bindings/core/v8/V8ScriptRunner.h"
37 #include "sky/engine/public/platform/Platform.h"
38 #include "sky/engine/wtf/MainThread.h"
39
40 namespace blink {
41
42 static V8PerIsolateData* mainThreadPerIsolateData = 0;
43
44 #if ENABLE(ASSERT)
45 static void assertV8RecursionScope()
46 {
47 ASSERT(V8RecursionScope::properlyUsed(v8::Isolate::GetCurrent()));
48 }
49 #endif
50
51 V8PerIsolateData::V8PerIsolateData()
52 : m_isolateHolder(adoptPtr(new gin::IsolateHolder()))
53 , m_stringCache(adoptPtr(new StringCache(isolate())))
54 , m_hiddenValue(adoptPtr(new V8HiddenValue()))
55 , m_constructorMode(ConstructorMode::CreateNewObject)
56 , m_recursionLevel(0)
57 , m_isHandlingRecursionLevelError(false)
58 #if ENABLE(ASSERT)
59 , m_internalScriptRecursionLevel(0)
60 #endif
61 , m_gcEventData(adoptPtr(new GCEventData()))
62 , m_performingMicrotaskCheckpoint(false)
63 {
64 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone.
65 isolate()->Enter();
66 #if ENABLE(ASSERT)
67 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
68 isolate()->AddCallCompletedCallback(&assertV8RecursionScope);
69 #endif
70 if (isMainThread())
71 mainThreadPerIsolateData = this;
72 }
73
74 V8PerIsolateData::~V8PerIsolateData()
75 {
76 if (m_scriptRegexpScriptState)
77 m_scriptRegexpScriptState->disposePerContextData();
78 if (isMainThread())
79 mainThreadPerIsolateData = 0;
80 }
81
82 v8::Isolate* V8PerIsolateData::mainThreadIsolate()
83 {
84 ASSERT(isMainThread());
85 ASSERT(mainThreadPerIsolateData);
86 return mainThreadPerIsolateData->isolate();
87 }
88
89 v8::Isolate* V8PerIsolateData::initialize()
90 {
91 V8PerIsolateData* data = new V8PerIsolateData();
92 v8::Isolate* isolate = data->isolate();
93 isolate->SetData(gin::kEmbedderBlink, data);
94 return isolate;
95 }
96
97 v8::Persistent<v8::Value>& V8PerIsolateData::ensureLiveRoot()
98 {
99 if (m_liveRoot.isEmpty())
100 m_liveRoot.set(isolate(), v8::Null(isolate()));
101 return m_liveRoot.getUnsafe();
102 }
103
104 void V8PerIsolateData::dispose(v8::Isolate* isolate)
105 {
106 #if ENABLE(ASSERT)
107 isolate->RemoveCallCompletedCallback(&assertV8RecursionScope);
108 #endif
109 void* data = isolate->GetData(gin::kEmbedderBlink);
110 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone.
111 isolate->Exit();
112 delete static_cast<V8PerIsolateData*>(data);
113 }
114
115 V8PerIsolateData::DOMTemplateMap& V8PerIsolateData::currentDOMTemplateMap()
116 {
117 if (DOMWrapperWorld::current(isolate()).isMainWorld())
118 return m_domTemplateMapForMainWorld;
119 return m_domTemplateMapForNonMainWorld;
120 }
121
122 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::domTemplate(void* domTemplate Key, v8::FunctionCallback callback, v8::Handle<v8::Value> data, v8::Handle<v8::S ignature> signature, int length)
123 {
124 DOMTemplateMap& domTemplateMap = currentDOMTemplateMap();
125 DOMTemplateMap::iterator result = domTemplateMap.find(domTemplateKey);
126 if (result != domTemplateMap.end())
127 return result->value.Get(isolate());
128
129 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate(), callback, data, signature, length);
130 domTemplateMap.add(domTemplateKey, v8::Eternal<v8::FunctionTemplate>(isolate (), templ));
131 return templ;
132 }
133
134 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::existingDOMTemplate(void* dom TemplateKey)
135 {
136 DOMTemplateMap& domTemplateMap = currentDOMTemplateMap();
137 DOMTemplateMap::iterator result = domTemplateMap.find(domTemplateKey);
138 if (result != domTemplateMap.end())
139 return result->value.Get(isolate());
140 return v8::Local<v8::FunctionTemplate>();
141 }
142
143 void V8PerIsolateData::setDOMTemplate(void* domTemplateKey, v8::Handle<v8::Funct ionTemplate> templ)
144 {
145 currentDOMTemplateMap().add(domTemplateKey, v8::Eternal<v8::FunctionTemplate >(isolate(), v8::Local<v8::FunctionTemplate>(templ)));
146 }
147
148 v8::Local<v8::Context> V8PerIsolateData::ensureScriptRegexpContext()
149 {
150 if (!m_scriptRegexpScriptState) {
151 v8::Local<v8::Context> context(v8::Context::New(isolate()));
152 m_scriptRegexpScriptState = ScriptState::create(context, DOMWrapperWorld ::create(FakeWorld));
153 }
154 return m_scriptRegexpScriptState->context();
155 }
156
157 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V alue> value)
158 {
159 return hasInstance(info, value, m_domTemplateMapForMainWorld)
160 || hasInstance(info, value, m_domTemplateMapForNonMainWorld);
161 }
162
163 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V alue> value, DOMTemplateMap& domTemplateMap)
164 {
165 DOMTemplateMap::iterator result = domTemplateMap.find(info);
166 if (result == domTemplateMap.end())
167 return false;
168 v8::Handle<v8::FunctionTemplate> templ = result->value.Get(isolate());
169 return templ->HasInstance(value);
170 }
171
172 v8::Handle<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const Wrap perTypeInfo* info, v8::Handle<v8::Value> value)
173 {
174 v8::Handle<v8::Object> wrapper = findInstanceInPrototypeChain(info, value, m _domTemplateMapForMainWorld);
175 if (!wrapper.IsEmpty())
176 return wrapper;
177 return findInstanceInPrototypeChain(info, value, m_domTemplateMapForNonMainW orld);
178 }
179
180 v8::Handle<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const Wrap perTypeInfo* info, v8::Handle<v8::Value> value, DOMTemplateMap& domTemplateMap)
181 {
182 if (value.IsEmpty() || !value->IsObject())
183 return v8::Handle<v8::Object>();
184 DOMTemplateMap::iterator result = domTemplateMap.find(info);
185 if (result == domTemplateMap.end())
186 return v8::Handle<v8::Object>();
187 v8::Handle<v8::FunctionTemplate> templ = result->value.Get(isolate());
188 return v8::Handle<v8::Object>::Cast(value)->FindInstanceInPrototypeChain(tem pl);
189 }
190
191 static void constructorOfToString(const v8::FunctionCallbackInfo<v8::Value>& inf o)
192 {
193 // The DOM constructors' toString functions grab the current toString
194 // for Functions by taking the toString function of itself and then
195 // calling it with the constructor as its receiver. This means that
196 // changes to the Function prototype chain or toString function are
197 // reflected when printing DOM constructors. The only wart is that
198 // changes to a DOM constructor's toString's toString will cause the
199 // toString of the DOM constructor itself to change. This is extremely
200 // obscure and unlikely to be a problem.
201 v8::Handle<v8::Value> value = info.Callee()->Get(v8AtomicString(info.GetIsol ate(), "toString"));
202 if (!value->IsFunction()) {
203 v8SetReturnValue(info, v8::String::Empty(info.GetIsolate()));
204 return;
205 }
206 v8SetReturnValue(info, V8ScriptRunner::callInternalFunction(v8::Handle<v8::F unction>::Cast(value), info.This(), 0, 0, info.GetIsolate()));
207 }
208
209 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::toStringTemplate()
210 {
211 if (m_toStringTemplate.isEmpty())
212 m_toStringTemplate.set(isolate(), v8::FunctionTemplate::New(isolate(), c onstructorOfToString));
213 return m_toStringTemplate.newLocal(isolate());
214 }
215
216 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/V8PerIsolateData.h ('k') | sky/engine/bindings/core/v8/V8PersistentValueMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698