diff options
Diffstat (limited to 'WebCore/bindings/v8')
30 files changed, 554 insertions, 743 deletions
diff --git a/WebCore/bindings/v8/DOMDataStore.cpp b/WebCore/bindings/v8/DOMDataStore.cpp index 0b06a69..0d37dc0 100644 --- a/WebCore/bindings/v8/DOMDataStore.cpp +++ b/WebCore/bindings/v8/DOMDataStore.cpp @@ -88,7 +88,6 @@ DOMDataStore::DOMDataStore(DOMData* domData) , m_activeDomObjectMap(0) #if ENABLE(SVG) , m_domSvgElementInstanceMap(0) - , m_domSvgObjectWithContextMap(0) #endif , m_domData(domData) { @@ -126,8 +125,6 @@ void* DOMDataStore::getDOMWrapperMap(DOMWrapperMapType type) #if ENABLE(SVG) case DOMSVGElementInstanceMap: return m_domSvgElementInstanceMap; - case DOMSVGObjectWithContextMap: - return m_domSvgObjectWithContextMap; #endif } @@ -197,13 +194,6 @@ void DOMDataStore::weakSVGElementInstanceCallback(v8::Persistent<v8::Value> v8Ob DOMData::handleWeakObject(DOMDataStore::DOMSVGElementInstanceMap, v8::Persistent<v8::Object>::Cast(v8Object), static_cast<SVGElementInstance*>(domObject)); } -void DOMDataStore::weakSVGObjectWithContextCallback(v8::Persistent<v8::Value> v8Object, void* domObject) -{ - v8::HandleScope scope; - ASSERT(v8Object->IsObject()); - DOMData::handleWeakObject(DOMDataStore::DOMSVGObjectWithContextMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject); -} - #endif // ENABLE(SVG) } // namespace WebCore diff --git a/WebCore/bindings/v8/DOMDataStore.h b/WebCore/bindings/v8/DOMDataStore.h index c39a0ed..3758e23 100644 --- a/WebCore/bindings/v8/DOMDataStore.h +++ b/WebCore/bindings/v8/DOMDataStore.h @@ -156,8 +156,7 @@ namespace WebCore { DOMObjectMap, ActiveDOMObjectMap, #if ENABLE(SVG) - DOMSVGElementInstanceMap, - DOMSVGObjectWithContextMap + DOMSVGElementInstanceMap #endif }; @@ -251,7 +250,6 @@ namespace WebCore { DOMWrapperMap<void>& activeDomObjectMap() { return *m_activeDomObjectMap; } #if ENABLE(SVG) DOMWrapperMap<SVGElementInstance>& domSvgElementInstanceMap() { return *m_domSvgElementInstanceMap; } - DOMWrapperMap<void>& domSvgObjectWithContextMap() { return *m_domSvgObjectWithContextMap; } #endif // Need by V8GCController. @@ -262,8 +260,6 @@ namespace WebCore { static void weakDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject); #if ENABLE(SVG) static void weakSVGElementInstanceCallback(v8::Persistent<v8::Value> v8Object, void* domObject); - // SVG non-node elements may have a reference to a context node which should be notified when the element is change. - static void weakSVGObjectWithContextCallback(v8::Persistent<v8::Value> v8Object, void* domObject); #endif DOMNodeMapping* m_domNodeMap; @@ -271,7 +267,6 @@ namespace WebCore { DOMWrapperMap<void>* m_activeDomObjectMap; #if ENABLE(SVG) DOMWrapperMap<SVGElementInstance>* m_domSvgElementInstanceMap; - DOMWrapperMap<void>* m_domSvgObjectWithContextMap; #endif private: diff --git a/WebCore/bindings/v8/IDBBindingUtilities.cpp b/WebCore/bindings/v8/IDBBindingUtilities.cpp index 123b15c..644e2d2 100644 --- a/WebCore/bindings/v8/IDBBindingUtilities.cpp +++ b/WebCore/bindings/v8/IDBBindingUtilities.cpp @@ -45,7 +45,8 @@ PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value) return IDBKey::create(value->Int32Value()); if (value->IsString()) return IDBKey::create(v8ValueToWebCoreString(value)); - // FIXME: Implement dates. + if (value->IsDate()) + return 0; // Signals type error. FIXME: Implement dates. return 0; // Signals type error. } diff --git a/WebCore/bindings/v8/OptionsObject.cpp b/WebCore/bindings/v8/OptionsObject.cpp new file mode 100644 index 0000000..ce9189a --- /dev/null +++ b/WebCore/bindings/v8/OptionsObject.cpp @@ -0,0 +1,156 @@ +/* + * 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: + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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 "OptionsObject.h" + +#include "DOMStringList.h" +#include "V8Binding.h" +#include <limits> + +#if ENABLE(INDEXED_DATABASE) +#include "IDBKeyRange.h" +#include "V8IDBKeyRange.h" +#endif + +namespace WebCore { + +OptionsObject::OptionsObject() +{ +} + +OptionsObject::OptionsObject(const v8::Local<v8::Value>& options) + : m_options(options) +{ +} + +OptionsObject::~OptionsObject() +{ +} + +OptionsObject& OptionsObject::operator=(const OptionsObject& optionsObject) +{ + m_options = optionsObject.m_options; + return *this; +} + +bool OptionsObject::isUndefinedOrNull() const +{ + if (m_options.IsEmpty()) + return true; + return WebCore::isUndefinedOrNull(m_options); +} + +bool OptionsObject::getKeyBool(const String& key, bool& value) const +{ + v8::Local<v8::Value> v8Value; + if (!getKey(key, v8Value)) + return false; + + v8::Local<v8::Boolean> v8Bool = v8Value->ToBoolean(); + if (v8Bool.IsEmpty()) + return false; + value = v8Bool->Value(); + return true; +} + +bool OptionsObject::getKeyInt32(const String& key, int32_t& value) const +{ + v8::Local<v8::Value> v8Value; + if (!getKey(key, v8Value)) + return false; + + v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32(); + if (v8Int32.IsEmpty()) + return false; + value = v8Int32->Value(); + return true; +} + +bool OptionsObject::getKeyString(const String& key, String& value) const +{ + v8::Local<v8::Value> v8Value; + if (!getKey(key, v8Value)) + return false; + + // FIXME: It is possible for this to throw in which case we'd be getting back + // an empty string and returning true when we should be returning false. + // See fast/dom/Geolocation/script-tests/argument-types.js for a similar + // example. + value = v8ValueToWebCoreString(v8Value); + return true; +} + +PassRefPtr<DOMStringList> OptionsObject::getKeyDOMStringList(const String& key) const +{ + v8::Local<v8::Value> v8Value; + if (!getKey(key, v8Value)) + return 0; + + if (!v8Value->IsArray()) + return 0; + + RefPtr<DOMStringList> ret = DOMStringList::create(); + v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); + for (size_t i = 0; i < v8Array->Length(); ++i) { + v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(i)); + ret->append(v8ValueToWebCoreString(indexedValue)); + } + return ret.release(); +} + +#if ENABLE(INDEXED_DATABASE) + +PassRefPtr<IDBKeyRange> OptionsObject::getKeyKeyRange(const String& key) const +{ + v8::Local<v8::Value> v8Value; + if (!getKey(key, v8Value)) + return 0; + + if (!V8IDBKeyRange::HasInstance(v8Value)) + return 0; + + return V8IDBKeyRange::toNative(v8::Handle<v8::Object>::Cast(v8Value)); +} + +#endif + +bool OptionsObject::getKey(const String& key, v8::Local<v8::Value>& value) const +{ + if (isUndefinedOrNull()) + return false; + v8::Local<v8::Object> options = m_options->ToObject(); + ASSERT(!options.IsEmpty()); + + v8::Handle<v8::String> v8Key = v8String(key); + if (!options->Has(v8Key)) + return false; + value = options->Get(v8Key); + if (value.IsEmpty()) + return false; + return !value->IsUndefined(); // FIXME: Is the undefined check necessary? +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/OptionsObject.h b/WebCore/bindings/v8/OptionsObject.h new file mode 100644 index 0000000..b006927 --- /dev/null +++ b/WebCore/bindings/v8/OptionsObject.h @@ -0,0 +1,65 @@ +/* + * 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: + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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 OptionsObject_h +#define OptionsObject_h + +#include "PlatformString.h" +#include <v8.h> + +namespace WebCore { + +class DOMStringList; +class IDBKeyRange; + +class OptionsObject { +public: + OptionsObject(); + OptionsObject(const v8::Local<v8::Value>& options); + ~OptionsObject(); + + OptionsObject& operator=(const OptionsObject&); + + bool isUndefinedOrNull() const; + bool getKeyBool(const String& key, bool& value) const; + bool getKeyInt32(const String& key, int32_t& value) const; + bool getKeyString(const String& key, String& value) const; + PassRefPtr<DOMStringList> getKeyDOMStringList(const String& key) const; + PassRefPtr<IDBKeyRange> getKeyKeyRange(const String& key) const; + +private: + bool getKey(const String& key, v8::Local<v8::Value>&) const; + + // This object can only be used safely when stack allocated because of v8::Local. + static void* operator new(size_t); + static void* operator new[](size_t); + static void operator delete(void *); + + v8::Local<v8::Value> m_options; +}; + +} + +#endif // OptionsObject_h diff --git a/WebCore/bindings/v8/ScopedDOMDataStore.cpp b/WebCore/bindings/v8/ScopedDOMDataStore.cpp index df4a63a..60a6c67 100644 --- a/WebCore/bindings/v8/ScopedDOMDataStore.cpp +++ b/WebCore/bindings/v8/ScopedDOMDataStore.cpp @@ -41,7 +41,6 @@ ScopedDOMDataStore::ScopedDOMDataStore(DOMData* domData) m_activeDomObjectMap = new DOMWrapperMap<void>(&DOMDataStore::weakActiveDOMObjectCallback); #if ENABLE(SVG) m_domSvgElementInstanceMap = new DOMWrapperMap<SVGElementInstance>(&DOMDataStore::weakSVGElementInstanceCallback); - m_domSvgObjectWithContextMap = new DOMWrapperMap<void>(&DOMDataStore::weakSVGObjectWithContextCallback); #endif } @@ -52,7 +51,6 @@ ScopedDOMDataStore::~ScopedDOMDataStore() delete m_activeDomObjectMap; #if ENABLE(SVG) delete m_domSvgElementInstanceMap; - delete m_domSvgObjectWithContextMap; #endif } diff --git a/WebCore/bindings/v8/ScriptCallStackFactory.cpp b/WebCore/bindings/v8/ScriptCallStackFactory.cpp index 62fbeef..5d4e146 100644 --- a/WebCore/bindings/v8/ScriptCallStackFactory.cpp +++ b/WebCore/bindings/v8/ScriptCallStackFactory.cpp @@ -78,17 +78,17 @@ static void toScriptCallFramesVector(v8::Local<v8::Context> context, v8::Handle< } } -PassOwnPtr<ScriptCallStack> createScriptCallStack(v8::Local<v8::Context> context, v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize) +PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Local<v8::Context> context, v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize) { v8::HandleScope scope; v8::Context::Scope contextScope(context); Vector<ScriptCallFrame> scriptCallFrames; toScriptCallFramesVector(context, stackTrace, scriptCallFrames, maxStackSize); - return new ScriptCallStack(scriptCallFrames); + return ScriptCallStack::create(scriptCallFrames); } -PassOwnPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize) +PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize) { v8::HandleScope scope; v8::Local<v8::Context> context = v8::Context::GetCurrent(); @@ -98,7 +98,7 @@ PassOwnPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize) return createScriptCallStack(context, stackTrace, maxStackSize); } -PassOwnPtr<ScriptArguments> createScriptArguments(const v8::Arguments& v8arguments, unsigned skipArgumentCount) +PassRefPtr<ScriptArguments> createScriptArguments(const v8::Arguments& v8arguments, unsigned skipArgumentCount) { v8::HandleScope scope; v8::Local<v8::Context> context = v8::Context::GetCurrent(); @@ -108,7 +108,7 @@ PassOwnPtr<ScriptArguments> createScriptArguments(const v8::Arguments& v8argumen for (int i = skipArgumentCount; i < v8arguments.Length(); ++i) arguments.append(ScriptValue(v8arguments[i])); - return new ScriptArguments(state, arguments); + return ScriptArguments::create(state, arguments); } bool ScriptCallStack::stackTrace(int frameLimit, const RefPtr<InspectorArray>& stackTrace) diff --git a/WebCore/bindings/v8/ScriptCallStackFactory.h b/WebCore/bindings/v8/ScriptCallStackFactory.h index 613af7b..66e44f5 100644 --- a/WebCore/bindings/v8/ScriptCallStackFactory.h +++ b/WebCore/bindings/v8/ScriptCallStackFactory.h @@ -32,10 +32,12 @@ #define ScriptCallStackFactory_h #include <v8.h> -#include <wtf/PassOwnPtr.h> +#include <wtf/Forward.h> namespace WebCore { +class ScriptArguments; +class ScriptCallStack; class ScriptState; const v8::StackTrace::StackTraceOptions stackTraceOptions = static_cast<v8::StackTrace::StackTraceOptions>( @@ -44,12 +46,9 @@ const v8::StackTrace::StackTraceOptions stackTraceOptions = static_cast<v8::Stac | v8::StackTrace::kScriptNameOrSourceURL | v8::StackTrace::kFunctionName); -class ScriptArguments; -class ScriptCallStack; - -PassOwnPtr<ScriptCallStack> createScriptCallStack(v8::Local<v8::Context>, v8::Handle<v8::StackTrace>, size_t maxStackSize); -PassOwnPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize); -PassOwnPtr<ScriptArguments> createScriptArguments(const v8::Arguments& v8arguments, unsigned skipArgumentCount); +PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Local<v8::Context>, v8::Handle<v8::StackTrace>, size_t maxStackSize); +PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize); +PassRefPtr<ScriptArguments> createScriptArguments(const v8::Arguments& v8arguments, unsigned skipArgumentCount); } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptHeapSnapshot.cpp b/WebCore/bindings/v8/ScriptHeapSnapshot.cpp index 885d039..c35d508 100644 --- a/WebCore/bindings/v8/ScriptHeapSnapshot.cpp +++ b/WebCore/bindings/v8/ScriptHeapSnapshot.cpp @@ -33,6 +33,7 @@ #include "InspectorValues.h" #include "V8Binding.h" +#include <v8.h> #include <v8-profiler.h> #include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> @@ -50,50 +51,29 @@ unsigned int ScriptHeapSnapshot::uid() const return m_snapshot->GetUid(); } -static PassRefPtr<InspectorObject> buildInspectorObjectFor(const v8::HeapGraphNode* root) -{ - v8::HandleScope scope; - RefPtr<InspectorObject> result = InspectorObject::create(); - RefPtr<InspectorObject> lowLevels = InspectorObject::create(); - RefPtr<InspectorObject> entries = InspectorObject::create(); - RefPtr<InspectorObject> children = InspectorObject::create(); - for (int i = 0, count = root->GetChildrenCount(); i < count; ++i) { - const v8::HeapGraphNode* node = root->GetChild(i)->GetToNode(); - if (node->GetType() == v8::HeapGraphNode::kInternal) { - RefPtr<InspectorObject> lowLevel = InspectorObject::create(); - lowLevel->setNumber("count", node->GetInstancesCount()); - lowLevel->setNumber("size", node->GetSelfSize()); - lowLevel->setString("type", toWebCoreString(node->GetName())); - lowLevels->setObject(toWebCoreString(node->GetName()), lowLevel); - } else if (node->GetInstancesCount()) { - RefPtr<InspectorObject> entry = InspectorObject::create(); - entry->setString("constructorName", toWebCoreString(node->GetName())); - entry->setNumber("count", node->GetInstancesCount()); - entry->setNumber("size", node->GetSelfSize()); - entries->setObject(toWebCoreString(node->GetName()), entry); - } else { - RefPtr<InspectorObject> entry = InspectorObject::create(); - entry->setString("constructorName", toWebCoreString(node->GetName())); - for (int j = 0, count = node->GetChildrenCount(); j < count; ++j) { - const v8::HeapGraphEdge* v8Edge = node->GetChild(j); - const v8::HeapGraphNode* v8Child = v8Edge->GetToNode(); - RefPtr<InspectorObject> child = InspectorObject::create(); - child->setString("constructorName", toWebCoreString(v8Child->GetName())); - child->setNumber("count", v8Edge->GetName()->ToInteger()->Value()); - entry->setObject(String::number(reinterpret_cast<unsigned long long>(v8Child)), child); - } - children->setObject(String::number(reinterpret_cast<unsigned long long>(node)), entry); - } +namespace { + +class OutputStreamAdapter : public v8::OutputStream { +public: + OutputStreamAdapter(ScriptHeapSnapshot::OutputStream* output) + : m_output(output) { } + void EndOfStream() { m_output->Close(); } + int GetChunkSize() { return 10240; } + WriteResult WriteAsciiChunk(char* data, int size) + { + m_output->Write(String(data, size)); + return kContinue; } - result->setObject("lowlevels", lowLevels); - result->setObject("entries", entries); - result->setObject("children", children); - return result.release(); -} +private: + ScriptHeapSnapshot::OutputStream* m_output; +}; + +} // namespace -PassRefPtr<InspectorObject> ScriptHeapSnapshot::buildInspectorObjectForHead() const +void ScriptHeapSnapshot::writeJSON(ScriptHeapSnapshot::OutputStream* stream) { - return buildInspectorObjectFor(m_snapshot->GetRoot()); + OutputStreamAdapter outputStream(stream); + m_snapshot->Serialize(&outputStream, v8::HeapSnapshot::kJSON); } } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptHeapSnapshot.h b/WebCore/bindings/v8/ScriptHeapSnapshot.h index 794a5a9..d3ae022 100644 --- a/WebCore/bindings/v8/ScriptHeapSnapshot.h +++ b/WebCore/bindings/v8/ScriptHeapSnapshot.h @@ -43,6 +43,13 @@ class InspectorObject; class ScriptHeapSnapshot : public RefCounted<ScriptHeapSnapshot> { public: + class OutputStream { + public: + virtual ~OutputStream() { } + virtual void Write(const String& chunk) = 0; + virtual void Close() = 0; + }; + static PassRefPtr<ScriptHeapSnapshot> create(const v8::HeapSnapshot* snapshot) { return adoptRef(new ScriptHeapSnapshot(snapshot)); @@ -51,8 +58,7 @@ public: String title() const; unsigned int uid() const; - - PassRefPtr<InspectorObject> buildInspectorObjectForHead() const; + void writeJSON(OutputStream* stream); private: ScriptHeapSnapshot(const v8::HeapSnapshot* snapshot) diff --git a/WebCore/bindings/v8/ScriptValue.h b/WebCore/bindings/v8/ScriptValue.h index 1743da0..d412901 100644 --- a/WebCore/bindings/v8/ScriptValue.h +++ b/WebCore/bindings/v8/ScriptValue.h @@ -100,6 +100,11 @@ public: return m_value == value.m_value; } + bool isFunction() const + { + return m_value->IsFunction(); + } + bool operator!=(const ScriptValue value) const { return !operator==(value); diff --git a/WebCore/bindings/v8/StaticDOMDataStore.cpp b/WebCore/bindings/v8/StaticDOMDataStore.cpp index 0b0d531..b4c36b9 100644 --- a/WebCore/bindings/v8/StaticDOMDataStore.cpp +++ b/WebCore/bindings/v8/StaticDOMDataStore.cpp @@ -40,7 +40,6 @@ StaticDOMDataStore::StaticDOMDataStore(DOMData* domData) , m_staticActiveDomObjectMap(&DOMDataStore::weakActiveDOMObjectCallback) #if ENABLE(SVG) , m_staticDomSvgElementInstanceMap(&DOMDataStore::weakSVGElementInstanceCallback) - , m_staticDomSvgObjectWithContextMap(&DOMDataStore::weakSVGObjectWithContextCallback) #endif { m_domNodeMap = &m_staticDomNodeMap; @@ -48,7 +47,6 @@ StaticDOMDataStore::StaticDOMDataStore(DOMData* domData) m_activeDomObjectMap = &m_staticActiveDomObjectMap; #if ENABLE(SVG) m_domSvgElementInstanceMap = &m_staticDomSvgElementInstanceMap; - m_domSvgObjectWithContextMap = &m_staticDomSvgObjectWithContextMap; #endif } diff --git a/WebCore/bindings/v8/StaticDOMDataStore.h b/WebCore/bindings/v8/StaticDOMDataStore.h index d1e5a30..fb6aa42 100644 --- a/WebCore/bindings/v8/StaticDOMDataStore.h +++ b/WebCore/bindings/v8/StaticDOMDataStore.h @@ -53,7 +53,6 @@ private: DOMWrapperMap<void> m_staticActiveDomObjectMap; #if ENABLE(SVG) DOMWrapperMap<SVGElementInstance> m_staticDomSvgElementInstanceMap; - DOMWrapperMap<void> m_staticDomSvgObjectWithContextMap; #endif }; diff --git a/WebCore/bindings/v8/V8Binding.cpp b/WebCore/bindings/v8/V8Binding.cpp index d0bf0ca..52b23bd 100644 --- a/WebCore/bindings/v8/V8Binding.cpp +++ b/WebCore/bindings/v8/V8Binding.cpp @@ -368,7 +368,8 @@ StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode template String v8StringToWebCoreString<String>(v8::Handle<v8::String>, ExternalMode); template AtomicString v8StringToWebCoreString<AtomicString>(v8::Handle<v8::String>, ExternalMode); -String int32ToWebCoreString(int value) +// Fast but non thread-safe version. +String int32ToWebCoreStringFast(int value) { // Caching of small strings below is not thread safe: newly constructed AtomicString // are not safely published. @@ -390,6 +391,14 @@ String int32ToWebCoreString(int value) return webCoreString; } +String int32ToWebCoreString(int value) +{ + // If we are on the main thread (this should always true for non-workers), call the faster one. + if (WTF::isMainThread()) + return int32ToWebCoreStringFast(value); + return String::number(value); +} + String v8NonStringValueToWebCoreString(v8::Handle<v8::Value> object) { ASSERT(!object->IsString()); diff --git a/WebCore/bindings/v8/V8ConsoleMessage.cpp b/WebCore/bindings/v8/V8ConsoleMessage.cpp index 40f9a7a..9e6e267 100644 --- a/WebCore/bindings/v8/V8ConsoleMessage.cpp +++ b/WebCore/bindings/v8/V8ConsoleMessage.cpp @@ -114,7 +114,7 @@ void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::V String errorMessage = toWebCoreString(errorMessageString); v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); - OwnPtr<ScriptCallStack> callStack; + RefPtr<ScriptCallStack> callStack; // Currently stack trace is only collected when inspector is open. if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) { v8::Local<v8::Context> context = v8::Context::GetEntered(); @@ -125,10 +125,10 @@ void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::V bool useURL = resourceName.IsEmpty() || !resourceName->IsString(); String resourceNameString = useURL ? frame->document()->url() : toWebCoreString(resourceName); V8ConsoleMessage consoleMessage(errorMessage, resourceNameString, message->GetLineNumber()); - consoleMessage.dispatchNow(page, callStack.release()); + consoleMessage.dispatchNow(page, callStack); } -void V8ConsoleMessage::dispatchNow(Page* page, PassOwnPtr<ScriptCallStack> callStack) +void V8ConsoleMessage::dispatchNow(Page* page, PassRefPtr<ScriptCallStack> callStack) { ASSERT(page); diff --git a/WebCore/bindings/v8/V8ConsoleMessage.h b/WebCore/bindings/v8/V8ConsoleMessage.h index 6b892dd..97de24f 100644 --- a/WebCore/bindings/v8/V8ConsoleMessage.h +++ b/WebCore/bindings/v8/V8ConsoleMessage.h @@ -82,7 +82,7 @@ namespace WebCore { const String m_sourceID; const unsigned m_lineNumber; - void dispatchNow(Page*, PassOwnPtr<ScriptCallStack>); + void dispatchNow(Page*, PassRefPtr<ScriptCallStack>); // All delayed messages are stored in this vector. If the vector // is 0, there are no delayed messages. diff --git a/WebCore/bindings/v8/V8DOMMap.cpp b/WebCore/bindings/v8/V8DOMMap.cpp index b478d06..e1ac2c6 100644 --- a/WebCore/bindings/v8/V8DOMMap.cpp +++ b/WebCore/bindings/v8/V8DOMMap.cpp @@ -86,12 +86,6 @@ DOMWrapperMap<SVGElementInstance>& getDOMSVGElementInstanceMap() return getDOMDataStore().domSvgElementInstanceMap(); } -// Map of SVG objects with contexts to V8 objects -DOMWrapperMap<void>& getDOMSVGObjectWithContextMap() -{ - return getDOMDataStore().domSvgObjectWithContextMap(); -} - #endif // ENABLE(SVG) void removeAllDOMObjectsInCurrentThread() @@ -106,9 +100,6 @@ void removeAllDOMObjectsInCurrentThread() #if ENABLE(SVG) // Remove all SVG element instances in the wrapper map. DOMData::removeObjectsFromWrapperMap<SVGElementInstance>(getDOMSVGElementInstanceMap()); - - // Remove all SVG objects with context in the wrapper map. - DOMData::removeObjectsFromWrapperMap<void>(getDOMSVGObjectWithContextMap()); #endif } @@ -181,21 +172,6 @@ void visitDOMSVGElementInstancesInCurrentThread(DOMWrapperMap<SVGElementInstance } } -void visitSVGObjectsInCurrentThread(DOMWrapperMap<void>::Visitor* visitor) -{ - v8::HandleScope scope; - - WTF::MutexLocker locker(DOMDataStore::allStoresMutex()); - DOMDataList& list = DOMDataStore::allStores(); - for (size_t i = 0; i < list.size(); ++i) { - DOMDataStore* store = list[i]; - if (!store->domData()->owningThread() == WTF::currentThread()) - continue; - - store->domSvgObjectWithContextMap().visit(visitor); - } -} - #endif } // namespace WebCore diff --git a/WebCore/bindings/v8/V8DOMMap.h b/WebCore/bindings/v8/V8DOMMap.h index d8d5c04..b50bc99 100644 --- a/WebCore/bindings/v8/V8DOMMap.h +++ b/WebCore/bindings/v8/V8DOMMap.h @@ -170,10 +170,6 @@ namespace WebCore { // A map for SVGElementInstances to its JS wrapper. DOMWrapperMap<SVGElementInstance>& getDOMSVGElementInstanceMap(); void visitSVGElementInstancesInCurrentThread(DOMWrapperMap<SVGElementInstance>::Visitor*); - - // Map of SVG objects with contexts to V8 objects. - DOMWrapperMap<void>& getDOMSVGObjectWithContextMap(); - void visitDOMSVGObjectsInCurrentThread(DOMWrapperMap<void>::Visitor*); #endif void enableFasterDOMStoreAccess(); diff --git a/WebCore/bindings/v8/V8NPUtils.cpp b/WebCore/bindings/v8/V8NPUtils.cpp index 8fa19d7..65c30a0 100644 --- a/WebCore/bindings/v8/V8NPUtils.cpp +++ b/WebCore/bindings/v8/V8NPUtils.cpp @@ -53,9 +53,7 @@ void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NP if (object.IsEmpty()) return; - if (object->IsInt32()) - INT32_TO_NPVARIANT(object->NumberValue(), *result); - else if (object->IsNumber()) + if (object->IsNumber()) DOUBLE_TO_NPVARIANT(object->NumberValue(), *result); else if (object->IsBoolean()) BOOLEAN_TO_NPVARIANT(object->BooleanValue(), *result); diff --git a/WebCore/bindings/v8/V8Proxy.cpp b/WebCore/bindings/v8/V8Proxy.cpp index 8dc1487..df3670d 100644 --- a/WebCore/bindings/v8/V8Proxy.cpp +++ b/WebCore/bindings/v8/V8Proxy.cpp @@ -43,7 +43,6 @@ #include "Page.h" #include "PageGroup.h" #include "PlatformBridge.h" -#include "SVGElement.h" #include "ScriptController.h" #include "Settings.h" #include "StorageNamespace.h" @@ -131,42 +130,6 @@ void batchConfigureConstants(v8::Handle<v8::FunctionTemplate> functionDescriptor typedef HashMap<Node*, v8::Object*> DOMNodeMap; typedef HashMap<void*, v8::Object*> DOMObjectMap; - -#if ENABLE(SVG) -// Map of SVG objects with contexts to their contexts -static HashMap<void*, SVGElement*>& svgObjectToContextMap() -{ - typedef HashMap<void*, SVGElement*> SvgObjectToContextMap; - DEFINE_STATIC_LOCAL(SvgObjectToContextMap, staticSvgObjectToContextMap, ()); - return staticSvgObjectToContextMap; -} - -void V8Proxy::setSVGContext(void* object, SVGElement* context) -{ - if (!object) - return; - - SVGElement* oldContext = svgObjectToContextMap().get(object); - - if (oldContext == context) - return; - - if (oldContext) - oldContext->deref(); - - if (context) - context->ref(); - - svgObjectToContextMap().set(object, context); -} - -SVGElement* V8Proxy::svgContext(void* object) -{ - return svgObjectToContextMap().get(object); -} - -#endif - typedef HashMap<int, v8::FunctionTemplate*> FunctionTemplateMap; bool AllowAllocation::m_current = false; diff --git a/WebCore/bindings/v8/V8Proxy.h b/WebCore/bindings/v8/V8Proxy.h index 6f09dae..34e80e1 100644 --- a/WebCore/bindings/v8/V8Proxy.h +++ b/WebCore/bindings/v8/V8Proxy.h @@ -58,7 +58,6 @@ namespace WebCore { class DOMWindow; class Frame; class Node; - class SVGElement; class ScriptExecutionContext; class V8EventListener; class V8IsolatedContext; @@ -159,40 +158,6 @@ namespace WebCore { // and clears all timeouts on the DOM window. void disconnectFrame(); -#if ENABLE(SVG) - static void setSVGContext(void*, SVGElement*); - static SVGElement* svgContext(void*); - - // These helper functions are required in case we are given a PassRefPtr - // to a (possibly) newly created object and must prevent its reference - // count from dropping to zero as would happen in code like - // - // V8Proxy::setSVGContext(imp->getNewlyCreatedObject().get(), context); - // foo(imp->getNewlyCreatedObject().get()); - // - // In the above two lines each time getNewlyCreatedObject() is called it - // creates a new object because we don't ref() it. (So our attemts to - // associate a context with it fail.) Such code should be rewritten to - // - // foo(V8Proxy::withSVGContext(imp->getNewlyCreatedObject(), context).get()); - // - // where PassRefPtr::~PassRefPtr() is invoked only after foo() is - // called. - template <typename T> - static PassRefPtr<T> withSVGContext(PassRefPtr<T> object, SVGElement* context) - { - setSVGContext(object.get(), context); - return object; - } - - template <typename T> - static T* withSVGContext(T* object, SVGElement* context) - { - setSVGContext(object, context); - return object; - } -#endif - void finishedWithEvent(Event*) { } // Evaluate JavaScript in a new isolated world. The script gets its own diff --git a/WebCore/bindings/v8/V8SVGPODTypeWrapper.h b/WebCore/bindings/v8/V8SVGPODTypeWrapper.h deleted file mode 100644 index c044a06..0000000 --- a/WebCore/bindings/v8/V8SVGPODTypeWrapper.h +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> - * Copyright (C) 2008 Apple Inc. All rights reserved. - * Copyright (C) 2008, 2009 Google. 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. - * - * 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 - * (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 V8SVGPODTypeWrapper_h -#define V8SVGPODTypeWrapper_h - -#if ENABLE(SVG) - -#include <utility> - -#include "SVGElement.h" -#include "SVGList.h" -#include "V8Proxy.h" - -#include <wtf/Assertions.h> -#include <wtf/HashFunctions.h> -#include <wtf/HashMap.h> -#include <wtf/RefCounted.h> -#include <wtf/StdLibExtras.h> - -namespace WebCore { - -template<typename PODType> -class V8SVGPODTypeWrapper : public RefCounted<V8SVGPODTypeWrapper<PODType> > { -public: - V8SVGPODTypeWrapper() { } - virtual ~V8SVGPODTypeWrapper() { } - virtual operator PODType() = 0; - virtual void commitChange(PODType, SVGElement*) = 0; - - static V8SVGPODTypeWrapper<PODType>* toNative(v8::Handle<v8::Object> object) - { - return reinterpret_cast<V8SVGPODTypeWrapper<PODType>*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); - } -}; - -template<typename PODType> -class V8SVGPODTypeWrapperCreatorForList : public V8SVGPODTypeWrapper<PODType> { -public: - typedef SVGPODListItem<PODType> PODListItemPtrType; - - typedef PODType (SVGPODListItem<PODType>::*GetterMethod)() const; - typedef void (SVGPODListItem<PODType>::*SetterMethod)(const PODType&); - - static PassRefPtr<V8SVGPODTypeWrapperCreatorForList> create(PassRefPtr<PODListItemPtrType> creator, const QualifiedName& attributeName) - { - return adoptRef(new V8SVGPODTypeWrapperCreatorForList(creator, attributeName)); - } - - virtual ~V8SVGPODTypeWrapperCreatorForList() { } - - // Getter wrapper - virtual operator PODType() { return (m_creator.get()->*m_getter)(); } - - // Setter wrapper - virtual void commitChange(PODType type, SVGElement* context) - { - if (!m_setter) - return; - - (m_creator.get()->*m_setter)(type); - - if (context) - context->svgAttributeChanged(m_associatedAttributeName); - } - -private: - V8SVGPODTypeWrapperCreatorForList(PassRefPtr<PODListItemPtrType> creator, const QualifiedName& attributeName) - : m_creator(creator) - , m_getter(&SVGPODListItem<PODType>::value) - , m_setter(&SVGPODListItem<PODType>::setValue) - , m_associatedAttributeName(attributeName) - { - ASSERT(m_creator); - ASSERT(m_getter); - ASSERT(m_setter); - } - - // Update callbacks - RefPtr<SVGPODListItem<PODType> > m_creator; - GetterMethod m_getter; - SetterMethod m_setter; - const QualifiedName& m_associatedAttributeName; -}; - -template<typename PODType> -class V8SVGStaticPODTypeWrapper : public V8SVGPODTypeWrapper<PODType> { -public: - static PassRefPtr<V8SVGStaticPODTypeWrapper> create(PODType type) - { - return adoptRef(new V8SVGStaticPODTypeWrapper(type)); - } - - virtual ~V8SVGStaticPODTypeWrapper() { } - - // Getter wrapper - virtual operator PODType() { return m_podType; } - - // Setter wrapper - virtual void commitChange(PODType type, SVGElement*) - { - m_podType = type; - } - -protected: - V8SVGStaticPODTypeWrapper(PODType type) - : m_podType(type) - { - } - - PODType m_podType; -}; - -template<typename PODType, typename ParentTypeArg> -class V8SVGStaticPODTypeWrapperWithPODTypeParent : public V8SVGStaticPODTypeWrapper<PODType> { -public: - typedef V8SVGPODTypeWrapper<ParentTypeArg> ParentType; - - static PassRefPtr<V8SVGStaticPODTypeWrapperWithPODTypeParent> create(PODType type, PassRefPtr<ParentType> parent) - { - return adoptRef(new V8SVGStaticPODTypeWrapperWithPODTypeParent(type, parent)); - } - - virtual void commitChange(PODType type, SVGElement* context) - { - V8SVGStaticPODTypeWrapper<PODType>::commitChange(type, context); - m_parentType->commitChange(ParentTypeArg(type), context); - } - -private: - V8SVGStaticPODTypeWrapperWithPODTypeParent(PODType type, PassRefPtr<ParentType> parent) - : V8SVGStaticPODTypeWrapper<PODType>(type) - , m_parentType(parent) - { - } - - RefPtr<ParentType> m_parentType; -}; - -template<typename PODType, typename ParentType> -class V8SVGStaticPODTypeWrapperWithParent : public V8SVGPODTypeWrapper<PODType> { -public: - typedef PODType (ParentType::*GetterMethod)() const; - typedef void (ParentType::*SetterMethod)(const PODType&); - - static PassRefPtr<V8SVGStaticPODTypeWrapperWithParent> create(PassRefPtr<ParentType> parent, GetterMethod getter, SetterMethod setter) - { - return adoptRef(new V8SVGStaticPODTypeWrapperWithParent(parent, getter, setter)); - } - - virtual operator PODType() - { - return (m_parent.get()->*m_getter)(); - } - - virtual void commitChange(PODType type, SVGElement* context) - { - (m_parent.get()->*m_setter)(type); - } - -private: - V8SVGStaticPODTypeWrapperWithParent(PassRefPtr<ParentType> parent, GetterMethod getter, SetterMethod setter) - : m_parent(parent) - , m_getter(getter) - , m_setter(setter) - { - ASSERT(m_parent); - ASSERT(m_getter); - ASSERT(m_setter); - } - - RefPtr<ParentType> m_parent; - GetterMethod m_getter; - SetterMethod m_setter; -}; - -template<typename PODType, typename PODTypeCreator> -class V8SVGDynamicPODTypeWrapper : public V8SVGPODTypeWrapper<PODType> { -public: - typedef PODType (PODTypeCreator::*GetterMethod)() const; - typedef void (PODTypeCreator::*SetterMethod)(const PODType&); - typedef void (*CacheRemovalCallback)(V8SVGPODTypeWrapper<PODType>*); - - static PassRefPtr<V8SVGDynamicPODTypeWrapper> create(PassRefPtr<PODTypeCreator> creator, GetterMethod getter, SetterMethod setter, CacheRemovalCallback cacheRemovalCallback) - { - return adoptRef(new V8SVGDynamicPODTypeWrapper(creator, getter, setter, cacheRemovalCallback)); - } - - virtual ~V8SVGDynamicPODTypeWrapper() { - ASSERT(m_cacheRemovalCallback); - - (*m_cacheRemovalCallback)(this); - } - - // Getter wrapper - virtual operator PODType() { return (m_creator.get()->*m_getter)(); } - - // Setter wrapper - virtual void commitChange(PODType type, SVGElement* context) - { - (m_creator.get()->*m_setter)(type); - - if (context) - context->svgAttributeChanged(m_creator->associatedAttributeName()); - } - -private: - V8SVGDynamicPODTypeWrapper(PassRefPtr<PODTypeCreator> creator, GetterMethod getter, SetterMethod setter, CacheRemovalCallback cacheRemovalCallback) - : m_creator(creator) - , m_getter(getter) - , m_setter(setter) - , m_cacheRemovalCallback(cacheRemovalCallback) - { - ASSERT(m_creator); // |creator|'s pointer was taken by m_creator. - ASSERT(getter); - ASSERT(setter); - ASSERT(cacheRemovalCallback); - } - - // Update callbacks - RefPtr<PODTypeCreator> m_creator; - GetterMethod m_getter; - SetterMethod m_setter; - CacheRemovalCallback m_cacheRemovalCallback; -}; - -// Caching facilities -template<typename PODType, typename PODTypeCreator> -struct PODTypeWrapperCacheInfo { - typedef PODType (PODTypeCreator::*GetterMethod)() const; - typedef void (PODTypeCreator::*SetterMethod)(const PODType&); - - // Empty value - PODTypeWrapperCacheInfo() - : creator(0) - , getter(0) - , setter(0) - , fieldHash(0) - { } - - // Deleted value - explicit PODTypeWrapperCacheInfo(WTF::HashTableDeletedValueType) - : creator(reinterpret_cast<PODTypeCreator*>(-1)) - , getter(0) - , setter(0) - , fieldHash(0) - { - } - - bool isHashTableDeletedValue() const - { - return creator == reinterpret_cast<PODTypeCreator*>(-1); - } - - PODTypeWrapperCacheInfo(PODTypeCreator* _creator, GetterMethod _getter, SetterMethod _setter, unsigned _fieldHash) - : creator(_creator) - , getter(_getter) - , setter(_setter) - , fieldHash(_fieldHash) - { - ASSERT(creator); - ASSERT(getter); - } - - bool operator==(const PODTypeWrapperCacheInfo& other) const - { - return creator == other.creator && fieldHash == other.fieldHash && getter == other.getter && setter == other.setter; - } - - PODTypeCreator* creator; - GetterMethod getter; - SetterMethod setter; - unsigned fieldHash; -}; - -template<typename PODType, typename PODTypeCreator> -struct PODTypeWrapperCacheInfoHash { - static unsigned hash(const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& info) - { - // We can't hash member function pointers, but we have enough material - // to hash the pointer and field identifier, and on a collision - // operator== will still differentiate the member function pointers. - return WTF::PairHash<void*, unsigned>::hash(std::pair<void*, unsigned>(info.creator, info.fieldHash)); - } - - static bool equal(const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& a, const PODTypeWrapperCacheInfo<PODType, PODTypeCreator>& b) - { - return a == b; - } - - static const bool safeToCompareToEmptyOrDeleted = true; -}; - -template<typename PODType, typename PODTypeCreator> -struct PODTypeWrapperCacheInfoTraits : WTF::GenericHashTraits<PODTypeWrapperCacheInfo<PODType, PODTypeCreator> > { - typedef PODTypeWrapperCacheInfo<PODType, PODTypeCreator> CacheInfo; - - static const bool emptyValueIsZero = true; - static const bool needsDestruction = false; - - static const CacheInfo& emptyValue() - { - DEFINE_STATIC_LOCAL(CacheInfo, key, ()); - return key; - } - - static void constructDeletedValue(CacheInfo& slot) - { - new (&slot) CacheInfo(WTF::HashTableDeletedValue); - } - - static bool isDeletedValue(const CacheInfo& value) - { - return value.isHashTableDeletedValue(); - } -}; - -template<typename PODType, typename PODTypeCreator> -class V8SVGDynamicPODTypeWrapperCache { -public: - typedef PODType (PODTypeCreator::*GetterMethod)() const; - typedef void (PODTypeCreator::*SetterMethod)(const PODType&); - - typedef PODTypeWrapperCacheInfo<PODType, PODTypeCreator> CacheInfo; - typedef PODTypeWrapperCacheInfoHash<PODType, PODTypeCreator> CacheInfoHash; - typedef PODTypeWrapperCacheInfoTraits<PODType, PODTypeCreator> CacheInfoTraits; - - typedef V8SVGPODTypeWrapper<PODType> WrapperBase; - typedef V8SVGDynamicPODTypeWrapper<PODType, PODTypeCreator> DynamicWrapper; - - typedef HashMap<CacheInfo, DynamicWrapper*, CacheInfoHash, CacheInfoTraits> DynamicWrapperHashMap; - typedef typename DynamicWrapperHashMap::const_iterator DynamicWrapperHashMapIterator; - - static DynamicWrapperHashMap& dynamicWrapperHashMap() - { - DEFINE_STATIC_LOCAL(DynamicWrapperHashMap, dynamicWrapperHashMap, ()); - return dynamicWrapperHashMap; - } - - // Used for readwrite attributes only - static PassRefPtr<WrapperBase> lookupOrCreateWrapper(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter, unsigned fieldHash) - { - DynamicWrapperHashMap& map(dynamicWrapperHashMap()); - CacheInfo info(creator, getter, setter, fieldHash); - - if (map.contains(info)) - return map.get(info); - - RefPtr<DynamicWrapper> wrapper = V8SVGDynamicPODTypeWrapper<PODType, PODTypeCreator>::create(creator, getter, setter, forgetWrapper); - map.set(info, wrapper.get()); - return wrapper.release(); - } - - static void forgetWrapper(V8SVGPODTypeWrapper<PODType>* wrapper) - { - DynamicWrapperHashMap& map(dynamicWrapperHashMap()); - - DynamicWrapperHashMapIterator it = map.begin(); - DynamicWrapperHashMapIterator end = map.end(); - - for (; it != end; ++it) { - if (it->second != wrapper) - continue; - - // It's guaranteed that there's just one object we need to take care of. - map.remove(it->first); - break; - } - } -}; - -class V8SVGPODTypeUtil { -public: - template <class P> - static P toSVGPODType(WrapperTypeInfo* info, v8::Handle<v8::Value> object, bool& ok); -}; - -template <class P> -P V8SVGPODTypeUtil::toSVGPODType(WrapperTypeInfo* info, v8::Handle<v8::Value> object, bool& ok) -{ - if (!V8DOMWrapper::isWrapperOfType(object, info)) { - ok = false; - return P(); - } - ok = true; - return *V8SVGPODTypeWrapper<P>::toNative(v8::Handle<v8::Object>::Cast(object)); -} - -} // namespace WebCore - -#endif // ENABLE(SVG) -#endif // V8SVGPODTypeWrapper_h diff --git a/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp b/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp deleted file mode 100644 index 4671c61..0000000 --- a/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp +++ /dev/null @@ -1,95 +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(3D_CANVAS) || ENABLE(BLOB) -#include "V8ArrayBufferView.h" - -#include "V8Binding.h" -#include "V8Proxy.h" -#include "V8Int8Array.h" -#include "V8Float32Array.h" -#include "V8Int32Array.h" -#include "V8Int16Array.h" -#include "V8Uint8Array.h" -#include "V8Uint32Array.h" -#include "V8Uint16Array.h" - -namespace WebCore { - -v8::Handle<v8::Value> toV8(ArrayBufferView* impl) -{ - if (!impl) - return v8::Null(); - if (impl->isByteArray()) - return toV8(static_cast<Int8Array*>(impl)); - if (impl->isFloatArray()) - return toV8(static_cast<Float32Array*>(impl)); - if (impl->isIntArray()) - return toV8(static_cast<Int32Array*>(impl)); - if (impl->isShortArray()) - return toV8(static_cast<Int16Array*>(impl)); - if (impl->isUnsignedByteArray()) - return toV8(static_cast<Uint8Array*>(impl)); - if (impl->isUnsignedIntArray()) - return toV8(static_cast<Uint32Array*>(impl)); - if (impl->isUnsignedShortArray()) - return toV8(static_cast<Uint16Array*>(impl)); - return v8::Handle<v8::Value>(); -} - -v8::Handle<v8::Value> V8ArrayBufferView::sliceCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.ArrayBufferView.slice"); - // Forms: - // * slice(long start, long end); - - ArrayBufferView* imp = V8ArrayBufferView::toNative(args.Holder()); - int start, end; - switch (args.Length()) { - case 0: - start = 0; - end = imp->length(); - break; - case 1: - start = toInt32(args[0]); - end = imp->length(); - break; - default: - start = toInt32(args[0]); - end = toInt32(args[1]); - } - return toV8(imp->slice(start, end)); -} - -} // namespace WebCore - -#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h b/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h index 2566b67..6881a01 100644 --- a/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h +++ b/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h @@ -28,27 +28,64 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config.h" +#ifndef V8ArrayBufferViewCustom_h +#define V8ArrayBufferViewCustom_h #if ENABLE(3D_CANVAS) || ENABLE(BLOB) #include "ArrayBuffer.h" -#include "V8Binding.h" #include "V8ArrayBuffer.h" +#include "V8Binding.h" #include "V8Proxy.h" namespace WebCore { // Template function used by the ArrayBufferView*Constructor callbacks. template<class ArrayClass, class ElementType> +v8::Handle<v8::Value> constructWebGLArrayWithArrayBufferArgument(const v8::Arguments& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType, bool hasIndexer) +{ + ArrayBuffer* buf = V8ArrayBuffer::toNative(args[0]->ToObject()); + if (!buf) + return throwError("Could not convert argument 0 to a ArrayBuffer"); + bool ok; + uint32_t offset = 0; + int argLen = args.Length(); + if (argLen > 1) { + offset = toUInt32(args[1], ok); + if (!ok) + return throwError("Could not convert argument 1 to a number"); + } + if ((buf->byteLength() - offset) % sizeof(ElementType)) + return throwError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.", V8Proxy::RangeError); + uint32_t length = (buf->byteLength() - offset) / sizeof(ElementType); + if (argLen > 2) { + length = toUInt32(args[2], ok); + if (!ok) + return throwError("Could not convert argument 2 to a number"); + } + + RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); + if (!array) { + V8Proxy::setDOMException(INDEX_SIZE_ERR); + return notHandledByInterceptor(); + } + // Transform the holder into a wrapper object for the array. + V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); + if (hasIndexer) + args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length()); + return toV8(array.release(), args.Holder()); +} + +// Template function used by the ArrayBufferView*Constructor callbacks. +template<class ArrayClass, class ElementType> v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType) { if (!args.IsConstructCall()) return throwError("DOM object constructor cannot be called as a function."); int argLen = args.Length(); - if (argLen == 0) { + if (!argLen) { // This happens when we return a previously constructed // ArrayBufferView, e.g. from the call to <Type>Array.slice(). // The V8DOMWrapper will set the internal pointer in the @@ -83,36 +120,8 @@ v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, WrapperType } // See whether the first argument is a ArrayBuffer. - if (V8ArrayBuffer::HasInstance(args[0])) { - ArrayBuffer* buf = V8ArrayBuffer::toNative(args[0]->ToObject()); - if (!buf) - return throwError("Could not convert argument 0 to a ArrayBuffer"); - bool ok; - uint32_t offset = 0; - if (argLen > 1) { - offset = toUInt32(args[1], ok); - if (!ok) - return throwError("Could not convert argument 1 to a number"); - } - if ((buf->byteLength() - offset) % sizeof(ElementType)) - return throwError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.", V8Proxy::RangeError); - uint32_t length = (buf->byteLength() - offset) / sizeof(ElementType); - if (argLen > 2) { - length = toUInt32(args[2], ok); - if (!ok) - return throwError("Could not convert argument 2 to a number"); - } - - RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); - if (!array) { - V8Proxy::setDOMException(INDEX_SIZE_ERR); - return notHandledByInterceptor(); - } - // Transform the holder into a wrapper object for the array. - V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); - args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length()); - return toV8(array.release(), args.Holder()); - } + if (V8ArrayBuffer::HasInstance(args[0])) + return constructWebGLArrayWithArrayBufferArgument<ArrayClass, ElementType>(args, type, arrayType, true); uint32_t len = 0; v8::Handle<v8::Object> srcArray; @@ -201,3 +210,5 @@ v8::Handle<v8::Value> setWebGLArrayHelper(const v8::Arguments& args) } #endif // ENABLE(3D_CANVAS) + +#endif // V8ArrayBufferViewCustom_h diff --git a/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp index 9142ad7..e21354e 100644 --- a/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp @@ -65,9 +65,9 @@ v8::Handle<v8::Value> V8Console::traceCallback(const v8::Arguments& args) { INC_STATS("DOM.Console.traceCallback"); Console* imp = V8Console::toNative(args.Holder()); - OwnPtr<ScriptCallStack> callStack(createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture)); - OwnPtr<ScriptArguments> scriptArguments(createScriptArguments(args, 0)); - imp->trace(scriptArguments.release(), callStack.release()); + RefPtr<ScriptCallStack> callStack(createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture)); + RefPtr<ScriptArguments> scriptArguments(createScriptArguments(args, 0)); + imp->trace(scriptArguments.release(), callStack); return v8::Handle<v8::Value>(); } @@ -75,10 +75,10 @@ v8::Handle<v8::Value> V8Console::assertCallback(const v8::Arguments& args) { INC_STATS("DOM.Console.assertCallback"); Console* imp = V8Console::toNative(args.Holder()); - OwnPtr<ScriptCallStack> callStack(createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture)); + RefPtr<ScriptCallStack> callStack(createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture)); bool condition = args[0]->BooleanValue(); - OwnPtr<ScriptArguments> scriptArguments(createScriptArguments(args, 1)); - imp->assertCondition(condition, scriptArguments.release(), callStack.release()); + RefPtr<ScriptArguments> scriptArguments(createScriptArguments(args, 1)); + imp->assertCondition(condition, scriptArguments.release(), callStack); return v8::Handle<v8::Value>(); } @@ -87,11 +87,11 @@ v8::Handle<v8::Value> V8Console::profileCallback(const v8::Arguments& args) { INC_STATS("DOM.Console.profile"); Console* imp = V8Console::toNative(args.Holder()); - OwnPtr<ScriptCallStack> callStack(createScriptCallStack(1)); + RefPtr<ScriptCallStack> callStack(createScriptCallStack(1)); if (!callStack) return v8::Undefined(); STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<WithUndefinedOrNullCheck>, title, args[0]); - imp->profile(title, ScriptState::current(), callStack.release()); + imp->profile(title, ScriptState::current(), callStack); return v8::Handle<v8::Value>(); } @@ -99,11 +99,11 @@ v8::Handle<v8::Value> V8Console::profileEndCallback(const v8::Arguments& args) { INC_STATS("DOM.Console.profileEnd"); Console* imp = V8Console::toNative(args.Holder()); - OwnPtr<ScriptCallStack> callStack(createScriptCallStack(1)); + RefPtr<ScriptCallStack> callStack(createScriptCallStack(1)); if (!callStack) return v8::Undefined(); STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<WithUndefinedOrNullCheck>, title, args[0]); - imp->profileEnd(title, ScriptState::current(), callStack.release()); + imp->profileEnd(title, ScriptState::current(), callStack); return v8::Handle<v8::Value>(); } #endif diff --git a/WebCore/bindings/v8/custom/V8DataViewCustom.cpp b/WebCore/bindings/v8/custom/V8DataViewCustom.cpp new file mode 100755 index 0000000..16bd4a5 --- /dev/null +++ b/WebCore/bindings/v8/custom/V8DataViewCustom.cpp @@ -0,0 +1,124 @@ +/* + * 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: + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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(3D_CANVAS) || ENABLE(BLOB) + +#include "DataView.h" + +#include "V8ArrayBufferViewCustom.h" +#include "V8Binding.h" +#include "V8BindingMacros.h" +#include "V8DataView.h" +#include "V8Proxy.h" + +namespace WebCore { + +v8::Handle<v8::Value> V8DataView::constructorCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.ArrayBuffer.Constructor"); + + if (args[0]->IsNull() || !V8ArrayBuffer::HasInstance(args[0])) + return V8Proxy::throwTypeError(); + return constructWebGLArrayWithArrayBufferArgument<DataView, char>(args, &info, v8::kExternalByteArray, false); +} + +v8::Handle<v8::Value> toV8(DataView* impl) +{ + if (!impl) + return v8::Null(); + return V8DataView::wrap(impl); +} + +v8::Handle<v8::Value> V8DataView::getInt8Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.DataView.getInt8"); + if (args.Length() < 1) + return throwError("Not enough arguments", V8Proxy::SyntaxError); + + DataView* imp = V8DataView::toNative(args.Holder()); + ExceptionCode ec = 0; + EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(args[0])); + char result = imp->getInt8(byteOffset, ec); + if (UNLIKELY(ec)) { + V8Proxy::setDOMException(ec); + return v8::Handle<v8::Value>(); + } + return v8::Integer::New(result); +} + +v8::Handle<v8::Value> V8DataView::getUint8Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.DataView.getUint8"); + if (args.Length() < 1) + return throwError("Not enough arguments", V8Proxy::SyntaxError); + + DataView* imp = V8DataView::toNative(args.Holder()); + ExceptionCode ec = 0; + EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(args[0])); + unsigned char result = imp->getUint8(byteOffset, ec); + if (UNLIKELY(ec)) { + V8Proxy::setDOMException(ec); + return v8::Handle<v8::Value>(); + } + return v8::Integer::New(result); +} + +v8::Handle<v8::Value> V8DataView::setInt8Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.DataView.setInt8"); + if (args.Length() < 2) + return throwError("Not enough arguments", V8Proxy::SyntaxError); + + DataView* imp = V8DataView::toNative(args.Holder()); + ExceptionCode ec = 0; + EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(args[0])); + EXCEPTION_BLOCK(int, value, toInt32(args[1])); + imp->setInt8(byteOffset, static_cast<char>(value), ec); + if (UNLIKELY(ec)) + V8Proxy::setDOMException(ec); + return v8::Handle<v8::Value>(); +} + +v8::Handle<v8::Value> V8DataView::setUint8Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.DataView.setUint8"); + if (args.Length() < 2) + return throwError("Not enough arguments", V8Proxy::SyntaxError); + + DataView* imp = V8DataView::toNative(args.Holder()); + ExceptionCode ec = 0; + EXCEPTION_BLOCK(unsigned, byteOffset, toUInt32(args[0])); + EXCEPTION_BLOCK(int, value, toInt32(args[1])); + imp->setUint8(byteOffset, static_cast<unsigned char>(value), ec); + if (UNLIKELY(ec)) + V8Proxy::setDOMException(ec); + return v8::Handle<v8::Value>(); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/WebCore/bindings/v8/custom/V8EventCustom.cpp b/WebCore/bindings/v8/custom/V8EventCustom.cpp index bb885b9..ff9b98b 100644 --- a/WebCore/bindings/v8/custom/V8EventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8EventCustom.cpp @@ -55,6 +55,7 @@ #include "V8PopStateEvent.h" #include "V8ProgressEvent.h" #include "V8Proxy.h" +#include "V8SpeechInputEvent.h" #include "V8StorageEvent.h" #include "V8TextEvent.h" #include "V8TouchEvent.h" @@ -172,6 +173,10 @@ v8::Handle<v8::Value> toV8(Event* impl) if (impl->isAudioProcessingEvent()) return toV8(static_cast<AudioProcessingEvent*>(impl)); #endif +#if ENABLE(INPUT_SPEECH) + if (impl->isSpeechInputEvent()) + return toV8(static_cast<SpeechInputEvent*>(impl)); +#endif if (impl->isCustomEvent()) return toV8(static_cast<CustomEvent*>(impl)); return V8Event::wrap(impl); diff --git a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp index b3007a4..81ad955 100644 --- a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp @@ -114,9 +114,8 @@ ScriptObject InjectedScriptHost::createInjectedScript(const String& scriptSource scriptHostWrapper, windowGlobal, v8::Number::New(id), - v8::String::New("v8") }; - v8::Local<v8::Value> injectedScriptValue = v8::Function::Cast(*v)->Call(windowGlobal, 4, args); + v8::Local<v8::Value> injectedScriptValue = v8::Function::Cast(*v)->Call(windowGlobal, 3, args); v8::Local<v8::Object> injectedScript(v8::Object::Cast(*injectedScriptValue)); return ScriptObject(inspectedScriptState, injectedScript); } @@ -155,6 +154,18 @@ v8::Handle<v8::Value> V8InjectedScriptHost::nodeForIdCallback(const v8::Argument return toV8(node); } +v8::Handle<v8::Value> V8InjectedScriptHost::internalConstructorNameCallback(const v8::Arguments& args) +{ + INC_STATS("InjectedScriptHost.internalConstructorName()"); + if (args.Length() < 1) + return v8::Undefined(); + + if (!args[0]->IsObject()) + return v8::Undefined(); + + return args[0]->ToObject()->GetConstructorName(); +} + v8::Handle<v8::Value> V8InjectedScriptHost::pushNodePathToFrontendCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.pushNodePathToFrontend()"); diff --git a/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp b/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp index ec6324d..58f26fd 100644 --- a/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SVGLengthCustom.cpp @@ -56,12 +56,17 @@ v8::Handle<v8::Value> V8SVGLength::valueAccessorGetter(v8::Local<v8::String> nam void V8SVGLength::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.SVGLength.value._set"); + SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder()); + if (wrapper->role() == AnimValRole) { + V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR); + return; + } + if (!isUndefinedOrNull(value) && !value->IsNumber() && !value->IsBoolean()) { V8Proxy::throwTypeError(); return; } - SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder()); SVGLength& imp = wrapper->propertyReference(); ExceptionCode ec = 0; imp.setValue(static_cast<float>(value->NumberValue()), wrapper->contextElement(), ec); @@ -74,10 +79,15 @@ void V8SVGLength::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8:: v8::Handle<v8::Value> V8SVGLength::convertToSpecifiedUnitsCallback(const v8::Arguments& args) { INC_STATS("DOM.SVGLength.convertToSpecifiedUnits"); + SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(args.Holder()); + if (wrapper->role() == AnimValRole) { + V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR); + return v8::Handle<v8::Value>(); + } + if (args.Length() < 1) return throwError("Not enough arguments", V8Proxy::SyntaxError); - SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(args.Holder()); SVGLength& imp = wrapper->propertyReference(); ExceptionCode ec = 0; EXCEPTION_BLOCK(int, unitType, toUInt32(args[0])); diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp index 393e544..6a571ae 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp @@ -31,8 +31,10 @@ #include "config.h" #include "V8XMLHttpRequest.h" +#include "ArrayBuffer.h" #include "Frame.h" #include "InspectorInstrumentation.h" +#include "V8ArrayBuffer.h" #include "V8Binding.h" #include "V8Blob.h" #include "V8DOMFormData.h" @@ -57,6 +59,59 @@ v8::Handle<v8::Value> V8XMLHttpRequest::responseTextAccessorGetter(v8::Local<v8: return v8String(text); } +v8::Handle<v8::Value> V8XMLHttpRequest::responseAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.XMLHttpRequest.response._get"); + XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); + + switch (xmlHttpRequest->responseTypeCode()) { + case XMLHttpRequest::ResponseTypeDefault: + case XMLHttpRequest::ResponseTypeText: + return responseTextAccessorGetter(name, info); + + case XMLHttpRequest::ResponseTypeDocument: + { + ExceptionCode ec = 0; + Document* document = xmlHttpRequest->responseXML(ec); + if (ec) { + V8Proxy::setDOMException(ec); + return v8::Undefined(); + } + return toV8(document); + } + + case XMLHttpRequest::ResponseTypeBlob: +#if ENABLE(XHR_RESPONSE_BLOB) + { + ExceptionCode ec = 0; + Blob* blob = xmlHttpRequest->responseBlob(ec); + if (ec) { + V8Proxy::setDOMException(ec); + return v8::Undefined(); + } + return toV8(blob); + } +#else + return v8::Undefined(); +#endif + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + case XMLHttpRequest::ResponseTypeArrayBuffer: + { + ExceptionCode ec = 0; + ArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(ec); + if (ec) { + V8Proxy::setDOMException(ec); + return v8::Undefined(); + } + return toV8(arrayBuffer); + } +#endif + } + + return v8::Undefined(); +} + v8::Handle<v8::Value> V8XMLHttpRequest::openCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.open()"); @@ -138,6 +193,13 @@ v8::Handle<v8::Value> V8XMLHttpRequest::sendCallback(const v8::Arguments& args) DOMFormData* domFormData = V8DOMFormData::toNative(object); ASSERT(domFormData); xmlHttpRequest->send(domFormData, ec); +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + } else if (V8ArrayBuffer::HasInstance(arg)) { + v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); + ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(object); + ASSERT(arrayBuffer); + xmlHttpRequest->send(arrayBuffer, ec); +#endif } else xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), ec); } |