OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2010 Google Inc. 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 |
| 31 #include "config.h" |
| 32 #include "DartScriptArguments.h" |
| 33 |
| 34 #include "DartIsolateState.h" |
| 35 #include "DartUtilities.h" |
| 36 #include "InspectorValues.h" |
| 37 #include "ScriptValue.h" |
| 38 |
| 39 namespace WebCore { |
| 40 |
| 41 static PassRefPtr<InspectorValue> toInspectorValue(Dart_Handle value) |
| 42 { |
| 43 if (Dart_IsNull(value)) |
| 44 return InspectorValue::null(); |
| 45 if (Dart_IsInteger(value)) |
| 46 return InspectorBasicValue::create(DartUtilities::toDouble(value)); |
| 47 if (Dart_IsBoolean(value)) |
| 48 return InspectorBasicValue::create(DartUtilities::toBool(value)); |
| 49 if (Dart_IsDouble(value)) |
| 50 return InspectorBasicValue::create(DartUtilities::toDouble(value)); |
| 51 if (Dart_IsString(value)) |
| 52 return InspectorString::create(DartUtilities::dartStringToString(value))
; |
| 53 if (Dart_IsList(value)) { |
| 54 // FIXME: implement Dart list conversion. |
| 55 return InspectorString::create("[...]"); |
| 56 } |
| 57 // FIXME: implement Dart object conversion. |
| 58 return InspectorString::create("{...}"); |
| 59 } |
| 60 |
| 61 PassRefPtr<DartScriptArguments> DartScriptArguments::create(Dart_Handle argument
, Dart_Isolate isolate) |
| 62 { |
| 63 return adoptRef(new DartScriptArguments(argument, isolate)); |
| 64 } |
| 65 |
| 66 DartScriptArguments::DartScriptArguments(Dart_Handle argument, Dart_Isolate isol
ate) |
| 67 : m_argument(argument) |
| 68 , m_isolate(isolate) |
| 69 { |
| 70 } |
| 71 |
| 72 DartScriptArguments::~DartScriptArguments() |
| 73 { |
| 74 // FIXME: isolate can already be shut down at this point, so we can't delete |
| 75 // persistent handle here safely. |
| 76 // Uncomment this when isolate lifetime is managed more carefully. |
| 77 // DartIsolateState::push(m_isolate); |
| 78 // Dart_DeletePersistentHandle(m_argument); |
| 79 // DartIsolateState::pop(); |
| 80 } |
| 81 |
| 82 PassRefPtr<InspectorArray> DartScriptArguments::wrap(InjectedScriptManager*) con
st |
| 83 { |
| 84 DartIsolateState::Scope scope(m_isolate); |
| 85 DartApiScope apiScope; |
| 86 RefPtr<InspectorArray> wrappedArguments = InspectorArray::create(); |
| 87 wrappedArguments->pushValue(toInspectorValue(m_argument)); |
| 88 return wrappedArguments.release(); |
| 89 } |
| 90 |
| 91 bool DartScriptArguments::argumentGetString(size_t index, String& result) const |
| 92 { |
| 93 if (index >= argumentCount()) |
| 94 return false; |
| 95 if (!Dart_IsString(m_argument)) |
| 96 return false; |
| 97 result = DartUtilities::dartStringToString(m_argument); |
| 98 return true; |
| 99 } |
| 100 |
| 101 bool DartScriptArguments::argumentToString(size_t index, String& result) const |
| 102 { |
| 103 if (index >= argumentCount()) |
| 104 return false; |
| 105 Dart_Handle stringHandle = Dart_ToString(m_argument); |
| 106 if (!Dart_IsError(stringHandle)) |
| 107 result = DartUtilities::dartStringToString(stringHandle); |
| 108 return true; |
| 109 } |
| 110 |
| 111 ScriptValue DartScriptArguments::argumentAt(size_t index) const |
| 112 { |
| 113 return ScriptValue(); |
| 114 } |
| 115 |
| 116 |
| 117 } // namespace WebCore |
OLD | NEW |