OLD | NEW |
(Empty) | |
| 1 // Copyright 2011, Google Inc. |
| 2 // 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 #include "config.h" |
| 31 #include "DartIsolateState.h" |
| 32 |
| 33 #include "DartController.h" |
| 34 #include "DartDOMWrapper.h" |
| 35 #include "DartUtilities.h" |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 struct DartIsolateLink { |
| 40 DartIsolateLink(Dart_Isolate isolate, DartIsolateLink* previous) |
| 41 : isolate(isolate), previous(previous) {} |
| 42 |
| 43 Dart_Isolate isolate; |
| 44 DartIsolateLink* previous; |
| 45 }; |
| 46 |
| 47 DartIsolateLink* DartIsolateState::m_current = 0; |
| 48 |
| 49 void DartIsolateState::pushLink(Dart_Isolate isolate) |
| 50 { |
| 51 m_current = new DartIsolateLink(isolate, m_current); |
| 52 } |
| 53 |
| 54 void DartIsolateState::popLink() |
| 55 { |
| 56 DartIsolateLink* previous = m_current->previous; |
| 57 delete m_current; |
| 58 m_current = previous; |
| 59 } |
| 60 |
| 61 // Creates a new isolates and sets it as the current. |
| 62 Dart_Isolate DartIsolateState::create(ScriptExecutionContext* context, void* dat
a) |
| 63 { |
| 64 if (m_current) { |
| 65 ASSERT(m_current->isolate && m_current->isolate == Dart_CurrentIsolate()
); |
| 66 Dart_ExitIsolate(); |
| 67 } |
| 68 // FIXME: proper error reporting. |
| 69 char* errorMsg = 0; |
| 70 Dart_Isolate isolate = Dart_CreateIsolate(0, data, &errorMsg); |
| 71 pushLink(isolate); |
| 72 ASSERT(Dart_CurrentIsolate() == isolate); |
| 73 DartController::setupDOMEnabledIsolate(context); |
| 74 return isolate; |
| 75 } |
| 76 |
| 77 // Push the given isolate as the current one. |
| 78 void DartIsolateState::push(Dart_Isolate isolate) |
| 79 { |
| 80 if (m_current) { |
| 81 Dart_Isolate current = Dart_CurrentIsolate(); |
| 82 ASSERT(current && m_current->isolate == current); |
| 83 if (current != isolate) { |
| 84 Dart_ExitIsolate(); |
| 85 Dart_EnterIsolate(isolate); |
| 86 } |
| 87 } else { |
| 88 ASSERT(!Dart_CurrentIsolate()); |
| 89 Dart_EnterIsolate(isolate); |
| 90 } |
| 91 pushLink(isolate); |
| 92 } |
| 93 |
| 94 // Return the currently active isolate. |
| 95 Dart_Isolate DartIsolateState::current() |
| 96 { |
| 97 ASSERT(m_current && m_current->isolate == Dart_CurrentIsolate()); |
| 98 return m_current->isolate; |
| 99 } |
| 100 |
| 101 // Pop the currently active isolate and restore the previous one (if any). |
| 102 void DartIsolateState::pop() |
| 103 { |
| 104 ASSERT(m_current && m_current->isolate == Dart_CurrentIsolate()); |
| 105 DartIsolateLink* previous = m_current->previous; |
| 106 if (previous) { |
| 107 if (previous->isolate != m_current->isolate) { |
| 108 Dart_ExitIsolate(); |
| 109 Dart_EnterIsolate(previous->isolate); |
| 110 } |
| 111 } else { |
| 112 Dart_ExitIsolate(); |
| 113 } |
| 114 popLink(); |
| 115 } |
| 116 |
| 117 // Shutdown the given isolate. |
| 118 void DartIsolateState::shutdown(Dart_Isolate isolate) |
| 119 { |
| 120 ASSERT(!m_current || m_current->isolate != isolate); |
| 121 |
| 122 push(isolate); |
| 123 // FIXME: clear event listeners. |
| 124 // FIXME: clear console messages. |
| 125 DartDOMMap* domMap = DartUtilities::domMapForIsolate(isolate); |
| 126 for (DartDOMMap::iterator it = domMap->begin(); it != domMap->end(); ++it) |
| 127 DartDOMWrapper::derefDOMObject(it->second, it->first); |
| 128 pop(); |
| 129 |
| 130 if (m_current) |
| 131 Dart_ExitIsolate(); |
| 132 Dart_EnterIsolate(isolate); |
| 133 Dart_ShutdownIsolate(); |
| 134 DartUtilities::unregisterIsolateContext(isolate); |
| 135 if (m_current) |
| 136 Dart_EnterIsolate(m_current->isolate); |
| 137 } |
| 138 |
| 139 } |
OLD | NEW |