diff options
Diffstat (limited to 'WebCore/bindings/v8')
39 files changed, 323 insertions, 877 deletions
diff --git a/WebCore/bindings/v8/ScheduledAction.cpp b/WebCore/bindings/v8/ScheduledAction.cpp index f511e2b..dcd0bb3 100644 --- a/WebCore/bindings/v8/ScheduledAction.cpp +++ b/WebCore/bindings/v8/ScheduledAction.cpp @@ -34,7 +34,6 @@ #include "Document.h" #include "ScriptExecutionContext.h" #include "ScriptSourceCode.h" -#include "ScriptValue.h" #include "V8Binding.h" #include "V8Proxy.h" diff --git a/WebCore/bindings/v8/ScheduledAction.h b/WebCore/bindings/v8/ScheduledAction.h index 003885f..aefe7ef 100644 --- a/WebCore/bindings/v8/ScheduledAction.h +++ b/WebCore/bindings/v8/ScheduledAction.h @@ -34,12 +34,12 @@ #include "OwnHandle.h" #include "ScriptSourceCode.h" #include "V8GCController.h" +#include <wtf/Forward.h> #include <v8.h> namespace WebCore { - class String; class ScriptExecutionContext; class V8Proxy; class WorkerContext; @@ -47,7 +47,7 @@ namespace WebCore { class ScheduledAction { public: ScheduledAction(v8::Handle<v8::Context>, v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); - explicit ScheduledAction(v8::Handle<v8::Context> context, const WebCore::String& code, const KURL& url = KURL()) + explicit ScheduledAction(v8::Handle<v8::Context> context, const WTF::String& code, const KURL& url = KURL()) : m_context(context) , m_argc(0) , m_argv(0) diff --git a/WebCore/bindings/v8/ScriptArray.cpp b/WebCore/bindings/v8/ScriptArray.cpp deleted file mode 100644 index 7119b27..0000000 --- a/WebCore/bindings/v8/ScriptArray.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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" -#include "ScriptArray.h" - -#include "Document.h" -#include "Frame.h" -#include "ScriptScope.h" -#include "ScriptState.h" -#include "SerializedScriptValue.h" -#include "V8Binding.h" -#include "V8Proxy.h" - -namespace WebCore { - -ScriptArray::ScriptArray(ScriptState* scriptState, v8::Handle<v8::Array> v8Array) - : ScriptObject(scriptState, v8Array) -{ -} - -bool ScriptArray::set(unsigned index, const ScriptObject& value) -{ - if (value.scriptState() != m_scriptState) { - ASSERT_NOT_REACHED(); - return false; - } - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), value.v8Value()); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, SerializedScriptValue* value) -{ - ScriptValue scriptValue = ScriptValue::deserialize(m_scriptState, value); - if (scriptValue.hasNoValue()) { - ASSERT_NOT_REACHED(); - return false; - } - - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), scriptValue.v8Value()); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, const String& value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8String(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, double value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, long long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, int value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, bool value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8Boolean(value)); - return scope.success(); -} - -unsigned ScriptArray::length() -{ - ScriptScope scope(m_scriptState); - return v8::Array::Cast(*v8Value())->Length(); -} - -ScriptArray ScriptArray::createNew(ScriptState* scriptState) -{ - ScriptScope scope(scriptState); - return ScriptArray(scriptState, v8::Array::New()); -} - -} // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptArray.h b/WebCore/bindings/v8/ScriptArray.h deleted file mode 100644 index 9aa8764..0000000 --- a/WebCore/bindings/v8/ScriptArray.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 ScriptArray_h -#define ScriptArray_h - -#include "ScriptObject.h" - -#include <v8.h> - -namespace WebCore { -class ScriptState; -class SerializedScriptValue; - -class ScriptArray : public ScriptObject { -public: - ScriptArray(ScriptState* scriptState, v8::Handle<v8::Array>); - ScriptArray() {}; - virtual ~ScriptArray() {} - - bool set(unsigned index, const ScriptObject&); - bool set(unsigned index, SerializedScriptValue*); - bool set(unsigned index, const String&); - bool set(unsigned index, double); - bool set(unsigned index, long long); - bool set(unsigned index, int); - bool set(unsigned index, bool); - unsigned length(); - - static ScriptArray createNew(ScriptState*); -}; -} - -#endif // ScriptArray_h diff --git a/WebCore/bindings/v8/ScriptCallStack.h b/WebCore/bindings/v8/ScriptCallStack.h index b608563..215cdec 100644 --- a/WebCore/bindings/v8/ScriptCallStack.h +++ b/WebCore/bindings/v8/ScriptCallStack.h @@ -31,7 +31,6 @@ #ifndef ScriptCallStack_h #define ScriptCallStack_h -#include "ScriptArray.h" #include "ScriptCallFrame.h" #include "ScriptState.h" #include "ScriptValue.h" diff --git a/WebCore/bindings/v8/ScriptController.h b/WebCore/bindings/v8/ScriptController.h index 04a15f6..cd20cda 100644 --- a/WebCore/bindings/v8/ScriptController.h +++ b/WebCore/bindings/v8/ScriptController.h @@ -39,6 +39,7 @@ #include <v8.h> +#include <wtf/Forward.h> #include <wtf/HashMap.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> @@ -52,7 +53,6 @@ class Event; class Frame; class HTMLPlugInElement; class ScriptSourceCode; -class String; class Widget; class XSSAuditor; diff --git a/WebCore/bindings/v8/ScriptObject.cpp b/WebCore/bindings/v8/ScriptObject.cpp index 8f81537..3d38a9e 100644 --- a/WebCore/bindings/v8/ScriptObject.cpp +++ b/WebCore/bindings/v8/ScriptObject.cpp @@ -57,86 +57,6 @@ v8::Local<v8::Object> ScriptObject::v8Object() const return v8::Local<v8::Object>(v8::Object::Cast(*v8Value())); } -bool ScriptObject::set(const String& name, const String& value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8String(name), v8String(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, const ScriptObject& value) -{ - if (value.scriptState() != m_scriptState) { - ASSERT_NOT_REACHED(); - return false; - } - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), value.v8Value()); - return scope.success(); -} - -bool ScriptObject::set(const char* name, const String& value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8String(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, double value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, long long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, int value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, unsigned value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, unsigned long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, bool value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8Boolean(value)); - return scope.success(); -} - -ScriptObject ScriptObject::createNew(ScriptState* scriptState) -{ - ScriptScope scope(scriptState); - return ScriptObject(scriptState, v8::Object::New()); -} - bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, const ScriptObject& value) { ScriptScope scope(scriptState); diff --git a/WebCore/bindings/v8/ScriptObject.h b/WebCore/bindings/v8/ScriptObject.h index bee079c..6b78cfc 100644 --- a/WebCore/bindings/v8/ScriptObject.h +++ b/WebCore/bindings/v8/ScriptObject.h @@ -48,19 +48,6 @@ namespace WebCore { v8::Local<v8::Object> v8Object() const; ScriptState* scriptState() const { return m_scriptState; } - - bool set(const String& name, const String&); - bool set(const char* name, const ScriptObject&); - bool set(const char* name, const String&); - bool set(const char* name, double); - bool set(const char* name, long); - bool set(const char* name, long long); - bool set(const char* name, int); - bool set(const char* name, unsigned); - bool set(const char* name, unsigned long); - bool set(const char* name, bool); - - static ScriptObject createNew(ScriptState*); protected: ScriptState* m_scriptState; }; diff --git a/WebCore/bindings/v8/ScriptProfile.cpp b/WebCore/bindings/v8/ScriptProfile.cpp index 3b71d5f..32e0066 100644 --- a/WebCore/bindings/v8/ScriptProfile.cpp +++ b/WebCore/bindings/v8/ScriptProfile.cpp @@ -29,12 +29,13 @@ */ #include "config.h" - #include "ScriptProfile.h" +#include "InspectorValues.h" #include "V8Binding.h" - #include <v8-profiler.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> namespace WebCore { @@ -54,4 +55,32 @@ PassRefPtr<ScriptProfileNode> ScriptProfile::head() const return ScriptProfileNode::create(m_profile->GetTopDownRoot()); } +static PassRefPtr<InspectorObject> buildInspectorObjectFor(const v8::CpuProfileNode* node) +{ + v8::HandleScope handleScope; + RefPtr<InspectorObject> result = InspectorObject::create(); + result->setString("functionName", toWebCoreString(node->GetFunctionName())); + result->setString("url", toWebCoreString(node->GetScriptResourceName())); + result->setNumber("lineNumber", node->GetLineNumber()); + result->setNumber("totalTime", node->GetTotalTime()); + result->setNumber("selfTime", node->GetSelfTime()); + result->setNumber("numberOfCalls", 0); + result->setBool("visible", true); + result->setNumber("callUID", node->GetCallUid()); + + RefPtr<InspectorArray> children = InspectorArray::create(); + const int childrenCount = node->GetChildrenCount(); + for (int i = 0; i < childrenCount; i++) { + const v8::CpuProfileNode* child = node->GetChild(i); + children->push(buildInspectorObjectFor(child)); + } + result->set("children", children); + return result; +} + +PassRefPtr<InspectorObject> ScriptProfile::buildInspectorObjectForHead() const +{ + return buildInspectorObjectFor(m_profile->GetTopDownRoot()); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptProfile.h b/WebCore/bindings/v8/ScriptProfile.h index 2f42ad2..0182669 100644 --- a/WebCore/bindings/v8/ScriptProfile.h +++ b/WebCore/bindings/v8/ScriptProfile.h @@ -40,6 +40,8 @@ class CpuProfile; namespace WebCore { +class InspectorObject; + class ScriptProfile : public RefCounted<ScriptProfile> { public: static PassRefPtr<ScriptProfile> create(const v8::CpuProfile* profile) @@ -52,12 +54,13 @@ public: unsigned int uid() const; PassRefPtr<ScriptProfileNode> head() const; -protected: + PassRefPtr<InspectorObject> buildInspectorObjectForHead() const; + +private: ScriptProfile(const v8::CpuProfile* profile) : m_profile(profile) {} -private: const v8::CpuProfile* m_profile; }; diff --git a/WebCore/bindings/v8/ScriptProfiler.cpp b/WebCore/bindings/v8/ScriptProfiler.cpp index 4891892..9213774 100644 --- a/WebCore/bindings/v8/ScriptProfiler.cpp +++ b/WebCore/bindings/v8/ScriptProfiler.cpp @@ -59,4 +59,14 @@ void ScriptProfiler::takeHeapSnapshot() | v8::PROFILER_MODULE_JS_CONSTRUCTORS); } +long ScriptProfiler::getProfilerLogLines(long position, String* data) +{ + static char buffer[65536]; + const int readSize = v8::V8::GetLogLines(position, buffer, sizeof(buffer) - 1); + buffer[readSize] = '\0'; + position += readSize; + *data = buffer; + return position; +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptProfiler.h b/WebCore/bindings/v8/ScriptProfiler.h index aff3ce7..5c1054b 100644 --- a/WebCore/bindings/v8/ScriptProfiler.h +++ b/WebCore/bindings/v8/ScriptProfiler.h @@ -44,6 +44,7 @@ public: static void start(ScriptState* state, const String& title); static PassRefPtr<ScriptProfile> stop(ScriptState* state, const String& title); static void takeHeapSnapshot(); + static long getProfilerLogLines(long position, String* data); }; } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptStringImpl.h b/WebCore/bindings/v8/ScriptStringImpl.h index 8a47b4f..84a25c4 100644 --- a/WebCore/bindings/v8/ScriptStringImpl.h +++ b/WebCore/bindings/v8/ScriptStringImpl.h @@ -41,7 +41,7 @@ namespace WebCore { // This class is used for strings that tend to be shared with JavaScript frequently. The JSC implementation uses wtf::UString - see bindings/js/ScriptString.h // Currently XMLHttpRequest uses a ScriptString to build up the responseText attribute. As data arrives from the network, it is appended to the ScriptString // via operator+= and a JavaScript readystatechange event is fired. JavaScript can access the responseText attribute of the XMLHttpRequest object. JavaScript -// may also query the responseXML attribute of the XMLHttpRequest object which results in the responseText attribute being coerced into a WebCore::String and +// may also query the responseXML attribute of the XMLHttpRequest object which results in the responseText attribute being coerced into a WTF::String and // then parsed as an XML document. // This implementation optimizes for the common case where the responseText is built up with many calls to operator+= before the actual text is queried. class ScriptStringImpl : public RefCounted<ScriptStringImpl> { diff --git a/WebCore/bindings/v8/ScriptValue.cpp b/WebCore/bindings/v8/ScriptValue.cpp index 54f3860..6d3fe20 100755 --- a/WebCore/bindings/v8/ScriptValue.cpp +++ b/WebCore/bindings/v8/ScriptValue.cpp @@ -104,6 +104,9 @@ static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value uint32_t length = propertyNames->Length(); for (uint32_t i = 0; i < length; i++) { v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(i)); + // FIXME(yurys): v8::Object should support GetOwnPropertyNames + if (!object->HasRealNamedProperty(v8::Handle<v8::String>::Cast(name))) + continue; RefPtr<InspectorValue> propertyValue = v8ToInspectorValue(object->Get(name)); if (!propertyValue) { ASSERT_NOT_REACHED(); @@ -113,6 +116,7 @@ static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value } return inspectorObject; } + ASSERT_NOT_REACHED(); return 0; } diff --git a/WebCore/bindings/v8/V8Binding.h b/WebCore/bindings/v8/V8Binding.h index a15ece1..4656aa2 100644 --- a/WebCore/bindings/v8/V8Binding.h +++ b/WebCore/bindings/v8/V8Binding.h @@ -1,10 +1,10 @@ /* * 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 @@ -14,7 +14,7 @@ * * 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 @@ -40,7 +40,7 @@ #include <v8.h> namespace WebCore { - + class EventListener; class EventTarget; class V8BindingDOMWindow; @@ -50,6 +50,8 @@ namespace WebCore { public: typedef v8::Handle<v8::Value> Value; typedef V8BindingDOMWindow DOMWindow; + + static Value emptyScriptValue() { return v8::Local<v8::Value>(); } }; typedef BindingSecurity<V8Binding> V8BindingSecurity; @@ -61,7 +63,7 @@ namespace WebCore { template <typename StringType> StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode external); - // Convert v8 types to a WebCore::String. If the V8 string is not already + // Convert v8 types to a WTF::String. If the V8 string is not already // an external string then it is transformed into an external string at this // point to avoid repeated conversions. inline String v8StringToWebCoreString(v8::Handle<v8::String> v8String) @@ -71,7 +73,7 @@ namespace WebCore { String v8NonStringValueToWebCoreString(v8::Handle<v8::Value>); String v8ValueToWebCoreString(v8::Handle<v8::Value> value); - // Convert v8 types to a WebCore::AtomicString. + // Convert v8 types to a WTF::AtomicString. inline AtomicString v8StringToAtomicWebCoreString(v8::Handle<v8::String> v8String) { return v8StringToWebCoreString<AtomicString>(v8String, Externalize); @@ -110,8 +112,8 @@ namespace WebCore { return v8ExternalString(string); } - // Enables caching v8 wrappers created for WebCore::StringImpl. Currently this cache requires - // all the calls (both to convert WebCore::String to v8::String and to GC the handle) + // Enables caching v8 wrappers created for WTF::StringImpl. Currently this cache requires + // all the calls (both to convert WTF::String to v8::String and to GC the handle) // to be performed on the main thread. void enableStringImplCache(); @@ -152,7 +154,7 @@ namespace WebCore { { return v8ValueToWebCoreString(object); } - + String toWebCoreString(const v8::Arguments&, int index); // The string returned by this function is still owned by the argument @@ -171,7 +173,7 @@ namespace WebCore { AtomicString toAtomicWebCoreStringWithNullCheck(v8::Handle<v8::Value> value); String toWebCoreStringWithNullOrUndefinedCheck(v8::Handle<v8::Value> value); - + v8::Handle<v8::String> v8UndetectableString(const String& str); v8::Handle<v8::Value> v8StringOrNull(const String& str); @@ -183,31 +185,31 @@ namespace WebCore { double toWebCoreDate(v8::Handle<v8::Value> object); v8::Handle<v8::Value> v8DateOrNull(double value); - + v8::Persistent<v8::FunctionTemplate> createRawTemplate(); struct BatchedAttribute; struct BatchedCallback; - + v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate>, const char* interfaceName, v8::Persistent<v8::FunctionTemplate> parentClass, int fieldCount, - const BatchedAttribute*, + const BatchedAttribute*, size_t attributeCount, const BatchedCallback*, size_t callbackCount); - + v8::Handle<v8::Value> getElementStringAttr(const v8::AccessorInfo&, const QualifiedName&); void setElementStringAttr(const v8::AccessorInfo&, const QualifiedName&, v8::Local<v8::Value>); - + v8::Persistent<v8::String> getToStringName(); v8::Persistent<v8::FunctionTemplate> getToStringTemplate(); - + // V8Parameter is an adapter class that converts V8 values to Strings // or AtomicStrings as appropriate, using multiple typecast operators. enum V8ParameterMode { @@ -218,13 +220,13 @@ namespace WebCore { template <V8ParameterMode MODE = DefaultMode> class V8Parameter { public: - V8Parameter (v8::Local<v8::Value> object) :m_v8Object(object) { } + V8Parameter(v8::Local<v8::Value> object = v8::Local<v8::Value>()) : m_v8Object(object) { } operator String(); operator AtomicString(); private: v8::Local<v8::Value> m_v8Object; }; - + template<> inline V8Parameter<DefaultMode>::operator String() { return toWebCoreString(m_v8Object); } template<> inline V8Parameter<WithNullCheck>::operator String() { return toWebCoreStringWithNullCheck(m_v8Object); } template<> inline V8Parameter<WithUndefinedOrNullCheck>::operator String() { return toWebCoreStringWithNullOrUndefinedCheck(m_v8Object); } diff --git a/WebCore/bindings/v8/V8DOMWindowShell.cpp b/WebCore/bindings/v8/V8DOMWindowShell.cpp index c7c77d3..6676f6c 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.cpp +++ b/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -86,7 +86,11 @@ static void reportFatalErrorInV8(const char* location, const char* message) // V8 is shutdown, we cannot use V8 api. // The only thing we can do is to disable JavaScript. // FIXME: clean up V8Proxy and disable JavaScript. - printf("V8 error: %s (%s)\n", message, location); + int memoryUsageMB = -1; +#if PLATFORM(CHROMIUM) + memoryUsageMB = ChromiumBridge::memoryUsageMB(); +#endif + printf("V8 error: %s (%s). Current memory usage: %d MB\n", message, location, memoryUsageMB); handleFatalErrorInV8(); } diff --git a/WebCore/bindings/v8/V8DOMWindowShell.h b/WebCore/bindings/v8/V8DOMWindowShell.h index f4eaff2..2ccb410 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.h +++ b/WebCore/bindings/v8/V8DOMWindowShell.h @@ -32,6 +32,7 @@ #define V8DOMWindowShell_h #include "WrapperTypeInfo.h" +#include <wtf/Forward.h> #include <wtf/HashMap.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> @@ -41,7 +42,6 @@ namespace WebCore { class DOMWindow; class Frame; -class String; // V8WindowShell represents all the per-global object state for a Frame that // persist between navigations. diff --git a/WebCore/bindings/v8/V8DOMWrapper.cpp b/WebCore/bindings/v8/V8DOMWrapper.cpp index 4a09c34..d6f05f4 100644 --- a/WebCore/bindings/v8/V8DOMWrapper.cpp +++ b/WebCore/bindings/v8/V8DOMWrapper.cpp @@ -423,7 +423,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertEventTargetToV8Object(EventTarget* ta return toV8(eventSource); #endif -#if ENABLE(FILE_READER) +#if ENABLE(BLOB) if (FileReader* fileReader = target->toFileReader()) return toV8(fileReader); #endif diff --git a/WebCore/bindings/v8/V8DOMWrapper.h b/WebCore/bindings/v8/V8DOMWrapper.h index 97e269a..943cb8a 100644 --- a/WebCore/bindings/v8/V8DOMWrapper.h +++ b/WebCore/bindings/v8/V8DOMWrapper.h @@ -35,7 +35,7 @@ #include "Event.h" #include "Node.h" #include "NodeFilter.h" -#include "PlatformString.h" // for WebCore::String +#include "PlatformString.h" #include "V8CustomXPathNSResolver.h" #include "V8DOMMap.h" #include "V8Event.h" diff --git a/WebCore/bindings/v8/V8Proxy.h b/WebCore/bindings/v8/V8Proxy.h index 4dc28ef..94ff17c 100644 --- a/WebCore/bindings/v8/V8Proxy.h +++ b/WebCore/bindings/v8/V8Proxy.h @@ -42,6 +42,7 @@ #include "V8Utilities.h" #include "WrapperTypeInfo.h" #include <v8.h> +#include <wtf/Forward.h> #include <wtf/PassRefPtr.h> // so generated bindings don't have to #include <wtf/Vector.h> @@ -59,7 +60,6 @@ namespace WebCore { class Node; class SVGElement; class ScriptExecutionContext; - class String; class V8EventListener; class V8IsolatedContext; class WorldContextHandle; diff --git a/WebCore/bindings/v8/V8Utilities.cpp b/WebCore/bindings/v8/V8Utilities.cpp index f780218..2e5cf8b 100644 --- a/WebCore/bindings/v8/V8Utilities.cpp +++ b/WebCore/bindings/v8/V8Utilities.cpp @@ -38,6 +38,8 @@ #include "ScriptExecutionContext.h" #include "ScriptState.h" #include "V8Binding.h" +#include "V8BindingDOMWindow.h" // FIXME: remove when completeURL moves +#include "V8BindingState.h" #include "V8Proxy.h" #include "WorkerContext.h" #include "WorkerContextExecutionProxy.h" @@ -92,41 +94,25 @@ void transferHiddenDependency(v8::Handle<v8::Object> object, if (!newValue->IsNull() && !newValue->IsUndefined()) createHiddenDependency(object, newValue, cacheIndex); } - bool processingUserGesture() { - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - return frame && frame->script()->processingUserGesture(); + return V8BindingState::Only()->processingUserGesture(); } Frame* callingOrEnteredFrame() { - Frame* frame = V8Proxy::retrieveFrameForCallingContext(); - if (!frame) { - // Unfortunately, when processing script from a plug-in, we might not - // have a calling context. In those cases, we fall back to the - // entered context for security checks. - // FIXME: We need a better API for retrieving frames that abstracts - // away this concern. - frame = V8Proxy::retrieveFrameForEnteredContext(); - } - return frame; + return V8BindingState::Only()->getActiveFrame(); } bool shouldAllowNavigation(Frame* frame) { - Frame* callingOrEntered = callingOrEnteredFrame(); - return callingOrEntered && callingOrEntered->loader()->shouldAllowNavigation(frame); + return V8BindingSecurity::shouldAllowNavigation(V8BindingState::Only(), frame); } KURL completeURL(const String& relativeURL) { - // For histoical reasons, we need to complete the URL using the dynamic frame. - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - if (!frame) - return KURL(); - return frame->loader()->completeURL(relativeURL); + return V8BindingDOMWindow::completeURL(V8BindingState::Only(), relativeURL); } void navigateIfAllowed(Frame* frame, const KURL& url, bool lockHistory, bool lockBackForwardList) diff --git a/WebCore/bindings/v8/V8Utilities.h b/WebCore/bindings/v8/V8Utilities.h index cbe7a7b..2b82f4d 100644 --- a/WebCore/bindings/v8/V8Utilities.h +++ b/WebCore/bindings/v8/V8Utilities.h @@ -31,6 +31,7 @@ #ifndef V8Utilities_h #define V8Utilities_h +#include <wtf/Forward.h> #include <v8.h> namespace WebCore { @@ -40,7 +41,6 @@ namespace WebCore { class KURL; class ScriptExecutionContext; class ScriptState; - class String; // Use an array to hold dependents. It works like a ref-counted scheme. A value can be added more than once to the DOM object. void createHiddenDependency(v8::Handle<v8::Object>, v8::Local<v8::Value>, int cacheIndex); diff --git a/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp b/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp index 501e5a2..305fb18 100644 --- a/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp @@ -34,6 +34,7 @@ #include "ArrayBuffer.h" +#include "ExceptionCode.h" #include "V8Binding.h" #include "V8ArrayBuffer.h" #include "V8Proxy.h" diff --git a/WebCore/bindings/v8/custom/V8BindingMacros.h b/WebCore/bindings/v8/custom/V8BindingMacros.h index 4c8ecd3..b569b10 100644 --- a/WebCore/bindings/v8/custom/V8BindingMacros.h +++ b/WebCore/bindings/v8/custom/V8BindingMacros.h @@ -37,12 +37,13 @@ return block.ReThrow(); \ } -#define TO_WEBCORE_STRING_EXCEPTION_BLOCK(var, value) \ - String var; \ - { \ - v8::TryCatch block; \ - v8::Handle<v8::String> v8String = (value)->ToString(); \ - if (block.HasCaught()) \ - return block.ReThrow(); \ - var = v8StringToWebCoreString<String>(v8String, DoNotExternalize); \ +#define STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(type, var, value) \ + type var; \ + { \ + v8::Local<v8::Value> v8Value = (value); \ + v8::TryCatch block; \ + (value)->ToString(); \ + if (block.HasCaught()) \ + return block.ReThrow(); \ + var = v8Value; \ } diff --git a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp index 6603344..17fca22 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp @@ -43,11 +43,14 @@ namespace WebCore { -bool V8SQLStatementErrorCallback::handleEvent(ScriptExecutionContext* context, SQLTransaction* transaction, SQLError* error) +bool V8SQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error) { + if (!canInvokeCallback()) + return true; + v8::HandleScope handleScope; - v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; @@ -65,15 +68,12 @@ bool V8SQLStatementErrorCallback::handleEvent(ScriptExecutionContext* context, S errorHandle }; - // Protect the context until the callback returns. - RefPtr<ScriptExecutionContext> protector(context); - bool callbackReturnValue = false; // Step 6: If the error callback returns false, then move on to the next // statement, if any, or onto the next overall step otherwise. Otherwise, // the error callback did not return false, or there was no error callback. // Jump to the last step in the overall steps. - return invokeCallback(m_callback, 2, argv, callbackReturnValue, context) || callbackReturnValue; + return invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext()) || callbackReturnValue; } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h index cf84438..9677252 100644 --- a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h +++ b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h @@ -41,7 +41,6 @@ namespace WebCore { -class String; class V8Proxy; // V8CustomXPathNSResolver does not create a persistent handle to the diff --git a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp index d1e0701..a74faee 100644 --- a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp @@ -32,7 +32,6 @@ #include "V8DOMWindow.h" #include "Chrome.h" -#include "Database.h" #include "DOMTimer.h" #include "DOMWindow.h" #include "ExceptionCode.h" @@ -55,8 +54,6 @@ #include "V8BindingMacros.h" #include "V8BindingState.h" #include "V8CustomEventListener.h" -#include "V8Database.h" -#include "V8DatabaseCallback.h" #include "V8GCForContextDispose.h" #include "V8HiddenPropertyName.h" #include "V8HTMLAudioElementConstructor.h" @@ -82,10 +79,6 @@ #endif #include "WindowFeatures.h" -// Horizontal and vertical offset, from the parent content area, around newly -// opened popups that don't specify a location. -static const int popupTilePixels = 10; - namespace WebCore { v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments& args, bool singleShot) @@ -104,7 +97,7 @@ v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments& args, bool singl } v8::Handle<v8::Value> function = args[0]; - WebCore::String functionString; + WTF::String functionString; if (!function->IsFunction()) { if (function->IsString()) functionString = toWebCoreString(function); @@ -449,17 +442,6 @@ static bool canShowModalDialogNow(const Frame* frame) return frame->page()->chrome()->canRunModalNow(); } -static bool allowPopUp() -{ - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - - ASSERT(frame); - if (frame->script()->processingUserGesture()) - return true; - Settings* settings = frame->settings(); - return settings && settings->javaScriptCanOpenWindowsAutomatically(); -} - static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg) { HashMap<String, String> map; @@ -513,7 +495,7 @@ v8::Handle<v8::Value> V8DOMWindow::showModalDialogCallback(const v8::Arguments& if (!enteredFrame) return v8::Undefined(); - if (!canShowModalDialogNow(frame) || !allowPopUp()) + if (!canShowModalDialogNow(frame) || !V8BindingSecurity::allowPopUp(V8BindingState::Only())) return v8::Undefined(); const HashMap<String, String> features = parseModalDialogFeatures(featureArgs); @@ -584,134 +566,16 @@ v8::Handle<v8::Value> V8DOMWindow::openCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.open()"); + DOMWindow* parent = V8DOMWindow::toNative(args.Holder()); String urlString = toWebCoreStringWithNullOrUndefinedCheck(args[0]); AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_blank" : AtomicString(toWebCoreString(args[1])); - - DOMWindow* parent = V8DOMWindow::toNative(args.Holder()); - Frame* frame = parent->frame(); - - if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, true)) - return v8::Undefined(); - - Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); - if (!enteredFrame) - return v8::Undefined(); - - Frame* callingFrame = V8Proxy::retrieveFrameForCallingContext(); - // We may not have a calling context if we are invoked by a plugin via NPAPI. - if (!callingFrame) - callingFrame = enteredFrame; - - Page* page = frame->page(); - if (!page) - return v8::Undefined(); - - // Because FrameTree::find() returns true for empty strings, we must check - // for empty framenames. Otherwise, illegitimate window.open() calls with - // no name will pass right through the popup blocker. - if (!allowPopUp() && - (frameName.isEmpty() || !frame->tree()->find(frameName))) { - return v8::Undefined(); - } - - // Get the target frame for the special cases of _top and _parent. In those - // cases, we can schedule a location change right now and return early. - bool topOrParent = false; - if (frameName == "_top") { - frame = frame->tree()->top(); - topOrParent = true; - } else if (frameName == "_parent") { - if (Frame* parent = frame->tree()->parent()) - frame = parent; - topOrParent = true; - } - if (topOrParent) { - if (!shouldAllowNavigation(frame)) - return v8::Undefined(); - - String completedUrl; - if (!urlString.isEmpty()) - completedUrl = completeURL(urlString); - - if (!completedUrl.isEmpty() && - (!protocolIsJavaScript(completedUrl) || ScriptController::isSafeScript(frame))) { - bool userGesture = processingUserGesture(); - - // For whatever reason, Firefox uses the entered frame to determine - // the outgoingReferrer. We replicate that behavior here. - String referrer = enteredFrame->loader()->outgoingReferrer(); - - frame->redirectScheduler()->scheduleLocationChange(completedUrl, referrer, false, false, userGesture); - } - return toV8(frame->domWindow()); - } - - // In the case of a named frame or a new window, we'll use the - // createWindow() helper. - - // Parse the values, and then work with a copy of the parsed values - // so we can restore the values we may not want to overwrite after - // we do the multiple monitor fixes. WindowFeatures rawFeatures(toWebCoreStringWithNullOrUndefinedCheck(args[2])); - WindowFeatures windowFeatures(rawFeatures); - FloatRect screenRect = screenAvailableRect(page->mainFrame()->view()); - - // Set default size and location near parent window if none were specified. - // These may be further modified by adjustWindowRect, below. - if (!windowFeatures.xSet) { - windowFeatures.x = parent->screenX() - screenRect.x() + popupTilePixels; - windowFeatures.xSet = true; - } - if (!windowFeatures.ySet) { - windowFeatures.y = parent->screenY() - screenRect.y() + popupTilePixels; - windowFeatures.ySet = true; - } - if (!windowFeatures.widthSet) { - windowFeatures.width = parent->innerWidth(); - windowFeatures.widthSet = true; - } - if (!windowFeatures.heightSet) { - windowFeatures.height = parent->innerHeight(); - windowFeatures.heightSet = true; - } - - FloatRect windowRect(windowFeatures.x, windowFeatures.y, windowFeatures.width, windowFeatures.height); - - // The new window's location is relative to its current screen, so shift - // it in case it's on a secondary monitor. See http://b/viewIssue?id=967905. - windowRect.move(screenRect.x(), screenRect.y()); - WebCore::DOMWindow::adjustWindowRect(screenRect, windowRect, windowRect); - - windowFeatures.x = windowRect.x(); - windowFeatures.y = windowRect.y(); - windowFeatures.height = windowRect.height(); - windowFeatures.width = windowRect.width(); - - // If either of the origin coordinates or dimensions weren't set in the original - // string, make sure they aren't set now. - if (!rawFeatures.xSet) { - windowFeatures.x = 0; - windowFeatures.xSet = false; - } - if (!rawFeatures.ySet) { - windowFeatures.y = 0; - windowFeatures.ySet = false; - } - if (!rawFeatures.widthSet) { - windowFeatures.width = 0; - windowFeatures.widthSet = false; - } - if (!rawFeatures.heightSet) { - windowFeatures.height = 0; - windowFeatures.heightSet = false; - } - - frame = V8BindingDOMWindow::createWindow(V8BindingState::Only(), callingFrame, enteredFrame, frame, urlString, frameName, windowFeatures, v8::Local<v8::Value>()); + DOMWindow* child = V8BindingDOMWindow::open(V8BindingState::Only(), parent, urlString, frameName, rawFeatures); - if (!frame) + if (!child) return v8::Undefined(); - return toV8(frame->domWindow()); + return toV8(child); } @@ -790,38 +654,6 @@ v8::Handle<v8::Value> V8DOMWindow::setIntervalCallback(const v8::Arguments& args return WindowSetTimeoutImpl(args, false); } -#if ENABLE(DATABASE) -v8::Handle<v8::Value> V8DOMWindow::openDatabaseCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DOMWindow.openDatabase"); - if (args.Length() < 4) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(name, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(version, args[1]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(displayName, args[2]); - EXCEPTION_BLOCK(unsigned long, estimatedSize, args[3]->Uint32Value()); - - DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) - return v8::Undefined(); - - RefPtr<DatabaseCallback> creationCallback; - if (args.Length() >= 5) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - creationCallback = V8DatabaseCallback::create(args[4]); - } - - ExceptionCode ec = 0; - v8::Handle<v8::Value> result = toV8(imp->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec)); - - V8Proxy::setDOMException(ec); - return result; -} -#endif // ENABLE(DATABASE) - bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>) { v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), host); diff --git a/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp b/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp deleted file mode 100644 index 31406fb..0000000 --- a/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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" - -#if ENABLE(DATABASE) -#include "V8Database.h" - -#include "Database.h" -#include "ExceptionCode.h" -#include "V8Binding.h" -#include "V8BindingMacros.h" -#include "V8SQLTransactionCallback.h" -#include "V8SQLTransactionErrorCallback.h" -#include "V8CustomVoidCallback.h" -#include "V8Proxy.h" - -namespace WebCore { - -v8::Handle<v8::Value> V8Database::changeVersionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Database.changeVersion()"); - - if (args.Length() < 2) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(oldVersion, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(newVersion, args[1]); - - Database* database = V8Database::toNative(args.Holder()); - - ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext(); - if (!scriptExecutionContext) - return v8::Undefined(); - - RefPtr<V8SQLTransactionCallback> callback; - if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { - if (!args[2]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - callback = V8SQLTransactionCallback::create(args[2]); - } - - RefPtr<V8SQLTransactionErrorCallback> errorCallback; - if (args.Length() > 3 && !isUndefinedOrNull(args[3])) { - if (!args[3]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - errorCallback = V8SQLTransactionErrorCallback::create(args[3]); - } - - RefPtr<V8CustomVoidCallback> successCallback; - if (args.Length() > 4 && !isUndefinedOrNull(args[4])) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - successCallback = V8CustomVoidCallback::create(args[4], scriptExecutionContext); - } - - database->changeVersion(oldVersion, newVersion, callback.release(), errorCallback.release(), successCallback.release()); - - return v8::Undefined(); -} - -static v8::Handle<v8::Value> createTransaction(const v8::Arguments& args, bool readOnly) -{ - if (!args.Length()) - return throwError(SYNTAX_ERR); - - if (!args[0]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - Database* database = V8Database::toNative(args.Holder()); - - ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext(); - if (!scriptExecutionContext) - return v8::Undefined(); - RefPtr<V8SQLTransactionCallback> callback = V8SQLTransactionCallback::create(args[0]); - - RefPtr<V8SQLTransactionErrorCallback> errorCallback; - if (args.Length() > 1 && !isUndefinedOrNull(args[1])) { - if (!args[1]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - errorCallback = V8SQLTransactionErrorCallback::create(args[1]); - } - - RefPtr<V8CustomVoidCallback> successCallback; - if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { - if (!args[2]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - successCallback = V8CustomVoidCallback::create(args[2], scriptExecutionContext); - } - - database->transaction(callback.release(), errorCallback.release(), successCallback.release(), readOnly); - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8Database::transactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Database.transaction()"); - return createTransaction(args, false); -} - -v8::Handle<v8::Value> V8Database::readTransactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Database.readTransaction()"); - return createTransaction(args, true); -} - -} // namespace WebCore - -#endif diff --git a/WebCore/bindings/v8/custom/V8DatabaseSyncCustom.cpp b/WebCore/bindings/v8/custom/V8DatabaseSyncCustom.cpp deleted file mode 100644 index 079f6e9..0000000 --- a/WebCore/bindings/v8/custom/V8DatabaseSyncCustom.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2010 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" - -#if ENABLE(DATABASE) -#include "V8DatabaseSync.h" - -#include "DatabaseSync.h" -#include "ExceptionCode.h" -#include "V8Binding.h" -#include "V8BindingMacros.h" -#include "V8Proxy.h" -#include "V8SQLTransactionSyncCallback.h" - -namespace WebCore { - -v8::Handle<v8::Value> V8DatabaseSync::changeVersionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DatabaseSync.changeVersion()"); - - if (args.Length() < 2) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(oldVersion, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(newVersion, args[1]); - - DatabaseSync* database = V8DatabaseSync::toNative(args.Holder()); - - RefPtr<V8SQLTransactionSyncCallback> callback; - if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { - if (!args[2]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - callback = V8SQLTransactionSyncCallback::create(args[2]); - } - - ExceptionCode ec = 0; - database->changeVersion(oldVersion, newVersion, callback.release(), ec); - V8Proxy::setDOMException(ec); - - return v8::Undefined(); -} - -static v8::Handle<v8::Value> createTransaction(const v8::Arguments& args, bool readOnly) -{ - if (!args.Length()) - return throwError(SYNTAX_ERR); - - if (!args[0]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - DatabaseSync* database = V8DatabaseSync::toNative(args.Holder()); - - RefPtr<V8SQLTransactionSyncCallback> callback = V8SQLTransactionSyncCallback::create(args[0]); - - ExceptionCode ec = 0; - database->transaction(callback.release(), readOnly, ec); - V8Proxy::setDOMException(ec); - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8DatabaseSync::transactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DatabaseSync.transaction()"); - return createTransaction(args, false); -} - -v8::Handle<v8::Value> V8DatabaseSync::readTransactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DatabaseSync.readTransaction()"); - return createTransaction(args, true); -} - -} // namespace WebCore - -#endif diff --git a/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp new file mode 100644 index 0000000..39692b6 --- /dev/null +++ b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2010 Apple 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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" +#include "V8DeviceMotionEvent.h" + +#if ENABLE(DEVICE_ORIENTATION) + +#include "DeviceMotionData.h" +#include "V8Binding.h" +#include "V8Proxy.h" + +#include <v8.h> + +namespace WebCore { + +v8::Handle<v8::Value> V8DeviceMotionEvent::xAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.xAcceleration._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideXAcceleration()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->xAcceleration()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::yAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.yAcceleration._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideYAcceleration()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->yAcceleration()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::zAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.zAcceleration._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideZAcceleration()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->zAcceleration()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::xRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.xRotationRate._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideXRotationRate()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->xRotationRate()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::yRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.yRotationRate._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideYRotationRate()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->yRotationRate()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::zRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.zRotationRate._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideZRotationRate()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->zRotationRate()); +} + + +v8::Handle<v8::Value> V8DeviceMotionEvent::intervalAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.interval._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideInterval()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->interval()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::initDeviceMotionEventCallback(const v8::Arguments& args) +{ + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(args.Holder()); + V8Parameter<> type = args[0]; + bool bubbles = args[1]->BooleanValue(); + bool cancelable = args[2]->BooleanValue(); + // If any of the parameters are null or undefined, mark them as not provided. + // Otherwise, use the standard JavaScript conversion. + bool xAccelerationProvided = !isUndefinedOrNull(args[3]); + double xAcceleration = static_cast<double>(args[3]->NumberValue()); + bool yAccelerationProvided = !isUndefinedOrNull(args[4]); + double yAcceleration = static_cast<double>(args[4]->NumberValue()); + bool zAccelerationProvided = !isUndefinedOrNull(args[5]); + double zAcceleration = static_cast<double>(args[5]->NumberValue()); + bool xRotationRateProvided = !isUndefinedOrNull(args[6]); + double xRotationRate = static_cast<double>(args[6]->NumberValue()); + bool yRotationRateProvided = !isUndefinedOrNull(args[7]); + double yRotationRate = static_cast<double>(args[7]->NumberValue()); + bool zRotationRateProvided = !isUndefinedOrNull(args[8]); + double zRotationRate = static_cast<double>(args[8]->NumberValue()); + bool intervalProvided = !isUndefinedOrNull(args[9]); + double interval = static_cast<double>(args[9]->NumberValue()); + RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(xAccelerationProvided, xAcceleration, yAccelerationProvided, yAcceleration, zAccelerationProvided, zAcceleration, xRotationRateProvided, xRotationRate, yRotationRateProvided, yRotationRate, zRotationRateProvided, zRotationRate, intervalProvided, interval); + imp->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData.get()); + return v8::Handle<v8::Value>(); +} + +} // namespace WebCore + +#endif // ENABLE(DEVICE_ORIENTATION) diff --git a/WebCore/bindings/v8/custom/V8EventCustom.cpp b/WebCore/bindings/v8/custom/V8EventCustom.cpp index bce1561..e0bb02b 100644 --- a/WebCore/bindings/v8/custom/V8EventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8EventCustom.cpp @@ -40,6 +40,7 @@ #include "V8Clipboard.h" #include "V8CompositionEvent.h" #include "V8CustomEvent.h" +#include "V8DeviceMotionEvent.h" #include "V8DeviceOrientationEvent.h" #include "V8ErrorEvent.h" #include "V8IDBErrorEvent.h" @@ -155,6 +156,8 @@ v8::Handle<v8::Value> toV8(Event* impl) if (impl->isBeforeLoadEvent()) return toV8(static_cast<BeforeLoadEvent*>(impl)); #if ENABLE(DEVICE_ORIENTATION) + if (impl->isDeviceMotionEvent()) + return toV8(static_cast<DeviceMotionEvent*>(impl)); if (impl->isDeviceOrientationEvent()) return toV8(static_cast<DeviceOrientationEvent*>(impl)); #endif diff --git a/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp b/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp index 2ec3dcd..3dffeb5 100644 --- a/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp +++ b/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp @@ -32,11 +32,12 @@ #include "V8IDBAny.h" #include "SerializedScriptValue.h" -#include "V8IDBDatabaseRequest.h" +#include "V8IDBCursor.h" +#include "V8IDBDatabase.h" #include "V8IDBFactory.h" #include "V8IDBIndex.h" #include "V8IDBKey.h" -#include "V8IDBObjectStoreRequest.h" +#include "V8IDBObjectStore.h" namespace WebCore { @@ -50,14 +51,16 @@ v8::Handle<v8::Value> toV8(IDBAny* impl) return v8::Undefined(); case IDBAny::NullType: return v8::Null(); - case IDBAny::IDBDatabaseRequestType: - return toV8(impl->idbDatabaseRequest()); + case IDBAny::IDBCursorType: + return toV8(impl->idbCursor()); + case IDBAny::IDBDatabaseType: + return toV8(impl->idbDatabase()); case IDBAny::IDBIndexType: return toV8(impl->idbIndex()); case IDBAny::IDBKeyType: return toV8(impl->idbKey()); - case IDBAny::IDBObjectStoreRequestType: - return toV8(impl->idbObjectStoreRequest()); + case IDBAny::IDBObjectStoreType: + return toV8(impl->idbObjectStore()); case IDBAny::IDBFactoryType: return toV8(impl->idbFactory()); case IDBAny::SerializedScriptValueType: diff --git a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp index c7cd54c..435cf73 100644 --- a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp @@ -37,10 +37,10 @@ #include "InjectedScript.h" #include "InjectedScriptHost.h" #include "InspectorController.h" +#include "InspectorValues.h" #include "Node.h" #include "Page.h" #include "ScriptDebugServer.h" -#include "SerializedScriptValue.h" #include "V8Binding.h" #include "V8BindingState.h" @@ -164,19 +164,6 @@ v8::Handle<v8::Value> V8InjectedScriptHost::currentCallFrameCallback(const v8::A #endif #if ENABLE(DATABASE) -v8::Handle<v8::Value> V8InjectedScriptHost::databaseForIdCallback(const v8::Arguments& args) -{ - INC_STATS("InjectedScriptHost.databaseForId()"); - if (args.Length() < 1) - return v8::Undefined(); - - InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); - Database* database = host->databaseForId(args[0]->ToInt32()->Value()); - if (!database) - return v8::Undefined(); - return toV8(database); -} - v8::Handle<v8::Value> V8InjectedScriptHost::selectDatabaseCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.selectDatabase()"); @@ -208,19 +195,6 @@ v8::Handle<v8::Value> V8InjectedScriptHost::selectDOMStorageCallback(const v8::A } #endif -v8::Handle<v8::Value> V8InjectedScriptHost::reportDidDispatchOnInjectedScriptCallback(const v8::Arguments& args) -{ - INC_STATS("InjectedScriptHost.reportDidDispatchOnInjectedScript()"); - if (args.Length() < 3) - return v8::Undefined(); - InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); - int callId = args[0]->ToInt32()->Value(); - RefPtr<SerializedScriptValue> result(SerializedScriptValue::create(args[1])); - bool isException = args[2]->ToBoolean()->Value(); - host->reportDidDispatchOnInjectedScript(callId, result.get(), isException); - return v8::Undefined(); -} - InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState* inspectedScriptState) { v8::HandleScope handleScope; diff --git a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp index 2ce4780..340f0a8 100644 --- a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp @@ -83,6 +83,10 @@ v8::Handle<v8::Value> V8NotificationCenter::requestPermissionCallback(const v8:: NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder()); ScriptExecutionContext* context = notificationCenter->context(); + // Make sure that script execution context is valid. + if (!context) + return throwError(INVALID_STATE_ERR); + // Requesting permission is only valid from a page context. if (context->isWorkerContext()) return throwError(NOT_SUPPORTED_ERR); diff --git a/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp b/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp index e2a5070..af4185b 100644 --- a/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp @@ -55,7 +55,7 @@ v8::Handle<v8::Value> V8SQLTransaction::executeSqlCallback(const v8::Arguments& if (args.Length() == 0) return throwError(SYNTAX_ERR); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(statement, args[0]); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, statement, args[0]); Vector<SQLValue> sqlValues; @@ -82,7 +82,7 @@ v8::Handle<v8::Value> V8SQLTransaction::executeSqlCallback(const v8::Arguments& EXCEPTION_BLOCK(double, sqlValue, value->NumberValue()); sqlValues.append(SQLValue(sqlValue)); } else { - TO_WEBCORE_STRING_EXCEPTION_BLOCK(sqlValue, value); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, sqlValue, value); sqlValues.append(SQLValue(sqlValue)); } } @@ -90,22 +90,22 @@ v8::Handle<v8::Value> V8SQLTransaction::executeSqlCallback(const v8::Arguments& SQLTransaction* transaction = V8SQLTransaction::toNative(args.Holder()); - ScriptExecutionContext* executionContext = getScriptExecutionContext(); - if (!executionContext) + ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext(); + if (!scriptExecutionContext) return v8::Undefined(); RefPtr<SQLStatementCallback> callback; if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { if (!args[2]->IsObject()) return throwError(TYPE_MISMATCH_ERR); - callback = V8SQLStatementCallback::create(args[2]); + callback = V8SQLStatementCallback::create(args[2], scriptExecutionContext); } RefPtr<SQLStatementErrorCallback> errorCallback; if (args.Length() > 3 && !isUndefinedOrNull(args[3])) { if (!args[3]->IsObject()) return throwError(TYPE_MISMATCH_ERR); - errorCallback = V8SQLStatementErrorCallback::create(args[3]); + errorCallback = V8SQLStatementErrorCallback::create(args[3], scriptExecutionContext); } ExceptionCode ec = 0; diff --git a/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp b/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp index 495a8e4..8a57a9a 100644 --- a/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp @@ -55,7 +55,7 @@ v8::Handle<v8::Value> V8SQLTransactionSync::executeSqlCallback(const v8::Argumen if (!args.Length()) return throwError(SYNTAX_ERR); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(statement, args[0]); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, statement, args[0]); Vector<SQLValue> sqlValues; @@ -82,7 +82,7 @@ v8::Handle<v8::Value> V8SQLTransactionSync::executeSqlCallback(const v8::Argumen EXCEPTION_BLOCK(double, sqlValue, value->NumberValue()); sqlValues.append(SQLValue(sqlValue)); } else { - TO_WEBCORE_STRING_EXCEPTION_BLOCK(sqlValue, value); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, sqlValue, value); sqlValues.append(SQLValue(sqlValue)); } } diff --git a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp index f66ff3d..53d731d 100755 --- a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp @@ -33,12 +33,6 @@ #if ENABLE(WORKERS) #include "V8WorkerContext.h" -#if ENABLE(DATABASE) -#include "Database.h" -#include "V8Database.h" -#include "V8DatabaseCallback.h" -#include "V8DatabaseSync.h" -#endif #include "DOMTimer.h" #include "ExceptionCode.h" #include "ScheduledAction.h" @@ -71,7 +65,7 @@ v8::Handle<v8::Value> SetTimeoutOrInterval(const v8::Arguments& args, bool singl v8::Handle<v8::Context> v8Context = proxy->context(); if (function->IsString()) { - WebCore::String stringFunction = toWebCoreString(function); + WTF::String stringFunction = toWebCoreString(function); timerId = DOMTimer::install(workerContext, new ScheduledAction(v8Context, stringFunction, workerContext->url()), timeout, singleShot); } else if (function->IsFunction()) { size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; @@ -143,64 +137,6 @@ v8::Handle<v8::Value> toV8(WorkerContext* impl) return global; } -#if ENABLE(DATABASE) -v8::Handle<v8::Value> V8WorkerContext::openDatabaseCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.V8WorkerContext.openDatabase()"); - if (args.Length() < 4) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(name, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(version, args[1]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(displayName, args[2]); - EXCEPTION_BLOCK(unsigned long, estimatedSize, args[3]->Uint32Value()); - - WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); - - RefPtr<DatabaseCallback> creationCallback; - if (args.Length() >= 5) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - creationCallback = V8DatabaseCallback::create(args[4]); - } - - ExceptionCode ec = 0; - v8::Handle<v8::Value> result = toV8(workerContext->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec)); - - V8Proxy::setDOMException(ec); - return result; -} - -v8::Handle<v8::Value> V8WorkerContext::openDatabaseSyncCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.V8WorkerContext.openDatabaseSync()"); - if (args.Length() < 4) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(name, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(version, args[1]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(displayName, args[2]); - EXCEPTION_BLOCK(unsigned long, estimatedSize, args[3]->Uint32Value()); - - WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); - - RefPtr<DatabaseCallback> creationCallback; - if (args.Length() >= 5) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - creationCallback = V8DatabaseCallback::create(args[4]); - } - - ExceptionCode ec = 0; - v8::Handle<v8::Value> result = toV8(workerContext->openDatabaseSync(name, version, displayName, estimatedSize, creationCallback.release(), ec)); - - V8Proxy::setDOMException(ec); - return result; -} -#endif - } // namespace WebCore #endif // ENABLE(WORKERS) diff --git a/WebCore/bindings/v8/specialization/V8BindingState.cpp b/WebCore/bindings/v8/specialization/V8BindingState.cpp index 4710271..d95d578 100644 --- a/WebCore/bindings/v8/specialization/V8BindingState.cpp +++ b/WebCore/bindings/v8/specialization/V8BindingState.cpp @@ -1,10 +1,10 @@ /* * 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 @@ -14,7 +14,7 @@ * * 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 @@ -31,6 +31,8 @@ #include "config.h" #include "V8BindingState.h" +#include "Frame.h" +#include "ScriptController.h" #include "V8Proxy.h" #include <wtf/StdLibExtras.h> @@ -53,9 +55,34 @@ DOMWindow* State<V8Binding>::getActiveWindow() return V8Proxy::retrieveWindow(activeContext); } +Frame* State<V8Binding>::getActiveFrame() +{ + Frame* frame = V8Proxy::retrieveFrameForCallingContext(); + if (!frame) { + // Unfortunately, when processing script from a plug-in, we might not + // have a calling context. In those cases, we fall back to the + // entered context for security checks. + // FIXME: We need a better API for retrieving frames that abstracts + // away this concern. + frame = V8Proxy::retrieveFrameForEnteredContext(); + } + return frame; +} + +Frame* State<V8Binding>::getFirstFrame() +{ + return V8Proxy::retrieveFrameForEnteredContext(); +} + void State<V8Binding>::immediatelyReportUnsafeAccessTo(Frame* target) { V8Proxy::reportUnsafeAccessTo(target, V8Proxy::ReportNow); } +bool State<V8Binding>::processingUserGesture() +{ + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); + return frame && frame->script()->processingUserGesture(); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/specialization/V8BindingState.h b/WebCore/bindings/v8/specialization/V8BindingState.h index f305c14..baba0c6 100644 --- a/WebCore/bindings/v8/specialization/V8BindingState.h +++ b/WebCore/bindings/v8/specialization/V8BindingState.h @@ -1,10 +1,10 @@ /* * 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 @@ -14,7 +14,7 @@ * * 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 @@ -36,6 +36,8 @@ namespace WebCore { +class Frame; + // Singleton implementation of State<V8Binding>. Uses V8's global data // structures to return information about relevant execution state. template <> @@ -44,11 +46,19 @@ public: // Singleton static State* Only(); + // Reports an error message (without delay) if the security check fails. + static void immediatelyReportUnsafeAccessTo(Frame*); + // The DOMWindow corresponding to the 'calling context' of execution. DOMWindow* getActiveWindow(); - // Reports an error message (without delay) if the security check fails. - static void immediatelyReportUnsafeAccessTo(Frame*); + // The frame corresponding to the 'calling context' of execution. + Frame* getActiveFrame(); + + // The first frame in which execution entered user script. + Frame* getFirstFrame(); + + bool processingUserGesture(); private: explicit State() {} |