| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013 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/DartScriptState.h" |
| 33 |
| 34 #include "bindings/core/dart/DartScriptPromise.h" |
| 35 #include "bindings/core/dart/DartScriptPromiseResolver.h" |
| 36 #include "bindings/core/dart/DartUtilities.h" |
| 37 #include "platform/SharedBuffer.h" |
| 38 #include <dart_debugger_api.h> |
| 39 |
| 40 namespace blink { |
| 41 |
| 42 DartScriptState::DartScriptState(Dart_Isolate isolate, intptr_t libraryId, V8Scr
iptState* v8ScriptState) |
| 43 { |
| 44 m_isolate = isolate; |
| 45 m_libraryId = libraryId; |
| 46 m_libraryUrl = DartUtilities::toString(Dart_GetLibraryURL(libraryId)); |
| 47 m_v8ScriptState = v8ScriptState; |
| 48 } |
| 49 |
| 50 bool DartScriptState::contextIsEmpty() const |
| 51 { |
| 52 if (m_v8ScriptState) |
| 53 return m_v8ScriptState->contextIsEmpty(); |
| 54 return true; |
| 55 } |
| 56 |
| 57 PassRefPtr<AbstractScriptValue> DartScriptState::createNull() |
| 58 { |
| 59 return DartScriptValue::create(this, Dart_Null()); |
| 60 } |
| 61 |
| 62 PassRefPtr<AbstractScriptValue> DartScriptState::createUndefined() |
| 63 { |
| 64 return DartScriptValue::create(this, Dart_Null()); |
| 65 } |
| 66 |
| 67 PassRefPtr<AbstractScriptValue> DartScriptState::createBoolean(bool value) |
| 68 { |
| 69 return DartScriptValue::create(this, value ? Dart_True() : Dart_False()); |
| 70 } |
| 71 |
| 72 PassRefPtr<AbstractScriptPromise> DartScriptState::createEmptyPromise() |
| 73 { |
| 74 return DartScriptPromise::create(); |
| 75 } |
| 76 |
| 77 PassRefPtr<AbstractScriptPromise> DartScriptState::createRejectedPromise(PassRef
PtrWillBeRawPtr<DOMException> domException) |
| 78 { |
| 79 Dart_Handle dartException = DartDOMException::toDart(domException); |
| 80 return DartScriptPromise::create(this, DartUtilities::newSmashedPromise(dart
Exception)); |
| 81 } |
| 82 |
| 83 PassRefPtr<AbstractScriptPromise> DartScriptState::createPromiseRejectedWithType
Error(const String& message) |
| 84 { |
| 85 Dart_Handle argumentError = DartUtilities::newArgumentError(message); |
| 86 return DartScriptPromise::create(this, DartUtilities::newSmashedPromise(argu
mentError)); |
| 87 } |
| 88 |
| 89 PassOwnPtr<AbstractScriptPromiseResolver> DartScriptState::createPromiseResolver
(ScriptPromiseResolver* owner) |
| 90 { |
| 91 return DartScriptPromiseResolver::create(this, owner); |
| 92 } |
| 93 |
| 94 class DartScriptStateProtectingContext : public AbstractScriptStateProtectingCon
text { |
| 95 public: |
| 96 DartScriptStateProtectingContext(DartScriptState* scriptState) |
| 97 : m_scriptState(scriptState) |
| 98 { |
| 99 } |
| 100 |
| 101 DartScriptState* get() const { return m_scriptState.get(); } |
| 102 void clear() { m_scriptState.clear(); } |
| 103 |
| 104 private: |
| 105 RefPtr<DartScriptState> m_scriptState; |
| 106 }; |
| 107 |
| 108 AbstractScriptStateProtectingContext* DartScriptState::createProtectingContext() |
| 109 { |
| 110 return new DartScriptStateProtectingContext(this); |
| 111 } |
| 112 |
| 113 PassRefPtr<AbstractScriptValue> DartScriptState::idbAnyToScriptValue(IDBAny* any
) |
| 114 { |
| 115 // FIXMEDART: Implement without Dart<->V8 conversion. |
| 116 return v8ScriptState()->idbAnyToScriptValue(any); |
| 117 } |
| 118 |
| 119 PassRefPtr<AbstractScriptValue> DartScriptState::idbKeyToScriptValue(IDBKey* key
) |
| 120 { |
| 121 // FIXMEDART: Implement without Dart<->V8 conversion. |
| 122 return v8ScriptState()->idbKeyToScriptValue(key); |
| 123 } |
| 124 |
| 125 #ifndef NDEBUG |
| 126 void DartScriptState::assertPrimaryKeyValidOrInjectable(PassRefPtr<SharedBuffer>
buffer, const Vector<blink::WebBlobInfo>* blobInfo, IDBKey* key, const IDBKeyPa
th& keyPath) |
| 127 { |
| 128 // FIXMEDART: Implement without Dart<->V8 conversion. |
| 129 return v8ScriptState()->assertPrimaryKeyValidOrInjectable(buffer, blobInfo,
key, keyPath); |
| 130 } |
| 131 #endif |
| 132 |
| 133 } // namespace blink |
| OLD | NEW |