summaryrefslogtreecommitdiffstats
path: root/webkit/port
diff options
context:
space:
mode:
authordimich@google.com <dimich@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 23:49:22 +0000
committerdimich@google.com <dimich@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 23:49:22 +0000
commit9eef357377e89bffd2d5ff9fad9de0c94d8cc934 (patch)
tree8b19430b9214d833a0a2ce0f80499b527a3536c5 /webkit/port
parent249949482987ef55250a2dcd07419359225c6112 (diff)
downloadchromium_src-9eef357377e89bffd2d5ff9fad9de0c94d8cc934.zip
chromium_src-9eef357377e89bffd2d5ff9fad9de0c94d8cc934.tar.gz
chromium_src-9eef357377e89bffd2d5ff9fad9de0c94d8cc934.tar.bz2
Pre-upstream cleaning of files - changing them to follow WebKit coding style.
Review URL: http://codereview.chromium.org/42308 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port')
-rw-r--r--webkit/port/bindings/v8/WorkerContextExecutionProxy.cpp583
-rw-r--r--webkit/port/bindings/v8/WorkerContextExecutionProxy.h170
-rw-r--r--webkit/port/bindings/v8/WorkerScriptController.cpp70
-rw-r--r--webkit/port/bindings/v8/WorkerScriptController.h41
4 files changed, 416 insertions, 448 deletions
diff --git a/webkit/port/bindings/v8/WorkerContextExecutionProxy.cpp b/webkit/port/bindings/v8/WorkerContextExecutionProxy.cpp
index b9ccf66..c7e200f 100644
--- a/webkit/port/bindings/v8/WorkerContextExecutionProxy.cpp
+++ b/webkit/port/bindings/v8/WorkerContextExecutionProxy.cpp
@@ -1,31 +1,33 @@
-// Copyright (c) 2009, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*
+ * Copyright (C) 009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include "config.h"
@@ -33,9 +35,9 @@
#include "WorkerContextExecutionProxy.h"
-#include "v8_binding.h"
+#include "v8Binding.h"
+#include "v8Proxy.h"
#include "v8_index.h"
-#include "v8_proxy.h"
#include "Event.h"
#include "V8WorkerContextEventListener.h"
#include "WorkerContext.h"
@@ -45,326 +47,301 @@
namespace WebCore {
-WorkerContextExecutionProxy::WorkerContextExecutionProxy(
- WorkerContext* workerContext)
- : m_workerContext(workerContext),
- m_recursion(0) {
+WorkerContextExecutionProxy::WorkerContextExecutionProxy(WorkerContext* workerContext)
+ : m_workerContext(workerContext)
+ , m_recursion(0)
+{
}
-WorkerContextExecutionProxy::~WorkerContextExecutionProxy() {
- Dispose();
+WorkerContextExecutionProxy::~WorkerContextExecutionProxy()
+{
+ dispose();
}
-void WorkerContextExecutionProxy::Dispose() {
- // Disconnect all event listeners.
- for (EventListenerList::iterator iter = m_listeners.begin();
- iter != m_listeners.end();
- ++iter) {
- static_cast<V8WorkerContextEventListener*>(*iter)->disconnect();
- }
- m_listeners.clear();
-
- // Detach all events from their JS wrappers.
- for (EventSet::iterator iter = m_events.begin();
- iter != m_events.end();
- ++iter) {
- Event* event = *iter;
- if (ForgetV8EventObject(event)) {
- event->deref();
+void WorkerContextExecutionProxy::dispose()
+{
+ // Disconnect all event listeners.
+ for (EventListenerList::iterator iter = m_listeners.begin(); iter != m_listeners.end(); ++iter)
+ static_cast<V8WorkerContextEventListener*>(*iter)->disconnect();
+
+ m_listeners.clear();
+
+ // Detach all events from their JS wrappers.
+ for (EventSet::iterator iter = m_events.begin(); iter != m_events.end(); ++iter) {
+ Event* event = *iter;
+ if (forgetV8EventObject(event))
+ event->deref();
}
- }
- m_events.clear();
-
- // Dispose the context.
- if (!m_context.IsEmpty()) {
- m_context.Dispose();
- m_context.Clear();
- }
-
- // Remove the wrapping between JS object and DOM object. This is because
- // the worker context object is going to be disposed immediately when a
- // worker thread is tearing down. We do not want to re-delete the real object
- // when JS object is garbage collected.
- v8::Locker locker;
- v8::HandleScope scope;
- v8::Persistent<v8::Object> wrapper = GetDOMObjectMap().get(m_workerContext);
- if (!wrapper.IsEmpty())
- V8Proxy::SetDOMWrapper(wrapper, V8ClassIndex::INVALID_CLASS_INDEX, NULL);
- GetDOMObjectMap().forget(m_workerContext);
+ m_events.clear();
+
+ // Dispose the context.
+ if (!m_context.IsEmpty()) {
+ m_context.Dispose();
+ m_context.Clear();
+ }
+
+ // Remove the wrapping between JS object and DOM object. This is because
+ // the worker context object is going to be disposed immediately when a
+ // worker thread is tearing down. We do not want to re-delete the real object
+ // when JS object is garbage collected.
+ v8::Locker locker;
+ v8::HandleScope scope;
+ v8::Persistent<v8::Object> wrapper = GetDOMObjectMap().get(m_workerContext);
+ if (!wrapper.IsEmpty())
+ V8Proxy::SetDOMWrapper(wrapper, V8ClassIndex::INVALID_CLASS_INDEX, NULL);
+ GetDOMObjectMap().forget(m_workerContext);
}
-WorkerContextExecutionProxy* WorkerContextExecutionProxy::retrieve() {
- v8::Handle<v8::Context> context = v8::Context::GetCurrent();
- v8::Handle<v8::Object> global = context->Global();
- global = V8Proxy::LookupDOMWrapper(V8ClassIndex::WORKERCONTEXT, global);
- ASSERT(!global.IsEmpty());
- WorkerContext* worker_context =
- V8Proxy::ToNativeObject<WorkerContext>(V8ClassIndex::WORKERCONTEXT,
- global);
- return worker_context->script()->proxy();
+WorkerContextExecutionProxy* WorkerContextExecutionProxy::retrieve()
+{
+ v8::Handle<v8::Context> context = v8::Context::GetCurrent();
+ v8::Handle<v8::Object> global = context->Global();
+ global = V8Proxy::LookupDOMWrapper(V8ClassIndex::WORKERCONTEXT, global);
+ ASSERT(!global.IsEmpty());
+ WorkerContext* worker_context = V8Proxy::ToNativeObject<WorkerContext>(V8ClassIndex::WORKERCONTEXT, global);
+ return worker_context->script()->proxy();
}
-void WorkerContextExecutionProxy::InitContextIfNeeded() {
- // Bail out if the context has already been initialized.
- if (!m_context.IsEmpty()) {
- return;
- }
-
- // Create a new environment
- v8::Persistent<v8::ObjectTemplate> global_template;
- m_context = v8::Context::New(NULL, global_template);
-
- // Starting from now, use local context only.
- v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_context);
- v8::Context::Scope scope(context);
-
- // Allocate strings used during initialization.
- v8::Handle<v8::String> implicit_proto_string = v8::String::New("__proto__");
-
- // Create a new JS object and use it as the prototype for the
- // shadow global object.
- v8::Handle<v8::Function> worker_context_constructor =
- GetConstructor(V8ClassIndex::WORKERCONTEXT);
- v8::Local<v8::Object> js_worker_context =
- SafeAllocation::NewInstance(worker_context_constructor);
- // Bail out if allocation failed.
- if (js_worker_context.IsEmpty()) {
- Dispose();
- return;
- }
-
- // Wrap the object.
- V8Proxy::SetDOMWrapper(js_worker_context,
- V8ClassIndex::ToInt(V8ClassIndex::WORKERCONTEXT),
- m_workerContext);
-
- V8Proxy::SetJSWrapperForDOMObject(m_workerContext,
- v8::Persistent<v8::Object>::New(js_worker_context));
-
- // Insert the object instance as the prototype of the shadow object.
- v8::Handle<v8::Object> v8_global = m_context->Global();
- v8_global->Set(implicit_proto_string, js_worker_context);
+void WorkerContextExecutionProxy::initContextIfNeeded()
+{
+ // Bail out if the context has already been initialized.
+ if (!m_context.IsEmpty())
+ return;
+
+ // Create a new environment
+ v8::Persistent<v8::ObjectTemplate> global_template;
+ m_context = v8::Context::New(NULL, global_template);
+
+ // Starting from now, use local context only.
+ v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_context);
+ v8::Context::Scope scope(context);
+
+ // Allocate strings used during initialization.
+ v8::Handle<v8::String> implicit_proto_string = v8::String::New("__proto__");
+
+ // Create a new JS object and use it as the prototype for the shadow global object.
+ v8::Handle<v8::Function> worker_context_constructor = GetConstructor(V8ClassIndex::WORKERCONTEXT);
+ v8::Local<v8::Object> js_worker_context = SafeAllocation::NewInstance(worker_context_constructor);
+ // Bail out if allocation failed.
+ if (js_worker_context.IsEmpty()) {
+ dispose();
+ return;
+ }
+
+ // Wrap the object.
+ V8Proxy::SetDOMWrapper(js_worker_context, V8ClassIndex::ToInt(V8ClassIndex::WORKERCONTEXT), m_workerContext);
+
+ V8Proxy::SetJSWrapperForDOMObject(m_workerContext, v8::Persistent<v8::Object>::New(js_worker_context));
+
+ // Insert the object instance as the prototype of the shadow object.
+ v8::Handle<v8::Object> v8_global = m_context->Global();
+ v8_global->Set(implicit_proto_string, js_worker_context);
}
-v8::Local<v8::Function> WorkerContextExecutionProxy::GetConstructor(
- V8ClassIndex::V8WrapperType t) {
- // Enter the context of the proxy to make sure that the
- // function is constructed in the context corresponding to
- // this proxy.
- v8::Context::Scope scope(m_context);
- v8::Handle<v8::FunctionTemplate> templ = V8Proxy::GetTemplate(t);
-
- // Getting the function might fail if we're running out of
- // stack or memory.
- v8::TryCatch try_catch;
- v8::Local<v8::Function> value = templ->GetFunction();
- if (value.IsEmpty()) {
- return v8::Local<v8::Function>();
- }
-
- return value;
+v8::Local<v8::Function> WorkerContextExecutionProxy::GetConstructor(V8ClassIndex::V8WrapperType type)
+{
+ // Enter the context of the proxy to make sure that the function is
+ // constructed in the context corresponding to this proxy.
+ v8::Context::Scope scope(m_context);
+ v8::Handle<v8::FunctionTemplate> functionTemplate = V8Proxy::GetTemplate(type);
+
+ // Getting the function might fail if we're running out of
+ // stack or memory.
+ v8::TryCatch try_catch;
+ v8::Local<v8::Function> value = functionTemplate->GetFunction();
+ if (value.IsEmpty())
+ return v8::Local<v8::Function>();
+
+ return value;
}
-v8::Handle<v8::Value> WorkerContextExecutionProxy::ToV8Object(
- V8ClassIndex::V8WrapperType type, void* imp) {
- if (!imp) return v8::Null();
-
- if (type == V8ClassIndex::WORKERCONTEXT)
- return WorkerContextToV8Object(static_cast<WorkerContext*>(imp));
-
- // Non DOM node
- v8::Persistent<v8::Object> result = GetDOMObjectMap().get(imp);
- if (result.IsEmpty()) {
- v8::Local<v8::Object> v8obj = InstantiateV8Object(type, type, imp);
- if (!v8obj.IsEmpty()) {
- switch (type) {
- case V8ClassIndex::WORKERLOCATION:
- static_cast<WorkerLocation*>(imp)->ref();
- break;
- case V8ClassIndex::WORKERNAVIGATOR:
- static_cast<WorkerNavigator*>(imp)->ref();
- break;
- default:
- ASSERT(false);
- }
- result = v8::Persistent<v8::Object>::New(v8obj);
- V8Proxy::SetJSWrapperForDOMObject(imp, result);
+v8::Handle<v8::Value> WorkerContextExecutionProxy::ToV8Object(V8ClassIndex::V8WrapperType type, void* impl)
+{
+ if (!impl)
+ return v8::Null();
+
+ if (type == V8ClassIndex::WORKERCONTEXT)
+ return WorkerContextToV8Object(static_cast<WorkerContext*>(impl));
+
+ // Non DOM node
+ v8::Persistent<v8::Object> result = GetDOMObjectMap().get(impl);
+ if (result.IsEmpty()) {
+ v8::Local<v8::Object> v8obj = instantiateV8Object(type, type, impl);
+ if (!v8obj.IsEmpty()) {
+ switch (type) {
+ case V8ClassIndex::WORKERLOCATION:
+ static_cast<WorkerLocation*>(impl)->ref();
+ break;
+ case V8ClassIndex::WORKERNAVIGATOR:
+ static_cast<WorkerNavigator*>(impl)->ref();
+ break;
+ default:
+ ASSERT(false);
+ }
+ result = v8::Persistent<v8::Object>::New(v8obj);
+ V8Proxy::SetJSWrapperForDOMObject(impl, result);
+ }
}
- }
- return result;
+ return result;
}
-v8::Handle<v8::Value> WorkerContextExecutionProxy::EventToV8Object(
- Event* event) {
- if (!event)
- return v8::Null();
+v8::Handle<v8::Value> WorkerContextExecutionProxy::EventToV8Object(Event* event)
+{
+ if (!event)
+ return v8::Null();
- v8::Handle<v8::Object> wrapper = GetDOMObjectMap().get(event);
- if (!wrapper.IsEmpty())
- return wrapper;
+ v8::Handle<v8::Object> wrapper = GetDOMObjectMap().get(event);
+ if (!wrapper.IsEmpty())
+ return wrapper;
- V8ClassIndex::V8WrapperType type = V8ClassIndex::EVENT;
+ V8ClassIndex::V8WrapperType type = V8ClassIndex::EVENT;
- if (event->isMessageEvent())
- type = V8ClassIndex::MESSAGEEVENT;
+ if (event->isMessageEvent())
+ type = V8ClassIndex::MESSAGEEVENT;
- v8::Handle<v8::Object> result =
- InstantiateV8Object(type, V8ClassIndex::EVENT, event);
- if (result.IsEmpty()) {
- // Instantiation failed. Avoid updating the DOM object map and
- // return null which is already handled by callers of this function
- // in case the event is NULL.
- return v8::Null();
- }
+ v8::Handle<v8::Object> result = instantiateV8Object(type, V8ClassIndex::EVENT, event);
+ if (result.IsEmpty()) {
+ // Instantiation failed. Avoid updating the DOM object map and return null which
+ // is already handled by callers of this function in case the event is NULL.
+ return v8::Null();
+ }
- event->ref(); // fast ref
- V8Proxy::SetJSWrapperForDOMObject(
- event, v8::Persistent<v8::Object>::New(result));
+ event->ref(); // fast ref
+ V8Proxy::SetJSWrapperForDOMObject(event, v8::Persistent<v8::Object>::New(result));
- return result;
+ return result;
}
-// A JS object of type EventTarget in the worker context can only be
-// WorkerContext.
-v8::Handle<v8::Value> WorkerContextExecutionProxy::EventTargetToV8Object(
- EventTarget* target) {
- if (!target)
- return v8::Null();
+// A JS object of type EventTarget in the worker context can only be WorkerContext.
+v8::Handle<v8::Value> WorkerContextExecutionProxy::EventTargetToV8Object(EventTarget* target)
+{
+ if (!target)
+ return v8::Null();
- WorkerContext* worker_context = target->toWorkerContext();
- if (worker_context)
- return WorkerContextToV8Object(worker_context);
+ WorkerContext* worker_context = target->toWorkerContext();
+ if (worker_context)
+ return WorkerContextToV8Object(worker_context);
- ASSERT(0);
- return v8::Handle<v8::Value>();
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
}
-v8::Handle<v8::Value> WorkerContextExecutionProxy::WorkerContextToV8Object(
- WorkerContext* worker_context) {
- if (!worker_context) return v8::Null();
+v8::Handle<v8::Value> WorkerContextExecutionProxy::WorkerContextToV8Object(WorkerContext* workerContext)
+{
+ if (!workerContext)
+ return v8::Null();
- v8::Handle<v8::Context> context =
- worker_context->script()->proxy()->GetContext();
+ v8::Handle<v8::Context> context = workerContext->script()->proxy()->GetContext();
- v8::Handle<v8::Object> global = context->Global();
- ASSERT(!global.IsEmpty());
- return global;
+ v8::Handle<v8::Object> global = context->Global();
+ ASSERT(!global.IsEmpty());
+ return global;
}
-v8::Local<v8::Object> WorkerContextExecutionProxy::InstantiateV8Object(
- V8ClassIndex::V8WrapperType desc_type,
- V8ClassIndex::V8WrapperType cptr_type,
- void* imp) {
- v8::Local<v8::Function> function;
- WorkerContextExecutionProxy* proxy = retrieve();
- if (proxy) {
- function = proxy->GetConstructor(desc_type);
- } else {
- function = V8Proxy::GetTemplate(desc_type)->GetFunction();
- }
- v8::Local<v8::Object> instance = SafeAllocation::NewInstance(function);
- if (!instance.IsEmpty()) {
- // Avoid setting the DOM wrapper for failed allocations.
- V8Proxy::SetDOMWrapper(instance, V8ClassIndex::ToInt(cptr_type), imp);
- }
- return instance;
+v8::Local<v8::Object> WorkerContextExecutionProxy::instantiateV8Object(V8ClassIndex::V8WrapperType descType, V8ClassIndex::V8WrapperType cptrType, void* impl)
+{
+ v8::Local<v8::Function> function;
+ WorkerContextExecutionProxy* proxy = retrieve();
+ if (proxy)
+ function = proxy->GetConstructor(descType);
+ else
+ function = V8Proxy::GetTemplate(descType)->GetFunction();
+
+ v8::Local<v8::Object> instance = SafeAllocation::NewInstance(function);
+ if (!instance.IsEmpty()) {
+ // Avoid setting the DOM wrapper for failed allocations.
+ V8Proxy::SetDOMWrapper(instance, V8ClassIndex::ToInt(cptrType), impl);
+ }
+ return instance;
}
-bool WorkerContextExecutionProxy::ForgetV8EventObject(Event* event) {
- if (GetDOMObjectMap().contains(event)) {
- GetDOMObjectMap().forget(event);
- return true;
- } else {
- return false;
- }
+bool WorkerContextExecutionProxy::forgetV8EventObject(Event* event)
+{
+ if (GetDOMObjectMap().contains(event)) {
+ GetDOMObjectMap().forget(event);
+ return true;
+ } else
+ return false;
}
-v8::Local<v8::Value> WorkerContextExecutionProxy::Evaluate(
- const String& str, const String& file_name, int base_line) {
- v8::Locker locker;
- v8::HandleScope hs;
+v8::Local<v8::Value> WorkerContextExecutionProxy::evaluate(const String& str, const String& fileName, int baseLine)
+{
+ v8::Locker locker;
+ v8::HandleScope hs;
- InitContextIfNeeded();
- v8::Context::Scope scope(m_context);
+ initContextIfNeeded();
+ v8::Context::Scope scope(m_context);
- v8::Local<v8::String> code = v8ExternalString(str);
- v8::Handle<v8::Script> script = V8Proxy::CompileScript(code,
- file_name,
- base_line);
- return RunScript(script);
+ v8::Local<v8::String> code = v8ExternalString(str);
+ v8::Handle<v8::Script> script = V8Proxy::CompileScript(code, fileName, baseLine);
+ return runScript(script);
}
-v8::Local<v8::Value> WorkerContextExecutionProxy::RunScript(
- v8::Handle<v8::Script> script) {
- if (script.IsEmpty())
- return v8::Local<v8::Value>();
-
- // Compute the source string and prevent against infinite recursion.
- if (m_recursion >= kMaxRecursionDepth) {
- v8::Local<v8::String> code =
- v8ExternalString("throw RangeError('Recursion too deep')");
- script = V8Proxy::CompileScript(code, "", 0);
- }
-
- if (V8Proxy::HandleOutOfMemory())
- ASSERT(script.IsEmpty());
-
- if (script.IsEmpty())
- return v8::Local<v8::Value>();
-
- // Run the script and keep track of the current recursion depth.
- v8::Local<v8::Value> result;
- {
- m_recursion++;
- result = script->Run();
- m_recursion--;
- }
-
- // Handle V8 internal error situation (Out-of-memory).
- if (result.IsEmpty())
- return v8::Local<v8::Value>();
-
- return result;
+v8::Local<v8::Value> WorkerContextExecutionProxy::runScript(v8::Handle<v8::Script> script)
+{
+ if (script.IsEmpty())
+ return v8::Local<v8::Value>();
+
+ // Compute the source string and prevent against infinite recursion.
+ if (m_recursion >= kMaxRecursionDepth) {
+ v8::Local<v8::String> code = v8ExternalString("throw RangeError('Recursion too deep')");
+ script = V8Proxy::CompileScript(code, "", 0);
+ }
+
+ if (V8Proxy::HandleOutOfMemory())
+ ASSERT(script.IsEmpty());
+
+ if (script.IsEmpty())
+ return v8::Local<v8::Value>();
+
+ // Run the script and keep track of the current recursion depth.
+ v8::Local<v8::Value> result;
+ {
+ m_recursion++;
+ result = script->Run();
+ m_recursion--;
+ }
+
+ // Handle V8 internal error situation (Out-of-memory).
+ if (result.IsEmpty())
+ return v8::Local<v8::Value>();
+
+ return result;
}
-PassRefPtr<V8EventListener>
-WorkerContextExecutionProxy::FindOrCreateEventListener(
- v8::Local<v8::Value> obj, bool is_inline, bool find_only) {
- if (!obj->IsObject())
- return 0;
-
- for (EventListenerList::iterator iter = m_listeners.begin();
- iter != m_listeners.end();
- ++iter) {
- V8EventListener* el = *iter;
- if (el->isInline() == is_inline && el->getListenerObject() == obj)
- return el;
- }
- if (find_only)
- return NULL;
-
- // Create a new one, and add to cache.
- RefPtr<V8EventListener> listener = V8WorkerContextEventListener::create(
- this, v8::Local<v8::Object>::Cast(obj), is_inline);
- m_listeners.push_back(listener.get());
-
- return listener.release();
+PassRefPtr<V8EventListener> WorkerContextExecutionProxy::FindOrCreateEventListener(v8::Local<v8::Value> obj, bool isInline, bool findOnly)
+{
+ if (!obj->IsObject())
+ return 0;
+
+ for (EventListenerList::iterator iter = m_listeners.begin(); iter != m_listeners.end(); ++iter) {
+ V8EventListener* el = *iter;
+ if (el->isInline() == isInline && el->getListenerObject() == obj)
+ return el;
+ }
+ if (findOnly)
+ return NULL;
+
+ // Create a new one, and add to cache.
+ RefPtr<V8EventListener> listener = V8WorkerContextEventListener::create(this, v8::Local<v8::Object>::Cast(obj), isInline);
+ m_listeners.push_back(listener.get());
+
+ return listener.release();
}
-void WorkerContextExecutionProxy::RemoveEventListener(
- V8EventListener* listener) {
- for (EventListenerList::iterator iter = m_listeners.begin();
- iter != m_listeners.end();
- ++iter) {
- if (*iter == listener) {
- m_listeners.erase(iter);
- return;
+void WorkerContextExecutionProxy::RemoveEventListener(V8EventListener* listener)
+{
+ for (EventListenerList::iterator iter = m_listeners.begin(); iter != m_listeners.end(); ++iter) {
+ if (*iter == listener) {
+ m_listeners.erase(iter);
+ return;
+ }
}
- }
}
-void WorkerContextExecutionProxy::TrackEvent(Event* event) {
- m_events.add(event);
+void WorkerContextExecutionProxy::TrackEvent(Event* event)
+{
+ m_events.add(event);
}
} // namespace WebCore
diff --git a/webkit/port/bindings/v8/WorkerContextExecutionProxy.h b/webkit/port/bindings/v8/WorkerContextExecutionProxy.h
index 2aaa160..b34f92d 100644
--- a/webkit/port/bindings/v8/WorkerContextExecutionProxy.h
+++ b/webkit/port/bindings/v8/WorkerContextExecutionProxy.h
@@ -1,120 +1,112 @@
-// Copyright (c) 2009, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef WorkerContextExecutionProxy_h_
-#define WorkerContextExecutionProxy_h_
+/*
+ * Copyright (C) 009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef WorkerContextExecutionProxy_h
+#define WorkerContextExecutionProxy_h
#if ENABLE(WORKERS)
#include <list>
-#include <wtf/HashSet.h>
#include "v8.h"
#include "v8_index.h"
+#include <wtf/HashSet.h>
namespace WebCore {
-class Event;
-class EventTarget;
-class V8EventListener;
-class WorkerContext;
+ class Event;
+ class EventTarget;
+ class V8EventListener;
+ class WorkerContext;
-class WorkerContextExecutionProxy {
- public:
- WorkerContextExecutionProxy(WorkerContext*);
- ~WorkerContextExecutionProxy();
+ class WorkerContextExecutionProxy {
+ public:
+ WorkerContextExecutionProxy(WorkerContext*);
+ ~WorkerContextExecutionProxy();
- // Returns a local handle of the context.
- v8::Local<v8::Context> GetContext() {
- return v8::Local<v8::Context>::New(m_context);
- }
+ // Returns a local handle of the context.
+ v8::Local<v8::Context> GetContext() { return v8::Local<v8::Context>::New(m_context); }
- // Returns the dom constructor function for the given node type.
- v8::Local<v8::Function> GetConstructor(V8ClassIndex::V8WrapperType t);
+ // Returns the dom constructor function for the given node type.
+ v8::Local<v8::Function> GetConstructor(V8ClassIndex::V8WrapperType);
- // Finds or creates an event listener;
- PassRefPtr<V8EventListener> FindOrCreateEventListener(
- v8::Local<v8::Value> listener, bool is_inline, bool find_only);
+ // Finds or creates an event listener;
+ PassRefPtr<V8EventListener> FindOrCreateEventListener(v8::Local<v8::Value> listener, bool isInline, bool findOnly);
- // Removes an event listener;
- void RemoveEventListener(V8EventListener* listener);
+ // Removes an event listener;
+ void RemoveEventListener(V8EventListener*);
- // Track the event so that we can detach it from the JS wrapper when a worker
- // terminates. This is needed because we need to be able to dispose these
- // events and releases references to their event targets: WorkerContext.
- void TrackEvent(Event* event);
+ // Track the event so that we can detach it from the JS wrapper when a worker
+ // terminates. This is needed because we need to be able to dispose these
+ // events and releases references to their event targets: WorkerContext.
+ void TrackEvent(Event*);
- // Evaluate a script file in the current execution environment.
- v8::Local<v8::Value> Evaluate(const String& str,
- const String& file_name,
- int base_line);
+ // Evaluate a script file in the current execution environment.
+ v8::Local<v8::Value> evaluate(const String& str, const String& fileName, int baseLine);
- // Returns WorkerContext object.
- WorkerContext* worker_context() { return m_workerContext; }
+ // Returns WorkerContext object.
+ WorkerContext* workerContext() { return m_workerContext; }
- // Returns WorkerContextExecutionProxy object of the currently executing
- // context.
- static WorkerContextExecutionProxy* retrieve();
+ // Returns WorkerContextExecutionProxy object of the currently executing context.
+ static WorkerContextExecutionProxy* retrieve();
- // Returns the JS wrapper of object.
- static v8::Handle<v8::Value> ToV8Object(V8ClassIndex::V8WrapperType type,
- void* imp);
- static v8::Handle<v8::Value> EventToV8Object(Event* event);
- static v8::Handle<v8::Value> EventTargetToV8Object(EventTarget* target);
- static v8::Handle<v8::Value> WorkerContextToV8Object(WorkerContext* wc);
+ // Returns the JS wrapper of object.
+ static v8::Handle<v8::Value> ToV8Object(V8ClassIndex::V8WrapperType type, void* impl);
+ static v8::Handle<v8::Value> EventToV8Object(Event* event);
+ static v8::Handle<v8::Value> EventTargetToV8Object(EventTarget* target);
+ static v8::Handle<v8::Value> WorkerContextToV8Object(WorkerContext* wc);
- private:
- void InitContextIfNeeded();
- void Dispose();
+ private:
+ void initContextIfNeeded();
+ void dispose();
- // Run an already compiled script.
- v8::Local<v8::Value> RunScript(v8::Handle<v8::Script> script);
+ // Run an already compiled script.
+ v8::Local<v8::Value> runScript(v8::Handle<v8::Script>);
- static v8::Local<v8::Object> InstantiateV8Object(
- V8ClassIndex::V8WrapperType desc_type,
- V8ClassIndex::V8WrapperType cptr_type,
- void* impl);
+ static v8::Local<v8::Object> instantiateV8Object(V8ClassIndex::V8WrapperType descType, V8ClassIndex::V8WrapperType cptrType, void* impl);
- static bool ForgetV8EventObject(Event* event);
+ static bool forgetV8EventObject(Event*);
- WorkerContext* m_workerContext;
- v8::Persistent<v8::Context> m_context;
- int m_recursion;
+ WorkerContext* m_workerContext;
+ v8::Persistent<v8::Context> m_context;
+ int m_recursion;
- typedef std::list<V8EventListener*> EventListenerList;
- EventListenerList m_listeners;
+ typedef std::list<V8EventListener*> EventListenerList;
+ EventListenerList m_listeners;
- typedef HashSet<Event*> EventSet;
- EventSet m_events;
-};
+ typedef HashSet<Event*> EventSet;
+ EventSet m_events;
+ };
} // namespace WebCore
#endif // ENABLE(WORKERS)
-#endif // WorkerContextExecutionProxy_h_
+#endif // WorkerContextExecutionProxy_h
diff --git a/webkit/port/bindings/v8/WorkerScriptController.cpp b/webkit/port/bindings/v8/WorkerScriptController.cpp
index d0e03bf..761d92a 100644
--- a/webkit/port/bindings/v8/WorkerScriptController.cpp
+++ b/webkit/port/bindings/v8/WorkerScriptController.cpp
@@ -1,31 +1,32 @@
-// Copyright (c) 2008, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
#include "config.h"
@@ -33,6 +34,8 @@
#include "WorkerScriptController.h"
+#include "v8.h"
+
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "DOMTimer.h"
@@ -62,14 +65,8 @@ ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode)
return ScriptValue();
}
- v8::Local<v8::Value> result =
- m_proxy->Evaluate(sourceCode.source(),
- sourceCode.url().string(),
- sourceCode.startLine() - 1);
-
- m_workerContext->thread()->workerObjectProxy()->
- reportPendingActivity(m_workerContext->hasPendingActivity());
-
+ v8::Local<v8::Value> result = m_proxy->evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startLine() - 1);
+ m_workerContext->thread()->workerObjectProxy()->reportPendingActivity(m_workerContext->hasPendingActivity());
return ScriptValue();
}
@@ -88,7 +85,6 @@ void WorkerScriptController::forbidExecution()
void WorkerScriptController::setException(ScriptValue exception)
{
- // FIXME(jianli): to be implemented.
notImplemented();
}
diff --git a/webkit/port/bindings/v8/WorkerScriptController.h b/webkit/port/bindings/v8/WorkerScriptController.h
index 703afd5..07e224c 100644
--- a/webkit/port/bindings/v8/WorkerScriptController.h
+++ b/webkit/port/bindings/v8/WorkerScriptController.h
@@ -1,27 +1,31 @@
/*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
+ * modification, are permitted provided that the following conditions are
+ * met:
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
*/
#ifndef WorkerScriptController_h
@@ -31,7 +35,6 @@
#include <wtf/OwnPtr.h>
#include <wtf/Threading.h>
-#include "v8.h"
namespace WebCore {