| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "bindings/core/dart/DartDOMStringMap.h" | |
| 7 | |
| 8 namespace blink { | |
| 9 | |
| 10 namespace DartDOMStringMapInternal { | |
| 11 | |
| 12 static void containsKeyCallback(Dart_NativeArguments args) | |
| 13 { | |
| 14 Dart_Handle exception = 0; | |
| 15 { | |
| 16 DOMStringMap* receiver = DartDOMWrapper::receiver<DOMStringMap>(args); | |
| 17 | |
| 18 DartStringAdapter key = DartUtilities::dartToString(args, 1, exception); | |
| 19 if (exception) | |
| 20 goto fail; | |
| 21 | |
| 22 Dart_SetReturnValue(args, DartUtilities::boolToDart(receiver->contains(k
ey))); | |
| 23 return; | |
| 24 } | |
| 25 | |
| 26 fail: | |
| 27 Dart_ThrowException(exception); | |
| 28 ASSERT_NOT_REACHED(); | |
| 29 } | |
| 30 | |
| 31 static void itemCallback(Dart_NativeArguments args) | |
| 32 { | |
| 33 Dart_Handle exception = 0; | |
| 34 { | |
| 35 DOMStringMap* receiver = DartDOMWrapper::receiver<DOMStringMap>(args); | |
| 36 | |
| 37 DartStringAdapter key = DartUtilities::dartToString(args, 1, exception); | |
| 38 if (exception) | |
| 39 goto fail; | |
| 40 | |
| 41 Dart_SetReturnValue(args, DartUtilities::stringToDart(receiver->item(key
))); | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 fail: | |
| 46 Dart_ThrowException(exception); | |
| 47 ASSERT_NOT_REACHED(); | |
| 48 } | |
| 49 | |
| 50 static void setItemCallback(Dart_NativeArguments args) | |
| 51 { | |
| 52 Dart_Handle exception = 0; | |
| 53 { | |
| 54 DOMStringMap* receiver = DartDOMWrapper::receiver<DOMStringMap>(args); | |
| 55 | |
| 56 DartStringAdapter key = DartUtilities::dartToString(args, 1, exception); | |
| 57 if (exception) | |
| 58 goto fail; | |
| 59 | |
| 60 DartStringAdapter value = DartUtilities::dartToString(args, 2, exception
); | |
| 61 if (exception) | |
| 62 goto fail; | |
| 63 | |
| 64 DartExceptionState es; | |
| 65 receiver->setItem(key, value, es); | |
| 66 if (es.hadException()) { | |
| 67 exception = es.toDart(args); | |
| 68 goto fail; | |
| 69 } | |
| 70 | |
| 71 return; | |
| 72 } | |
| 73 | |
| 74 fail: | |
| 75 Dart_ThrowException(exception); | |
| 76 ASSERT_NOT_REACHED(); | |
| 77 } | |
| 78 | |
| 79 static void removeCallback(Dart_NativeArguments args) | |
| 80 { | |
| 81 Dart_Handle exception = 0; | |
| 82 { | |
| 83 DOMStringMap* receiver = DartDOMWrapper::receiver<DOMStringMap>(args); | |
| 84 | |
| 85 DartStringAdapter key = DartUtilities::dartToString(args, 1, exception); | |
| 86 if (exception) | |
| 87 goto fail; | |
| 88 | |
| 89 String value = receiver->item(key); | |
| 90 | |
| 91 // FIXMEDART: is the signature for removeCallback now incorrect? Should | |
| 92 // we instead just return the boolean return value of | |
| 93 // receiver->deleteItem(key)? | |
| 94 receiver->deleteItem(key); | |
| 95 Dart_SetReturnValue(args, DartUtilities::stringToDartWithNullCheck(value
)); | |
| 96 return; | |
| 97 } | |
| 98 | |
| 99 fail: | |
| 100 Dart_ThrowException(exception); | |
| 101 ASSERT_NOT_REACHED(); | |
| 102 } | |
| 103 | |
| 104 static void getKeysCallback(Dart_NativeArguments args) | |
| 105 { | |
| 106 Dart_Handle exception = 0; | |
| 107 { | |
| 108 DOMStringMap* receiver = DartDOMWrapper::receiver<DOMStringMap>(args); | |
| 109 | |
| 110 Vector<String> names; | |
| 111 receiver->getNames(names); | |
| 112 | |
| 113 Dart_Handle result = Dart_NewList(names.size()); | |
| 114 if (!DartUtilities::checkResult(result, exception)) | |
| 115 goto fail; | |
| 116 | |
| 117 for (size_t i = 0; i < names.size(); ++i) | |
| 118 Dart_ListSetAt(result, i, DartUtilities::stringToDartString(names[i]
)); | |
| 119 | |
| 120 Dart_SetReturnValue(args, result); | |
| 121 return; | |
| 122 } | |
| 123 | |
| 124 fail: | |
| 125 Dart_ThrowException(exception); | |
| 126 ASSERT_NOT_REACHED(); | |
| 127 } | |
| 128 | |
| 129 } | |
| 130 | |
| 131 static DartNativeEntry nativeEntries[] = { | |
| 132 { DartDOMStringMapInternal::containsKeyCallback, 2, "DOMStringMap_containsKe
y_Callback" }, | |
| 133 { DartDOMStringMapInternal::itemCallback, 2, "DOMStringMap_item_Callback" }, | |
| 134 { DartDOMStringMapInternal::setItemCallback, 3, "DOMStringMap_setItem_Callba
ck" }, | |
| 135 { DartDOMStringMapInternal::removeCallback, 2, "DOMStringMap_remove_Callback
" }, | |
| 136 { DartDOMStringMapInternal::getKeysCallback, 1, "DOMStringMap_getKeys_Callba
ck" }, | |
| 137 { 0, 0, 0 } | |
| 138 }; | |
| 139 | |
| 140 Dart_NativeFunction customDartDOMStringMapResolver(Dart_Handle nameHandle, int a
rgumentCount, bool* autoSetupScope) | |
| 141 { | |
| 142 ASSERT(autoSetupScope); | |
| 143 *autoSetupScope = true; | |
| 144 String name = DartUtilities::toString(nameHandle); | |
| 145 | |
| 146 for (intptr_t i = 0; nativeEntries[i].nativeFunction != 0; i++) { | |
| 147 if (argumentCount == nativeEntries[i].argumentCount && name == nativeEnt
ries[i].name) { | |
| 148 return nativeEntries[i].nativeFunction; | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 return 0; | |
| 153 } | |
| 154 | |
| 155 const uint8_t* customDartDOMStringMapSymbolizer(Dart_NativeFunction nf) | |
| 156 { | |
| 157 for (intptr_t i = 0; nativeEntries[i].nativeFunction != 0; i++) { | |
| 158 if (nf == nativeEntries[i].nativeFunction) { | |
| 159 return reinterpret_cast<const uint8_t*>(nativeEntries[i].name); | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 return 0; | |
| 164 } | |
| 165 | |
| 166 } | |
| OLD | NEW |