diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp')
-rw-r--r-- | Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp | 134 |
1 files changed, 41 insertions, 93 deletions
diff --git a/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp index 7ad36f8b2..172c0d997 100644 --- a/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp +++ b/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2016 Apple Inc. All rights reserved. * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -27,119 +27,67 @@ #include "config.h" #include "JSHTMLCanvasElement.h" -#include "CanvasContextAttributes.h" #include "HTMLCanvasElement.h" -#include "InspectorCanvasInstrumentation.h" #include "JSCanvasRenderingContext2D.h" #include <bindings/ScriptObject.h> #include <wtf/GetPtr.h> #if ENABLE(WEBGL) -#include "JSDictionary.h" -#include "JSWebGLRenderingContext.h" -#include "WebGLContextAttributes.h" +#include "JSWebGLContextAttributes.h" +#include "JSWebGLRenderingContextBase.h" #endif using namespace JSC; namespace WebCore { -#if ENABLE(WEBGL) -static void get3DContextAttributes(ExecState* exec, RefPtr<CanvasContextAttributes>& attrs) +JSValue JSHTMLCanvasElement::getContext(ExecState& state) { - JSValue initializerValue = exec->argument(1); - if (initializerValue.isUndefinedOrNull()) - return; - - JSObject* initializerObject = initializerValue.toObject(exec); - JSDictionary dictionary(exec, initializerObject); - - GraphicsContext3D::Attributes graphicsAttrs; - - dictionary.tryGetProperty("alpha", graphicsAttrs.alpha); - dictionary.tryGetProperty("depth", graphicsAttrs.depth); - dictionary.tryGetProperty("stencil", graphicsAttrs.stencil); - dictionary.tryGetProperty("antialias", graphicsAttrs.antialias); - dictionary.tryGetProperty("premultipliedAlpha", graphicsAttrs.premultipliedAlpha); - dictionary.tryGetProperty("preserveDrawingBuffer", graphicsAttrs.preserveDrawingBuffer); - - attrs = WebGLContextAttributes::create(graphicsAttrs); -} -#endif + auto& vm = state.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); -JSValue JSHTMLCanvasElement::getContext(ExecState* exec) -{ - HTMLCanvasElement& canvas = impl(); - const String& contextId = exec->argument(0).toString(exec)->value(exec); - - RefPtr<CanvasContextAttributes> attrs; -#if ENABLE(WEBGL) - if (HTMLCanvasElement::is3dType(contextId)) { - get3DContextAttributes(exec, attrs); - if (exec->hadException()) - return jsUndefined(); - } -#endif - - CanvasRenderingContext* context = canvas.getContext(contextId, attrs.get()); - if (!context) - return jsNull(); - JSValue jsValue = toJS(exec, globalObject(), WTF::getPtr(context)); - if (InspectorInstrumentation::canvasAgentEnabled(&canvas.document())) { - Deprecated::ScriptObject contextObject(exec, jsValue.getObject()); - Deprecated::ScriptObject wrapped; - if (context->is2d()) - wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(&canvas.document(), contextObject); -#if ENABLE(WEBGL) - else if (context->is3d()) - wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(&canvas.document(), contextObject); -#endif - if (!wrapped.hasNoValue()) - return wrapped.jsValue(); - } - return jsValue; -} + if (UNLIKELY(state.argumentCount() < 1)) + return throwException(&state, scope, createNotEnoughArgumentsError(&state)); + + auto contextId = convert<IDLDOMString>(state, state.uncheckedArgument(0), StringConversionConfiguration::Normal); + RETURN_IF_EXCEPTION(scope, JSValue()); + + if (HTMLCanvasElement::is2dType(contextId)) + return toJS<IDLNullable<IDLInterface<CanvasRenderingContext2D>>>(state, *globalObject(), static_cast<CanvasRenderingContext2D*>(wrapped().getContext2d(contextId))); -JSValue JSHTMLCanvasElement::probablySupportsContext(ExecState* exec) -{ - HTMLCanvasElement& canvas = impl(); - if (!exec->argumentCount()) - return jsBoolean(false); - const String& contextId = exec->uncheckedArgument(0).toString(exec)->value(exec); - if (exec->hadException()) - return jsUndefined(); - - RefPtr<CanvasContextAttributes> attrs; #if ENABLE(WEBGL) if (HTMLCanvasElement::is3dType(contextId)) { - get3DContextAttributes(exec, attrs); - if (exec->hadException()) - return jsUndefined(); + auto attributes = convert<IDLDictionary<WebGLContextAttributes>>(state, state.argument(1)); + RETURN_IF_EXCEPTION(scope, JSValue()); + + return toJS<IDLNullable<IDLInterface<WebGLRenderingContextBase>>>(state, *globalObject(), static_cast<WebGLRenderingContextBase*>(wrapped().getContextWebGL(contextId, WTFMove(attributes)))); } #endif - - return jsBoolean(canvas.probablySupportsContext(contextId, attrs.get())); + + return jsNull(); } -JSValue JSHTMLCanvasElement::toDataURL(ExecState* exec) +JSValue JSHTMLCanvasElement::toDataURL(ExecState& state) { - HTMLCanvasElement& canvas = impl(); - ExceptionCode ec = 0; - - const String& type = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); - double quality; - double* qualityPtr = 0; - if (exec->argumentCount() > 1) { - JSValue v = exec->uncheckedArgument(1); - if (v.isNumber()) { - quality = v.toNumber(exec); - qualityPtr = &quality; - } - } + VM& vm = state.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + auto type = convert<IDLNullable<IDLDOMString>>(state, state.argument(0)); + RETURN_IF_EXCEPTION(scope, JSC::JSValue()); - JSValue result = JSC::jsString(exec, canvas.toDataURL(type, qualityPtr, ec)); - setDOMException(exec, ec); - return result; + std::optional<double> quality; + auto qualityValue = state.argument(1); + if (qualityValue.isNumber()) + quality = qualityValue.toNumber(&state); + + // We would use toJS<IDLString> here, but it uses jsStringWithCache and we historically + // did not cache here, presumably because results are likely to be differing long strings. + auto result = wrapped().toDataURL(type, quality); + if (result.hasException()) { + propagateException(state, scope, result.releaseException()); + return { }; + } + return jsString(&state, result.releaseReturnValue()); } } // namespace WebCore |