Chromium Code Reviews| Index: Source/WebCore/bindings/dart/custom/DartArrayBufferViewCustom.h |
| diff --git a/Source/WebCore/bindings/dart/custom/DartArrayBufferViewCustom.h b/Source/WebCore/bindings/dart/custom/DartArrayBufferViewCustom.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..187c77aa14ab44116430c34d02c9efc9b563c1da |
| --- /dev/null |
| +++ b/Source/WebCore/bindings/dart/custom/DartArrayBufferViewCustom.h |
| @@ -0,0 +1,154 @@ |
| +/* |
| + * Copyright (C) 2009, 2012 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 DartArrayBufferViewCustom_h |
| +#define DartArrayBufferViewCustom_h |
| + |
| +#include "DartUtilities.h" |
| + |
| +#include <dart_api.h> |
| + |
| +namespace WebCore { |
| + |
| +namespace DartArrayBufferViewInternal { |
| + |
| +template<class ArrayClass, class ElementType> |
| +void constructWebGLArray(Dart_NativeArguments args) |
| +{ |
| + DartApiScope dartApiScope; |
| + Dart_Handle exception; |
| + { |
| + Dart_Handle arg1 = Dart_GetNativeArgument(args, 1); |
| + RefPtr<ArrayClass> array; |
| + if (Dart_IsNumber(arg1)) { |
| + ParameterAdapter<int> length(arg1); |
| + if (!length.conversionSuccessful()) { |
| + exception = length.exception(); |
| + goto fail; |
| + } |
| + array = ArrayClass::create(length); |
| + } else { |
| + ParameterAdapter<Vector<ElementType> > list(arg1); |
| + if (!list.conversionSuccessful()) { |
| + exception = list.exception(); |
| + goto fail; |
| + } |
| + array = ArrayClass::create(list->data(), list->size()); |
| + } |
| + // FIXME: also process 3 argument constructor. |
| + DartDOMWrapper::bindDOMObjectToDartWrapper(array.get(), Dart_GetNativeArgument(args, 0)); |
| + return; |
| + } |
| + |
| +fail: |
| + Dart_ThrowException(exception); |
| + ASSERT_NOT_REACHED(); |
| +} |
| + |
| +template <class ArrayClass, class DartArrayClass> |
| +void setWebGLArrayHelper(Dart_NativeArguments args) |
| +{ |
| + DartApiScope dartApiScope; |
| + Dart_Handle exception; |
| + { |
| + ArrayClass* receiver = DartDOMWrapper::receiver<ArrayClass>(args); |
| + ParameterAdapter<ArrayClass, DartArrayClass> arrayParam(Dart_GetNativeArgument(args, 1)); |
| + if (!arrayParam.conversionSuccessful()) { |
| + exception = arrayParam.exception(); |
| + goto fail; |
| + } |
| + ParameterAdapter<int> offsetParam(Dart_GetNativeArgument(args, 2)); |
| + if (!offsetParam.conversionSuccessful()) { |
| + exception = offsetParam.exception(); |
| + goto fail; |
| + } |
| + |
| + receiver->set(arrayParam, offsetParam); |
| + return; |
| + } |
| + |
| +fail: |
| + Dart_ThrowException(exception); |
| + ASSERT_NOT_REACHED(); |
| +} |
| + |
| +template <class ArrayClass, class ElementType> |
| +void indexGetter(Dart_NativeArguments args) |
| +{ |
| + DartApiScope dartApiScope; |
| + Dart_Handle exception; |
| + { |
| + ArrayClass* receiver = DartDOMWrapper::receiver<ArrayClass>(args); |
| + const ParameterAdapter<unsigned int> index(Dart_GetNativeArgument(args, 1)); |
| + if (!index.conversionSuccessful()) { |
| + exception = index.exception(); |
| + goto fail; |
| + } |
| + |
| + DartDOMWrapper::returnValue(args, static_cast<ElementType>(receiver->item(index))); |
|
antonm
2012/01/18 15:12:23
do we need this static_cast, just double checking?
Nikolay
2012/01/19 13:27:34
Yes, we do.
On 2012/01/18 15:12:23, antonm wrote:
|
| + return; |
| + } |
| + |
| +fail: |
| + Dart_ThrowException(exception); |
| + ASSERT_NOT_REACHED(); |
| +} |
| + |
| +template <class ArrayClass, class ElementType> |
| +void indexSetter(Dart_NativeArguments args) |
| +{ |
| + DartApiScope dartApiScope; |
| + Dart_Handle exception; |
| + { |
| + ArrayClass* receiver = DartDOMWrapper::receiver<ArrayClass>(args); |
| + const ParameterAdapter<unsigned int> index(Dart_GetNativeArgument(args, 1)); |
| + if (!index.conversionSuccessful()) { |
| + exception = index.exception(); |
| + goto fail; |
| + } |
| + const ParameterAdapter<double> value(Dart_GetNativeArgument(args, 2)); |
| + if (!value.conversionSuccessful()) { |
| + exception = value.exception(); |
| + goto fail; |
| + } |
| + |
| + receiver->set(index, value); |
| + return; |
| + } |
| + |
| +fail: |
| + Dart_ThrowException(exception); |
| + ASSERT_NOT_REACHED(); |
| +} |
| + |
| +} |
| + |
| +} |
| +#endif // DartArrayBufferViewCustom_h |