diff options
Diffstat (limited to 'WebCore/bindings/v8/custom')
78 files changed, 1018 insertions, 1442 deletions
diff --git a/WebCore/bindings/v8/custom/V8AbstractWorkerCustom.cpp b/WebCore/bindings/v8/custom/V8AbstractWorkerCustom.cpp deleted file mode 100644 index e776438..0000000 --- a/WebCore/bindings/v8/custom/V8AbstractWorkerCustom.cpp +++ /dev/null @@ -1,81 +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(WORKERS) -#include "V8AbstractWorker.h" - -#include "AbstractWorker.h" -#include "ExceptionCode.h" -#include "ScriptExecutionContext.h" -#include "V8Binding.h" -#include "V8Proxy.h" -#include "V8Utilities.h" -#include "WorkerContextExecutionProxy.h" - -namespace WebCore { - -v8::Handle<v8::Value> V8AbstractWorker::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS(L"DOM.AbstractWorker.addEventListener()"); - AbstractWorker* worker = V8AbstractWorker::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(worker, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - worker->addEventListener(type, listener, useCapture); - - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8AbstractWorker::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS(L"DOM.AbstractWorker.removeEventListener()"); - AbstractWorker* worker = V8AbstractWorker::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(worker, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - worker->removeEventListener(type, listener.get(), useCapture); - - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - -} // namespace WebCore - -#endif // ENABLE(WORKERS) diff --git a/WebCore/bindings/v8/custom/V8CSSStyleSheetCustom.cpp b/WebCore/bindings/v8/custom/V8CSSStyleSheetCustom.cpp index 5dcc966..9effca3 100644 --- a/WebCore/bindings/v8/custom/V8CSSStyleSheetCustom.cpp +++ b/WebCore/bindings/v8/custom/V8CSSStyleSheetCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "V8CSSStyleSheet.h" +#include "V8DOMWrapper.h" #include "V8Node.h" namespace WebCore { @@ -43,7 +44,7 @@ v8::Handle<v8::Value> toV8(CSSStyleSheet* impl) // Add a hidden reference from stylesheet object to its owner node. Node* ownerNode = impl->ownerNode(); if (ownerNode && !wrapper.IsEmpty()) - wrapper->SetInternalField(V8CSSStyleSheet::ownerNodeIndex, toV8(ownerNode)); + V8DOMWrapper::setHiddenReference(wrapper, toV8(ownerNode)); return wrapper; } diff --git a/WebCore/bindings/v8/custom/V8CSSValueCustom.cpp b/WebCore/bindings/v8/custom/V8CSSValueCustom.cpp index b06bc3c..601a62a 100644 --- a/WebCore/bindings/v8/custom/V8CSSValueCustom.cpp +++ b/WebCore/bindings/v8/custom/V8CSSValueCustom.cpp @@ -33,9 +33,12 @@ #include "V8CSSPrimitiveValue.h" #include "V8CSSValueList.h" +#include "V8WebKitCSSTransformValue.h" + +#if ENABLE(SVG) #include "V8SVGColor.h" #include "V8SVGPaint.h" -#include "V8WebKitCSSTransformValue.h" +#endif namespace WebCore { diff --git a/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp b/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp index 9a05d72..26fc626 100644 --- a/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp +++ b/WebCore/bindings/v8/custom/V8CanvasRenderingContext2DCustom.cpp @@ -98,362 +98,4 @@ void V8CanvasRenderingContext2D::fillStyleAccessorSetter(v8::Local<v8::String> n impl->setFillStyle(toCanvasStyle(value)); } -// TODO: SetStrokeColor and SetFillColor are similar except function names, -// consolidate them into one. -v8::Handle<v8::Value> V8CanvasRenderingContext2D::setStrokeColorCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.setStrokeColor()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - switch (args.Length()) { - case 1: - if (args[0]->IsString()) - context->setStrokeColor(toWebCoreString(args[0])); - else - context->setStrokeColor(toFloat(args[0])); - break; - case 2: - if (args[0]->IsString()) - context->setStrokeColor(toWebCoreString(args[0]), toFloat(args[1])); - else - context->setStrokeColor(toFloat(args[0]), toFloat(args[1])); - break; - case 4: - context->setStrokeColor(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3])); - break; - case 5: - context->setStrokeColor(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])); - break; - default: - V8Proxy::throwError(V8Proxy::SyntaxError, "setStrokeColor: Invalid number of arguments"); - break; - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::setFillColorCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.setFillColor()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - switch (args.Length()) { - case 1: - if (args[0]->IsString()) - context->setFillColor(toWebCoreString(args[0])); - else - context->setFillColor(toFloat(args[0])); - break; - case 2: - if (args[0]->IsString()) - context->setFillColor(toWebCoreString(args[0]), toFloat(args[1])); - else - context->setFillColor(toFloat(args[0]), toFloat(args[1])); - break; - case 4: - context->setFillColor(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3])); - break; - case 5: - context->setFillColor(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])); - break; - default: - V8Proxy::throwError(V8Proxy::SyntaxError, "setFillColor: Invalid number of arguments"); - break; - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::strokeRectCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.strokeRect()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - if (args.Length() == 5) - context->strokeRect(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])); - else if (args.Length() == 4) - context->strokeRect(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3])); - else { - V8Proxy::setDOMException(INDEX_SIZE_ERR); - return notHandledByInterceptor(); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::setShadowCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.setShadow()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - - switch (args.Length()) { - case 3: - context->setShadow(toFloat(args[0]), toFloat(args[1]), toFloat(args[2])); - break; - case 4: - if (args[3]->IsString()) - context->setShadow(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toWebCoreString(args[3])); - else - context->setShadow(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3])); - break; - case 5: - if (args[3]->IsString()) - context->setShadow(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toWebCoreString(args[3]), toFloat(args[4])); - else - context->setShadow(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])); - break; - case 7: - context->setShadow(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), toFloat(args[5]), toFloat(args[6])); - break; - case 8: - context->setShadow(toFloat(args[0]), toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), toFloat(args[5]), toFloat(args[6]), toFloat(args[7])); - break; - default: - V8Proxy::throwError(V8Proxy::SyntaxError, "setShadow: Invalid number of arguments"); - break; - } - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::drawImageCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.drawImage()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - - v8::Handle<v8::Value> arg = args[0]; - - if (V8HTMLImageElement::HasInstance(arg)) { - ExceptionCode ec = 0; - HTMLImageElement* imageElement = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); - switch (args.Length()) { - case 3: - context->drawImage(imageElement, toFloat(args[1]), toFloat(args[2])); - break; - case 5: - context->drawImage(imageElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - break; - case 9: - context->drawImage(imageElement, - FloatRect(toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])), - FloatRect(toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8])), - ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - break; - default: - return throwError("drawImage: Invalid number of arguments", V8Proxy::SyntaxError); - } - return v8::Undefined(); - } - - // HTMLCanvasElement - if (V8HTMLCanvasElement::HasInstance(arg)) { - ExceptionCode ec = 0; - HTMLCanvasElement* canvasElement = V8HTMLCanvasElement::toNative(v8::Handle<v8::Object>::Cast(arg)); - switch (args.Length()) { - case 3: - context->drawImage(canvasElement, toFloat(args[1]), toFloat(args[2])); - break; - case 5: - context->drawImage(canvasElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - break; - case 9: - context->drawImage(canvasElement, - FloatRect(toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])), - FloatRect(toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8])), - ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - break; - default: - return throwError("drawImage: Invalid number of arguments", V8Proxy::SyntaxError); - } - return v8::Undefined(); - } - -#if ENABLE(VIDEO) - // HTMLVideoElement - if (V8HTMLVideoElement::HasInstance(arg)) { - ExceptionCode ec = 0; - HTMLVideoElement* videoElement = V8HTMLVideoElement::toNative(v8::Handle<v8::Object>::Cast(arg)); - switch (args.Length()) { - case 3: - context->drawImage(videoElement, toFloat(args[1]), toFloat(args[2])); - break; - case 5: - context->drawImage(videoElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - break; - case 9: - context->drawImage(videoElement, - FloatRect(toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4])), - FloatRect(toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8])), - ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - break; - default: - return throwError("drawImage: Invalid number of arguments", V8Proxy::SyntaxError); - } - return v8::Undefined(); - } -#endif - - V8Proxy::setDOMException(TYPE_MISMATCH_ERR); - return notHandledByInterceptor(); -} - - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::drawImageFromRectCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.drawImageFromRect()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - - v8::Handle<v8::Value> arg = args[0]; - - if (V8HTMLImageElement::HasInstance(arg)) { - HTMLImageElement* imageElement = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); - context->drawImageFromRect(imageElement, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), toFloat(args[5]), toFloat(args[6]), toFloat(args[7]), toFloat(args[8]), toWebCoreString(args[9])); - } else - V8Proxy::throwError(V8Proxy::TypeError, "drawImageFromRect: Invalid type of arguments"); - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::createPatternCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.createPattern()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - - v8::Handle<v8::Value> arg = args[0]; - - if (V8HTMLImageElement::HasInstance(arg)) { - HTMLImageElement* imageElement = V8HTMLImageElement::toNative(v8::Handle<v8::Object>::Cast(arg)); - ExceptionCode ec = 0; - RefPtr<CanvasPattern> pattern = context->createPattern(imageElement, toWebCoreStringWithNullCheck(args[1]), ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - return toV8(pattern.release()); - } - - if (V8HTMLCanvasElement::HasInstance(arg)) { - HTMLCanvasElement* canvasElement = V8HTMLCanvasElement::toNative(v8::Handle<v8::Object>::Cast(arg)); - ExceptionCode ec = 0; - RefPtr<CanvasPattern> pattern = context->createPattern(canvasElement, toWebCoreStringWithNullCheck(args[1]), ec); - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - return toV8(pattern.release()); - } - - V8Proxy::setDOMException(TYPE_MISMATCH_ERR); - return notHandledByInterceptor(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::fillTextCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.fillText()"); - - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - - // Two forms: - // * fillText(text, x, y) - // * fillText(text, x, y, maxWidth) - if (args.Length() < 3 || args.Length() > 4) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } - - String text = toWebCoreString(args[0]); - float x = toFloat(args[1]); - float y = toFloat(args[2]); - - if (args.Length() == 4) { - float maxWidth = toFloat(args[3]); - context->fillText(text, x, y, maxWidth); - } else - context->fillText(text, x, y); - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::strokeTextCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.strokeText()"); - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - - // Two forms: - // * strokeText(text, x, y) - // * strokeText(text, x, y, maxWidth) - if (args.Length() < 3 || args.Length() > 4) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } - - String text = toWebCoreString(args[0]); - float x = toFloat(args[1]); - float y = toFloat(args[2]); - - if (args.Length() == 4) { - float maxWidth = toFloat(args[3]); - context->strokeText(text, x, y, maxWidth); - } else - context->strokeText(text, x, y); - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8CanvasRenderingContext2D::putImageDataCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.CanvasRenderingContext2D.putImageData()"); - - // Two froms: - // * putImageData(ImageData, x, y) - // * putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) - if (args.Length() != 3 && args.Length() != 7) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } - - CanvasRenderingContext2D* context = V8CanvasRenderingContext2D::toNative(args.Holder()); - - ImageData* imageData = 0; - - // Need to check that the argument is of the correct type, since - // toNative() expects it to be correct. If the argument was incorrect - // we leave it null, and putImageData() will throw the correct exception - // (TYPE_MISMATCH_ERR). - if (V8DOMWrapper::isWrapperOfType(args[0], V8ClassIndex::IMAGEDATA)) - imageData = V8ImageData::toNative(v8::Handle<v8::Object>::Cast(args[0])); - - ExceptionCode ec = 0; - - if (args.Length() == 7) - context->putImageData(imageData, toFloat(args[1]), toFloat(args[2]), toFloat(args[3]), toFloat(args[4]), toFloat(args[5]), toFloat(args[6]), ec); - else - context->putImageData(imageData, toFloat(args[1]), toFloat(args[2]), ec); - - if (ec != 0) { - V8Proxy::setDOMException(ec); - return notHandledByInterceptor(); - } - - return v8::Undefined(); -} - } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8ScreenCustom.cpp b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp index 98d9dd7..9026420 100644 --- a/WebCore/bindings/v8/custom/V8ScreenCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp @@ -29,24 +29,30 @@ */ #include "config.h" -#include "V8Screen.h" -#include "V8DOMWindow.h" -#include "V8DOMWrapper.h" +#include "V8Console.h" + +#include "Console.h" +#include "ScriptProfile.h" +#include "V8Binding.h" +#include "V8Proxy.h" +#include "V8ScriptProfile.h" namespace WebCore { -v8::Handle<v8::Value> toV8(Screen* impl) +typedef Vector<RefPtr<ScriptProfile> > ProfilesArray; + +v8::Handle<v8::Value> V8Console::profilesAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - if (!impl) - return v8::Null(); - v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(impl); - if (wrapper.IsEmpty()) { - wrapper = V8Screen::wrap(impl); - if (!wrapper.IsEmpty()) - V8DOMWrapper::setHiddenWindowReference(impl->frame(), V8DOMWindow::screenIndex, wrapper); - } - return wrapper; + INC_STATS("DOM.Console.profilesAccessorGetter"); + Console* imp = V8Console::toNative(info.Holder()); + const ProfilesArray& profiles = imp->profiles(); + v8::Handle<v8::Array> result = v8::Array::New(profiles.size()); + int index = 0; + ProfilesArray::const_iterator end = profiles.end(); + for (ProfilesArray::const_iterator iter = profiles.begin(); iter != end; ++iter) + result->Set(v8::Integer::New(index++), toV8(iter->get())); + return result; } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomBinding.h b/WebCore/bindings/v8/custom/V8CustomBinding.h deleted file mode 100644 index e69de29..0000000 --- a/WebCore/bindings/v8/custom/V8CustomBinding.h +++ /dev/null diff --git a/WebCore/bindings/v8/custom/V8CustomIDBCallbacks.h b/WebCore/bindings/v8/custom/V8CustomIDBCallbacks.h new file mode 100644 index 0000000..1517f15 --- /dev/null +++ b/WebCore/bindings/v8/custom/V8CustomIDBCallbacks.h @@ -0,0 +1,123 @@ +/* + * 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 V8CustomIDBCallbacks_h +#define V8CustomIDBCallbacks_h + +#include "Document.h" +#include "Frame.h" +#include "IDBDatabaseError.h" +#include "V8CustomVoidCallback.h" +#include "V8IDBDatabaseError.h" +#include "WorldContextHandle.h" +#include <v8.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +#if ENABLE(INDEXED_DATABASE) + +namespace WebCore { + +// FIXME: Maybe split common parts into a base class. +template <typename ResultType, typename ResultWrapperType> +class V8CustomIDBCallbacks : public IDBCallbacks<ResultType> { +public: + static PassRefPtr<V8CustomIDBCallbacks> create(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, ScriptExecutionContext* scriptExecutionContext) + { + return adoptRef(new V8CustomIDBCallbacks(onSuccess, onError, scriptExecutionContext)); + } + + virtual ~V8CustomIDBCallbacks() + { + m_onSuccess.Dispose(); + m_onError.Dispose(); + } + + // FIXME: Handle suspend/resume correctly. + +private: + V8CustomIDBCallbacks(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, ScriptExecutionContext* scriptExecutionContext) + : IDBCallbacks<ResultType>(scriptExecutionContext, this) + , m_onSuccess(onSuccess->IsObject() ? v8::Persistent<v8::Object>::New(onSuccess->ToObject()) : v8::Persistent<v8::Object>()) + , m_onError(onError->IsObject() ? v8::Persistent<v8::Object>::New(onError->ToObject()) : v8::Persistent<v8::Object>()) + , m_worldContext(UseCurrentWorld) + { + } + + template <typename Type> + void onEvent(v8::Persistent<v8::Object> callback, PassRefPtr<Type> value) + { + if (!ActiveDOMObject::scriptExecutionContext()) + return; + if (callback.IsEmpty()) + return; + + v8::HandleScope handleScope; + v8::Handle<v8::Context> context = toV8Context(ActiveDOMObject::scriptExecutionContext(), m_worldContext); + if (context.IsEmpty()) + return; + + v8::Context::Scope scope(context); + v8::Handle<v8::Value> argv[] = { + toV8(value) + }; + + // FIXME: Make this work for workers. + ASSERT(ActiveDOMObject::scriptExecutionContext()->isDocument()); + RefPtr<Frame> protector(static_cast<Document*>(ActiveDOMObject::scriptExecutionContext())->frame()); + + bool callbackReturnValue = false; + // FIXME: Do we care if this thing returns true (i.e. it raised an exception)? + invokeCallback(callback, 1, argv, callbackReturnValue); + } + + virtual void onSuccessAsync(PassRefPtr<ResultType> result) + { + onEvent(m_onSuccess, ResultWrapperType::create(result)); + } + + virtual void onErrorAsync(PassRefPtr<IDBDatabaseError> error) + { + onEvent(m_onError, error); + } + + // FIXME: Use OwnHandles. + v8::Persistent<v8::Object> m_onSuccess; + v8::Persistent<v8::Object> m_onError; + + WorldContextHandle m_worldContext; +}; + +} + +#endif + +#endif // V8CustomIDBCallbacks_h diff --git a/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.cpp b/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.cpp index d30b95a..df0cc53 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.cpp @@ -35,6 +35,7 @@ #include "V8CustomSQLStatementCallback.h" #include "Frame.h" +#include "ScriptExecutionContext.h" #include "V8CustomVoidCallback.h" #include "V8SQLResultSet.h" #include "V8SQLTransaction.h" @@ -44,6 +45,7 @@ namespace WebCore { V8CustomSQLStatementCallback::V8CustomSQLStatementCallback(v8::Local<v8::Object> callback, Frame* frame) : m_callback(v8::Persistent<v8::Object>::New(callback)) , m_frame(frame) + , m_worldContext(UseCurrentWorld) { } @@ -52,15 +54,15 @@ V8CustomSQLStatementCallback::~V8CustomSQLStatementCallback() m_callback.Dispose(); } -void V8CustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLResultSet* resultSet, bool& raisedException) +void V8CustomSQLStatementCallback::handleEvent(ScriptExecutionContext* context, SQLTransaction* transaction, SQLResultSet* resultSet, bool& raisedException) { v8::HandleScope handleScope; - v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get()); - if (context.IsEmpty()) + v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + if (v8Context.IsEmpty()) return; - v8::Context::Scope scope(context); + v8::Context::Scope scope(v8Context); v8::Handle<v8::Value> argv[] = { toV8(transaction), @@ -77,4 +79,3 @@ void V8CustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLR } // namespace WebCore #endif - diff --git a/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.h b/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.h index 58ee943..31f53e4 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.h +++ b/WebCore/bindings/v8/custom/V8CustomSQLStatementCallback.h @@ -34,9 +34,9 @@ #if ENABLE(DATABASE) #include "SQLStatementCallback.h" +#include "WorldContextHandle.h" #include <v8.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> +#include <wtf/Forward.h> namespace WebCore { @@ -51,12 +51,13 @@ public: } virtual ~V8CustomSQLStatementCallback(); - virtual void handleEvent(SQLTransaction*, SQLResultSet*, bool& raisedException); + virtual void handleEvent(ScriptExecutionContext*, SQLTransaction*, SQLResultSet*, bool& raisedException); private: V8CustomSQLStatementCallback(v8::Local<v8::Object>, Frame*); v8::Persistent<v8::Object> m_callback; RefPtr<Frame> m_frame; + WorldContextHandle m_worldContext; }; } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp index f733ede..2545f24 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp @@ -35,6 +35,7 @@ #include "V8CustomSQLStatementErrorCallback.h" #include "Frame.h" +#include "ScriptExecutionContext.h" #include "V8CustomVoidCallback.h" #include "V8SQLError.h" #include "V8SQLTransaction.h" @@ -44,6 +45,7 @@ namespace WebCore { V8CustomSQLStatementErrorCallback::V8CustomSQLStatementErrorCallback(v8::Local<v8::Object> callback, Frame* frame) : m_callback(v8::Persistent<v8::Object>::New(callback)) , m_frame(frame) + , m_worldContext(UseCurrentWorld) { } @@ -52,15 +54,15 @@ V8CustomSQLStatementErrorCallback::~V8CustomSQLStatementErrorCallback() m_callback.Dispose(); } -bool V8CustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error) +bool V8CustomSQLStatementErrorCallback::handleEvent(ScriptExecutionContext* context, SQLTransaction* transaction, SQLError* error) { v8::HandleScope handleScope; - v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get()); - if (context.IsEmpty()) + v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + if (v8Context.IsEmpty()) return true; - v8::Context::Scope scope(context); + v8::Context::Scope scope(v8Context); v8::Handle<v8::Value> argv[] = { toV8(transaction), @@ -75,7 +77,7 @@ bool V8CustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, // 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 invokeCallbackTreatOnlyExplicitFalseAsFalse(m_callback, 2, argv, callbackReturnValue) || callbackReturnValue; + return invokeCallback(m_callback, 2, argv, callbackReturnValue) || callbackReturnValue; } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.h b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.h index 685efc6..c3d7f79 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.h +++ b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.h @@ -34,8 +34,7 @@ #if ENABLE(DATABASE) #include "SQLStatementErrorCallback.h" - -#include "SQLStatementErrorCallback.h" +#include "WorldContextHandle.h" #include <v8.h> #include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> @@ -53,12 +52,13 @@ public: } virtual ~V8CustomSQLStatementErrorCallback(); - virtual bool handleEvent(SQLTransaction*, SQLError*); + virtual bool handleEvent(ScriptExecutionContext*, SQLTransaction*, SQLError*); private: V8CustomSQLStatementErrorCallback(v8::Local<v8::Object>, Frame*); v8::Persistent<v8::Object> m_callback; RefPtr<Frame> m_frame; + WorldContextHandle m_worldContext; }; } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.cpp b/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.cpp index 68002d7..efe415c 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.cpp @@ -35,6 +35,7 @@ #include "V8CustomSQLTransactionCallback.h" #include "Frame.h" +#include "ScriptExecutionContext.h" #include "V8CustomVoidCallback.h" #include "V8SQLTransaction.h" @@ -43,6 +44,7 @@ namespace WebCore { V8CustomSQLTransactionCallback::V8CustomSQLTransactionCallback(v8::Local<v8::Object> callback, Frame* frame) : m_callback(v8::Persistent<v8::Object>::New(callback)) , m_frame(frame) + , m_worldContext(UseCurrentWorld) { } @@ -52,15 +54,15 @@ V8CustomSQLTransactionCallback::~V8CustomSQLTransactionCallback() } -void V8CustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bool& raisedException) +void V8CustomSQLTransactionCallback::handleEvent(ScriptExecutionContext* context, SQLTransaction* transaction, bool& raisedException) { v8::HandleScope handleScope; - v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get()); - if (context.IsEmpty()) + v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + if (v8Context.IsEmpty()) return; - v8::Context::Scope scope(context); + v8::Context::Scope scope(v8Context); v8::Handle<v8::Value> argv[] = { toV8(transaction) @@ -79,4 +81,3 @@ void V8CustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bo } // namespace WebCore #endif - diff --git a/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.h b/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.h index 665404d..60ad529 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.h +++ b/WebCore/bindings/v8/custom/V8CustomSQLTransactionCallback.h @@ -34,9 +34,9 @@ #if ENABLE(DATABASE) #include "SQLTransactionCallback.h" +#include "WorldContextHandle.h" #include <v8.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> +#include <wtf/Forward.h> namespace WebCore { @@ -51,12 +51,13 @@ public: } virtual ~V8CustomSQLTransactionCallback(); - virtual void handleEvent(SQLTransaction*, bool& raisedException); + virtual void handleEvent(ScriptExecutionContext*, SQLTransaction*, bool& raisedException); private: V8CustomSQLTransactionCallback(v8::Local<v8::Object>, Frame*); v8::Persistent<v8::Object> m_callback; RefPtr<Frame> m_frame; + WorldContextHandle m_worldContext; }; } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp b/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp index cf5a0ef..1ef711a 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.cpp @@ -35,6 +35,7 @@ #include "V8CustomSQLTransactionErrorCallback.h" #include "Frame.h" +#include "ScriptExecutionContext.h" #include "V8CustomVoidCallback.h" #include "V8SQLError.h" @@ -43,6 +44,7 @@ namespace WebCore { V8CustomSQLTransactionErrorCallback::V8CustomSQLTransactionErrorCallback(v8::Local<v8::Object> callback, Frame* frame) : m_callback(v8::Persistent<v8::Object>::New(callback)) , m_frame(frame) + , m_worldContext(UseCurrentWorld) { } @@ -51,15 +53,15 @@ V8CustomSQLTransactionErrorCallback::~V8CustomSQLTransactionErrorCallback() m_callback.Dispose(); } -void V8CustomSQLTransactionErrorCallback::handleEvent(SQLError* error) +void V8CustomSQLTransactionErrorCallback::handleEvent(ScriptExecutionContext* context, SQLError* error) { v8::HandleScope handleScope; - v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get()); - if (context.IsEmpty()) + v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + if (v8Context.IsEmpty()) return; - v8::Context::Scope scope(context); + v8::Context::Scope scope(v8Context); v8::Handle<v8::Value> argv[] = { toV8(error) @@ -75,4 +77,3 @@ void V8CustomSQLTransactionErrorCallback::handleEvent(SQLError* error) } // namespace WebCore #endif - diff --git a/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.h b/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.h index 0387deb..72e9e7a 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.h +++ b/WebCore/bindings/v8/custom/V8CustomSQLTransactionErrorCallback.h @@ -34,9 +34,9 @@ #if ENABLE(DATABASE) #include "SQLTransactionErrorCallback.h" +#include "WorldContextHandle.h" #include <v8.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> +#include <wtf/Forward.h> namespace WebCore { @@ -51,13 +51,14 @@ public: } virtual ~V8CustomSQLTransactionErrorCallback(); - virtual void handleEvent(SQLError*); + virtual void handleEvent(ScriptExecutionContext*, SQLError*); private: V8CustomSQLTransactionErrorCallback(v8::Local<v8::Object>, Frame*); v8::Persistent<v8::Object> m_callback; RefPtr<Frame> m_frame; + WorldContextHandle m_worldContext; }; } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp b/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp index 8c69e76..f4ea62a 100644 --- a/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp @@ -29,10 +29,10 @@ */ #include "config.h" -#include "V8Binding.h" #include "V8CustomVoidCallback.h" #include "Frame.h" +#include "V8Binding.h" namespace WebCore { @@ -64,7 +64,7 @@ void V8CustomVoidCallback::handleEvent() invokeCallback(m_callback, 0, 0, callbackReturnValue); } -static bool invokeCallbackHelper(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], v8::Handle<v8::Value>& returnValue) +bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue) { v8::TryCatch exceptionCatcher; @@ -73,9 +73,8 @@ static bool invokeCallbackHelper(v8::Persistent<v8::Object> callback, int argc, callbackFunction = v8::Local<v8::Function>::New(v8::Persistent<v8::Function>::Cast(callback)); } else if (callback->IsObject()) { v8::Local<v8::Value> handleEventFunction = callback->Get(v8::String::NewSymbol("handleEvent")); - if (handleEventFunction->IsFunction()) { + if (handleEventFunction->IsFunction()) callbackFunction = v8::Local<v8::Function>::Cast(handleEventFunction); - } } else return false; @@ -87,7 +86,8 @@ static bool invokeCallbackHelper(v8::Persistent<v8::Object> callback, int argc, V8Proxy* proxy = V8Proxy::retrieve(); ASSERT(proxy); - returnValue = proxy->callFunction(callbackFunction, thisObject, argc, argv); + v8::Handle<v8::Value> result = proxy->callFunction(callbackFunction, thisObject, argc, argv); + callbackReturnValue = !result.IsEmpty() && result->BooleanValue(); if (exceptionCatcher.HasCaught()) { v8::Local<v8::Message> message = exceptionCatcher.Message(); @@ -98,20 +98,4 @@ static bool invokeCallbackHelper(v8::Persistent<v8::Object> callback, int argc, return false; } -bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue) -{ - v8::Handle<v8::Value> returnValue; - bool result = invokeCallbackHelper(callback, argc, argv, returnValue); - callbackReturnValue = !returnValue.IsEmpty() && returnValue->IsBoolean() && returnValue->BooleanValue(); - return result; -} - -bool invokeCallbackTreatOnlyExplicitFalseAsFalse(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue) -{ - v8::Handle<v8::Value> returnValue; - bool result = invokeCallbackHelper(callback, argc, argv, returnValue); - callbackReturnValue = !returnValue.IsEmpty() && !returnValue->IsFalse(); - return result; -} - } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomVoidCallback.h b/WebCore/bindings/v8/custom/V8CustomVoidCallback.h index 6b7b3e8..586296b 100644 --- a/WebCore/bindings/v8/custom/V8CustomVoidCallback.h +++ b/WebCore/bindings/v8/custom/V8CustomVoidCallback.h @@ -60,7 +60,6 @@ private: // Returns false if callback failed (null, wrong type, or threw exception). bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue); -bool invokeCallbackTreatOnlyExplicitFalseAsFalse(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue); } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.cpp b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.cpp index e45cba0..01448d9 100644 --- a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.cpp +++ b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.cpp @@ -38,14 +38,13 @@ namespace WebCore { -PassRefPtr<V8CustomXPathNSResolver> V8CustomXPathNSResolver::create(V8Proxy* proxy, v8::Handle<v8::Object> resolver) +PassRefPtr<V8CustomXPathNSResolver> V8CustomXPathNSResolver::create(v8::Handle<v8::Object> resolver) { - return adoptRef(new V8CustomXPathNSResolver(proxy, resolver)); + return adoptRef(new V8CustomXPathNSResolver(resolver)); } -V8CustomXPathNSResolver::V8CustomXPathNSResolver(V8Proxy* proxy, v8::Handle<v8::Object> resolver) - : m_proxy(proxy) - , m_resolver(resolver) +V8CustomXPathNSResolver::V8CustomXPathNSResolver(v8::Handle<v8::Object> resolver) + : m_resolver(resolver) { } @@ -55,14 +54,6 @@ V8CustomXPathNSResolver::~V8CustomXPathNSResolver() String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix) { - V8Proxy* proxy = m_proxy; - - if (!proxy) { - proxy = V8Proxy::retrieve(); - if (!proxy) - return String(); - } - v8::Handle<v8::Function> lookupNamespaceURIFunc; v8::Handle<v8::String> lookupNamespaceURIName = v8::String::New("lookupNamespaceURI"); @@ -74,8 +65,10 @@ String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix) } if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) { - Frame* frame = proxy->frame(); - logInfo(frame, "XPathNSResolver does not have a lookupNamespaceURI method.", String()); + if (V8Proxy* proxy = V8Proxy::retrieve()) { + if (Frame* frame = proxy->frame()) + logInfo(frame, "XPathNSResolver does not have a lookupNamespaceURI method.", String()); + } return String(); } @@ -87,7 +80,7 @@ String V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix) v8::Handle<v8::Value> argv[argc] = { v8String(prefix) }; v8::Handle<v8::Function> function = lookupNamespaceURIFunc.IsEmpty() ? v8::Handle<v8::Function>::Cast(m_resolver) : lookupNamespaceURIFunc; - v8::Handle<v8::Value> retval = proxy->callFunction(function, m_resolver, argc, argv); + v8::Handle<v8::Value> retval = V8Proxy::callFunctionWithoutFrame(function, m_resolver, argc, argv); // Eat exceptions from namespace resolver and return an empty string. This will most likely cause NAMESPACE_ERR. if (try_catch.HasCaught()) diff --git a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h index 15ac27d..cf84438 100644 --- a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h +++ b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h @@ -49,15 +49,14 @@ class V8Proxy; // must not exceed the lifetime of the passed handle. class V8CustomXPathNSResolver : public XPathNSResolver { public: - static PassRefPtr<V8CustomXPathNSResolver> create(V8Proxy* proxy, v8::Handle<v8::Object> resolver); + static PassRefPtr<V8CustomXPathNSResolver> create(v8::Handle<v8::Object> resolver); virtual ~V8CustomXPathNSResolver(); virtual String lookupNamespaceURI(const String& prefix); private: - V8CustomXPathNSResolver(V8Proxy* proxy, v8::Handle<v8::Object> resolver); + explicit V8CustomXPathNSResolver(v8::Handle<v8::Object> resolver); - V8Proxy* m_proxy; v8::Handle<v8::Object> m_resolver; // Handle to resolver object. }; diff --git a/WebCore/bindings/v8/custom/V8DOMApplicationCacheCustom.cpp b/WebCore/bindings/v8/custom/V8DOMApplicationCacheCustom.cpp deleted file mode 100644 index 61760b3..0000000 --- a/WebCore/bindings/v8/custom/V8DOMApplicationCacheCustom.cpp +++ /dev/null @@ -1,80 +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 "V8DOMApplicationCache.h" - -#if ENABLE(OFFLINE_WEB_APPLICATIONS) - -#include "ApplicationCacheHost.h" -#include "DOMApplicationCache.h" -#include "V8Binding.h" -#include "V8Document.h" -#include "V8Proxy.h" -#include "V8Utilities.h" -#include "WorkerContextExecutionProxy.h" - -namespace WebCore { - -// Handles appcache.addEventListner(name, func, capture) method calls -v8::Handle<v8::Value> V8DOMApplicationCache::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOMApplicationCache.addEventListener()"); - DOMApplicationCache* appcache = V8DOMApplicationCache::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(appcache, args[1], false, ListenerFindOrCreate); - if (listener) { - createHiddenDependency(args.Holder(), args[1], cacheIndex); - String eventType = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - appcache->addEventListener(eventType, listener, useCapture); - } - return v8::Undefined(); -} - -// Handles appcache.removeEventListner(name, func, capture) method calls -v8::Handle<v8::Value> V8DOMApplicationCache::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOMApplicationCache.removeEventListener()"); - DOMApplicationCache* appcache = V8DOMApplicationCache::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(appcache, args[1], false, ListenerFindOnly); - if (listener) { - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - String eventType = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - appcache->removeEventListener(eventType, listener.get(), useCapture); - } - return v8::Undefined(); -} - -} // namespace WebCore - -#endif // ENABLE(OFFLINE_WEB_APPLICATIONS) diff --git a/WebCore/bindings/v8/custom/V8BarInfoCustom.cpp b/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp index 44f0b62..8a39332 100644 --- a/WebCore/bindings/v8/custom/V8BarInfoCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp @@ -29,45 +29,37 @@ */ #include "config.h" -#include "V8BarInfo.h" +#include "V8DOMFormData.h" -#include "V8DOMWindow.h" -#include "V8DOMWrapper.h" +#include "DOMFormData.h" +#include "V8Binding.h" +#include "V8Blob.h" +#include "V8Proxy.h" +#include "V8Utilities.h" namespace WebCore { -v8::Handle<v8::Value> toV8(BarInfo* impl) +v8::Handle<v8::Value> V8DOMFormData::appendCallback(const v8::Arguments& args) { - if (!impl) - return v8::Null(); - v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(impl); - if (wrapper.IsEmpty()) { - wrapper = V8BarInfo::wrap(impl); - if (!wrapper.IsEmpty()) { - Frame* frame = impl->frame(); - switch (impl->type()) { - case BarInfo::Locationbar: - V8DOMWrapper::setHiddenWindowReference(frame, V8DOMWindow::locationbarIndex, wrapper); - break; - case BarInfo::Menubar: - V8DOMWrapper::setHiddenWindowReference(frame, V8DOMWindow::menubarIndex, wrapper); - break; - case BarInfo::Personalbar: - V8DOMWrapper::setHiddenWindowReference(frame, V8DOMWindow::personalbarIndex, wrapper); - break; - case BarInfo::Scrollbars: - V8DOMWrapper::setHiddenWindowReference(frame, V8DOMWindow::scrollbarsIndex, wrapper); - break; - case BarInfo::Statusbar: - V8DOMWrapper::setHiddenWindowReference(frame, V8DOMWindow::statusbarIndex, wrapper); - break; - case BarInfo::Toolbar: - V8DOMWrapper::setHiddenWindowReference(frame, V8DOMWindow::toolbarIndex, wrapper); - break; - } - } - } - return wrapper; + INC_STATS("DOM.FormData.append()"); + + if (args.Length() < 2) + return throwError("Not enough arguments", V8Proxy::SyntaxError); + + DOMFormData* domFormData = V8DOMFormData::toNative(args.Holder()); + + String name = toWebCoreStringWithNullCheck(args[0]); + + v8::Handle<v8::Value> arg = args[1]; + if (V8Blob::HasInstance(arg)) { + v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); + Blob* blob = V8Blob::toNative(object); + ASSERT(blob); + domFormData->append(name, blob); + } else + domFormData->append(name, toWebCoreStringWithNullCheck(arg)); + + return v8::Undefined(); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp index 9719837..6a53a1f 100644 --- a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp @@ -31,7 +31,6 @@ #include "config.h" #include "V8DOMWindow.h" -#include "Base64.h" #include "Chrome.h" #include "Database.h" #include "DOMTimer.h" @@ -55,7 +54,13 @@ #include "V8BindingDOMWindow.h" #include "V8BindingState.h" #include "V8CustomEventListener.h" +#include "V8Database.h" +#include "V8DatabaseCallback.h" +#include "V8GCForContextDispose.h" +#include "V8HTMLAudioElementConstructor.h" #include "V8HTMLCollection.h" +#include "V8HTMLImageElementConstructor.h" +#include "V8HTMLOptionElementConstructor.h" #include "V8MessagePortCustom.h" #include "V8Node.h" #include "V8Proxy.h" @@ -135,38 +140,14 @@ v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments& args, bool singl id = DOMTimer::install(scriptContext, new ScheduledAction(V8Proxy::context(imp->frame()), functionString), timeout, singleShot); } - return v8::Integer::New(id); -} - -static bool isAscii(const String& str) -{ - for (size_t i = 0; i < str.length(); i++) { - if (str[i] > 0xFF) - return false; + // Try to do the idle notification before the timeout expires to get better + // use of any idle time. Aim for the middle of the interval for simplicity. + if (timeout > 0) { + double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; + V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); } - return true; -} -static v8::Handle<v8::Value> convertBase64(const String& str, bool encode) -{ - if (!isAscii(str)) { - V8Proxy::setDOMException(INVALID_CHARACTER_ERR); - return notHandledByInterceptor(); - } - - Vector<char> inputCharacters(str.length()); - for (size_t i = 0; i < str.length(); i++) - inputCharacters[i] = static_cast<char>(str[i]); - Vector<char> outputCharacters; - - if (encode) - base64Encode(inputCharacters, outputCharacters); - else { - if (!base64Decode(inputCharacters, outputCharacters)) - return throwError("Cannot decode base64", V8Proxy::GeneralError); - } - - return v8String(String(outputCharacters.data(), outputCharacters.size())); + return v8::Integer::New(id); } v8::Handle<v8::Value> V8DOMWindow::eventAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) @@ -250,7 +231,7 @@ void V8DOMWindow::openerAccessorSetter(v8::Local<v8::String> name, v8::Local<v8: v8::Handle<v8::Value> V8DOMWindow::AudioAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { DOMWindow* window = V8DOMWindow::toNative(info.Holder()); - return V8DOMWrapper::getConstructor(V8ClassIndex::AUDIO, window); + return V8DOMWrapper::getConstructor(&V8HTMLAudioElementConstructor::info, window); } #endif @@ -258,13 +239,13 @@ v8::Handle<v8::Value> V8DOMWindow::AudioAccessorGetter(v8::Local<v8::String> nam v8::Handle<v8::Value> V8DOMWindow::ImageAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { DOMWindow* window = V8DOMWindow::toNative(info.Holder()); - return V8DOMWrapper::getConstructor(V8ClassIndex::IMAGE, window); + return V8DOMWrapper::getConstructor(&V8HTMLImageElementConstructor::info, window); } v8::Handle<v8::Value> V8DOMWindow::OptionAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { DOMWindow* window = V8DOMWindow::toNative(info.Holder()); - return V8DOMWrapper::getConstructor(V8ClassIndex::OPTION, window); + return V8DOMWrapper::getConstructor(&V8HTMLOptionElementConstructor::info, window); } v8::Handle<v8::Value> V8DOMWindow::addEventListenerCallback(const v8::Arguments& args) @@ -289,11 +270,11 @@ v8::Handle<v8::Value> V8DOMWindow::addEventListenerCallback(const v8::Arguments& if (!proxy) return v8::Undefined(); - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(proxy, args[1], false, ListenerFindOrCreate); + RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOrCreate); if (listener) { imp->addEventListener(eventType, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], cacheIndex); + createHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex); } return v8::Undefined(); @@ -321,11 +302,11 @@ v8::Handle<v8::Value> V8DOMWindow::removeEventListenerCallback(const v8::Argumen if (!proxy) return v8::Undefined(); - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(proxy, args[1], false, ListenerFindOnly); + RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFindOnly); if (listener) { imp->removeEventListener(eventType, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], cacheIndex); + removeHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex); } return v8::Undefined(); @@ -339,8 +320,11 @@ v8::Handle<v8::Value> V8DOMWindow::postMessageCallback(const v8::Arguments& args DOMWindow* source = V8Proxy::retrieveFrameForCallingContext()->domWindow(); ASSERT(source->frame()); - v8::TryCatch tryCatch; - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); + bool didThrow = false; + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow); + if (didThrow) + return v8::Undefined(); + MessagePortArray portArray; String targetOrigin; @@ -348,6 +332,7 @@ v8::Handle<v8::Value> V8DOMWindow::postMessageCallback(const v8::Arguments& args // postMessage(message, port, targetOrigin); // or // postMessage(message, targetOrigin); + v8::TryCatch tryCatch; if (args.Length() > 2) { if (!getMessagePortArray(args[1], portArray)) return v8::Undefined(); @@ -364,44 +349,6 @@ v8::Handle<v8::Value> V8DOMWindow::postMessageCallback(const v8::Arguments& args return throwError(ec); } -v8::Handle<v8::Value> V8DOMWindow::atobCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DOMWindow.atob()"); - - if (args[0]->IsNull()) - return v8String(""); - String str = toWebCoreString(args[0]); - - DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - - if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) - return v8::Undefined(); - - if (args.Length() < 1) - return throwError("Not enough arguments", V8Proxy::SyntaxError); - - return convertBase64(str, false); -} - -v8::Handle<v8::Value> V8DOMWindow::btoaCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DOMWindow.btoa()"); - - if (args[0]->IsNull()) - return v8String(""); - String str = toWebCoreString(args[0]); - - DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - - if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) - return v8::Undefined(); - - if (args.Length() < 1) - return throwError("Not enough arguments", V8Proxy::SyntaxError); - - return convertBase64(str, true); -} - // FIXME(fqian): returning string is cheating, and we should // fix this by calling toString function on the receiver. // However, V8 implements toString in JavaScript, which requires @@ -768,39 +715,33 @@ v8::Handle<v8::Value> V8DOMWindow::setIntervalCallback(const v8::Arguments& args return WindowSetTimeoutImpl(args, false); } - -void ClearTimeoutImpl(const v8::Arguments& args) +v8::Handle<v8::Value> V8DOMWindow::openDatabaseCallback(const v8::Arguments& args) { - int handle = toInt32(args[0]); + INC_STATS("DOM.DOMWindow.openDatabase"); + if (args.Length() < 4) + return v8::Undefined(); - v8::Handle<v8::Object> holder = args.Holder(); - DOMWindow* imp = V8DOMWindow::toNative(holder); + DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) - return; - ScriptExecutionContext* context = static_cast<ScriptExecutionContext*>(imp->document()); - if (!context) - return; - DOMTimer::removeById(context, handle); -} + return v8::Undefined(); + ExceptionCode ec = 0; + String name = toWebCoreString(args[0]); + String version = toWebCoreString(args[1]); + String displayName = toWebCoreString(args[2]); + unsigned long estimatedSize = args[3]->IntegerValue(); + RefPtr<DatabaseCallback> creationCallback; + if ((args.Length() >= 5) && args[4]->IsObject()) + creationCallback = V8DatabaseCallback::create(args[4], imp->frame()); -v8::Handle<v8::Value> V8DOMWindow::clearTimeoutCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DOMWindow.clearTimeout"); - ClearTimeoutImpl(args); - return v8::Undefined(); -} + v8::Handle<v8::Value> result = toV8(imp->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec)); -v8::Handle<v8::Value> V8DOMWindow::clearIntervalCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DOMWindow.clearInterval"); - ClearTimeoutImpl(args); - return v8::Undefined(); + V8Proxy::setDOMException(ec); + return result; } -bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) +bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::DOMWINDOW); v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), host); if (window.IsEmpty()) return false; // the frame is gone. @@ -824,9 +765,8 @@ bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::V return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, false); } -bool V8DOMWindow::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) +bool V8DOMWindow::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::DOMWINDOW); v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), host); if (window.IsEmpty()) return false; diff --git a/WebCore/bindings/v8/custom/V8DatabaseCallback.cpp b/WebCore/bindings/v8/custom/V8DatabaseCallback.cpp new file mode 100644 index 0000000..088d89f --- /dev/null +++ b/WebCore/bindings/v8/custom/V8DatabaseCallback.cpp @@ -0,0 +1,79 @@ +/* + * 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 "V8DatabaseCallback.h" + +#include "Frame.h" +#include "ScriptExecutionContext.h" +#include "V8CustomVoidCallback.h" +#include "V8Database.h" + +namespace WebCore { + +V8DatabaseCallback::V8DatabaseCallback(v8::Local<v8::Object> callback, Frame* frame) + : m_callback(v8::Persistent<v8::Object>::New(callback)) + , m_frame(frame) + , m_worldContext(UseCurrentWorld) +{ +} + +V8DatabaseCallback::~V8DatabaseCallback() +{ + m_callback.Dispose(); +} + +void V8DatabaseCallback::handleEvent(ScriptExecutionContext* context, Database* database) +{ + v8::HandleScope handleScope; + + v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + if (v8Context.IsEmpty()) + return; + + v8::Context::Scope scope(v8Context); + + v8::Handle<v8::Value> argv[] = { + toV8(database) + }; + + // Protect the frame until the callback returns. + RefPtr<Frame> protector(m_frame); + + bool callbackReturnValue = false; + invokeCallback(m_callback, 1, argv, callbackReturnValue); +} + +} // namespace WebCore + +#endif diff --git a/WebCore/bindings/v8/custom/V8DOMSelectionCustom.cpp b/WebCore/bindings/v8/custom/V8DatabaseCallback.h index 0c9e745..064a9a7 100644 --- a/WebCore/bindings/v8/custom/V8DOMSelectionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DatabaseCallback.h @@ -28,24 +28,41 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config.h" -#include "V8DOMSelection.h" +#ifndef V8DatabaseCallback_h +#define V8DatabaseCallback_h -#include "V8DOMWindow.h" -#include "V8DOMWrapper.h" +#if ENABLE(DATABASE) + +#include "DatabaseCallback.h" +#include "WorldContextHandle.h" +#include <v8.h> +#include <wtf/Forward.h> namespace WebCore { -v8::Handle<v8::Value> toV8(DOMSelection* impl) -{ - if (!impl) - return v8::Null(); - v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(impl); - if (wrapper.IsEmpty()) { - wrapper = V8DOMSelection::wrap(impl); - V8DOMWrapper::setHiddenWindowReference(impl->frame(), V8DOMWindow::domSelectionIndex, wrapper); +class Frame; + +class V8DatabaseCallback : public DatabaseCallback { +public: + static PassRefPtr<V8DatabaseCallback> create(v8::Local<v8::Value> value, Frame* frame) + { + ASSERT(value->IsObject()); + return adoptRef(new V8DatabaseCallback(value->ToObject(), frame)); } - return wrapper; -} + virtual ~V8DatabaseCallback(); + + virtual void handleEvent(ScriptExecutionContext*, Database*); + +private: + V8DatabaseCallback(v8::Local<v8::Object>, Frame*); + + v8::Persistent<v8::Object> m_callback; + RefPtr<Frame> m_frame; + WorldContextHandle m_worldContext; +}; } // namespace WebCore + +#endif + +#endif // V8DatabaseCallback_h diff --git a/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp b/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp index 4486dbe..8fcf9a8 100644 --- a/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp @@ -46,7 +46,10 @@ v8::Handle<v8::Value> V8DedicatedWorkerContext::postMessageCallback(const v8::Ar { INC_STATS(L"DOM.DedicatedWorkerContext.postMessage"); DedicatedWorkerContext* workerContext = V8DedicatedWorkerContext::toNative(args.Holder()); - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); + bool didThrow = false; + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow); + if (didThrow) + return v8::Undefined(); MessagePortArray portArray; if (args.Length() > 1) { if (!getMessagePortArray(args[1], portArray)) diff --git a/WebCore/bindings/v8/custom/V8DocumentCustom.cpp b/WebCore/bindings/v8/custom/V8DocumentCustom.cpp index 8968707..9fa9f80 100644 --- a/WebCore/bindings/v8/custom/V8DocumentCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DocumentCustom.cpp @@ -46,11 +46,16 @@ #include "V8IsolatedContext.h" #include "V8Node.h" #include "V8Proxy.h" -#include "V8SVGDocument.h" +#if ENABLE(3D_CANVAS) #include "V8WebGLRenderingContext.h" +#endif #include "V8XPathNSResolver.h" #include "V8XPathResult.h" +#if ENABLE(SVG) +#include "V8SVGDocument.h" +#endif + #include <wtf/RefPtr.h> namespace WebCore { @@ -67,7 +72,7 @@ v8::Handle<v8::Value> V8Document::evaluateCallback(const v8::Arguments& args) if (V8Node::HasInstance(args[1])) contextNode = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])); - RefPtr<XPathNSResolver> resolver = V8DOMWrapper::getXPathNSResolver(args[2], V8Proxy::retrieve(V8Proxy::retrieveFrameForCallingContext())); + RefPtr<XPathNSResolver> resolver = V8DOMWrapper::getXPathNSResolver(args[2]); if (!resolver && !args[2]->IsNull() && !args[2]->IsUndefined()) return throwError(TYPE_MISMATCH_ERR); diff --git a/WebCore/bindings/v8/custom/V8ElementCustom.cpp b/WebCore/bindings/v8/custom/V8ElementCustom.cpp index 86f134e..8256110 100644 --- a/WebCore/bindings/v8/custom/V8ElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ElementCustom.cpp @@ -45,7 +45,10 @@ #include "V8BindingState.h" #include "V8HTMLElement.h" #include "V8Proxy.h" + +#if ENABLE(SVG) #include "V8SVGElement.h" +#endif #include <wtf/RefPtr.h> diff --git a/WebCore/bindings/v8/custom/V8EventCustom.cpp b/WebCore/bindings/v8/custom/V8EventCustom.cpp index 79bddc0..b2728ec 100644 --- a/WebCore/bindings/v8/custom/V8EventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8EventCustom.cpp @@ -33,11 +33,13 @@ #include "Clipboard.h" #include "ClipboardEvent.h" +#include "CustomEvent.h" #include "Event.h" #include "V8BeforeLoadEvent.h" #include "V8Binding.h" #include "V8Clipboard.h" #include "V8CompositionEvent.h" +#include "V8CustomEvent.h" #include "V8ErrorEvent.h" #include "V8KeyboardEvent.h" #include "V8MessageEvent.h" @@ -48,7 +50,6 @@ #include "V8PopStateEvent.h" #include "V8ProgressEvent.h" #include "V8Proxy.h" -#include "V8SVGZoomEvent.h" #include "V8StorageEvent.h" #include "V8TextEvent.h" #include "V8TouchEvent.h" @@ -58,6 +59,10 @@ #include "V8WheelEvent.h" #include "V8XMLHttpRequestProgressEvent.h" +#if ENABLE(SVG) +#include "V8SVGZoomEvent.h" +#endif + namespace WebCore { void V8Event::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) @@ -140,6 +145,8 @@ v8::Handle<v8::Value> toV8(Event* impl) #endif if (impl->isBeforeLoadEvent()) return toV8(static_cast<BeforeLoadEvent*>(impl)); + if (impl->isCustomEvent()) + return toV8(static_cast<CustomEvent*>(impl)); return V8Event::wrap(impl); } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8EventSourceConstructor.cpp b/WebCore/bindings/v8/custom/V8EventSourceConstructor.cpp index 793ffb6..01e9c44 100644 --- a/WebCore/bindings/v8/custom/V8EventSourceConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8EventSourceConstructor.cpp @@ -56,17 +56,17 @@ v8::Handle<v8::Value> V8EventSource::constructorCallback(const v8::Arguments& ar if (!context) return throwError("EventSource constructor's associated context is not available", V8Proxy::ReferenceError); if (args.Length() != 1) - return throwError("EventSource constructor wrong number of parameters", V8Proxy::TypeError); + return throwError("Not enough arguments", V8Proxy::SyntaxError); ExceptionCode ec = 0; String url = toWebCoreString(args[0]); RefPtr<EventSource> eventSource = EventSource::create(url, context, ec); - + if (ec) return throwError(ec); - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::EVENTSOURCE), eventSource.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &info, eventSource.get()); // Add object to the wrapper map. eventSource->ref(); diff --git a/WebCore/bindings/v8/custom/V8EventSourceCustom.cpp b/WebCore/bindings/v8/custom/V8EventSourceCustom.cpp deleted file mode 100644 index a7f79db..0000000 --- a/WebCore/bindings/v8/custom/V8EventSourceCustom.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2010, The Android Open Source Project - * - * 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" - -#if ENABLE(EVENTSOURCE) -#include "V8EventSource.h" - -#include "EventSource.h" - -#include "V8Binding.h" -#include "V8Proxy.h" - -namespace WebCore { - -v8::Handle<v8::Value> V8EventSource::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.EventSource.addEventListener()"); - EventSource* eventSource = V8EventSource::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(eventSource, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - eventSource->addEventListener(type, listener, useCapture); - - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8EventSource::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.EventSource.removeEventListener()"); - EventSource* eventSource = V8EventSource::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(eventSource, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - eventSource->removeEventListener(type, listener.get(), useCapture); - - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - -} // namespace WebCore - -#endif // ENABLE(EVENTSOURCE) diff --git a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp index 9b75db8..df16501 100644 --- a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp @@ -44,6 +44,8 @@ namespace WebCore { +WrapperTypeInfo V8HTMLAudioElementConstructor::info = { V8HTMLAudioElementConstructor::GetTemplate, 0, false }; + static v8::Handle<v8::Value> v8HTMLAudioElementConstructorCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLAudioElement.Contructor"); @@ -69,7 +71,7 @@ static v8::Handle<v8::Value> v8HTMLAudioElementConstructorCallback(const v8::Arg src = toWebCoreString(args[0]); RefPtr<HTMLAudioElement> audio = HTMLAudioElement::createForJSConstructor(document, src); - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::AUDIO), audio.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &V8HTMLAudioElementConstructor::info, audio.get()); audio->ref(); V8DOMWrapper::setJSWrapperForDOMNode(audio.get(), v8::Persistent<v8::Object>::New(args.Holder())); return args.Holder(); diff --git a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.h b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.h index 711f539..8bc5f2c 100755 --- a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.h +++ b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.h @@ -31,6 +31,8 @@ #ifndef V8HTMLAudioElementConstructor_h #define V8HTMLAudioElementConstructor_h +#include "WrapperTypeInfo.h" + #include <v8.h> namespace WebCore { @@ -38,6 +40,7 @@ namespace WebCore { class V8HTMLAudioElementConstructor { public: static v8::Persistent<v8::FunctionTemplate> GetTemplate(); + static WrapperTypeInfo info; }; } diff --git a/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp index 54a003c..67ba38b 100644 --- a/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp @@ -39,7 +39,9 @@ #include "V8CanvasRenderingContext2D.h" #include "V8Node.h" #include "V8Proxy.h" +#if ENABLE(3D_CANVAS) #include "V8WebGLRenderingContext.h" +#endif namespace WebCore { @@ -54,7 +56,7 @@ v8::Handle<v8::Value> V8HTMLCanvasElement::getContextCallback(const v8::Argument if (contextId == "experimental-webgl" || contextId == "webkit-3d") { attrs = WebGLContextAttributes::create(); WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get()); - if (args.Length() > 1 && args[0]->IsObject()) { + if (args.Length() > 1 && args[1]->IsObject()) { v8::Handle<v8::Object> jsAttrs = args[1]->ToObject(); v8::Handle<v8::String> alpha = v8::String::New("alpha"); if (jsAttrs->Has(alpha)) diff --git a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp index 29b4813..4751224 100644 --- a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp @@ -44,6 +44,8 @@ namespace WebCore { +WrapperTypeInfo V8HTMLImageElementConstructor::info = { V8HTMLImageElementConstructor::GetTemplate, 0, false }; + static v8::Handle<v8::Value> v8HTMLImageElementConstructorCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLImageElement.Contructor"); @@ -80,7 +82,7 @@ static v8::Handle<v8::Value> v8HTMLImageElementConstructorCallback(const v8::Arg } RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight); - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::IMAGE), image.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &V8HTMLImageElementConstructor::info, image.get()); image->ref(); V8DOMWrapper::setJSWrapperForDOMNode(image.get(), v8::Persistent<v8::Object>::New(args.Holder())); return args.Holder(); diff --git a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.h b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.h index 19ee944..5db4946 100755 --- a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.h +++ b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.h @@ -31,6 +31,8 @@ #ifndef V8HTMLImageElementConstructor_h #define V8HTMLImageElementConstructor_h +#include "WrapperTypeInfo.h" + #include <v8.h> namespace WebCore { @@ -38,6 +40,7 @@ namespace WebCore { class V8HTMLImageElementConstructor { public: static v8::Persistent<v8::FunctionTemplate> GetTemplate(); + static WrapperTypeInfo info; }; } diff --git a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp index 1ff1d2e..6b84856 100644 --- a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp @@ -44,6 +44,8 @@ namespace WebCore { +WrapperTypeInfo V8HTMLOptionElementConstructor::info = { V8HTMLOptionElementConstructor::GetTemplate, 0, false }; + static v8::Handle<v8::Value> v8HTMLOptionElementConstructorCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLOptionElement.Contructor"); @@ -78,7 +80,7 @@ static v8::Handle<v8::Value> v8HTMLOptionElementConstructorCallback(const v8::Ar if (ec) throwError(ec); - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::OPTION), option.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &V8HTMLOptionElementConstructor::info, option.get()); option->ref(); V8DOMWrapper::setJSWrapperForDOMNode(option.get(), v8::Persistent<v8::Object>::New(args.Holder())); return args.Holder(); diff --git a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.h b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.h index 905a745..2adf0fe 100755 --- a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.h +++ b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.h @@ -31,6 +31,8 @@ #ifndef V8HTMLOptionElementConstructor_h #define V8HTMLOptionElementConstructor_h +#include "WrapperTypeInfo.h" + #include <v8.h> namespace WebCore { @@ -38,6 +40,7 @@ namespace WebCore { class V8HTMLOptionElementConstructor { public: static v8::Persistent<v8::FunctionTemplate> GetTemplate(); + static WrapperTypeInfo info; }; } diff --git a/WebCore/bindings/v8/custom/V8HistoryCustom.cpp b/WebCore/bindings/v8/custom/V8HistoryCustom.cpp index 6075ec5..ad2b9a9 100644 --- a/WebCore/bindings/v8/custom/V8HistoryCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HistoryCustom.cpp @@ -43,7 +43,10 @@ namespace WebCore { v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args) { - RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0]); + bool didThrow = false; + RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], didThrow); + if (didThrow) + return v8::Undefined(); v8::TryCatch tryCatch; String title = toWebCoreStringWithNullOrUndefinedCheck(args[1]); @@ -64,7 +67,10 @@ v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args) v8::Handle<v8::Value> V8History::replaceStateCallback(const v8::Arguments& args) { - RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0]); + bool didThrow = false; + RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], didThrow); + if (didThrow) + return v8::Undefined(); v8::TryCatch tryCatch; String title = toWebCoreStringWithNullOrUndefinedCheck(args[1]); @@ -83,33 +89,18 @@ v8::Handle<v8::Value> V8History::replaceStateCallback(const v8::Arguments& args) return throwError(ec); } -bool V8History::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) +bool V8History::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::HISTORY); // Only allow same origin access. History* history = V8History::toNative(host); return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), history->frame(), false); } -bool V8History::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) +bool V8History::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::HISTORY); // Only allow same origin access. History* history = V8History::toNative(host); return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), history->frame(), false); } -v8::Handle<v8::Value> toV8(History* impl) -{ - if (!impl) - return v8::Null(); - v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(impl); - if (wrapper.IsEmpty()) { - wrapper = V8History::wrap(impl); - if (!wrapper.IsEmpty()) - V8DOMWrapper::setHiddenWindowReference(impl->frame(), V8DOMWindow::historyIndex, wrapper); - } - return wrapper; -} - } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp b/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp index 0fd182c..e8c2b68 100644 --- a/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp @@ -33,7 +33,12 @@ #if ENABLE(INDEXED_DATABASE) #include "V8IndexedDatabaseRequest.h" +#include "IDBDatabaseError.h" +#include "IDBDatabaseRequest.h" #include "V8Binding.h" +#include "V8CustomIDBCallbacks.h" +#include "V8IDBDatabaseError.h" +#include "V8IDBDatabaseRequest.h" #include "V8Proxy.h" namespace WebCore { @@ -45,12 +50,32 @@ v8::Handle<v8::Value> V8IndexedDatabaseRequest::openCallback(const v8::Arguments return throwError(V8Proxy::TypeError); V8Parameter<> name = args[0]; V8Parameter<> description = args[1]; + bool modifyDatabase = true; - if (args.Length() > 2) + if (args.Length() > 2 && !args[2]->IsUndefined() && !args[2]->IsNull()) modifyDatabase = args[2]->BooleanValue(); + v8::Local<v8::Value> onError; + v8::Local<v8::Value> onSuccess; + if (args.Length() > 3 && !args[3]->IsUndefined() && !args[3]->IsNull()) { + if (!args[3]->IsObject()) + return throwError("onerror callback was not the proper type"); + onError = args[3]; + } + if (args.Length() > 4 && !args[4]->IsUndefined() && !args[4]->IsNull()) { + if (!args[4]->IsObject()) + return throwError("onsuccess callback was not the proper type"); + onSuccess = args[4]; + } + if (!onError->IsObject() && !onSuccess->IsObject()) + return throwError("Neither the onerror nor the onsuccess callbacks were set."); + + Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); + RefPtr<V8CustomIDBCallbacks<IDBDatabase, IDBDatabaseRequest> > callbacks = + V8CustomIDBCallbacks<IDBDatabase, IDBDatabaseRequest>::create(onSuccess, onError, frame->document()); + ExceptionCode ec = 0; - imp->open(name, description, modifyDatabase, ec); + imp->open(name, description, modifyDatabase, callbacks, ec); if (ec) return throwError(ec); return v8::Handle<v8::Value>(); diff --git a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp index 054f9ba..4c091c8 100644 --- a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp @@ -39,10 +39,14 @@ #include "InspectorController.h" #include "Node.h" #include "Page.h" +#include "ScriptDebugServer.h" #include "SerializedScriptValue.h" #include "V8Binding.h" +#include "V8BindingState.h" +#include "V8DOMWindow.h" #include "V8Database.h" +#include "V8JavaScriptCallFrame.h" #include "V8Node.h" #include "V8Proxy.h" #include "V8Storage.h" @@ -59,7 +63,6 @@ static void WeakReferenceCallback(v8::Persistent<v8::Value> object, void* parame static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHost* host) { - V8ClassIndex::V8WrapperType descriptorType = V8ClassIndex::INJECTEDSCRIPTHOST; v8::Local<v8::Function> function = V8InjectedScriptHost::GetTemplate()->GetFunction(); if (function.IsEmpty()) { // Return if allocation failed. @@ -70,7 +73,7 @@ static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHos // Avoid setting the wrapper if allocation failed. return v8::Local<v8::Object>(); } - V8DOMWrapper::setDOMWrapper(instance, V8ClassIndex::ToInt(descriptorType), host); + V8DOMWrapper::setDOMWrapper(instance, &V8InjectedScriptHost::info, host); // Create a weak reference to the v8 wrapper of InspectorBackend to deref // InspectorBackend when the wrapper is garbage collected. host->ref(); @@ -79,7 +82,7 @@ static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHos return instance; } -static ScriptObject createInjectedScript(const String& scriptSource, InjectedScriptHost* injectedScriptHost, ScriptState* inspectedScriptState, long id) +ScriptObject InjectedScriptHost::createInjectedScript(const String& scriptSource, ScriptState* inspectedScriptState, long id) { v8::HandleScope scope; @@ -90,7 +93,7 @@ static ScriptObject createInjectedScript(const String& scriptSource, InjectedScr // instead of calling toV8() that would create the // wrapper in the current context. // FIXME: make it possible to use generic bindings factory for InjectedScriptHost. - v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(injectedScriptHost); + v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(this); if (scriptHostWrapper.IsEmpty()) return ScriptObject(); @@ -109,9 +112,10 @@ static ScriptObject createInjectedScript(const String& scriptSource, InjectedScr v8::Handle<v8::Value> args[] = { scriptHostWrapper, windowGlobal, - v8::Number::New(id) + v8::Number::New(id), + v8::String::New("v8") }; - v8::Local<v8::Value> injectedScriptValue = v8::Function::Cast(*v)->Call(windowGlobal, 3, args); + v8::Local<v8::Value> injectedScriptValue = v8::Function::Cast(*v)->Call(windowGlobal, 4, args); v8::Local<v8::Object> injectedScript(v8::Object::Cast(*injectedScriptValue)); return ScriptObject(inspectedScriptState, injectedScript); } @@ -151,6 +155,20 @@ v8::Handle<v8::Value> V8InjectedScriptHost::pushNodePathToFrontendCallback(const return v8::Undefined(); } +#if ENABLE(JAVASCRIPT_DEBUGGER) +v8::Handle<v8::Value> V8InjectedScriptHost::currentCallFrameCallback(const v8::Arguments& args) +{ + INC_STATS("InjectedScriptHost.currentCallFrame()"); + return toV8(ScriptDebugServer::shared().currentCallFrame()); +} + +v8::Handle<v8::Value> V8InjectedScriptHost::isActivationCallback(const v8::Arguments& args) +{ + INC_STATS("InjectedScriptHost.isActivation()"); + return v8::Boolean::New(true); +} +#endif + #if ENABLE(DATABASE) v8::Handle<v8::Value> V8InjectedScriptHost::databaseForIdCallback(const v8::Arguments& args) { @@ -226,12 +244,27 @@ InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState* inspectedScrip return InjectedScript(ScriptObject(inspectedScriptState, v8::Local<v8::Object>::Cast(val))); ASSERT(!m_injectedScriptSource.isEmpty()); - ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSource, this, inspectedScriptState, m_nextInjectedScriptId); - InjectedScript result(injectedScriptObject); - m_idToInjectedScript.set(m_nextInjectedScriptId, result); - ++m_nextInjectedScriptId; - global->SetHiddenValue(key, injectedScriptObject.v8Object()); + pair<long, ScriptObject> injectedScript = injectScript(m_injectedScriptSource, inspectedScriptState); + InjectedScript result(injectedScript.second); + m_idToInjectedScript.set(injectedScript.first, result); + global->SetHiddenValue(key, injectedScript.second.v8Object()); return result; } +bool InjectedScriptHost::canAccessInspectedWindow(ScriptState* scriptState) +{ + v8::HandleScope handleScope; + v8::Local<v8::Context> context = scriptState->context(); + v8::Local<v8::Object> global = context->Global(); + if (global.IsEmpty()) + return false; + v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), global); + if (holder.IsEmpty()) + return false; + Frame* frame = V8DOMWindow::toNative(holder)->frame(); + + v8::Context::Scope contextScope(context); + return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, false); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp b/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp index b823034..7f4ccf7 100644 --- a/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp @@ -35,12 +35,65 @@ #include "InspectorFrontendHost.h" #include "V8Binding.h" +#include "V8MouseEvent.h" #include "V8Proxy.h" namespace WebCore { +v8::Handle<v8::Value> V8InspectorFrontendHost::platformCallback(const v8::Arguments&) +{ +#if defined(OS_MACOSX) + return v8String("mac"); +#elif defined(OS_LINUX) + return v8String("linux"); +#elif defined(OS_WIN) + return v8String("windows"); +#else + return v8String("unknown"); +#endif +} + +v8::Handle<v8::Value> V8InspectorFrontendHost::portCallback(const v8::Arguments&) +{ + return v8::Undefined(); +} + v8::Handle<v8::Value> V8InspectorFrontendHost::showContextMenuCallback(const v8::Arguments& args) { + if (args.Length() < 2) + return v8::Undefined(); + + v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(args[0]); + if (!V8MouseEvent::info.equals(V8DOMWrapper::domWrapperType(eventWrapper))) + return v8::Undefined(); + + Event* event = V8Event::toNative(eventWrapper); + if (!args[1]->IsArray()) + return v8::Undefined(); + + v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]); + Vector<ContextMenuItem*> items; + + for (size_t i = 0; i < array->Length(); ++i) { + v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(array->Get(v8::Integer::New(i))); + v8::Local<v8::Value> label = item->Get(v8::String::New("label")); + v8::Local<v8::Value> id = item->Get(v8::String::New("id")); + if (label->IsUndefined() || id->IsUndefined()) { + items.append(new ContextMenuItem(SeparatorType, + ContextMenuItemTagNoAction, + String())); + } else { + ContextMenuAction typedId = static_cast<ContextMenuAction>( + ContextMenuItemBaseCustomTag + id->ToInt32()->Value()); + items.append(new ContextMenuItem(ActionType, + typedId, + toWebCoreStringWithNullCheck(label))); + } + } + + InspectorFrontendHost* frontendHost = V8InspectorFrontendHost::toNative(args.Holder()); + frontendHost->showContextMenu(event, items); + return v8::Undefined(); } diff --git a/WebCore/bindings/v8/custom/V8JavaScriptCallFrameCustom.cpp b/WebCore/bindings/v8/custom/V8JavaScriptCallFrameCustom.cpp new file mode 100644 index 0000000..e2a691d --- /dev/null +++ b/WebCore/bindings/v8/custom/V8JavaScriptCallFrameCustom.cpp @@ -0,0 +1,79 @@ +/* + * 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 "V8JavaScriptCallFrame.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) + +#include "V8Binding.h" +#include "V8Proxy.h" + +namespace WebCore { + +v8::Handle<v8::Value> V8JavaScriptCallFrame::evaluateCallback(const v8::Arguments& args) +{ + INC_STATS("V8JavaScriptCallFrame.evaluateCallback()"); + JavaScriptCallFrame* impl = V8JavaScriptCallFrame::toNative(args.Holder()); + String expression = toWebCoreStringWithNullOrUndefinedCheck(args[0]); + return impl->evaluate(expression); +} + +v8::Handle<v8::Value> V8JavaScriptCallFrame::scopeChainAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("V8JavaScriptCallFrame.scopeChainAccessorGetter()"); + JavaScriptCallFrame* impl = V8JavaScriptCallFrame::toNative(info.Holder()); + return impl->scopeChain(); +} + +v8::Handle<v8::Value> V8JavaScriptCallFrame::scopeTypeCallback(const v8::Arguments& args) +{ + INC_STATS("V8JavaScriptCallFrame.scopeTypeCallback()"); + JavaScriptCallFrame* impl = V8JavaScriptCallFrame::toNative(args.Holder()); + int scopeIndex = args[0]->Int32Value(); + return v8::Int32::New(impl->scopeType(scopeIndex)); +} + +v8::Handle<v8::Value> V8JavaScriptCallFrame::thisObjectAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("V8JavaScriptCallFrame.thisObjectAccessorGetter()"); + JavaScriptCallFrame* impl = V8JavaScriptCallFrame::toNative(info.Holder()); + return impl->thisObject(); +} + +v8::Handle<v8::Value> V8JavaScriptCallFrame::typeAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("V8JavaScriptCallFrame.typeAccessorGetter()"); + return v8String("function"); +} + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) diff --git a/WebCore/bindings/v8/custom/V8LocationCustom.cpp b/WebCore/bindings/v8/custom/V8LocationCustom.cpp index b5df601..ac305c9 100644 --- a/WebCore/bindings/v8/custom/V8LocationCustom.cpp +++ b/WebCore/bindings/v8/custom/V8LocationCustom.cpp @@ -75,9 +75,14 @@ void V8Location::hashAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Va if (hash.startsWith("#")) hash = hash.substring(1); - if (oldRef == hash || (oldRef.isNull() && hash.isEmpty())) - return; + + // Note that by parsing the URL and *then* comparing fragments, we are + // comparing fragments post-canonicalization, and so this handles the + // cases where fragment identifiers are ignored or invalid. url.setFragmentIdentifier(hash); + String newRef = url.fragmentIdentifier(); + if (oldRef == newRef || (oldRef.isNull() && newRef.isEmpty())) + return; navigateIfAllowed(frame, url, false, false); } @@ -185,7 +190,10 @@ void V8Location::protocolAccessorSetter(v8::Local<v8::String> name, v8::Local<v8 return; KURL url = frame->loader()->url(); - url.setProtocol(protocol); + if (!url.setProtocol(protocol)) { + throwError("Can't set protocol", V8Proxy::SyntaxError); + return; + } navigateIfAllowed(frame, url, false, false); } @@ -342,17 +350,15 @@ v8::Handle<v8::Value> V8Location::toStringCallback(const v8::Arguments& args) return v8String(result); } -bool V8Location::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value> data) +bool V8Location::indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::LOCATION); // Only allow same origin access Location* imp = V8Location::toNative(host); return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false); } -bool V8Location::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) +bool V8Location::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::LOCATION); // Only allow same origin access Location* imp = V8Location::toNative(host); return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false); @@ -366,7 +372,7 @@ v8::Handle<v8::Value> toV8(Location* impl) if (wrapper.IsEmpty()) { wrapper = V8Location::wrap(impl); if (!wrapper.IsEmpty()) - V8DOMWrapper::setHiddenWindowReference(impl->frame(), V8DOMWindow::locationIndex, wrapper); + V8DOMWrapper::setHiddenWindowReference(impl->frame(), wrapper); } return wrapper; } diff --git a/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp b/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp index 4fb82ba..b966e42 100644 --- a/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8MessageChannelConstructor.cpp @@ -67,11 +67,11 @@ v8::Handle<v8::Value> V8MessageChannel::constructorCallback(const v8::Arguments& // Create references from the MessageChannel wrapper to the two // MessagePort wrappers to make sure that the MessagePort wrappers // stay alive as long as the MessageChannel wrapper is around. - messageChannel->SetInternalField(V8MessageChannel::port1Index, toV8(obj->port1())); - messageChannel->SetInternalField(V8MessageChannel::port2Index, toV8(obj->port2())); + V8DOMWrapper::setHiddenReference(messageChannel, toV8(obj->port1())); + V8DOMWrapper::setHiddenReference(messageChannel, toV8(obj->port2())); // Setup the standard wrapper object internal fields. - V8DOMWrapper::setDOMWrapper(messageChannel, V8ClassIndex::MESSAGECHANNEL, obj.get()); + V8DOMWrapper::setDOMWrapper(messageChannel, &info, obj.get()); return toV8(obj.release(), messageChannel); } diff --git a/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp b/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp index d41a785..cca4a24 100644 --- a/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp @@ -84,6 +84,8 @@ v8::Handle<v8::Value> V8MessageEvent::initMessageEventCallback(const v8::Argumen return v8::Undefined(); } event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, dataArg.release(), originArg, lastEventIdArg, sourceArg, portArray.release()); + v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly); + SerializedScriptValue::deserializeAndSetProperty(args.Holder(), "data", dataAttr, event->data()); return v8::Undefined(); } diff --git a/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp b/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp index 9890668..c41ed38 100644 --- a/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp +++ b/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp @@ -42,42 +42,14 @@ namespace WebCore { -v8::Handle<v8::Value> V8MessagePort::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.MessagePort.addEventListener()"); - MessagePort* messagePort = V8MessagePort::toNative(args.Holder()); - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(messagePort, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - messagePort->addEventListener(type, listener, useCapture); - - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8MessagePort::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.MessagePort.removeEventListener()"); - MessagePort* messagePort = V8MessagePort::toNative(args.Holder()); - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(messagePort, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - messagePort->removeEventListener(type, listener.get(), useCapture); - - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - v8::Handle<v8::Value> V8MessagePort::postMessageCallback(const v8::Arguments& args) { INC_STATS("DOM.MessagePort.postMessage"); MessagePort* messagePort = V8MessagePort::toNative(args.Holder()); - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); + bool didThrow = false; + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow); + if (didThrow) + return v8::Undefined(); MessagePortArray portArray; if (args.Length() > 1) { if (!getMessagePortArray(args[1], portArray)) diff --git a/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp b/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp index 611ab94..4e1dd21 100644 --- a/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NamedNodeMapCustom.cpp @@ -32,7 +32,9 @@ #include "V8NamedNodeMap.h" #include "NamedNodeMap.h" +#include "V8Attr.h" #include "V8Binding.h" +#include "V8BindingState.h" #include "V8Element.h" #include "V8Node.h" #include "V8Proxy.h" @@ -73,6 +75,48 @@ v8::Handle<v8::Value> V8NamedNodeMap::namedPropertyGetter(v8::Local<v8::String> return toV8(result.release()); } +v8::Handle<v8::Value> V8NamedNodeMap::setNamedItemNSCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.NamedNodeMap.setNamedItemNS"); + NamedNodeMap* imp = V8NamedNodeMap::toNative(args.Holder()); + Node* newNode = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + + if (newNode && newNode->nodeType() == Node::ATTRIBUTE_NODE && imp->element()) { + if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), imp->element(), newNode->nodeName(), newNode->nodeValue())) + return v8::Handle<v8::Value>(); + } + + ExceptionCode ec = 0; + RefPtr<Node> result = imp->setNamedItemNS(newNode, ec); + if (UNLIKELY(ec)) { + throwError(ec); + return v8::Handle<v8::Value>(); + } + + return toV8(result.release()); +} + +v8::Handle<v8::Value> V8NamedNodeMap::setNamedItemCallback(const v8::Arguments & args) +{ + INC_STATS("DOM.NamedNodeMap.setNamedItem"); + NamedNodeMap* imp = V8NamedNodeMap::toNative(args.Holder()); + Node* newNode = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + + if (newNode && newNode->nodeType() == Node::ATTRIBUTE_NODE && imp->element()) { + if (!V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), imp->element(), newNode->nodeName(), newNode->nodeValue())) + return v8::Handle<v8::Value>(); + } + + ExceptionCode ec = 0; + RefPtr<Node> result = imp->setNamedItem(newNode, ec); + if (UNLIKELY(ec)) { + throwError(ec); + return v8::Handle<v8::Value>(); + } + + return toV8(result.release()); +} + v8::Handle<v8::Value> toV8(NamedNodeMap* impl) { if (!impl) @@ -80,10 +124,8 @@ v8::Handle<v8::Value> toV8(NamedNodeMap* impl) v8::Handle<v8::Object> wrapper = V8NamedNodeMap::wrap(impl); // Add a hidden reference from named node map to its owner node. Element* element = impl->element(); - if (!wrapper.IsEmpty() && element) { - v8::Handle<v8::Value> owner = toV8(element); - wrapper->SetInternalField(V8NamedNodeMap::ownerNodeIndex, owner); - } + if (!wrapper.IsEmpty() && element) + V8DOMWrapper::setHiddenReference(wrapper, toV8(element)); return wrapper; } diff --git a/WebCore/bindings/v8/custom/V8NodeCustom.cpp b/WebCore/bindings/v8/custom/V8NodeCustom.cpp index 7907283..0a7198a 100644 --- a/WebCore/bindings/v8/custom/V8NodeCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NodeCustom.cpp @@ -37,6 +37,7 @@ #include "V8AbstractEventListener.h" #include "V8Attr.h" #include "V8Binding.h" +#include "V8BindingState.h" #include "V8CDATASection.h" #include "V8Comment.h" #include "V8CustomEventListener.h" @@ -56,38 +57,43 @@ namespace WebCore { -v8::Handle<v8::Value> V8Node::addEventListenerCallback(const v8::Arguments& args) +static inline bool isFrameSrc(Element *element, const String& name) { - INC_STATS("DOM.Node.addEventListener()"); - Node* node = V8Node::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(node, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - node->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], cacheIndex); + return element && (element->hasTagName(HTMLNames::iframeTag) || element->hasTagName(HTMLNames::frameTag)) && equalIgnoringCase(name, "src"); +} + +void V8Node::textContentAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + Node* imp = V8Node::toNative(info.Holder()); + String nodeValue = toWebCoreStringWithNullCheck(value); + + if (imp->nodeType() == Node::ATTRIBUTE_NODE) { + Element * ownerElement = V8Attr::toNative(info.Holder())->ownerElement(); + if (ownerElement && !V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), ownerElement, imp->nodeName(), nodeValue)) + return; } - return v8::Undefined(); + + ExceptionCode ec = 0; + imp->setTextContent(nodeValue, ec); + if (ec) + throwError(ec); } -v8::Handle<v8::Value> V8Node::removeEventListenerCallback(const v8::Arguments& args) +void V8Node::nodeValueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - INC_STATS("DOM.Node.removeEventListener()"); - Node* node = V8Node::toNative(args.Holder()); - - // It is possbile that the owner document of the node is detached - // from the frame. - // See issue http://b/878909 - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(node, args[1], false, ListenerFindOnly); - if (listener) { - AtomicString type = v8ValueToAtomicWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - node->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], cacheIndex); + Node* imp = V8Node::toNative(info.Holder()); + String nodeValue = toWebCoreStringWithNullCheck(value); + + if (imp->nodeType() == Node::ATTRIBUTE_NODE) { + Element * ownerElement = V8Attr::toNative(info.Holder())->ownerElement(); + if (ownerElement && !V8BindingSecurity::allowSettingSrcToJavascriptURL(V8BindingState::Only(), ownerElement, imp->nodeName(), nodeValue)) + return; } - return v8::Undefined(); + ExceptionCode ec = 0; + imp->setNodeValue(nodeValue, ec); + if (ec) + throwError(ec); } // This function is customized to take advantage of the optional 4th argument: shouldLazyAttach @@ -96,6 +102,12 @@ v8::Handle<v8::Value> V8Node::insertBeforeCallback(const v8::Arguments& args) INC_STATS("DOM.Node.insertBefore"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); + + if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { + V8Proxy::setDOMException(NOT_SUPPORTED_ERR); + return v8::Handle<v8::Value>(); + } + ExceptionCode ec = 0; Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; Node* refChild = V8Node::HasInstance(args[1]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; @@ -115,6 +127,12 @@ v8::Handle<v8::Value> V8Node::replaceChildCallback(const v8::Arguments& args) INC_STATS("DOM.Node.replaceChild"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); + + if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { + V8Proxy::setDOMException(NOT_SUPPORTED_ERR); + return v8::Handle<v8::Value>(); + } + ExceptionCode ec = 0; Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; Node* oldChild = V8Node::HasInstance(args[1]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; @@ -133,6 +151,12 @@ v8::Handle<v8::Value> V8Node::removeChildCallback(const v8::Arguments& args) INC_STATS("DOM.Node.removeChild"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); + + if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { + V8Proxy::setDOMException(NOT_SUPPORTED_ERR); + return v8::Handle<v8::Value>(); + } + ExceptionCode ec = 0; Node* oldChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool success = imp->removeChild(oldChild, ec); @@ -151,6 +175,12 @@ v8::Handle<v8::Value> V8Node::appendChildCallback(const v8::Arguments& args) INC_STATS("DOM.Node.appendChild"); v8::Handle<v8::Object> holder = args.Holder(); Node* imp = V8Node::toNative(holder); + + if (imp->nodeType() == Node::ATTRIBUTE_NODE && isFrameSrc(V8Attr::toNative(holder)->ownerElement(), imp->nodeName())) { + V8Proxy::setDOMException(NOT_SUPPORTED_ERR); + return v8::Handle<v8::Value>(); + } + ExceptionCode ec = 0; Node* newChild = V8Node::HasInstance(args[0]) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; bool success = imp->appendChild(newChild, ec, true ); diff --git a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp index 9c3ab45..30773e3 100644 --- a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp @@ -46,38 +46,6 @@ namespace WebCore { -v8::Handle<v8::Value> V8Notification::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Notification.addEventListener()"); - Notification* notification = V8Notification::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(notification, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - notification->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8Notification::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Notification.removeEventListener()"); - Notification* notification = V8Notification::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(notification, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - notification->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - v8::Handle<v8::Value> V8NotificationCenter::createHTMLNotificationCallback(const v8::Arguments& args) { INC_STATS(L"DOM.NotificationCenter.CreateHTMLNotification()"); diff --git a/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp b/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp index 46e9929..cdb160d 100644 --- a/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8PopStateEventCustom.cpp @@ -35,6 +35,8 @@ #include "SerializedScriptValue.h" #include "V8Proxy.h" +#include <v8.h> + namespace WebCore { v8::Handle<v8::Value> V8PopStateEvent::initPopStateEventCallback(const v8::Arguments& args) @@ -44,7 +46,11 @@ v8::Handle<v8::Value> V8PopStateEvent::initPopStateEventCallback(const v8::Argum String typeArg = v8ValueToWebCoreString(args[0]); bool canBubbleArg = args[1]->BooleanValue(); bool cancelableArg = args[2]->BooleanValue(); - RefPtr<SerializedScriptValue> stateArg = SerializedScriptValue::create(args[3]); + + bool didThrow = false; + RefPtr<SerializedScriptValue> stateArg = SerializedScriptValue::create(args[3], didThrow); + if (didThrow) + return v8::Undefined(); PopStateEvent* event = V8PopStateEvent::toNative(args.Holder()); event->initPopStateEvent(typeArg, canBubbleArg, cancelableArg, stateArg.release()); diff --git a/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp b/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp index 558c03b..8dce61b 100644 --- a/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp @@ -29,6 +29,8 @@ */ #include "config.h" + +#if ENABLE(SVG) #include "V8SVGDocument.h" #include "V8IsolatedContext.h" @@ -51,3 +53,5 @@ v8::Handle<v8::Value> toV8(SVGDocument* impl, bool forceNewObject) } } // namespace WebCore + +#endif diff --git a/WebCore/bindings/v8/custom/V8SVGElementCustom.cpp b/WebCore/bindings/v8/custom/V8SVGElementCustom.cpp index 0ce48ce..7ad5f41 100644 --- a/WebCore/bindings/v8/custom/V8SVGElementCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SVGElementCustom.cpp @@ -29,10 +29,10 @@ */ #include "config.h" -#include "V8SVGElement.h" #if ENABLE(SVG) +#include "V8SVGElement.h" #include "V8SVGElementWrapperFactory.h" namespace WebCore { diff --git a/WebCore/bindings/v8/custom/V8SVGElementInstanceCustom.cpp b/WebCore/bindings/v8/custom/V8SVGElementInstanceCustom.cpp deleted file mode 100644 index 56c37bd..0000000 --- a/WebCore/bindings/v8/custom/V8SVGElementInstanceCustom.cpp +++ /dev/null @@ -1,80 +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(SVG) -#include "V8SVGElementInstance.h" - -#include "EventListener.h" -#include "SVGElementInstance.h" - -#include "V8Binding.h" -#include "V8CustomEventListener.h" -#include "V8SVGPODTypeWrapper.h" -#include "V8Proxy.h" - -namespace WebCore { - -v8::Handle<v8::Value> V8SVGElementInstance::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.SVGElementInstance.AddEventListener()"); - SVGElementInstance* instance = V8SVGElementInstance::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(instance, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - instance->addEventListener(type, listener, useCapture); - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8SVGElementInstance::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.SVGElementInstance.RemoveEventListener()"); - SVGElementInstance* instance = V8SVGElementInstance::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(instance, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - instance->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - -} // namespace WebCore - -#endif diff --git a/WebCore/bindings/v8/custom/V8SVGPathSegCustom.cpp b/WebCore/bindings/v8/custom/V8SVGPathSegCustom.cpp index a96d55e..5544f83 100644 --- a/WebCore/bindings/v8/custom/V8SVGPathSegCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SVGPathSegCustom.cpp @@ -29,6 +29,8 @@ */ #include "config.h" + +#if ENABLE(SVG) #include "V8SVGPathSeg.h" #include "V8DOMWindow.h" @@ -104,3 +106,5 @@ v8::Handle<v8::Value> toV8(SVGPathSeg* impl) } } // namespace WebCore + +#endif diff --git a/WebCore/bindings/v8/custom/V8IDBRequestCustom.cpp b/WebCore/bindings/v8/custom/V8ScriptProfileCustom.cpp index ccf4d0e..ddaabb0 100644 --- a/WebCore/bindings/v8/custom/V8IDBRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ScriptProfileCustom.cpp @@ -29,25 +29,33 @@ */ #include "config.h" +#include "V8ScriptProfile.h" -#if ENABLE(INDEXED_DATABASE) -#include "V8IDBRequest.h" - -#include "SerializedScriptValue.h" +#include "ScriptProfile.h" +#include "V8Binding.h" #include "V8Proxy.h" +#include <v8-profiler.h> + namespace WebCore { -v8::Handle<v8::Value> V8IDBRequest::resultAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +v8::Handle<v8::Value> toV8(ScriptProfile* impl) { - IDBRequest* request = V8IDBRequest::toNative(info.Holder()); - SerializedScriptValue* result = request->result(); - if (!result) + if (!impl) return v8::Null(); - - return result->deserialize(); + v8::Local<v8::Function> function = V8ScriptProfile::GetTemplate()->GetFunction(); + if (function.IsEmpty()) { + // Return if allocation failed. + return v8::Local<v8::Object>(); + } + v8::Local<v8::Object> instance = SafeAllocation::newInstance(function); + if (instance.IsEmpty()) { + // Avoid setting the wrapper if allocation failed. + return v8::Local<v8::Object>(); + } + impl->ref(); + V8DOMWrapper::setDOMWrapper(instance, &V8ScriptProfile::info, impl); + return instance; } } // namespace WebCore - -#endif diff --git a/WebCore/bindings/v8/custom/V8ScriptProfileNodeCustom.cpp b/WebCore/bindings/v8/custom/V8ScriptProfileNodeCustom.cpp new file mode 100644 index 0000000..a4deeeb --- /dev/null +++ b/WebCore/bindings/v8/custom/V8ScriptProfileNodeCustom.cpp @@ -0,0 +1,81 @@ +/* + * 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 "V8ScriptProfileNode.h" + +#include "ScriptProfileNode.h" +#include "V8Binding.h" +#include "V8Proxy.h" + +#include <v8-profiler.h> + +namespace WebCore { + +v8::Handle<v8::Value> V8ScriptProfileNode::childrenAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.ScriptProfileNode.childrenAccessorGetter"); + ScriptProfileNode* imp = V8ScriptProfileNode::toNative(info.Holder()); + const ProfileNodesList& children = imp->children(); + v8::Handle<v8::Array> result = v8::Array::New(children.size()); + int index = 0; + ProfileNodesList::const_iterator end = children.end(); + for (ProfileNodesList::const_iterator iter = children.begin(); iter != end; ++iter) + result->Set(v8::Integer::New(index++), toV8(iter->get())); + return result; +} + +v8::Handle<v8::Value> V8ScriptProfileNode::callUIDAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.ScriptProfileNode.callUIDAccessorGetter"); + ScriptProfileNode* imp = V8ScriptProfileNode::toNative(info.Holder()); + return v8::Number::New(imp->callUID()); +} + +v8::Handle<v8::Value> toV8(ScriptProfileNode* impl) +{ + if (!impl) + return v8::Null(); + v8::Local<v8::Function> function = V8ScriptProfileNode::GetTemplate()->GetFunction(); + if (function.IsEmpty()) { + // Return if allocation failed. + return v8::Local<v8::Object>(); + } + v8::Local<v8::Object> instance = SafeAllocation::newInstance(function); + if (instance.IsEmpty()) { + // Avoid setting the wrapper if allocation failed. + return v8::Local<v8::Object>(); + } + impl->ref(); + V8DOMWrapper::setDOMWrapper(instance, &V8ScriptProfileNode::info, impl); + return instance; +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp b/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp index f69675a..2d72c37 100644 --- a/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SharedWorkerCustom.cpp @@ -80,7 +80,7 @@ v8::Handle<v8::Value> V8SharedWorker::constructorCallback(const v8::Arguments& a // Setup the standard wrapper object internal fields. v8::Handle<v8::Object> wrapperObject = args.Holder(); - V8DOMWrapper::setDOMWrapper(wrapperObject, V8ClassIndex::SHAREDWORKER, obj.get()); + V8DOMWrapper::setDOMWrapper(wrapperObject, &info, obj.get()); obj->ref(); V8DOMWrapper::setJSWrapperForActiveDOMObject(obj.get(), v8::Persistent<v8::Object>::New(wrapperObject)); diff --git a/WebCore/bindings/v8/custom/V8StyleSheetCustom.cpp b/WebCore/bindings/v8/custom/V8StyleSheetCustom.cpp index b062cdc..b3f6ff7 100644 --- a/WebCore/bindings/v8/custom/V8StyleSheetCustom.cpp +++ b/WebCore/bindings/v8/custom/V8StyleSheetCustom.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "V8StyleSheet.h" +#include "V8DOMWrapper.h" #include "V8CSSStyleSheet.h" #include "V8Node.h" @@ -45,10 +46,8 @@ v8::Handle<v8::Value> toV8(StyleSheet* impl) v8::Handle<v8::Object> wrapper = V8StyleSheet::wrap(impl); // Add a hidden reference from stylesheet object to its owner node. Node* ownerNode = impl->ownerNode(); - if (ownerNode && !wrapper.IsEmpty()) { - v8::Handle<v8::Object> owner = v8::Handle<v8::Object>::Cast(toV8(ownerNode)); - wrapper->SetInternalField(V8StyleSheet::ownerNodeIndex, owner); - } + if (ownerNode && !wrapper.IsEmpty()) + V8DOMWrapper::setHiddenReference(wrapper, toV8(ownerNode)); return wrapper; } diff --git a/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp index 5b54563..d3e6cb5 100644 --- a/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLArrayBufferCustom.cpp @@ -72,9 +72,13 @@ v8::Handle<v8::Value> V8WebGLArrayBuffer::constructorCallback(const v8::Argument len = toInt32(args[0]); } - RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(len); + RefPtr<WebGLArrayBuffer> buffer = WebGLArrayBuffer::create(len, 1); + if (!buffer.get()) { + V8Proxy::setDOMException(INDEX_SIZE_ERR); + return v8::Undefined(); + } // Transform the holder into a wrapper object for the array. - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::WEBGLARRAYBUFFER), buffer.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &info, buffer.get()); return toV8(buffer.release(), args.Holder()); } diff --git a/WebCore/bindings/v8/custom/V8WebGLArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLArrayCustom.cpp index a92e4f2..e15fa11 100644 --- a/WebCore/bindings/v8/custom/V8WebGLArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLArrayCustom.cpp @@ -33,6 +33,8 @@ #if ENABLE(3D_CANVAS) #include "V8WebGLArray.h" +#include "V8Binding.h" +#include "V8Proxy.h" #include "V8WebGLByteArray.h" #include "V8WebGLFloatArray.h" #include "V8WebGLIntArray.h" @@ -64,6 +66,30 @@ v8::Handle<v8::Value> toV8(WebGLArray* impl) return v8::Handle<v8::Value>(); } +v8::Handle<v8::Value> V8WebGLArray::sliceCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.WebGLArray.slice"); + // Forms: + // * slice(long start, long end); + + WebGLArray* imp = V8WebGLArray::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) diff --git a/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h b/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h index beea8e6..02bce9c 100644 --- a/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h +++ b/WebCore/bindings/v8/custom/V8WebGLArrayCustom.h @@ -41,9 +41,8 @@ namespace WebCore { // Template function used by the WebGLArray*Constructor callbacks. -template<class ArrayClass> -v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, - int classIndex) +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."); @@ -71,96 +70,64 @@ v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, // See whether the first argument is a WebGLArrayBuffer. if (V8WebGLArrayBuffer::HasInstance(args[0])) { - if (argLen > 3) - return throwError("Wrong number of arguments to new WebGL<T>Array(WebGLArrayBuffer, int, int)"); - WebGLArrayBuffer* buf = V8WebGLArrayBuffer::toNative(args[0]->ToObject()); - if (buf == NULL) + if (!buf) return throwError("Could not convert argument 0 to a WebGLArrayBuffer"); bool ok; - int offset = 0; + uint32_t offset = 0; if (argLen > 1) { - offset = toInt32(args[1], ok); + offset = toUInt32(args[1], ok); if (!ok) - return throwError("Could not convert argument 1 to an integer"); + return throwError("Could not convert argument 1 to a number"); } - int length = buf->byteLength() - offset; + uint32_t length = (buf->byteLength() - offset) / sizeof(ElementType); if (argLen > 2) { - length = toInt32(args[2], ok); + length = toUInt32(args[2], ok); if (!ok) - return throwError("Could not convert argument 2 to an integer"); + return throwError("Could not convert argument 2 to a number"); } - if (length < 0) - return throwError("Length / offset out of range"); RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length); - if (array == NULL) - return throwError("Invalid arguments to new WebGL<T>Array(WebGLArrayBuffer, int, int)"); + if (!array) + return throwError("Out-of-range offset and/or length"); // Transform the holder into a wrapper object for the array. - V8DOMWrapper::setDOMWrapper(args.Holder(), classIndex, array.get()); - V8DOMWrapper::setIndexedPropertiesToExternalArray(args.Holder(), - classIndex, - array.get()->baseAddress(), - array.get()->length()); + V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); + args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length()); return toV8(array.release(), args.Holder()); } - int len = 0; + uint32_t len = 0; v8::Handle<v8::Object> srcArray; - if (argLen != 1) - return throwError("Wrong number of arguments to new WebGL<T>Array(int / array)"); if (args[0]->IsInt32()) { - len = toInt32(args[0]); + len = toUInt32(args[0]); } else if (args[0]->IsObject()) { srcArray = args[0]->ToObject(); if (srcArray.IsEmpty()) - return throwError("Could not convert argument 0 to an object"); - len = toInt32(srcArray->Get(v8::String::New("length"))); + return throwError("Could not convert argument 0 to an array"); + len = toUInt32(srcArray->Get(v8::String::New("length"))); } else - return throwError("Could not convert argument 0 to either an int32 or an object"); + return throwError("Could not convert argument 0 to either a number or an array"); RefPtr<ArrayClass> array = ArrayClass::create(len); + if (!array.get()) { + V8Proxy::setDOMException(INDEX_SIZE_ERR); + return v8::Undefined(); + } if (!srcArray.IsEmpty()) { // Need to copy the incoming array into the newly created WebGLArray. - for (int i = 0; i < len; i++) { - v8::Local<v8::Value> val = srcArray->Get(v8::Integer::New(i)); + for (unsigned i = 0; i < len; i++) { + v8::Local<v8::Value> val = srcArray->Get(v8::Integer::NewFromUnsigned(i)); array->set(i, val->NumberValue()); } } // Transform the holder into a wrapper object for the array. - V8DOMWrapper::setDOMWrapper(args.Holder(), classIndex, array.get()); - V8DOMWrapper::setIndexedPropertiesToExternalArray(args.Holder(), - classIndex, - array.get()->baseAddress(), - array.get()->length()); + V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get()); + args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length()); return toV8(array.release(), args.Holder()); } -template <class T, typename ElementType> -v8::Handle<v8::Value> getWebGLArrayElement(const v8::Arguments& args, - V8ClassIndex::V8WrapperType wrapperType) -{ - if (args.Length() != 1) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } - bool ok; - uint32_t index = toInt32(args[0], ok); - if (!ok) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } - T* array = reinterpret_cast<T*>(args.Holder()->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); - if (index >= array->length()) - return v8::Undefined(); - ElementType result; - if (!array->get(index, result)) - return v8::Undefined(); - return v8::Number::New(result); -} - template <class T> v8::Handle<v8::Value> setWebGLArrayFromArray(T* webGLArray, const v8::Arguments& args) { @@ -169,21 +136,23 @@ v8::Handle<v8::Value> setWebGLArrayFromArray(T* webGLArray, const v8::Arguments& v8::Local<v8::Object> array = args[0]->ToObject(); uint32_t offset = 0; if (args.Length() == 2) - offset = toInt32(args[1]); - uint32_t length = toInt32(array->Get(v8::String::New("length"))); - if (offset + length > webGLArray->length()) + offset = toUInt32(args[1]); + uint32_t length = toUInt32(array->Get(v8::String::New("length"))); + if (offset > webGLArray->length() || + offset + length > webGLArray->length() || + offset + length < offset) + // Out of range offset or overflow V8Proxy::setDOMException(INDEX_SIZE_ERR); else for (uint32_t i = 0; i < length; i++) - webGLArray->set(offset + i, array->Get(v8::Integer::New(i))->NumberValue()); + webGLArray->set(offset + i, array->Get(v8::Integer::NewFromUnsigned(i))->NumberValue()); } return v8::Undefined(); } template <class CPlusPlusArrayType, class JavaScriptWrapperArrayType> -v8::Handle<v8::Value> setWebGLArray(const v8::Arguments& args, - V8ClassIndex::V8WrapperType wrapperType) +v8::Handle<v8::Value> setWebGLArray(const v8::Arguments& args) { if (args.Length() < 1 || args.Length() > 2) { V8Proxy::setDOMException(SYNTAX_ERR); @@ -192,9 +161,10 @@ v8::Handle<v8::Value> setWebGLArray(const v8::Arguments& args, CPlusPlusArrayType* array = JavaScriptWrapperArrayType::toNative(args.Holder()); + // FIXME: change to IsUInt32() when available if (args.Length() == 2 && args[0]->IsInt32()) { // void set(in unsigned long index, in {long|float} value); - uint32_t index = toInt32(args[0]); + uint32_t index = toUInt32(args[0]); array->set(index, args[1]->NumberValue()); return v8::Undefined(); } @@ -204,7 +174,7 @@ v8::Handle<v8::Value> setWebGLArray(const v8::Arguments& args, CPlusPlusArrayType* src = JavaScriptWrapperArrayType::toNative(args[0]->ToObject()); uint32_t offset = 0; if (args.Length() == 2) - offset = toInt32(args[1]); + offset = toUInt32(args[1]); ExceptionCode ec = 0; array->set(src, offset, ec); V8Proxy::setDOMException(ec); diff --git a/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp index dd6163a..8487ace 100644 --- a/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLByteArrayCustom.cpp @@ -47,19 +47,13 @@ v8::Handle<v8::Value> V8WebGLByteArray::constructorCallback(const v8::Arguments& { INC_STATS("DOM.WebGLByteArray.Contructor"); - return constructWebGLArray<WebGLByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLBYTEARRAY)); -} - -v8::Handle<v8::Value> V8WebGLByteArray::getCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebGLByteArray.get()"); - return getWebGLArrayElement<WebGLByteArray, signed char>(args, V8ClassIndex::WEBGLBYTEARRAY); + return constructWebGLArray<WebGLByteArray, signed char>(args, &info, v8::kExternalByteArray); } v8::Handle<v8::Value> V8WebGLByteArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLByteArray.set()"); - return setWebGLArray<WebGLByteArray, V8WebGLByteArray>(args, V8ClassIndex::WEBGLBYTEARRAY); + return setWebGLArray<WebGLByteArray, V8WebGLByteArray>(args); } v8::Handle<v8::Value> toV8(WebGLByteArray* impl) diff --git a/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp index 3fb8865..77223ea 100644 --- a/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLFloatArrayCustom.cpp @@ -47,19 +47,13 @@ v8::Handle<v8::Value> V8WebGLFloatArray::constructorCallback(const v8::Arguments { INC_STATS("DOM.WebGLFloatArray.Contructor"); - return constructWebGLArray<WebGLFloatArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLFLOATARRAY)); -} - -v8::Handle<v8::Value> V8WebGLFloatArray::getCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebGLFloatArray.get()"); - return getWebGLArrayElement<WebGLFloatArray, float>(args, V8ClassIndex::WEBGLFLOATARRAY); + return constructWebGLArray<WebGLFloatArray, float>(args, &info, v8::kExternalFloatArray); } v8::Handle<v8::Value> V8WebGLFloatArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLFloatArray.set()"); - return setWebGLArray<WebGLFloatArray, V8WebGLFloatArray>(args, V8ClassIndex::WEBGLFLOATARRAY); + return setWebGLArray<WebGLFloatArray, V8WebGLFloatArray>(args); } v8::Handle<v8::Value> toV8(WebGLFloatArray* impl) diff --git a/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp index 0141a0b..532bdef 100644 --- a/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLIntArrayCustom.cpp @@ -47,19 +47,13 @@ v8::Handle<v8::Value> V8WebGLIntArray::constructorCallback(const v8::Arguments& { INC_STATS("DOM.WebGLIntArray.Contructor"); - return constructWebGLArray<WebGLIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLINTARRAY)); -} - -v8::Handle<v8::Value> V8WebGLIntArray::getCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebGLIntArray.get()"); - return getWebGLArrayElement<WebGLIntArray, int>(args, V8ClassIndex::WEBGLINTARRAY); + return constructWebGLArray<WebGLIntArray, int>(args, &info, v8::kExternalIntArray); } v8::Handle<v8::Value> V8WebGLIntArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLIntArray.set()"); - return setWebGLArray<WebGLIntArray, V8WebGLIntArray>(args, V8ClassIndex::WEBGLINTARRAY); + return setWebGLArray<WebGLIntArray, V8WebGLIntArray>(args); } v8::Handle<v8::Value> toV8(WebGLIntArray* impl) diff --git a/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp index 78de5e6..1b8936d 100644 --- a/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp @@ -2,7 +2,7 @@ * 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 areV8ClassIndex::WEBGL + * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright @@ -429,10 +429,6 @@ v8::Handle<v8::Value> V8WebGLRenderingContext::getUniformCallback(const v8::Argu bool ok = false; WebGLUniformLocation* location = toWebGLUniformLocation(args[1], ok); - if (!ok) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } WebGLGetInfo info = context->getUniform(program, location, ec); if (ec) { V8Proxy::setDOMException(ec); @@ -786,10 +782,6 @@ static v8::Handle<v8::Value> vertexAttribAndUniformHelperf(const v8::Arguments& WebGLRenderingContext* context = V8WebGLRenderingContext::toNative(args.Holder()); - if (!ok) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } if (V8WebGLFloatArray::HasInstance(args[1])) { WebGLFloatArray* array = V8WebGLFloatArray::toNative(args[1]->ToObject()); ASSERT(array != NULL); @@ -862,10 +854,6 @@ static v8::Handle<v8::Value> uniformHelperi(const v8::Arguments& args, bool ok = false; WebGLUniformLocation* location = toWebGLUniformLocation(args[0], ok); - if (!ok) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } if (V8WebGLIntArray::HasInstance(args[1])) { WebGLIntArray* array = V8WebGLIntArray::toNative(args[1]->ToObject()); ASSERT(array != NULL); @@ -979,10 +967,6 @@ static v8::Handle<v8::Value> uniformMatrixHelper(const v8::Arguments& args, bool ok = false; WebGLUniformLocation* location = toWebGLUniformLocation(args[0], ok); - if (!ok) { - V8Proxy::setDOMException(SYNTAX_ERR); - return notHandledByInterceptor(); - } bool transpose = args[1]->BooleanValue(); if (V8WebGLFloatArray::HasInstance(args[2])) { WebGLFloatArray* array = V8WebGLFloatArray::toNative(args[2]->ToObject()); diff --git a/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp index 5a2408e..328f227 100644 --- a/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLShortArrayCustom.cpp @@ -47,19 +47,13 @@ v8::Handle<v8::Value> V8WebGLShortArray::constructorCallback(const v8::Arguments { INC_STATS("DOM.WebGLShortArray.Contructor"); - return constructWebGLArray<WebGLShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLSHORTARRAY)); -} - -v8::Handle<v8::Value> V8WebGLShortArray::getCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebGLShortArray.get()"); - return getWebGLArrayElement<WebGLShortArray, short>(args, V8ClassIndex::WEBGLSHORTARRAY); + return constructWebGLArray<WebGLShortArray, short>(args, &info, v8::kExternalShortArray); } v8::Handle<v8::Value> V8WebGLShortArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLShortArray.set()"); - return setWebGLArray<WebGLShortArray, V8WebGLShortArray>(args, V8ClassIndex::WEBGLSHORTARRAY); + return setWebGLArray<WebGLShortArray, V8WebGLShortArray>(args); } v8::Handle<v8::Value> toV8(WebGLShortArray* impl) diff --git a/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp index 5a30ace..5185298 100644 --- a/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLUnsignedByteArrayCustom.cpp @@ -47,19 +47,13 @@ v8::Handle<v8::Value> V8WebGLUnsignedByteArray::constructorCallback(const v8::Ar { INC_STATS("DOM.WebGLUnsignedByteArray.Contructor"); - return constructWebGLArray<WebGLUnsignedByteArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY)); -} - -v8::Handle<v8::Value> V8WebGLUnsignedByteArray::getCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebGLUnsignedByteArray.get()"); - return getWebGLArrayElement<WebGLUnsignedByteArray, unsigned char>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY); + return constructWebGLArray<WebGLUnsignedByteArray, unsigned char>(args, &info, v8::kExternalUnsignedByteArray); } v8::Handle<v8::Value> V8WebGLUnsignedByteArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedByteArray.set()"); - return setWebGLArray<WebGLUnsignedByteArray, V8WebGLUnsignedByteArray>(args, V8ClassIndex::WEBGLUNSIGNEDBYTEARRAY); + return setWebGLArray<WebGLUnsignedByteArray, V8WebGLUnsignedByteArray>(args); } v8::Handle<v8::Value> toV8(WebGLUnsignedByteArray* impl) diff --git a/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp index cefc60e..14aa1bb 100644 --- a/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLUnsignedIntArrayCustom.cpp @@ -47,19 +47,13 @@ v8::Handle<v8::Value> V8WebGLUnsignedIntArray::constructorCallback(const v8::Arg { INC_STATS("DOM.WebGLUnsignedIntArray.Contructor"); - return constructWebGLArray<WebGLUnsignedIntArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDINTARRAY)); -} - -v8::Handle<v8::Value> V8WebGLUnsignedIntArray::getCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebGLUnsignedIntArray.get()"); - return getWebGLArrayElement<WebGLUnsignedIntArray, unsigned int>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY); + return constructWebGLArray<WebGLUnsignedIntArray, unsigned int>(args, &info, v8::kExternalUnsignedIntArray); } v8::Handle<v8::Value> V8WebGLUnsignedIntArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedIntArray.set()"); - return setWebGLArray<WebGLUnsignedIntArray, V8WebGLUnsignedIntArray>(args, V8ClassIndex::WEBGLUNSIGNEDINTARRAY); + return setWebGLArray<WebGLUnsignedIntArray, V8WebGLUnsignedIntArray>(args); } v8::Handle<v8::Value> toV8(WebGLUnsignedIntArray* impl) diff --git a/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp b/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp index 56e34b8..e9ebb4f 100644 --- a/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebGLUnsignedShortArrayCustom.cpp @@ -47,19 +47,13 @@ v8::Handle<v8::Value> V8WebGLUnsignedShortArray::constructorCallback(const v8::A { INC_STATS("DOM.WebGLUnsignedShortArray.Contructor"); - return constructWebGLArray<WebGLUnsignedShortArray>(args, V8ClassIndex::ToInt(V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY)); -} - -v8::Handle<v8::Value> V8WebGLUnsignedShortArray::getCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebGLUnsignedShortArray.get()"); - return getWebGLArrayElement<WebGLUnsignedShortArray, unsigned short>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY); + return constructWebGLArray<WebGLUnsignedShortArray, unsigned short>(args, &info, v8::kExternalUnsignedShortArray); } v8::Handle<v8::Value> V8WebGLUnsignedShortArray::setCallback(const v8::Arguments& args) { INC_STATS("DOM.WebGLUnsignedShortArray.set()"); - return setWebGLArray<WebGLUnsignedShortArray, V8WebGLUnsignedShortArray>(args, V8ClassIndex::WEBGLUNSIGNEDSHORTARRAY); + return setWebGLArray<WebGLUnsignedShortArray, V8WebGLUnsignedShortArray>(args); } v8::Handle<v8::Value> toV8(WebGLUnsignedShortArray* impl) diff --git a/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp b/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp index 55518d2..b97d0e8 100644 --- a/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8WebKitCSSMatrixConstructor.cpp @@ -63,7 +63,7 @@ v8::Handle<v8::Value> V8WebKitCSSMatrix::constructorCallback(const v8::Arguments throwError(ec); // Transform the holder into a wrapper object for the matrix. - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::WEBKITCSSMATRIX), matrix.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &info, matrix.get()); return toV8(matrix.release(), args.Holder()); } diff --git a/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp b/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp index 1959454..cb29f82 100755 --- a/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8WebKitPointConstructor.cpp @@ -33,8 +33,8 @@ #include "V8Binding.h" #include "V8DOMWrapper.h" -#include "V8Index.h" #include "V8Proxy.h" +#include "WrapperTypeInfo.h" #include <wtf/MathExtras.h> @@ -63,7 +63,7 @@ v8::Handle<v8::Value> V8WebKitPoint::constructorCallback(const v8::Arguments& ar } PassRefPtr<WebKitPoint> point = WebKitPoint::create(x, y); point->ref(); - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::WEBKITPOINT, point.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &info, point.get()); return args.Holder(); } diff --git a/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp b/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp index 2451b90..b931053 100644 --- a/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp @@ -45,37 +45,6 @@ namespace WebCore { -v8::Handle<v8::Value> V8WebSocket::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebSocket.addEventListener()"); - WebSocket* webSocket = V8WebSocket::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(webSocket, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - webSocket->addEventListener(type, listener, useCapture); - - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8WebSocket::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.WebSocket.removeEventListener()"); - WebSocket* webSocket = V8WebSocket::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(webSocket, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - webSocket->removeEventListener(type, listener.get(), useCapture); - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - v8::Handle<v8::Value> V8WebSocket::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.WebSocket.Constructor"); @@ -115,7 +84,7 @@ v8::Handle<v8::Value> V8WebSocket::constructorCallback(const v8::Arguments& args return throwError(ec); // Setup the standard wrapper object internal fields. - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::WEBSOCKET), webSocket.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &info, webSocket.get()); // Add object to the wrapper map. webSocket->ref(); diff --git a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp index 7677e27..46bd966 100755 --- a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp @@ -58,7 +58,11 @@ v8::Handle<v8::Value> SetTimeoutOrInterval(const v8::Arguments& args, bool singl int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; int timerId; - v8::Handle<v8::Context> v8Context = workerContext->script()->proxy()->context(); + WorkerContextExecutionProxy* proxy = workerContext->script()->proxy(); + if (!proxy) + return v8::Undefined(); + + v8::Handle<v8::Context> v8Context = proxy->context(); if (function->IsString()) { WebCore::String stringFunction = toWebCoreString(function); timerId = DOMTimer::install(workerContext, new ScheduledAction(v8Context, stringFunction, workerContext->url()), timeout, singleShot); @@ -86,14 +90,6 @@ v8::Handle<v8::Value> V8WorkerContext::importScriptsCallback(const v8::Arguments if (!args.Length()) return v8::Undefined(); - String callerURL; - if (!V8Proxy::sourceName(callerURL)) - return v8::Undefined(); - int callerLine; - if (!V8Proxy::sourceLineNumber(callerLine)) - return v8::Undefined(); - callerLine += 1; - Vector<String> urls; for (int i = 0; i < args.Length(); i++) { v8::TryCatch tryCatch; @@ -106,7 +102,7 @@ v8::Handle<v8::Value> V8WorkerContext::importScriptsCallback(const v8::Arguments WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); ExceptionCode ec = 0; - workerContext->importScripts(urls, callerURL, callerLine, ec); + workerContext->importScripts(urls, ec); if (ec) return throwError(ec); @@ -126,44 +122,16 @@ v8::Handle<v8::Value> V8WorkerContext::setIntervalCallback(const v8::Arguments& return SetTimeoutOrInterval(args, false); } -v8::Handle<v8::Value> V8WorkerContext::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS(L"DOM.WorkerContext.addEventListener()"); - WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(workerContext, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - workerContext->addEventListener(type, listener, useCapture); - - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8WorkerContext::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS(L"DOM.WorkerContext.removeEventListener()"); - WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(workerContext, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - workerContext->removeEventListener(type, listener.get(), useCapture); - - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - v8::Handle<v8::Value> toV8(WorkerContext* impl) { if (!impl) return v8::Null(); - v8::Handle<v8::Object> global = impl->script()->proxy()->context()->Global(); + WorkerContextExecutionProxy* proxy = impl->script()->proxy(); + if (!proxy) + return v8::Null(); + + v8::Handle<v8::Object> global = proxy->context()->Global(); ASSERT(!global.IsEmpty()); return global; } diff --git a/WebCore/bindings/v8/custom/V8WorkerCustom.cpp b/WebCore/bindings/v8/custom/V8WorkerCustom.cpp index 6b41246..fdc6815 100755 --- a/WebCore/bindings/v8/custom/V8WorkerCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WorkerCustom.cpp @@ -79,7 +79,7 @@ v8::Handle<v8::Value> V8Worker::constructorCallback(const v8::Arguments& args) // Setup the standard wrapper object internal fields. v8::Handle<v8::Object> wrapperObject = args.Holder(); - V8DOMWrapper::setDOMWrapper(wrapperObject, V8ClassIndex::WORKER, obj.get()); + V8DOMWrapper::setDOMWrapper(wrapperObject, &info, obj.get()); obj->ref(); V8DOMWrapper::setJSWrapperForActiveDOMObject(obj.get(), v8::Persistent<v8::Object>::New(wrapperObject)); @@ -91,7 +91,10 @@ v8::Handle<v8::Value> V8Worker::postMessageCallback(const v8::Arguments& args) { INC_STATS("DOM.Worker.postMessage"); Worker* worker = V8Worker::toNative(args.Holder()); - RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0]); + bool didThrow = false; + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow); + if (didThrow) + return v8::Undefined(); MessagePortArray portArray; if (args.Length() > 1) { if (!getMessagePortArray(args[1], portArray)) diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp index f50248b..6b5b64f 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp @@ -53,7 +53,7 @@ v8::Handle<v8::Value> V8XMLHttpRequest::constructorCallback(const v8::Arguments& if (!context) return throwError("XMLHttpRequest constructor's associated context is not available", V8Proxy::ReferenceError); RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context); - V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::XMLHTTPREQUEST), xmlHttpRequest.get()); + V8DOMWrapper::setDOMWrapper(args.Holder(), &info, xmlHttpRequest.get()); // Add object to the wrapper map. xmlHttpRequest->ref(); diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp index d10c418..4e9c715 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Google Inc. All rights reserved. + * Copyright (C) 2008, 2009, 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 @@ -34,6 +34,7 @@ #include "Frame.h" #include "V8Binding.h" #include "V8Blob.h" +#include "V8DOMFormData.h" #include "V8Document.h" #include "V8HTMLDocument.h" #include "V8Proxy.h" @@ -51,39 +52,6 @@ v8::Handle<v8::Value> V8XMLHttpRequest::responseTextAccessorGetter(v8::Local<v8: return xmlHttpRequest->responseText().v8StringOrNull(); } -v8::Handle<v8::Value> V8XMLHttpRequest::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.XMLHttpRequest.addEventListener()"); - XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(xmlHttpRequest, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - xmlHttpRequest->addEventListener(type, listener, useCapture); - - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8XMLHttpRequest::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.XMLHttpRequest.removeEventListener()"); - XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(args.Holder()); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(xmlHttpRequest, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - xmlHttpRequest->removeEventListener(type, listener.get(), useCapture); - - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - v8::Handle<v8::Value> V8XMLHttpRequest::openCallback(const v8::Arguments& args) { INC_STATS("DOM.XMLHttpRequest.open()"); @@ -106,20 +74,23 @@ v8::Handle<v8::Value> V8XMLHttpRequest::openCallback(const v8::Arguments& args) KURL url = context->completeURL(urlstring); - bool async = (args.Length() < 3) ? true : args[2]->BooleanValue(); - ExceptionCode ec = 0; - String user, passwd; - if (args.Length() >= 4 && !args[3]->IsUndefined()) { - user = toWebCoreStringWithNullCheck(args[3]); - if (args.Length() >= 5 && !args[4]->IsUndefined()) { - passwd = toWebCoreStringWithNullCheck(args[4]); - xmlHttpRequest->open(method, url, async, user, passwd, ec); + if (args.Length() >= 3) { + bool async = args[2]->BooleanValue(); + + if (args.Length() >= 4 && !args[3]->IsUndefined()) { + String user = toWebCoreStringWithNullCheck(args[3]); + + if (args.Length() >= 5 && !args[4]->IsUndefined()) { + String passwd = toWebCoreStringWithNullCheck(args[4]); + xmlHttpRequest->open(method, url, async, user, passwd, ec); + } else + xmlHttpRequest->open(method, url, async, user, ec); } else - xmlHttpRequest->open(method, url, async, user, ec); + xmlHttpRequest->open(method, url, async, ec); } else - xmlHttpRequest->open(method, url, async, ec); + xmlHttpRequest->open(method, url, ec); if (ec) return throwError(ec); @@ -127,7 +98,7 @@ v8::Handle<v8::Value> V8XMLHttpRequest::openCallback(const v8::Arguments& args) return v8::Undefined(); } -static bool IsDocumentType(v8::Handle<v8::Value> value) +static bool isDocumentType(v8::Handle<v8::Value> value) { // FIXME: add other document types. return V8Document::HasInstance(value) || V8HTMLDocument::HasInstance(value); @@ -143,7 +114,9 @@ v8::Handle<v8::Value> V8XMLHttpRequest::sendCallback(const v8::Arguments& args) xmlHttpRequest->send(ec); else { v8::Handle<v8::Value> arg = args[0]; - if (IsDocumentType(arg)) { + if (isUndefinedOrNull(arg)) + xmlHttpRequest->send(ec); + else if (isDocumentType(arg)) { v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); Document* document = V8Document::toNative(object); ASSERT(document); @@ -153,6 +126,11 @@ v8::Handle<v8::Value> V8XMLHttpRequest::sendCallback(const v8::Arguments& args) Blob* blob = V8Blob::toNative(object); ASSERT(blob); xmlHttpRequest->send(blob, ec); + } else if (V8DOMFormData::HasInstance(arg)) { + v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); + DOMFormData* domFormData = V8DOMFormData::toNative(object); + ASSERT(domFormData); + xmlHttpRequest->send(domFormData, ec); } else xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), ec); } @@ -206,10 +184,4 @@ v8::Handle<v8::Value> V8XMLHttpRequest::overrideMimeTypeCallback(const v8::Argum return v8::Undefined(); } -v8::Handle<v8::Value> V8XMLHttpRequest::dispatchEventCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.XMLHttpRequest.dispatchEvent()"); - return v8::Undefined(); -} - } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp deleted file mode 100644 index c6c31bf..0000000 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestUploadCustom.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2008, 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 "V8XMLHttpRequestUpload.h" - -#include "ExceptionCode.h" -#include "V8Binding.h" -#include "V8Proxy.h" -#include "V8Utilities.h" -#include "XMLHttpRequest.h" -#include "XMLHttpRequestUpload.h" - -#include <wtf/Assertions.h> - -namespace WebCore { - -v8::Handle<v8::Value> V8XMLHttpRequestUpload::addEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.XMLHttpRequestUpload.addEventListener()"); - XMLHttpRequestUpload* xmlHttpRequestUpload = V8XMLHttpRequestUpload::toNative(args.Holder()); - - XMLHttpRequest* xmlHttpRequest = xmlHttpRequestUpload->associatedXMLHttpRequest(); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(xmlHttpRequest, args[1], false, ListenerFindOrCreate); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - xmlHttpRequestUpload->addEventListener(type, listener, useCapture); - - createHiddenDependency(args.Holder(), args[1], cacheIndex); - } - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8XMLHttpRequestUpload::removeEventListenerCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.XMLHttpRequestUpload.removeEventListener()"); - XMLHttpRequestUpload* xmlHttpRequestUpload = V8XMLHttpRequestUpload::toNative(args.Holder()); - - XMLHttpRequest* xmlHttpRequest = xmlHttpRequestUpload->associatedXMLHttpRequest(); - - RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(xmlHttpRequest, args[1], false, ListenerFindOnly); - if (listener) { - String type = toWebCoreString(args[0]); - bool useCapture = args[2]->BooleanValue(); - xmlHttpRequestUpload->removeEventListener(type, listener.get(), useCapture); - - removeHiddenDependency(args.Holder(), args[1], cacheIndex); - } - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8XMLHttpRequestUpload::dispatchEventCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.XMLHttpRequestUpload.dispatchEvent()"); - return throwError(NOT_SUPPORTED_ERR); -} - -} // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp b/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp index 89f804c..b624fcf 100644 --- a/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XSLTProcessorCustom.cpp @@ -49,7 +49,7 @@ namespace WebCore { v8::Handle<v8::Value> V8XSLTProcessor::constructorCallback(const v8::Arguments& args) { INC_STATS("DOM.XSLTProcessor.Constructor"); - return V8Proxy::constructDOMObject<V8ClassIndex::XSLTPROCESSOR, XSLTProcessor>(args); + return V8Proxy::constructDOMObject<XSLTProcessor>(args, &info); } |