OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 { | 54 { |
55 switch (feature) { | 55 switch (feature) { |
56 case v8::Isolate::kUseAsm: | 56 case v8::Isolate::kUseAsm: |
57 UseCounter::count(currentExecutionContext(isolate), UseCounter::UseAsm); | 57 UseCounter::count(currentExecutionContext(isolate), UseCounter::UseAsm); |
58 break; | 58 break; |
59 default: | 59 default: |
60 ASSERT_NOT_REACHED(); | 60 ASSERT_NOT_REACHED(); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 V8PerIsolateData::V8PerIsolateData(v8::Isolate* isolate) | 64 V8PerIsolateData::V8PerIsolateData() |
65 : m_isolate(isolate) | 65 : m_isolateHolder(adoptPtr(new gin::IsolateHolder())) |
66 , m_isolateHolder(adoptPtr(new gin::IsolateHolder(m_isolate, v8ArrayBufferAl locator()))) | 66 , m_stringCache(adoptPtr(new StringCache(m_isolateHolder->isolate()))) |
haraken
2014/09/11 09:07:06
m_isolateHolder->isolate() => isolate() ?
| |
67 , m_stringCache(adoptPtr(new StringCache(m_isolate))) | |
68 , m_hiddenValue(adoptPtr(new V8HiddenValue())) | 67 , m_hiddenValue(adoptPtr(new V8HiddenValue())) |
69 , m_constructorMode(ConstructorMode::CreateNewObject) | 68 , m_constructorMode(ConstructorMode::CreateNewObject) |
70 , m_recursionLevel(0) | 69 , m_recursionLevel(0) |
71 , m_isHandlingRecursionLevelError(false) | 70 , m_isHandlingRecursionLevelError(false) |
72 #if ENABLE(ASSERT) | 71 #if ENABLE(ASSERT) |
73 , m_internalScriptRecursionLevel(0) | 72 , m_internalScriptRecursionLevel(0) |
74 #endif | 73 #endif |
75 , m_gcEventData(adoptPtr(new GCEventData())) | 74 , m_gcEventData(adoptPtr(new GCEventData())) |
76 , m_performingMicrotaskCheckpoint(false) | 75 , m_performingMicrotaskCheckpoint(false) |
77 { | 76 { |
77 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. | |
78 isolate()->Enter(); | |
78 #if ENABLE(ASSERT) | 79 #if ENABLE(ASSERT) |
79 // currentThread will always be non-null in production, but can be null in C hromium unit tests. | 80 // currentThread will always be non-null in production, but can be null in C hromium unit tests. |
80 if (blink::Platform::current()->currentThread()) | 81 if (blink::Platform::current()->currentThread()) |
81 isolate->AddCallCompletedCallback(&assertV8RecursionScope); | 82 isolate()->AddCallCompletedCallback(&assertV8RecursionScope); |
82 #endif | 83 #endif |
83 if (isMainThread()) { | 84 if (isMainThread()) { |
84 mainThreadPerIsolateData = this; | 85 mainThreadPerIsolateData = this; |
85 PageScriptDebugServer::setMainThreadIsolate(isolate); | 86 PageScriptDebugServer::setMainThreadIsolate(isolate()); |
86 } | 87 } |
87 isolate->SetUseCounterCallback(&useCounterCallback); | 88 isolate()->SetUseCounterCallback(&useCounterCallback); |
88 } | 89 } |
89 | 90 |
90 V8PerIsolateData::~V8PerIsolateData() | 91 V8PerIsolateData::~V8PerIsolateData() |
91 { | 92 { |
92 if (m_scriptRegexpScriptState) | 93 if (m_scriptRegexpScriptState) |
93 m_scriptRegexpScriptState->disposePerContextData(); | 94 m_scriptRegexpScriptState->disposePerContextData(); |
94 if (isMainThread()) | 95 if (isMainThread()) |
95 mainThreadPerIsolateData = 0; | 96 mainThreadPerIsolateData = 0; |
96 } | 97 } |
97 | 98 |
98 v8::Isolate* V8PerIsolateData::mainThreadIsolate() | 99 v8::Isolate* V8PerIsolateData::mainThreadIsolate() |
99 { | 100 { |
100 ASSERT(isMainThread()); | 101 ASSERT(isMainThread()); |
101 ASSERT(mainThreadPerIsolateData); | 102 ASSERT(mainThreadPerIsolateData); |
102 return mainThreadPerIsolateData->isolate(); | 103 return mainThreadPerIsolateData->isolate(); |
103 } | 104 } |
104 | 105 |
105 void V8PerIsolateData::ensureInitialized(v8::Isolate* isolate) | 106 v8::Isolate* V8PerIsolateData::initialize() |
106 { | 107 { |
107 ASSERT(isolate); | 108 V8PerIsolateData* data = new V8PerIsolateData(); |
108 if (!isolate->GetData(gin::kEmbedderBlink)) { | 109 v8::Isolate* isolate = data->isolate(); |
109 V8PerIsolateData* data = new V8PerIsolateData(isolate); | 110 isolate->SetData(gin::kEmbedderBlink, data); |
110 isolate->SetData(gin::kEmbedderBlink, data); | 111 return isolate; |
111 } | |
112 } | 112 } |
113 | 113 |
114 v8::Persistent<v8::Value>& V8PerIsolateData::ensureLiveRoot() | 114 v8::Persistent<v8::Value>& V8PerIsolateData::ensureLiveRoot() |
115 { | 115 { |
116 if (m_liveRoot.isEmpty()) | 116 if (m_liveRoot.isEmpty()) |
117 m_liveRoot.set(m_isolate, v8::Null(m_isolate)); | 117 m_liveRoot.set(isolate(), v8::Null(isolate())); |
118 return m_liveRoot.getUnsafe(); | 118 return m_liveRoot.getUnsafe(); |
119 } | 119 } |
120 | 120 |
121 void V8PerIsolateData::dispose(v8::Isolate* isolate) | 121 void V8PerIsolateData::dispose(v8::Isolate* isolate) |
122 { | 122 { |
123 #if ENABLE(ASSERT) | 123 #if ENABLE(ASSERT) |
124 if (blink::Platform::current()->currentThread()) | 124 if (blink::Platform::current()->currentThread()) |
125 isolate->RemoveCallCompletedCallback(&assertV8RecursionScope); | 125 isolate->RemoveCallCompletedCallback(&assertV8RecursionScope); |
126 #endif | 126 #endif |
127 void* data = isolate->GetData(gin::kEmbedderBlink); | 127 void* data = isolate->GetData(gin::kEmbedderBlink); |
128 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. | |
129 isolate->Exit(); | |
haraken
2014/09/11 09:07:06
Just help me understand: What's the relationship b
| |
128 delete static_cast<V8PerIsolateData*>(data); | 130 delete static_cast<V8PerIsolateData*>(data); |
129 isolate->SetData(gin::kEmbedderBlink, 0); | |
haraken
2014/09/11 09:07:06
Why did you remove this? I guess it would be bette
| |
130 } | 131 } |
131 | 132 |
132 V8PerIsolateData::DOMTemplateMap& V8PerIsolateData::currentDOMTemplateMap() | 133 V8PerIsolateData::DOMTemplateMap& V8PerIsolateData::currentDOMTemplateMap() |
133 { | 134 { |
134 if (DOMWrapperWorld::current(m_isolate).isMainWorld()) | 135 if (DOMWrapperWorld::current(isolate()).isMainWorld()) |
135 return m_domTemplateMapForMainWorld; | 136 return m_domTemplateMapForMainWorld; |
136 return m_domTemplateMapForNonMainWorld; | 137 return m_domTemplateMapForNonMainWorld; |
137 } | 138 } |
138 | 139 |
139 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) | 140 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) |
140 { | 141 { |
141 DOMTemplateMap& domTemplateMap = currentDOMTemplateMap(); | 142 DOMTemplateMap& domTemplateMap = currentDOMTemplateMap(); |
142 DOMTemplateMap::iterator result = domTemplateMap.find(domTemplateKey); | 143 DOMTemplateMap::iterator result = domTemplateMap.find(domTemplateKey); |
143 if (result != domTemplateMap.end()) | 144 if (result != domTemplateMap.end()) |
144 return result->value.Get(m_isolate); | 145 return result->value.Get(isolate()); |
145 | 146 |
146 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(m_isolate, callback, data, signature, length); | 147 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate(), callback, data, signature, length); |
147 domTemplateMap.add(domTemplateKey, v8::Eternal<v8::FunctionTemplate>(m_isola te, templ)); | 148 domTemplateMap.add(domTemplateKey, v8::Eternal<v8::FunctionTemplate>(isolate (), templ)); |
148 return templ; | 149 return templ; |
149 } | 150 } |
150 | 151 |
151 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::existingDOMTemplate(void* dom TemplateKey) | 152 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::existingDOMTemplate(void* dom TemplateKey) |
152 { | 153 { |
153 DOMTemplateMap& domTemplateMap = currentDOMTemplateMap(); | 154 DOMTemplateMap& domTemplateMap = currentDOMTemplateMap(); |
154 DOMTemplateMap::iterator result = domTemplateMap.find(domTemplateKey); | 155 DOMTemplateMap::iterator result = domTemplateMap.find(domTemplateKey); |
155 if (result != domTemplateMap.end()) | 156 if (result != domTemplateMap.end()) |
156 return result->value.Get(m_isolate); | 157 return result->value.Get(isolate()); |
157 return v8::Local<v8::FunctionTemplate>(); | 158 return v8::Local<v8::FunctionTemplate>(); |
158 } | 159 } |
159 | 160 |
160 void V8PerIsolateData::setDOMTemplate(void* domTemplateKey, v8::Handle<v8::Funct ionTemplate> templ) | 161 void V8PerIsolateData::setDOMTemplate(void* domTemplateKey, v8::Handle<v8::Funct ionTemplate> templ) |
161 { | 162 { |
162 currentDOMTemplateMap().add(domTemplateKey, v8::Eternal<v8::FunctionTemplate >(m_isolate, v8::Local<v8::FunctionTemplate>(templ))); | 163 currentDOMTemplateMap().add(domTemplateKey, v8::Eternal<v8::FunctionTemplate >(isolate(), v8::Local<v8::FunctionTemplate>(templ))); |
163 } | 164 } |
164 | 165 |
165 v8::Local<v8::Context> V8PerIsolateData::ensureScriptRegexpContext() | 166 v8::Local<v8::Context> V8PerIsolateData::ensureScriptRegexpContext() |
166 { | 167 { |
167 if (!m_scriptRegexpScriptState) { | 168 if (!m_scriptRegexpScriptState) { |
168 v8::Local<v8::Context> context(v8::Context::New(m_isolate)); | 169 v8::Local<v8::Context> context(v8::Context::New(isolate())); |
169 m_scriptRegexpScriptState = ScriptState::create(context, DOMWrapperWorld ::create()); | 170 m_scriptRegexpScriptState = ScriptState::create(context, DOMWrapperWorld ::create()); |
170 } | 171 } |
171 return m_scriptRegexpScriptState->context(); | 172 return m_scriptRegexpScriptState->context(); |
172 } | 173 } |
173 | 174 |
174 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V alue> value) | 175 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V alue> value) |
175 { | 176 { |
176 return hasInstance(info, value, m_domTemplateMapForMainWorld) | 177 return hasInstance(info, value, m_domTemplateMapForMainWorld) |
177 || hasInstance(info, value, m_domTemplateMapForNonMainWorld); | 178 || hasInstance(info, value, m_domTemplateMapForNonMainWorld); |
178 } | 179 } |
179 | 180 |
180 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V alue> value, DOMTemplateMap& domTemplateMap) | 181 bool V8PerIsolateData::hasInstance(const WrapperTypeInfo* info, v8::Handle<v8::V alue> value, DOMTemplateMap& domTemplateMap) |
181 { | 182 { |
182 DOMTemplateMap::iterator result = domTemplateMap.find(info); | 183 DOMTemplateMap::iterator result = domTemplateMap.find(info); |
183 if (result == domTemplateMap.end()) | 184 if (result == domTemplateMap.end()) |
184 return false; | 185 return false; |
185 v8::Handle<v8::FunctionTemplate> templ = result->value.Get(m_isolate); | 186 v8::Handle<v8::FunctionTemplate> templ = result->value.Get(isolate()); |
186 return templ->HasInstance(value); | 187 return templ->HasInstance(value); |
187 } | 188 } |
188 | 189 |
189 v8::Handle<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const Wrap perTypeInfo* info, v8::Handle<v8::Value> value) | 190 v8::Handle<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const Wrap perTypeInfo* info, v8::Handle<v8::Value> value) |
190 { | 191 { |
191 v8::Handle<v8::Object> wrapper = findInstanceInPrototypeChain(info, value, m _domTemplateMapForMainWorld); | 192 v8::Handle<v8::Object> wrapper = findInstanceInPrototypeChain(info, value, m _domTemplateMapForMainWorld); |
192 if (!wrapper.IsEmpty()) | 193 if (!wrapper.IsEmpty()) |
193 return wrapper; | 194 return wrapper; |
194 return findInstanceInPrototypeChain(info, value, m_domTemplateMapForNonMainW orld); | 195 return findInstanceInPrototypeChain(info, value, m_domTemplateMapForNonMainW orld); |
195 } | 196 } |
196 | 197 |
197 v8::Handle<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const Wrap perTypeInfo* info, v8::Handle<v8::Value> value, DOMTemplateMap& domTemplateMap) | 198 v8::Handle<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const Wrap perTypeInfo* info, v8::Handle<v8::Value> value, DOMTemplateMap& domTemplateMap) |
198 { | 199 { |
199 if (value.IsEmpty() || !value->IsObject()) | 200 if (value.IsEmpty() || !value->IsObject()) |
200 return v8::Handle<v8::Object>(); | 201 return v8::Handle<v8::Object>(); |
201 DOMTemplateMap::iterator result = domTemplateMap.find(info); | 202 DOMTemplateMap::iterator result = domTemplateMap.find(info); |
202 if (result == domTemplateMap.end()) | 203 if (result == domTemplateMap.end()) |
203 return v8::Handle<v8::Object>(); | 204 return v8::Handle<v8::Object>(); |
204 v8::Handle<v8::FunctionTemplate> templ = result->value.Get(m_isolate); | 205 v8::Handle<v8::FunctionTemplate> templ = result->value.Get(isolate()); |
205 return v8::Handle<v8::Object>::Cast(value)->FindInstanceInPrototypeChain(tem pl); | 206 return v8::Handle<v8::Object>::Cast(value)->FindInstanceInPrototypeChain(tem pl); |
206 } | 207 } |
207 | 208 |
208 static void constructorOfToString(const v8::FunctionCallbackInfo<v8::Value>& inf o) | 209 static void constructorOfToString(const v8::FunctionCallbackInfo<v8::Value>& inf o) |
209 { | 210 { |
210 // The DOM constructors' toString functions grab the current toString | 211 // The DOM constructors' toString functions grab the current toString |
211 // for Functions by taking the toString function of itself and then | 212 // for Functions by taking the toString function of itself and then |
212 // calling it with the constructor as its receiver. This means that | 213 // calling it with the constructor as its receiver. This means that |
213 // changes to the Function prototype chain or toString function are | 214 // changes to the Function prototype chain or toString function are |
214 // reflected when printing DOM constructors. The only wart is that | 215 // reflected when printing DOM constructors. The only wart is that |
215 // changes to a DOM constructor's toString's toString will cause the | 216 // changes to a DOM constructor's toString's toString will cause the |
216 // toString of the DOM constructor itself to change. This is extremely | 217 // toString of the DOM constructor itself to change. This is extremely |
217 // obscure and unlikely to be a problem. | 218 // obscure and unlikely to be a problem. |
218 v8::Handle<v8::Value> value = info.Callee()->Get(v8AtomicString(info.GetIsol ate(), "toString")); | 219 v8::Handle<v8::Value> value = info.Callee()->Get(v8AtomicString(info.GetIsol ate(), "toString")); |
219 if (!value->IsFunction()) { | 220 if (!value->IsFunction()) { |
220 v8SetReturnValue(info, v8::String::Empty(info.GetIsolate())); | 221 v8SetReturnValue(info, v8::String::Empty(info.GetIsolate())); |
221 return; | 222 return; |
222 } | 223 } |
223 v8SetReturnValue(info, V8ScriptRunner::callInternalFunction(v8::Handle<v8::F unction>::Cast(value), info.This(), 0, 0, info.GetIsolate())); | 224 v8SetReturnValue(info, V8ScriptRunner::callInternalFunction(v8::Handle<v8::F unction>::Cast(value), info.This(), 0, 0, info.GetIsolate())); |
224 } | 225 } |
225 | 226 |
226 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::toStringTemplate() | 227 v8::Handle<v8::FunctionTemplate> V8PerIsolateData::toStringTemplate() |
227 { | 228 { |
228 if (m_toStringTemplate.isEmpty()) | 229 if (m_toStringTemplate.isEmpty()) |
229 m_toStringTemplate.set(m_isolate, v8::FunctionTemplate::New(m_isolate, c onstructorOfToString)); | 230 m_toStringTemplate.set(isolate(), v8::FunctionTemplate::New(isolate(), c onstructorOfToString)); |
230 return m_toStringTemplate.newLocal(m_isolate); | 231 return m_toStringTemplate.newLocal(isolate()); |
231 } | 232 } |
232 | 233 |
233 } // namespace blink | 234 } // namespace blink |
OLD | NEW |