| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011, Google Inc. | |
| 2 // All rights reserved. | |
| 3 // | |
| 4 // Redistribution and use in source and binary forms, with or without | |
| 5 // modification, are permitted provided that the following conditions are | |
| 6 // met: | |
| 7 // | |
| 8 // * Redistributions of source code must retain the above copyright | |
| 9 // notice, this list of conditions and the following disclaimer. | |
| 10 // * Redistributions in binary form must reproduce the above | |
| 11 // copyright notice, this list of conditions and the following disclaimer | |
| 12 // in the documentation and/or other materials provided with the | |
| 13 // distribution. | |
| 14 // * Neither the name of Google Inc. nor the names of its | |
| 15 // contributors may be used to endorse or promote products derived from | |
| 16 // this software without specific prior written permission. | |
| 17 // | |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 | |
| 30 #include "config.h" | |
| 31 #include "DartDOMStringMap.h" | |
| 32 | |
| 33 #include "DOMStringMap.h" | |
| 34 #include "DartDOMWrapper.h" | |
| 35 | |
| 36 namespace WebCore { | |
| 37 | |
| 38 namespace DartDOMStringMapInternal { | |
| 39 | |
| 40 void itemCallback(Dart_NativeArguments args) | |
| 41 { | |
| 42 DartApiScope dartApiScope; | |
| 43 Dart_Handle exception; | |
| 44 { | |
| 45 DOMStringMap* receiver = DartDOMWrapper::receiver< DOMStringMap >(args); | |
| 46 const ParameterAdapter< String > key(Dart_GetNativeArgument(args, 1)); | |
| 47 if (!key.conversionSuccessful()) { | |
| 48 exception = key.exception(); | |
| 49 goto fail; | |
| 50 } | |
| 51 | |
| 52 DartDOMWrapper::returnValue(args, receiver->item(key)); | |
| 53 return; | |
| 54 } | |
| 55 | |
| 56 fail: | |
| 57 Dart_ThrowException(exception); | |
| 58 ASSERT_NOT_REACHED(); | |
| 59 } | |
| 60 | |
| 61 void setItemCallback(Dart_NativeArguments args) | |
| 62 { | |
| 63 DartApiScope dartApiScope; | |
| 64 Dart_Handle exception; | |
| 65 { | |
| 66 DOMStringMap* receiver = DartDOMWrapper::receiver< DOMStringMap >(args); | |
| 67 const ParameterAdapter< String > key(Dart_GetNativeArgument(args, 1)); | |
| 68 if (!key.conversionSuccessful()) { | |
| 69 exception = key.exception(); | |
| 70 goto fail; | |
| 71 } | |
| 72 | |
| 73 const ParameterAdapter< String > value(Dart_GetNativeArgument(args, 2)); | |
| 74 if (!value.conversionSuccessful()) { | |
| 75 exception = value.exception(); | |
| 76 goto fail; | |
| 77 } | |
| 78 | |
| 79 ExceptionCode ec = 0; | |
| 80 receiver->setItem(key, value, ec); | |
| 81 if (UNLIKELY(ec)) { | |
| 82 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 83 goto fail; | |
| 84 } | |
| 85 | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 fail: | |
| 90 Dart_ThrowException(exception); | |
| 91 ASSERT_NOT_REACHED(); | |
| 92 } | |
| 93 | |
| 94 void getKeysCallback(Dart_NativeArguments args) | |
| 95 { | |
| 96 DartApiScope dartApiScope; | |
| 97 { | |
| 98 DOMStringMap* receiver = DartDOMWrapper::receiver< DOMStringMap >(args); | |
| 99 | |
| 100 Vector<String> names; | |
| 101 receiver->getNames(names); | |
| 102 | |
| 103 Dart_Handle list = Dart_NewList(names.size()); | |
| 104 for (size_t i = 0; i < names.size(); i++) | |
| 105 Dart_ListSetAt(list, i, DartUtilities::stringToDartString(names[i]))
; | |
| 106 | |
| 107 Dart_SetReturnValue(args, list); | |
| 108 return; | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void deleteItemCallback(Dart_NativeArguments args) | |
| 113 { | |
| 114 DartApiScope dartApiScope; | |
| 115 Dart_Handle exception; | |
| 116 { | |
| 117 DOMStringMap* receiver = DartDOMWrapper::receiver< DOMStringMap >(args); | |
| 118 const ParameterAdapter< String > key(Dart_GetNativeArgument(args, 1)); | |
| 119 if (!key.conversionSuccessful()) { | |
| 120 exception = key.exception(); | |
| 121 goto fail; | |
| 122 } | |
| 123 | |
| 124 if (receiver->contains(key)) { | |
| 125 String value = receiver->item(key); | |
| 126 | |
| 127 ExceptionCode ec = 0; | |
| 128 receiver->deleteItem(key, ec); | |
| 129 if (UNLIKELY(ec)) { | |
| 130 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 131 goto fail; | |
| 132 } | |
| 133 | |
| 134 DartDOMWrapper::returnValue(args, value); | |
| 135 } | |
| 136 | |
| 137 return; | |
| 138 } | |
| 139 | |
| 140 fail: | |
| 141 Dart_ThrowException(exception); | |
| 142 ASSERT_NOT_REACHED(); | |
| 143 } | |
| 144 | |
| 145 } | |
| 146 | |
| 147 } | |
| OLD | NEW |