OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2012 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 blink::Platform::current()->didStopWorkerRunLoop(blink::WebWorkerRunLoop(&m_
workerGlobalScope.thread()->runLoop())); | 113 blink::Platform::current()->didStopWorkerRunLoop(blink::WebWorkerRunLoop(&m_
workerGlobalScope.thread()->runLoop())); |
114 | 114 |
115 disposeContext(); | 115 disposeContext(); |
116 | 116 |
117 ThreadState::current()->addCleanupTask(IsolateCleanupTask::create(m_isolateH
older.release())); | 117 ThreadState::current()->addCleanupTask(IsolateCleanupTask::create(m_isolateH
older.release())); |
118 } | 118 } |
119 | 119 |
120 void WorkerScriptController::disposeContext() | 120 void WorkerScriptController::disposeContext() |
121 { | 121 { |
122 m_perContextData.clear(); | 122 m_perContextData.clear(); |
123 m_contextHolder.clear(); | |
124 } | 123 } |
125 | 124 |
126 bool WorkerScriptController::initializeContextIfNeeded() | 125 bool WorkerScriptController::initializeContextIfNeeded() |
127 { | 126 { |
128 if (m_contextHolder) | 127 if (m_perContextData) |
129 return true; | 128 return true; |
130 | 129 |
131 v8::Handle<v8::Context> context = v8::Context::New(isolate()); | 130 v8::Handle<v8::Context> context = v8::Context::New(isolate()); |
132 if (context.IsEmpty()) | 131 if (context.IsEmpty()) |
133 return false; | 132 return false; |
134 | 133 |
135 m_contextHolder = adoptPtr(new gin::ContextHolder(isolate())); | 134 m_perContextData = V8PerContextData::create(context, m_world.get()); |
136 m_contextHolder->SetContext(context); | |
137 | 135 |
138 v8::Context::Scope scope(context); | 136 v8::Context::Scope scope(context); |
139 | 137 |
140 V8PerContextDataHolder::install(context, m_world.get()); | |
141 | |
142 m_perContextData = V8PerContextData::create(context); | |
143 if (!m_perContextData->init()) { | |
144 disposeContext(); | |
145 return false; | |
146 } | |
147 | |
148 // Set DebugId for the new context. | 138 // Set DebugId for the new context. |
149 context->SetEmbedderData(0, v8AtomicString(isolate(), "worker")); | 139 context->SetEmbedderData(0, v8AtomicString(isolate(), "worker")); |
150 | 140 |
151 // Create a new JS object and use it as the prototype for the shadow global
object. | 141 // Create a new JS object and use it as the prototype for the shadow global
object. |
152 const WrapperTypeInfo* contextType = &V8DedicatedWorkerGlobalScope::wrapperT
ypeInfo; | 142 const WrapperTypeInfo* contextType = &V8DedicatedWorkerGlobalScope::wrapperT
ypeInfo; |
153 if (m_workerGlobalScope.isServiceWorkerGlobalScope()) | 143 if (m_workerGlobalScope.isServiceWorkerGlobalScope()) |
154 contextType = &V8ServiceWorkerGlobalScope::wrapperTypeInfo; | 144 contextType = &V8ServiceWorkerGlobalScope::wrapperTypeInfo; |
155 else if (!m_workerGlobalScope.isDedicatedWorkerGlobalScope()) | 145 else if (!m_workerGlobalScope.isDedicatedWorkerGlobalScope()) |
156 contextType = &V8SharedWorkerGlobalScope::wrapperTypeInfo; | 146 contextType = &V8SharedWorkerGlobalScope::wrapperTypeInfo; |
157 v8::Handle<v8::Function> workerGlobalScopeConstructor = m_perContextData->co
nstructorForType(contextType); | 147 v8::Handle<v8::Function> workerGlobalScopeConstructor = m_perContextData->co
nstructorForType(contextType); |
158 v8::Local<v8::Object> jsWorkerGlobalScope = V8ObjectConstructor::newInstance
(workerGlobalScopeConstructor); | 148 v8::Local<v8::Object> jsWorkerGlobalScope = V8ObjectConstructor::newInstance
(workerGlobalScopeConstructor); |
159 if (jsWorkerGlobalScope.IsEmpty()) { | 149 if (jsWorkerGlobalScope.IsEmpty()) { |
160 disposeContext(); | 150 disposeContext(); |
161 return false; | 151 return false; |
162 } | 152 } |
163 | 153 |
164 V8DOMWrapper::associateObjectWithWrapper<V8WorkerGlobalScope>(PassRefPtr<Wor
kerGlobalScope>(m_workerGlobalScope), contextType, jsWorkerGlobalScope, isolate(
), WrapperConfiguration::Dependent); | 154 V8DOMWrapper::associateObjectWithWrapper<V8WorkerGlobalScope>(PassRefPtr<Wor
kerGlobalScope>(m_workerGlobalScope), contextType, jsWorkerGlobalScope, isolate(
), WrapperConfiguration::Dependent); |
165 | 155 |
166 // Insert the object instance as the prototype of the shadow object. | 156 // Insert the object instance as the prototype of the shadow object. |
167 v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_context
Holder->context()->Global()->GetPrototype()); | 157 v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_perCont
extData->context()->Global()->GetPrototype()); |
168 globalObject->SetPrototype(jsWorkerGlobalScope); | 158 globalObject->SetPrototype(jsWorkerGlobalScope); |
169 | 159 |
170 return true; | 160 return true; |
171 } | 161 } |
172 | 162 |
173 ScriptValue WorkerScriptController::evaluate(const String& script, const String&
fileName, const TextPosition& scriptStartPosition, WorkerGlobalScopeExecutionSt
ate* state) | 163 ScriptValue WorkerScriptController::evaluate(const String& script, const String&
fileName, const TextPosition& scriptStartPosition, WorkerGlobalScopeExecutionSt
ate* state) |
174 { | 164 { |
175 v8::HandleScope handleScope(isolate()); | 165 v8::HandleScope handleScope(isolate()); |
176 | 166 |
177 if (!initializeContextIfNeeded()) | 167 if (!initializeContextIfNeeded()) |
178 return ScriptValue(); | 168 return ScriptValue(); |
179 | 169 |
180 v8::Handle<v8::Context> context = m_contextHolder->context(); | 170 v8::Handle<v8::Context> context = m_perContextData->context(); |
181 if (!m_disableEvalPending.isEmpty()) { | 171 if (!m_disableEvalPending.isEmpty()) { |
182 context->AllowCodeGenerationFromStrings(false); | 172 context->AllowCodeGenerationFromStrings(false); |
183 context->SetErrorMessageForCodeGenerationFromStrings(v8String(isolate(),
m_disableEvalPending)); | 173 context->SetErrorMessageForCodeGenerationFromStrings(v8String(isolate(),
m_disableEvalPending)); |
184 m_disableEvalPending = String(); | 174 m_disableEvalPending = String(); |
185 } | 175 } |
186 | 176 |
187 v8::Context::Scope scope(context); | 177 v8::Context::Scope scope(context); |
188 | 178 |
189 v8::TryCatch block; | 179 v8::TryCatch block; |
190 | 180 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | 276 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
287 v8::Handle<v8::Object> global = V8WorkerGlobalScope::findInstanceInPrototype
Chain(context->Global(), isolate); | 277 v8::Handle<v8::Object> global = V8WorkerGlobalScope::findInstanceInPrototype
Chain(context->Global(), isolate); |
288 // Return 0 if the current executing context is not the worker context. | 278 // Return 0 if the current executing context is not the worker context. |
289 if (global.IsEmpty()) | 279 if (global.IsEmpty()) |
290 return 0; | 280 return 0; |
291 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(global)
; | 281 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(global)
; |
292 return workerGlobalScope->script(); | 282 return workerGlobalScope->script(); |
293 } | 283 } |
294 | 284 |
295 } // namespace WebCore | 285 } // namespace WebCore |
OLD | NEW |