Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Unified Diff: Source/WebCore/bindings/dart/DartScriptArguments.cpp

Issue 8802010: Dart bindings for WebKit (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/WebCore/bindings/dart/DartScriptArguments.cpp
diff --git a/Source/WebCore/bindings/dart/DartScriptArguments.cpp b/Source/WebCore/bindings/dart/DartScriptArguments.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0cadf464f83a51d346c9457a3887ed0d2ab9d61b
--- /dev/null
+++ b/Source/WebCore/bindings/dart/DartScriptArguments.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2010 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 "DartScriptArguments.h"
+
+#include "DartIsolateState.h"
+#include "DartUtilities.h"
+#include "InspectorValues.h"
+#include "ScriptValue.h"
+
+namespace WebCore {
+
+static PassRefPtr<InspectorValue> toInspectorValue(Dart_Handle value)
+{
+ if (Dart_IsNull(value))
+ return InspectorValue::null();
+ if (Dart_IsInteger(value))
+ return InspectorBasicValue::create(DartUtilities::toDouble(value));
+ if (Dart_IsBoolean(value))
+ return InspectorBasicValue::create(DartUtilities::toBool(value));
+ if (Dart_IsDouble(value))
+ return InspectorBasicValue::create(DartUtilities::toDouble(value));
+ if (Dart_IsString(value))
+ return InspectorString::create(DartUtilities::dartStringToString(value));
+ if (Dart_IsList(value)) {
+ // FIXME: implement Dart list conversion.
+ return InspectorString::create("[...]");
+ }
+ // FIXME: implement Dart object conversion.
+ return InspectorString::create("{...}");
+}
+
+PassRefPtr<DartScriptArguments> DartScriptArguments::create(Dart_Handle argument, Dart_Isolate isolate)
+{
+ return adoptRef(new DartScriptArguments(argument, isolate));
+}
+
+DartScriptArguments::DartScriptArguments(Dart_Handle argument, Dart_Isolate isolate)
+ : m_argument(argument)
+ , m_isolate(isolate)
+{
+}
+
+DartScriptArguments::~DartScriptArguments()
+{
+ // FIXME: isolate can already be shut down at this point, so we can't delete
+ // persistent handle here safely.
+ // Uncomment this when isolate lifetime is managed more carefully.
+ // DartIsolateState::push(m_isolate);
+ // Dart_DeletePersistentHandle(m_argument);
+ // DartIsolateState::pop();
+}
+
+PassRefPtr<InspectorArray> DartScriptArguments::wrap(InjectedScriptManager*) const
+{
+ DartIsolateState::Scope scope(m_isolate);
+ DartApiScope apiScope;
+ RefPtr<InspectorArray> wrappedArguments = InspectorArray::create();
+ wrappedArguments->pushValue(toInspectorValue(m_argument));
+ return wrappedArguments.release();
+}
+
+bool DartScriptArguments::argumentGetString(size_t index, String& result) const
+{
+ if (index >= argumentCount())
+ return false;
+ if (!Dart_IsString(m_argument))
+ return false;
+ result = DartUtilities::dartStringToString(m_argument);
+ return true;
+}
+
+bool DartScriptArguments::argumentToString(size_t index, String& result) const
+{
+ if (index >= argumentCount())
+ return false;
+ Dart_Handle stringHandle = Dart_ToString(m_argument);
+ if (!Dart_IsError(stringHandle))
+ result = DartUtilities::dartStringToString(stringHandle);
+ return true;
+}
+
+ScriptValue DartScriptArguments::argumentAt(size_t index) const
+{
+ return ScriptValue();
+}
+
+
+} // namespace WebCore
« no previous file with comments | « Source/WebCore/bindings/dart/DartScriptArguments.h ('k') | Source/WebCore/bindings/dart/DartScriptValueDeserializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698