#include "bindings/v8/WorkerScriptController.h"
-#include "V8DedicatedWorkerGlobalScope.h"
-#include "V8ServiceWorkerGlobalScope.h"
-#include "V8SharedWorkerGlobalScope.h"
-#include "V8WorkerGlobalScope.h"
+#include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h"
+#include "bindings/core/v8/V8SharedWorkerGlobalScope.h"
+#include "bindings/core/v8/V8WorkerGlobalScope.h"
+#include "bindings/modules/v8/V8ServiceWorkerGlobalScope.h"
#include "bindings/v8/ScriptSourceCode.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8ErrorHandler.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/workers/WorkerObjectProxy.h"
#include "core/workers/WorkerThread.h"
-#include "heap/ThreadState.h"
+#include "platform/heap/ThreadState.h"
#include <v8.h>
#include "public/platform/Platform.h"
// See http://webkit.org/b/83104#c14 for why this is here.
blink::Platform::current()->didStopWorkerRunLoop(blink::WebWorkerRunLoop(&m_workerGlobalScope.thread()->runLoop()));
- disposeContext();
+ if (isContextInitialized())
+ m_scriptState->disposePerContextData();
ThreadState::current()->addCleanupTask(IsolateCleanupTask::create(m_isolate));
}
-void WorkerScriptController::disposeContext()
-{
- m_perContextData.clear();
-}
-
bool WorkerScriptController::initializeContextIfNeeded()
{
- if (m_perContextData)
+ v8::HandleScope handleScope(m_isolate);
+
+ if (isContextInitialized())
return true;
v8::Handle<v8::Context> context = v8::Context::New(m_isolate);
if (context.IsEmpty())
return false;
- m_perContextData = V8PerContextData::create(context, m_world);
+ m_scriptState = ScriptState::create(context, m_world);
- v8::Context::Scope scope(context);
+ ScriptState::Scope scope(m_scriptState.get());
// Set DebugId for the new context.
context->SetEmbedderData(0, v8AtomicString(m_isolate, "worker"));
contextType = &V8ServiceWorkerGlobalScope::wrapperTypeInfo;
else if (!m_workerGlobalScope.isDedicatedWorkerGlobalScope())
contextType = &V8SharedWorkerGlobalScope::wrapperTypeInfo;
- v8::Handle<v8::Function> workerGlobalScopeConstructor = m_perContextData->constructorForType(contextType);
- v8::Local<v8::Object> jsWorkerGlobalScope = V8ObjectConstructor::newInstance(workerGlobalScopeConstructor);
+ v8::Handle<v8::Function> workerGlobalScopeConstructor = m_scriptState->perContextData()->constructorForType(contextType);
+ v8::Local<v8::Object> jsWorkerGlobalScope = V8ObjectConstructor::newInstance(m_isolate, workerGlobalScopeConstructor);
if (jsWorkerGlobalScope.IsEmpty()) {
- disposeContext();
+ m_scriptState->disposePerContextData();
return false;
}
V8DOMWrapper::associateObjectWithWrapper<V8WorkerGlobalScope>(PassRefPtrWillBeRawPtr<WorkerGlobalScope>(&m_workerGlobalScope), contextType, jsWorkerGlobalScope, m_isolate, WrapperConfiguration::Dependent);
// Insert the object instance as the prototype of the shadow object.
- v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_perContextData->context()->Global()->GetPrototype());
+ v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_scriptState->context()->Global()->GetPrototype());
globalObject->SetPrototype(jsWorkerGlobalScope);
return true;
ScriptValue WorkerScriptController::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, WorkerGlobalScopeExecutionState* state)
{
- v8::HandleScope handleScope(m_isolate);
-
if (!initializeContextIfNeeded())
return ScriptValue();
- v8::Handle<v8::Context> context = m_perContextData->context();
+ ScriptState::Scope scope(m_scriptState.get());
+
if (!m_disableEvalPending.isEmpty()) {
- context->AllowCodeGenerationFromStrings(false);
- context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, m_disableEvalPending));
+ m_scriptState->context()->AllowCodeGenerationFromStrings(false);
+ m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, m_disableEvalPending));
m_disableEvalPending = String();
}
- v8::Context::Scope scope(context);
-
v8::TryCatch block;
v8::Handle<v8::String> scriptString = v8String(m_isolate, script);
state->errorMessage = toCoreString(message->Get());
state->lineNumber = message->GetLineNumber();
state->columnNumber = message->GetStartColumn() + 1;
- V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, sourceURL, message->GetScriptResourceName(), ScriptValue());
+ TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptResourceName(), ScriptValue());
state->sourceURL = sourceURL;
- state->exception = ScriptValue(block.Exception(), m_isolate);
+ state->exception = ScriptValue(m_scriptState.get(), block.Exception());
block.Reset();
} else
state->hadException = false;
if (result.IsEmpty() || result->IsUndefined())
return ScriptValue();
- return ScriptValue(result, m_isolate);
+ return ScriptValue(m_scriptState.get(), result);
}
-void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr<ErrorEvent>* errorEvent)
+void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtrWillBeRawPtr<ErrorEvent>* errorEvent)
{
if (isExecutionForbidden())
return;
if (state.hadException) {
if (errorEvent) {
*errorEvent = m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin) ?
- ErrorEvent::createSanitizedError(0) : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, 0);
- V8ErrorHandler::storeExceptionOnErrorEventWrapper(errorEvent->get(), state.exception.v8Value(), m_isolate);
+ ErrorEvent::createSanitizedError(m_world.get()) : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get());
+ V8ErrorHandler::storeExceptionOnErrorEventWrapper(errorEvent->get(), state.exception.v8Value(), m_scriptState->context()->Global(), m_isolate);
} else {
ASSERT(!m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin));
- RefPtr<ErrorEvent> event = m_errorEventFromImportedScript ? m_errorEventFromImportedScript.release() : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, 0);
+ RefPtrWillBeRawPtr<ErrorEvent> event = nullptr;
+ if (m_errorEventFromImportedScript) {
+ event = m_errorEventFromImportedScript.release();
+ } else {
+ event = ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get());
+ }
m_workerGlobalScope.reportException(event, nullptr, NotSharableCrossOrigin);
}
}
m_disableEvalPending = errorMessage;
}
-void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtr<ErrorEvent> errorEvent)
+void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent> errorEvent)
{
m_errorEventFromImportedScript = errorEvent;
throwError(V8ThrowException::createError(v8GeneralError, m_errorEventFromImportedScript->message(), m_isolate), m_isolate);