2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
35 #include "WorkerScriptController.h"
39 #include "ScriptSourceCode.h"
40 #include "ScriptValue.h"
44 #include "WorkerContext.h"
45 #include "WorkerContextExecutionProxy.h"
46 #include "WorkerObjectProxy.h"
47 #include "WorkerThread.h"
51 WorkerScriptController::WorkerScriptController(WorkerContext* workerContext)
52 : m_workerContext(workerContext)
53 , m_proxy(new WorkerContextExecutionProxy(workerContext))
54 , m_executionForbidden(false)
58 WorkerScriptController::~WorkerScriptController()
60 removeAllDOMObjectsInCurrentThread();
63 ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode)
65 return evaluate(sourceCode, 0);
68 ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, ScriptValue* exception)
71 MutexLocker lock(m_sharedDataMutex);
72 if (m_executionForbidden)
76 WorkerContextExecutionState state;
77 ScriptValue result = m_proxy->evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startLine() - 1, &state);
78 if (state.hadException) {
80 *exception = state.exception;
82 m_workerContext->reportException(state.errorMessage, state.lineNumber, state.sourceURL);
85 m_workerContext->thread()->workerObjectProxy().reportPendingActivity(m_workerContext->hasPendingActivity());
90 void WorkerScriptController::forbidExecution()
92 // This function is called from another thread.
93 MutexLocker lock(m_sharedDataMutex);
94 m_executionForbidden = true;
97 void WorkerScriptController::setException(ScriptValue exception)
99 throwError(*exception.v8Value());
102 } // namespace WebCore
104 #endif // ENABLE(WORKERS)