| 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 "DartNode.h" | |
| 32 | |
| 33 #include "DartAttr.h" | |
| 34 #include "DartCDATASection.h" | |
| 35 #include "DartComment.h" | |
| 36 #include "DartDOMWrapper.h" | |
| 37 #include "DartDocument.h" | |
| 38 #include "DartDocumentFragment.h" | |
| 39 #include "DartDocumentType.h" | |
| 40 #include "DartElement.h" | |
| 41 #include "DartEntity.h" | |
| 42 #include "DartEntityReference.h" | |
| 43 #include "DartNode.h" | |
| 44 #include "DartNotation.h" | |
| 45 #include "DartProcessingInstruction.h" | |
| 46 #include "DartText.h" | |
| 47 | |
| 48 namespace WebCore { | |
| 49 | |
| 50 namespace DartNodeInternal { | |
| 51 | |
| 52 // This function is customized to take advantage of the optional 4th argument: s
houldLazyAttach. | |
| 53 void insertBeforeCallback(Dart_NativeArguments args) | |
| 54 { | |
| 55 DartApiScope dartApiScope; | |
| 56 Dart_Handle exception; | |
| 57 { | |
| 58 Node* receiver = DartDOMWrapper::receiver<Node>(args); | |
| 59 | |
| 60 const ParameterAdapter<RefPtr<Node>, DartNode> newChild(Dart_GetNativeAr
gument(args, 1)); | |
| 61 if (!newChild.conversionSuccessful()) { | |
| 62 exception = newChild.exception(); | |
| 63 goto fail; | |
| 64 } | |
| 65 | |
| 66 const ParameterAdapter<RefPtr<Node>, DartNode> refChild(Dart_GetNativeAr
gument(args, 2)); | |
| 67 if (!refChild.conversionSuccessful()) { | |
| 68 exception = refChild.exception(); | |
| 69 goto fail; | |
| 70 } | |
| 71 | |
| 72 ExceptionCode ec = 0; | |
| 73 bool success = receiver->insertBefore(newChild, refChild, ec, true); | |
| 74 if (ec) { | |
| 75 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 76 goto fail; | |
| 77 } | |
| 78 | |
| 79 if (success) | |
| 80 DartDOMWrapper::returnValue<Node*>(args, newChild); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 fail: | |
| 85 Dart_ThrowException(exception); | |
| 86 ASSERT_NOT_REACHED(); | |
| 87 } | |
| 88 | |
| 89 // This function is customized to take advantage of the optional 4th argument: s
houldLazyAttach. | |
| 90 void replaceChildCallback(Dart_NativeArguments args) | |
| 91 { | |
| 92 DartApiScope dartApiScope; | |
| 93 Dart_Handle exception; | |
| 94 { | |
| 95 Node* receiver = DartDOMWrapper::receiver<Node>(args); | |
| 96 | |
| 97 const ParameterAdapter<RefPtr<Node>, DartNode> newChild(Dart_GetNativeAr
gument(args, 1)); | |
| 98 if (!newChild.conversionSuccessful()) { | |
| 99 exception = newChild.exception(); | |
| 100 goto fail; | |
| 101 } | |
| 102 | |
| 103 const ParameterAdapter<RefPtr<Node>, DartNode> oldChild(Dart_GetNativeAr
gument(args, 2)); | |
| 104 if (!oldChild.conversionSuccessful()) { | |
| 105 exception = oldChild.exception(); | |
| 106 goto fail; | |
| 107 } | |
| 108 | |
| 109 ExceptionCode ec = 0; | |
| 110 bool success = receiver->replaceChild(newChild, oldChild, ec, true); | |
| 111 if (ec) { | |
| 112 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 113 goto fail; | |
| 114 } | |
| 115 | |
| 116 if (success) | |
| 117 DartDOMWrapper::returnValue<Node*>(args, newChild); | |
| 118 return; | |
| 119 } | |
| 120 | |
| 121 fail: | |
| 122 Dart_ThrowException(exception); | |
| 123 ASSERT_NOT_REACHED(); | |
| 124 } | |
| 125 | |
| 126 // Custom handling of the return value. | |
| 127 void removeChildCallback(Dart_NativeArguments args) | |
| 128 { | |
| 129 DartApiScope dartApiScope; | |
| 130 Dart_Handle exception; | |
| 131 { | |
| 132 Node* receiver = DartDOMWrapper::receiver<Node>(args); | |
| 133 | |
| 134 const ParameterAdapter<RefPtr<Node>, DartNode> child(Dart_GetNativeArgum
ent(args, 1)); | |
| 135 if (!child.conversionSuccessful()) { | |
| 136 exception = child.exception(); | |
| 137 goto fail; | |
| 138 } | |
| 139 | |
| 140 ExceptionCode ec = 0; | |
| 141 bool success = receiver->removeChild(child, ec); | |
| 142 if (ec) { | |
| 143 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 144 goto fail; | |
| 145 } | |
| 146 | |
| 147 if (success) | |
| 148 DartDOMWrapper::returnValue<Node*>(args, child); | |
| 149 return; | |
| 150 } | |
| 151 | |
| 152 fail: | |
| 153 Dart_ThrowException(exception); | |
| 154 ASSERT_NOT_REACHED(); | |
| 155 } | |
| 156 | |
| 157 // This function is customized to enable lazy attaching - see the last argument
to appendChild. | |
| 158 void appendChildCallback(Dart_NativeArguments args) | |
| 159 { | |
| 160 DartApiScope dartApiScope; | |
| 161 Dart_Handle exception; | |
| 162 { | |
| 163 Node* receiver = DartDOMWrapper::receiver<Node>(args); | |
| 164 | |
| 165 const ParameterAdapter<RefPtr<Node>, DartNode> child(Dart_GetNativeArgum
ent(args, 1)); | |
| 166 if (!child.conversionSuccessful()) { | |
| 167 exception = child.exception(); | |
| 168 goto fail; | |
| 169 } | |
| 170 | |
| 171 ExceptionCode ec = 0; | |
| 172 bool success = receiver->appendChild(child, ec, true); | |
| 173 if (ec) { | |
| 174 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 175 goto fail; | |
| 176 } | |
| 177 | |
| 178 if (success) | |
| 179 DartDOMWrapper::returnValue<Node*>(args, child); | |
| 180 return; | |
| 181 } | |
| 182 | |
| 183 fail: | |
| 184 Dart_ThrowException(exception); | |
| 185 ASSERT_NOT_REACHED(); | |
| 186 } | |
| 187 | |
| 188 } | |
| 189 | |
| 190 Dart_Handle toDartValue(Node* node) | |
| 191 { | |
| 192 if (!node) | |
| 193 return 0; | |
| 194 | |
| 195 switch (node->nodeType()) { | |
| 196 case Node::ELEMENT_NODE: | |
| 197 return toDartValue(static_cast<Element*>(node)); | |
| 198 case Node::ATTRIBUTE_NODE: | |
| 199 return toDartValue(static_cast<Attr*>(node)); | |
| 200 case Node::TEXT_NODE: | |
| 201 return toDartValue(static_cast<Text*>(node)); | |
| 202 case Node::CDATA_SECTION_NODE: | |
| 203 return toDartValue(static_cast<CDATASection*>(node)); | |
| 204 case Node::ENTITY_REFERENCE_NODE: | |
| 205 return toDartValue(static_cast<EntityReference*>(node)); | |
| 206 case Node::ENTITY_NODE: | |
| 207 return toDartValue(static_cast<Entity*>(node)); | |
| 208 case Node::PROCESSING_INSTRUCTION_NODE: | |
| 209 return toDartValue(static_cast<ProcessingInstruction*>(node)); | |
| 210 case Node::COMMENT_NODE: | |
| 211 return toDartValue(static_cast<Comment*>(node)); | |
| 212 case Node::DOCUMENT_NODE: | |
| 213 return toDartValue(static_cast<Document*>(node)); | |
| 214 case Node::DOCUMENT_TYPE_NODE: | |
| 215 return toDartValue(static_cast<DocumentType*>(node)); | |
| 216 case Node::DOCUMENT_FRAGMENT_NODE: | |
| 217 return toDartValue(static_cast<DocumentFragment*>(node)); | |
| 218 case Node::NOTATION_NODE: | |
| 219 return toDartValue(static_cast<Notation*>(node)); | |
| 220 case Node::SHADOW_ROOT_NODE: // There's no IDL class for ShadowRoot, fall-th
rough to default and use Node instead. | |
| 221 default: break; // XPATH_NAMESPACE_NODE | |
| 222 } | |
| 223 return DartDOMWrapper::toDart<DartNode>(node); | |
| 224 } | |
| 225 | |
| 226 } | |
| OLD | NEW |