OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 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 "bindings/core/dart/DartScriptValue.h" |
| 33 |
| 34 #include "bindings/core/dart/DartUtilities.h" |
| 35 #include "bindings/core/dart/V8Converter.h" |
| 36 #include "platform/JSONValues.h" |
| 37 #include "platform/SharedBuffer.h" |
| 38 |
| 39 namespace blink { |
| 40 |
| 41 DartScriptValue::~DartScriptValue() |
| 42 { |
| 43 } |
| 44 |
| 45 bool DartScriptValue::toString(String& result) const |
| 46 { |
| 47 if (isEmpty()) |
| 48 return false; |
| 49 |
| 50 DartIsolateScope(m_scriptState->isolate()); |
| 51 DartApiScope apiScope; |
| 52 |
| 53 Dart_Handle exception = 0; |
| 54 DartStringAdapter string = DartUtilities::dartToString(Dart_ToString(dartVal
ue()), exception); |
| 55 if (exception) |
| 56 return false; |
| 57 result = string; |
| 58 return true; |
| 59 } |
| 60 |
| 61 // FIXMEDART: Implement without conversion to v8. |
| 62 PassRefPtr<JSONValue> DartScriptValue::toJSONValue(ScriptState* scriptState) con
st |
| 63 { |
| 64 Dart_Handle exception = 0; |
| 65 v8::Handle<v8::Value> v8Value = V8Converter::toV8(dartValue(), exception); |
| 66 if (exception) { |
| 67 ASSERT_NOT_REACHED(); |
| 68 return nullptr; |
| 69 } |
| 70 ScriptValue v8ScriptValue(m_scriptState->v8ScriptState(), v8Value); |
| 71 return v8ScriptValue.toJSONValue(scriptState); |
| 72 } |
| 73 |
| 74 PassRefPtr<AbstractScriptPromise> DartScriptValue::toPromise() const |
| 75 { |
| 76 RELEASE_ASSERT_NOT_REACHED(); |
| 77 return reinterpret_cast<AbstractScriptPromise*>(0); |
| 78 } |
| 79 |
| 80 PassRefPtr<AbstractScriptPromise> DartScriptValue::toRejectedPromise() const |
| 81 { |
| 82 RELEASE_ASSERT_NOT_REACHED(); |
| 83 return reinterpret_cast<AbstractScriptPromise*>(0); |
| 84 } |
| 85 |
| 86 IDBKey* DartScriptValue::createIDBKeyFromKeyPath(const IDBKeyPath& keyPath) |
| 87 { |
| 88 // FIXMEDART: Implement without conversion to v8. |
| 89 Dart_Handle exception = 0; |
| 90 v8::Handle<v8::Value> v8Value = V8Converter::toV8(dartValue(), exception); |
| 91 if (exception) { |
| 92 ASSERT_NOT_REACHED(); |
| 93 return nullptr; |
| 94 } |
| 95 return V8ScriptValue::create(m_scriptState->v8ScriptState(), v8Value)->creat
eIDBKeyFromKeyPath(keyPath); |
| 96 } |
| 97 |
| 98 bool DartScriptValue::canInjectIDBKey(const IDBKeyPath& keyPath) |
| 99 { |
| 100 // FIXMEDART: Implement without conversion to v8. |
| 101 Dart_Handle exception = 0; |
| 102 v8::Handle<v8::Value> v8Value = V8Converter::toV8(dartValue(), exception); |
| 103 if (exception) { |
| 104 ASSERT_NOT_REACHED(); |
| 105 return false; |
| 106 } |
| 107 return V8ScriptValue::create(m_scriptState->v8ScriptState(), v8Value)->canIn
jectIDBKey(keyPath); |
| 108 } |
| 109 |
| 110 IDBKey* DartScriptValue::toIDBKey() |
| 111 { |
| 112 // FIXMEDART: Implement without conversion to v8. |
| 113 Dart_Handle exception = 0; |
| 114 v8::Handle<v8::Value> v8Value = V8Converter::toV8(dartValue(), exception); |
| 115 if (exception) { |
| 116 ASSERT_NOT_REACHED(); |
| 117 return nullptr; |
| 118 } |
| 119 return V8ScriptValue::create(m_scriptState->v8ScriptState(), v8Value)->toIDB
Key(); |
| 120 } |
| 121 |
| 122 IDBKeyRange* DartScriptValue::toIDBKeyRange() |
| 123 { |
| 124 // FIXMEDART: Implement without conversion to v8. |
| 125 Dart_Handle exception = 0; |
| 126 v8::Handle<v8::Value> v8Value = V8Converter::toV8(dartValue(), exception); |
| 127 if (exception) { |
| 128 ASSERT_NOT_REACHED(); |
| 129 return nullptr; |
| 130 } |
| 131 return V8ScriptValue::create(m_scriptState->v8ScriptState(), v8Value)->toIDB
KeyRange(); |
| 132 } |
| 133 |
| 134 } // namespace blink |
OLD | NEW |