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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 31 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
32 | 32 |
33 #include "bindings/core/v8/ScriptCallStack.h" | 33 #include "bindings/core/v8/ScriptCallStack.h" |
34 #include "bindings/core/v8/ScriptController.h" | |
34 #include "bindings/core/v8/ScriptSourceCode.h" | 35 #include "bindings/core/v8/ScriptSourceCode.h" |
35 #include "bindings/core/v8/ScriptValue.h" | 36 #include "bindings/core/v8/ScriptValue.h" |
36 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" | 37 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" |
37 #include "bindings/core/v8/V8ErrorHandler.h" | 38 #include "bindings/core/v8/V8ErrorHandler.h" |
38 #include "bindings/core/v8/V8Initializer.h" | 39 #include "bindings/core/v8/V8Initializer.h" |
39 #include "bindings/core/v8/V8ObjectConstructor.h" | 40 #include "bindings/core/v8/V8ObjectConstructor.h" |
40 #include "bindings/core/v8/V8ScriptRunner.h" | 41 #include "bindings/core/v8/V8ScriptRunner.h" |
41 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" | 42 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" |
42 #include "bindings/core/v8/V8WorkerGlobalScope.h" | 43 #include "bindings/core/v8/V8WorkerGlobalScope.h" |
43 #include "bindings/core/v8/WrapperTypeInfo.h" | 44 #include "bindings/core/v8/WrapperTypeInfo.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 // Create a new v8::Context with the worker/worklet as the global object | 159 // Create a new v8::Context with the worker/worklet as the global object |
159 // (aka the inner global). | 160 // (aka the inner global). |
160 ScriptWrappable* scriptWrappable = m_globalScope->getScriptWrappable(); | 161 ScriptWrappable* scriptWrappable = m_globalScope->getScriptWrappable(); |
161 const WrapperTypeInfo* wrapperTypeInfo = scriptWrappable->wrapperTypeInfo(); | 162 const WrapperTypeInfo* wrapperTypeInfo = scriptWrappable->wrapperTypeInfo(); |
162 v8::Local<v8::FunctionTemplate> globalInterfaceTemplate = wrapperTypeInfo->d omTemplate(m_isolate, *m_world); | 163 v8::Local<v8::FunctionTemplate> globalInterfaceTemplate = wrapperTypeInfo->d omTemplate(m_isolate, *m_world); |
163 if (globalInterfaceTemplate.IsEmpty()) | 164 if (globalInterfaceTemplate.IsEmpty()) |
164 return false; | 165 return false; |
165 v8::Local<v8::ObjectTemplate> globalTemplate = globalInterfaceTemplate->Inst anceTemplate(); | 166 v8::Local<v8::ObjectTemplate> globalTemplate = globalInterfaceTemplate->Inst anceTemplate(); |
166 v8::Local<v8::Context> context; | 167 v8::Local<v8::Context> context; |
167 { | 168 { |
169 // Initialize V8 extensions before creating the context. | |
170 Vector<const char*> extensionNames; | |
171 if (m_globalScope->isServiceWorkerGlobalScope()) { | |
172 // TODO(lazyboy): Should we add V8Extensions to all service worker | |
173 // contexts, when we actually don't care about them in non extension | |
174 // service worker contexts? | |
175 const V8Extensions& extensions = ScriptController::registeredExtensi ons(); | |
haraken
2016/04/22 18:33:21
Nit: Now it doesn't make sense to put the register
lazyboy
2016/04/22 20:45:19
OK, I'll move it in a separate CL, I've also fixed
| |
176 extensionNames.reserveInitialCapacity(extensions.size()); | |
177 for (const auto* extension : extensions) | |
178 extensionNames.append(extension->name()); | |
179 } | |
180 v8::ExtensionConfiguration extensionConfiguration(extensionNames.size(), extensionNames.data()); | |
181 | |
168 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled(V8PerIsolat eData::from(m_isolate)); | 182 V8PerIsolateData::UseCounterDisabledScope useCounterDisabled(V8PerIsolat eData::from(m_isolate)); |
169 context = v8::Context::New(m_isolate, nullptr, globalTemplate); | 183 context = v8::Context::New(m_isolate, &extensionConfiguration, globalTem plate); |
170 } | 184 } |
171 if (context.IsEmpty()) | 185 if (context.IsEmpty()) |
172 return false; | 186 return false; |
173 | 187 |
174 m_scriptState = ScriptState::create(context, m_world); | 188 m_scriptState = ScriptState::create(context, m_world); |
175 | 189 |
176 ScriptState::Scope scope(m_scriptState.get()); | 190 ScriptState::Scope scope(m_scriptState.get()); |
177 | 191 |
178 // Name new context for debugging. For main thread worklet global scopes | 192 // Name new context for debugging. For main thread worklet global scopes |
179 // this is done once the context is initialized. | 193 // this is done once the context is initialized. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 m_executionState->m_errorEventFromImportedScript = errorEvent; | 333 m_executionState->m_errorEventFromImportedScript = errorEvent; |
320 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(m_iso late, errorMessage)); | 334 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(m_iso late, errorMessage)); |
321 } | 335 } |
322 | 336 |
323 DEFINE_TRACE(WorkerOrWorkletScriptController) | 337 DEFINE_TRACE(WorkerOrWorkletScriptController) |
324 { | 338 { |
325 visitor->trace(m_globalScope); | 339 visitor->trace(m_globalScope); |
326 } | 340 } |
327 | 341 |
328 } // namespace blink | 342 } // namespace blink |
OLD | NEW |