Index: Source/WebCore/bindings/dart/custom/DartNodeCustom.cpp |
diff --git a/Source/WebCore/bindings/dart/custom/DartNodeCustom.cpp b/Source/WebCore/bindings/dart/custom/DartNodeCustom.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..43552a3d52d8bd36e06be118a60ef9eba7efec7f |
--- /dev/null |
+++ b/Source/WebCore/bindings/dart/custom/DartNodeCustom.cpp |
@@ -0,0 +1,226 @@ |
+// Copyright 2011, 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. |
+ |
+#include "config.h" |
+#include "DartNode.h" |
+ |
+#include "DartAttr.h" |
+#include "DartCDATASection.h" |
+#include "DartComment.h" |
+#include "DartDOMWrapper.h" |
+#include "DartDocument.h" |
+#include "DartDocumentFragment.h" |
+#include "DartDocumentType.h" |
+#include "DartElement.h" |
+#include "DartEntity.h" |
+#include "DartEntityReference.h" |
+#include "DartNode.h" |
+#include "DartNotation.h" |
+#include "DartProcessingInstruction.h" |
+#include "DartText.h" |
+ |
+namespace WebCore { |
+ |
+namespace DartNodeInternal { |
+ |
+// This function is customized to take advantage of the optional 4th argument: shouldLazyAttach. |
+void insertBeforeCallback(Dart_NativeArguments args) |
+{ |
+ DartApiScope dartApiScope; |
+ Dart_Handle exception; |
+ { |
+ Node* receiver = DartDOMWrapper::receiver<Node>(args); |
+ |
+ const ParameterAdapter<RefPtr<Node>, DartNode> newChild(Dart_GetNativeArgument(args, 1)); |
+ if (!newChild.conversionSuccessful()) { |
+ exception = newChild.exception(); |
+ goto fail; |
+ } |
+ |
+ const ParameterAdapter<RefPtr<Node>, DartNode> refChild(Dart_GetNativeArgument(args, 2)); |
+ if (!refChild.conversionSuccessful()) { |
+ exception = refChild.exception(); |
+ goto fail; |
+ } |
+ |
+ ExceptionCode ec = 0; |
+ bool success = receiver->insertBefore(newChild, refChild, ec, true); |
+ if (ec) { |
+ exception = DartDOMWrapper::exceptionCodeToDartException(ec); |
+ goto fail; |
+ } |
+ |
+ if (success) |
+ DartDOMWrapper::returnValue<Node*>(args, newChild); |
+ return; |
+ } |
+ |
+fail: |
+ Dart_ThrowException(exception); |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
+// This function is customized to take advantage of the optional 4th argument: shouldLazyAttach. |
+void replaceChildCallback(Dart_NativeArguments args) |
+{ |
+ DartApiScope dartApiScope; |
+ Dart_Handle exception; |
+ { |
+ Node* receiver = DartDOMWrapper::receiver<Node>(args); |
+ |
+ const ParameterAdapter<RefPtr<Node>, DartNode> newChild(Dart_GetNativeArgument(args, 1)); |
+ if (!newChild.conversionSuccessful()) { |
+ exception = newChild.exception(); |
+ goto fail; |
+ } |
+ |
+ const ParameterAdapter<RefPtr<Node>, DartNode> oldChild(Dart_GetNativeArgument(args, 2)); |
+ if (!oldChild.conversionSuccessful()) { |
+ exception = oldChild.exception(); |
+ goto fail; |
+ } |
+ |
+ ExceptionCode ec = 0; |
+ bool success = receiver->replaceChild(newChild, oldChild, ec, true); |
+ if (ec) { |
+ exception = DartDOMWrapper::exceptionCodeToDartException(ec); |
+ goto fail; |
+ } |
+ |
+ if (success) |
+ DartDOMWrapper::returnValue<Node*>(args, newChild); |
+ return; |
+ } |
+ |
+fail: |
+ Dart_ThrowException(exception); |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
+// Custom handling of the return value. |
+void removeChildCallback(Dart_NativeArguments args) |
+{ |
+ DartApiScope dartApiScope; |
+ Dart_Handle exception; |
+ { |
+ Node* receiver = DartDOMWrapper::receiver<Node>(args); |
+ |
+ const ParameterAdapter<RefPtr<Node>, DartNode> child(Dart_GetNativeArgument(args, 1)); |
+ if (!child.conversionSuccessful()) { |
+ exception = child.exception(); |
+ goto fail; |
+ } |
+ |
+ ExceptionCode ec = 0; |
+ bool success = receiver->removeChild(child, ec); |
+ if (ec) { |
+ exception = DartDOMWrapper::exceptionCodeToDartException(ec); |
+ goto fail; |
+ } |
+ |
+ if (success) |
+ DartDOMWrapper::returnValue<Node*>(args, child); |
+ return; |
+ } |
+ |
+fail: |
+ Dart_ThrowException(exception); |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
+// This function is customized to enable lazy attaching - see the last argument to appendChild. |
+void appendChildCallback(Dart_NativeArguments args) |
+{ |
+ DartApiScope dartApiScope; |
+ Dart_Handle exception; |
+ { |
+ Node* receiver = DartDOMWrapper::receiver<Node>(args); |
+ |
+ const ParameterAdapter<RefPtr<Node>, DartNode> child(Dart_GetNativeArgument(args, 1)); |
+ if (!child.conversionSuccessful()) { |
+ exception = child.exception(); |
+ goto fail; |
+ } |
+ |
+ ExceptionCode ec = 0; |
+ bool success = receiver->appendChild(child, ec, true); |
+ if (ec) { |
+ exception = DartDOMWrapper::exceptionCodeToDartException(ec); |
+ goto fail; |
+ } |
+ |
+ if (success) |
+ DartDOMWrapper::returnValue<Node*>(args, child); |
+ return; |
+ } |
+ |
+fail: |
+ Dart_ThrowException(exception); |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
+} |
+ |
+Dart_Handle toDartValue(Node* node) |
+{ |
+ if (!node) |
+ return 0; |
+ |
+ switch (node->nodeType()) { |
+ case Node::ELEMENT_NODE: |
+ return toDartValue(static_cast<Element*>(node)); |
+ case Node::ATTRIBUTE_NODE: |
+ return toDartValue(static_cast<Attr*>(node)); |
+ case Node::TEXT_NODE: |
+ return toDartValue(static_cast<Text*>(node)); |
+ case Node::CDATA_SECTION_NODE: |
+ return toDartValue(static_cast<CDATASection*>(node)); |
+ case Node::ENTITY_REFERENCE_NODE: |
+ return toDartValue(static_cast<EntityReference*>(node)); |
+ case Node::ENTITY_NODE: |
+ return toDartValue(static_cast<Entity*>(node)); |
+ case Node::PROCESSING_INSTRUCTION_NODE: |
+ return toDartValue(static_cast<ProcessingInstruction*>(node)); |
+ case Node::COMMENT_NODE: |
+ return toDartValue(static_cast<Comment*>(node)); |
+ case Node::DOCUMENT_NODE: |
+ return toDartValue(static_cast<Document*>(node)); |
+ case Node::DOCUMENT_TYPE_NODE: |
+ return toDartValue(static_cast<DocumentType*>(node)); |
+ case Node::DOCUMENT_FRAGMENT_NODE: |
+ return toDartValue(static_cast<DocumentFragment*>(node)); |
+ case Node::NOTATION_NODE: |
+ return toDartValue(static_cast<Notation*>(node)); |
+ case Node::SHADOW_ROOT_NODE: // There's no IDL class for ShadowRoot, fall-through to default and use Node instead. |
+ default: break; // XPATH_NAMESPACE_NODE |
+ } |
+ return DartDOMWrapper::toDart<DartNode>(node); |
+} |
+ |
+} |