| 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/DartScriptPromise.h" | |
| 35 #include "bindings/core/dart/DartUtilities.h" | |
| 36 #include "bindings/core/dart/V8Converter.h" | |
| 37 #include "platform/JSONValues.h" | |
| 38 #include "platform/SharedBuffer.h" | |
| 39 | |
| 40 namespace blink { | |
| 41 | |
| 42 DartScriptValue::~DartScriptValue() | |
| 43 { | |
| 44 } | |
| 45 | |
| 46 bool DartScriptValue::toString(String& result) const | |
| 47 { | |
| 48 if (isEmpty()) | |
| 49 return false; | |
| 50 | |
| 51 DartIsolateScope(m_scriptState->isolate()); | |
| 52 DartApiScope apiScope; | |
| 53 | |
| 54 Dart_Handle exception = 0; | |
| 55 DartStringAdapter string = DartUtilities::dartToString(Dart_ToString(dartVal
ue()), exception); | |
| 56 if (exception) | |
| 57 return false; | |
| 58 result = string; | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 // FIXMEDART: Implement without conversion to v8. | |
| 63 PassRefPtr<JSONValue> DartScriptValue::toJSONValue(ScriptState* scriptState) con
st | |
| 64 { | |
| 65 Dart_Handle exception = 0; | |
| 66 v8::Handle<v8::Value> v8Value = V8Converter::toV8(dartValue(), exception); | |
| 67 if (exception) { | |
| 68 ASSERT_NOT_REACHED(); | |
| 69 return nullptr; | |
| 70 } | |
| 71 ScriptValue v8ScriptValue(m_scriptState->v8ScriptState(), v8Value); | |
| 72 return v8ScriptValue.toJSONValue(scriptState); | |
| 73 } | |
| 74 | |
| 75 PassRefPtr<AbstractScriptPromise> DartScriptValue::toPromise() const | |
| 76 { | |
| 77 // Does Blink rely on the value not being wrapped if it is already a future? | |
| 78 return DartScriptPromise::create(m_scriptState.get(), DartUtilities::newReso
lvedPromise(dartValue())); | |
| 79 } | |
| 80 | |
| 81 PassRefPtr<AbstractScriptPromise> DartScriptValue::toRejectedPromise() const | |
| 82 { | |
| 83 return DartScriptPromise::create(m_scriptState.get(), DartUtilities::newSmas
hedPromise(dartValue())); | |
| 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 |