diff options
Diffstat (limited to 'WebCore/bindings/v8')
-rw-r--r-- | WebCore/bindings/v8/ScriptHeapSnapshot.cpp | 99 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptHeapSnapshot.h | 67 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptProfile.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptProfiler.cpp | 21 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptProfiler.h | 6 | ||||
-rw-r--r-- | WebCore/bindings/v8/SerializedScriptValue.cpp | 6 | ||||
-rw-r--r-- | WebCore/bindings/v8/SerializedScriptValue.h | 2 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8Binding.cpp | 40 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8Binding.h | 95 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8BindingMacros.h | 17 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp | 96 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp | 3 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp | 3 | ||||
-rw-r--r-- | WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp | 6 |
14 files changed, 405 insertions, 60 deletions
diff --git a/WebCore/bindings/v8/ScriptHeapSnapshot.cpp b/WebCore/bindings/v8/ScriptHeapSnapshot.cpp new file mode 100644 index 0000000..885d039 --- /dev/null +++ b/WebCore/bindings/v8/ScriptHeapSnapshot.cpp @@ -0,0 +1,99 @@ +/* + * 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" +#include "ScriptHeapSnapshot.h" + +#include "InspectorValues.h" +#include "V8Binding.h" +#include <v8-profiler.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +String ScriptHeapSnapshot::title() const +{ + v8::HandleScope scope; + return toWebCoreString(m_snapshot->GetTitle()); +} + +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); + } + } + result->setObject("lowlevels", lowLevels); + result->setObject("entries", entries); + result->setObject("children", children); + return result.release(); +} + +PassRefPtr<InspectorObject> ScriptHeapSnapshot::buildInspectorObjectForHead() const +{ + return buildInspectorObjectFor(m_snapshot->GetRoot()); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptHeapSnapshot.h b/WebCore/bindings/v8/ScriptHeapSnapshot.h new file mode 100644 index 0000000..794a5a9 --- /dev/null +++ b/WebCore/bindings/v8/ScriptHeapSnapshot.h @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#ifndef ScriptHeapSnapshot_h +#define ScriptHeapSnapshot_h + +#include "PlatformString.h" + +namespace v8 { +class HeapSnapshot; +} + +namespace WebCore { + +class InspectorObject; + +class ScriptHeapSnapshot : public RefCounted<ScriptHeapSnapshot> { +public: + static PassRefPtr<ScriptHeapSnapshot> create(const v8::HeapSnapshot* snapshot) + { + return adoptRef(new ScriptHeapSnapshot(snapshot)); + } + virtual ~ScriptHeapSnapshot() {} + + String title() const; + unsigned int uid() const; + + PassRefPtr<InspectorObject> buildInspectorObjectForHead() const; + +private: + ScriptHeapSnapshot(const v8::HeapSnapshot* snapshot) + : m_snapshot(snapshot) + {} + + const v8::HeapSnapshot* m_snapshot; +}; + +} // namespace WebCore + +#endif // ScriptHeapSnapshot_h diff --git a/WebCore/bindings/v8/ScriptProfile.cpp b/WebCore/bindings/v8/ScriptProfile.cpp index 95ac0de..c5a6dbf 100644 --- a/WebCore/bindings/v8/ScriptProfile.cpp +++ b/WebCore/bindings/v8/ScriptProfile.cpp @@ -65,7 +65,7 @@ static PassRefPtr<InspectorObject> buildInspectorObjectFor(const v8::CpuProfileN result->setNumber("totalTime", node->GetTotalTime()); result->setNumber("selfTime", node->GetSelfTime()); result->setNumber("numberOfCalls", 0); - result->setBool("visible", true); + result->setBoolean("visible", true); result->setNumber("callUID", node->GetCallUid()); RefPtr<InspectorArray> children = InspectorArray::create(); @@ -75,7 +75,7 @@ static PassRefPtr<InspectorObject> buildInspectorObjectFor(const v8::CpuProfileN children->pushObject(buildInspectorObjectFor(child)); } result->setArray("children", children); - return result; + return result.release(); } PassRefPtr<InspectorObject> ScriptProfile::buildInspectorObjectForHead() const diff --git a/WebCore/bindings/v8/ScriptProfiler.cpp b/WebCore/bindings/v8/ScriptProfiler.cpp index 0de4a24..ab7cfa7 100644 --- a/WebCore/bindings/v8/ScriptProfiler.cpp +++ b/WebCore/bindings/v8/ScriptProfiler.cpp @@ -29,8 +29,9 @@ */ #include "config.h" - #include "ScriptProfiler.h" + +#include "InspectorValues.h" #include "ScriptString.h" #include <v8-profiler.h> @@ -52,21 +53,11 @@ PassRefPtr<ScriptProfile> ScriptProfiler::stop(ScriptState* state, const String& return profile ? ScriptProfile::create(profile) : 0; } -void ScriptProfiler::takeHeapSnapshot() -{ - v8::V8::ResumeProfilerEx(v8::PROFILER_MODULE_HEAP_SNAPSHOT - | v8::PROFILER_MODULE_HEAP_STATS - | v8::PROFILER_MODULE_JS_CONSTRUCTORS); -} - -long ScriptProfiler::getProfilerLogLines(long position, String* data) +PassRefPtr<ScriptHeapSnapshot> ScriptProfiler::takeHeapSnapshot(const String& title) { - static char buffer[65536]; - const int readSize = v8::V8::GetLogLines(position, buffer, sizeof(buffer) - 1); - buffer[readSize] = '\0'; - position += readSize; - *data = buffer; - return position; + v8::HandleScope hs; + const v8::HeapSnapshot* snapshot = v8::HeapProfiler::TakeSnapshot(v8String(title), v8::HeapSnapshot::kAggregated); + return snapshot ? ScriptHeapSnapshot::create(snapshot) : 0; } bool ScriptProfiler::isProfilerAlwaysEnabled() diff --git a/WebCore/bindings/v8/ScriptProfiler.h b/WebCore/bindings/v8/ScriptProfiler.h index b1ab3b1..b75a054 100644 --- a/WebCore/bindings/v8/ScriptProfiler.h +++ b/WebCore/bindings/v8/ScriptProfiler.h @@ -32,6 +32,7 @@ #define ScriptProfiler_h #include "PlatformString.h" +#include "ScriptHeapSnapshot.h" #include "ScriptProfile.h" #include "ScriptState.h" @@ -39,12 +40,13 @@ namespace WebCore { +class InspectorObject; + class ScriptProfiler : public Noncopyable { 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); + static PassRefPtr<ScriptHeapSnapshot> takeHeapSnapshot(const String& title); static bool isProfilerAlwaysEnabled(); }; diff --git a/WebCore/bindings/v8/SerializedScriptValue.cpp b/WebCore/bindings/v8/SerializedScriptValue.cpp index 395ef1a..0b908b8 100644 --- a/WebCore/bindings/v8/SerializedScriptValue.cpp +++ b/WebCore/bindings/v8/SerializedScriptValue.cpp @@ -1096,6 +1096,12 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValue::create() return adoptRef(new SerializedScriptValue()); } +SerializedScriptValue* SerializedScriptValue::nullValue() +{ + DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, nullValue, (SerializedScriptValue::create())); + return nullValue.get(); +} + PassRefPtr<SerializedScriptValue> SerializedScriptValue::release() { RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_data, WireData)); diff --git a/WebCore/bindings/v8/SerializedScriptValue.h b/WebCore/bindings/v8/SerializedScriptValue.h index 3710b5a..275e5f2 100644 --- a/WebCore/bindings/v8/SerializedScriptValue.h +++ b/WebCore/bindings/v8/SerializedScriptValue.h @@ -52,6 +52,8 @@ public: static PassRefPtr<SerializedScriptValue> createFromWire(String data); static PassRefPtr<SerializedScriptValue> create(String data); static PassRefPtr<SerializedScriptValue> create(); + + static SerializedScriptValue* nullValue(); PassRefPtr<SerializedScriptValue> release(); diff --git a/WebCore/bindings/v8/V8Binding.cpp b/WebCore/bindings/v8/V8Binding.cpp index 3799cdb..bfbc647 100644 --- a/WebCore/bindings/v8/V8Binding.cpp +++ b/WebCore/bindings/v8/V8Binding.cpp @@ -368,27 +368,33 @@ 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) +{ + // Caching of small strings below is not thread safe: newly constructed AtomicString + // are not safely published. + ASSERT(WTF::isMainThread()); + + // Most numbers used are <= 100. Even if they aren't used there's very little cost in using the space. + const int kLowNumbers = 100; + DEFINE_STATIC_LOCAL(Vector<AtomicString>, lowNumbers, (kLowNumbers + 1)); + String webCoreString; + if (0 <= value && value <= kLowNumbers) { + webCoreString = lowNumbers[value]; + if (!webCoreString) { + AtomicString valueString = AtomicString(String::number(value)); + lowNumbers[value] = valueString; + webCoreString = valueString; + } + } else + webCoreString = String::number(value); + return webCoreString; +} String v8NonStringValueToWebCoreString(v8::Handle<v8::Value> object) { ASSERT(!object->IsString()); - if (object->IsInt32()) { - int value = object->Int32Value(); - // Most numbers used are <= 100. Even if they aren't used there's very little in using the space. - const int kLowNumbers = 100; - static AtomicString lowNumbers[kLowNumbers + 1]; - String webCoreString; - if (0 <= value && value <= kLowNumbers) { - webCoreString = lowNumbers[value]; - if (!webCoreString) { - AtomicString valueString = AtomicString(String::number(value)); - lowNumbers[value] = valueString; - webCoreString = valueString; - } - } else - webCoreString = String::number(value); - return webCoreString; - } + if (object->IsInt32()) + return int32ToWebCoreString(object->Int32Value()); v8::TryCatch block; v8::Handle<v8::String> v8String = object->ToString(); diff --git a/WebCore/bindings/v8/V8Binding.h b/WebCore/bindings/v8/V8Binding.h index 087c128..58989ed 100644 --- a/WebCore/bindings/v8/V8Binding.h +++ b/WebCore/bindings/v8/V8Binding.h @@ -210,6 +210,61 @@ namespace WebCore { v8::Persistent<v8::String> getToStringName(); v8::Persistent<v8::FunctionTemplate> getToStringTemplate(); + String int32ToWebCoreString(int value); + + class V8ParameterBase { + public: + operator String() { return toString<String>(); } + operator AtomicString() { return toString<AtomicString>(); } + + protected: + V8ParameterBase(v8::Local<v8::Value> object) : m_v8Object(object), m_mode(Externalize), m_string() { } + + bool prepareBase() + { + if (LIKELY(m_v8Object->IsString())) + return true; + + if (LIKELY(m_v8Object->IsInt32())) { + setString(int32ToWebCoreString(m_v8Object->Int32Value())); + return true; + } + + m_mode = DoNotExternalize; + v8::TryCatch block; + m_v8Object = m_v8Object->ToString(); + // Handle the case where an exception is thrown as part of invoking toString on the object. + if (block.HasCaught()) { + block.ReThrow(); + return false; + } + + return true; + } + + v8::Local<v8::Value> object() { return m_v8Object; } + + void setString(String string) + { + m_string = string; + m_v8Object.Clear(); // To signal that String is ready. + } + + private: + v8::Local<v8::Value> m_v8Object; + ExternalMode m_mode; + String m_string; + + template <class StringType> + StringType toString() + { + if (LIKELY(!m_v8Object.IsEmpty())) + return v8StringToWebCoreString<StringType>(m_v8Object.As<v8::String>(), m_mode); + + return StringType(m_string); + } + }; + // V8Parameter is an adapter class that converts V8 values to Strings // or AtomicStrings as appropriate, using multiple typecast operators. enum V8ParameterMode { @@ -218,22 +273,38 @@ namespace WebCore { WithUndefinedOrNullCheck }; template <V8ParameterMode MODE = DefaultMode> - class V8Parameter { + class V8Parameter: public V8ParameterBase { public: - V8Parameter(v8::Local<v8::Value> object = v8::Local<v8::Value>()) : m_v8Object(object) { } - operator String(); - operator AtomicString(); - private: - v8::Local<v8::Value> m_v8Object; + V8Parameter(v8::Local<v8::Value> object) : V8ParameterBase(object) { } + V8Parameter(v8::Local<v8::Value> object, bool) : V8ParameterBase(object) { prepare(); } + + bool prepare(); }; - 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); } + template<> inline bool V8Parameter<DefaultMode>::prepare() + { + return V8ParameterBase::prepareBase(); + } + + template<> inline bool V8Parameter<WithNullCheck>::prepare() + { + if (object()->IsNull()) { + setString(String()); + return true; + } - template<> inline V8Parameter<DefaultMode>::operator AtomicString() { return v8ValueToAtomicWebCoreString(m_v8Object); } - template<> inline V8Parameter<WithNullCheck>::operator AtomicString() { return toAtomicWebCoreStringWithNullCheck(m_v8Object); } - template<> inline V8Parameter<WithUndefinedOrNullCheck>::operator AtomicString() { return toAtomicWebCoreStringWithNullCheck(m_v8Object); } + return V8ParameterBase::prepareBase(); + } + + template<> inline bool V8Parameter<WithUndefinedOrNullCheck>::prepare() + { + if (object()->IsNull() || object()->IsUndefined()) { + setString(String()); + return true; + } + + return V8ParameterBase::prepareBase(); + } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8BindingMacros.h b/WebCore/bindings/v8/custom/V8BindingMacros.h index b569b10..ad02c3e 100644 --- a/WebCore/bindings/v8/custom/V8BindingMacros.h +++ b/WebCore/bindings/v8/custom/V8BindingMacros.h @@ -38,12 +38,11 @@ } #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; \ - } + type var(value); \ + if (!var.prepare()) \ + return v8::Undefined(); + +#define STRING_TO_V8PARAMETER_EXCEPTION_BLOCK_VOID(type, var, value) \ + type var(value); \ + if (!var.prepare()) \ + return; diff --git a/WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp b/WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp new file mode 100644 index 0000000..7ca18ab --- /dev/null +++ b/WebCore/bindings/v8/custom/V8DOMStringMapCustom.cpp @@ -0,0 +1,96 @@ +/* + * 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" +#include "V8DOMStringMap.h" + +#include "DOMStringMap.h" +#include "V8Binding.h" + +namespace WebCore { + +v8::Handle<v8::Integer> V8DOMStringMap::namedPropertyQuery(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DOMStringMap.NamedPropertyQuery"); + if (V8DOMStringMap::toNative(info.Holder())->contains(toWebCoreString(name))) + return v8::Integer::New(v8::None); + return v8::Handle<v8::Integer>(); +} + +v8::Handle<v8::Value> V8DOMStringMap::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DOMStringMap.NamedPropertyGetter"); + return v8String(V8DOMStringMap::toNative(info.Holder())->item(toWebCoreString(name))); +} + +v8::Handle<v8::Array> V8DOMStringMap::namedPropertyEnumerator(const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DOMStringMap.NamedPropertyEnumerator"); + Vector<String> names; + V8DOMStringMap::toNative(info.Holder())->getNames(names); + v8::Handle<v8::Array> properties = v8::Array::New(names.size()); + for (unsigned i = 0; i < names.size(); ++i) + properties->Set(v8::Integer::New(i), v8String(names[i])); + return properties; +} + +v8::Handle<v8::Boolean> V8DOMStringMap::namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DOMStringMap.NamedPropertyDeleter"); + v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); + if (!value.IsEmpty()) + return v8::False(); + if (info.Holder()->HasRealNamedCallbackProperty(name)) + return v8::False(); + + ExceptionCode ec = 0; + V8DOMStringMap::toNative(info.Holder())->deleteItem(toWebCoreString(name), ec); + if (ec) + throwError(ec); + return v8::True(); +} + +v8::Handle<v8::Value> V8DOMStringMap::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DOMStringMap.NamedPropertySetter"); + v8::Handle<v8::Value> property = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); + if (!property.IsEmpty()) + return value; + if (info.Holder()->HasRealNamedCallbackProperty(name)) + return value; + + ExceptionCode ec = 0; + V8DOMStringMap::toNative(info.Holder())->setItem(toWebCoreString(name), toWebCoreString(value), ec); + if (ec) + return throwError(ec); + return value; +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp index 39692b6..67f27c5 100644 --- a/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp @@ -30,6 +30,7 @@ #include "DeviceMotionData.h" #include "V8Binding.h" +#include "V8BindingMacros.h" #include "V8Proxy.h" #include <v8.h> @@ -110,7 +111,7 @@ v8::Handle<v8::Value> V8DeviceMotionEvent::intervalAccessorGetter(v8::Local<v8:: v8::Handle<v8::Value> V8DeviceMotionEvent::initDeviceMotionEventCallback(const v8::Arguments& args) { DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(args.Holder()); - V8Parameter<> type = args[0]; + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(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. diff --git a/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp b/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp index 26cc6cc..72f759a 100644 --- a/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp @@ -30,6 +30,7 @@ #include "DeviceOrientation.h" #include "V8Binding.h" +#include "V8BindingMacros.h" #include "V8Proxy.h" #include <v8.h> @@ -69,7 +70,7 @@ v8::Handle<v8::Value> V8DeviceOrientationEvent::gammaAccessorGetter(v8::Local<v8 v8::Handle<v8::Value> V8DeviceOrientationEvent::initDeviceOrientationEventCallback(const v8::Arguments& args) { DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(args.Holder()); - V8Parameter<> type = args[0]; + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, type, args[0]); bool bubbles = args[1]->BooleanValue(); bool cancelable = args[2]->BooleanValue(); // If alpha, beta or gamma are null or undefined, mark them as not provided. diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp index 3da664f..cfeb503 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp @@ -49,7 +49,11 @@ v8::Handle<v8::Value> V8XMLHttpRequest::responseTextAccessorGetter(v8::Local<v8: { INC_STATS("DOM.XMLHttpRequest.responsetext._get"); XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); - return xmlHttpRequest->responseText().v8StringOrNull(); + ExceptionCode ec = 0; + const ScriptString& text = xmlHttpRequest->responseText(ec); + if (ec) + return throwError(ec); + return text.v8StringOrNull(); } v8::Handle<v8::Value> V8XMLHttpRequest::openCallback(const v8::Arguments& args) |