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 ASSERT(data); | |
71 Dart_Isolate isolate = Dart_CreateIsolate(DartUtilities::fullSnapshot(), dat
a, &errorMsg); | |
72 pushLink(isolate); | |
73 ASSERT(Dart_CurrentIsolate() == isolate); | |
74 DartController::setupDOMEnabledIsolate(context); | |
75 return isolate; | |
76 } | |
77 | |
78 // Push the given isolate as the current one. | |
79 void DartIsolateState::push(Dart_Isolate isolate) | |
80 { | |
81 if (m_current) { | |
82 Dart_Isolate current = Dart_CurrentIsolate(); | |
83 ASSERT(current && m_current->isolate == current); | |
84 if (current != isolate) { | |
85 Dart_ExitIsolate(); | |
86 Dart_EnterIsolate(isolate); | |
87 } | |
88 } else { | |
89 ASSERT(!Dart_CurrentIsolate()); | |
90 Dart_EnterIsolate(isolate); | |
91 } | |
92 pushLink(isolate); | |
93 } | |
94 | |
95 // Return the currently active isolate. | |
96 Dart_Isolate DartIsolateState::current() | |
97 { | |
98 ASSERT(m_current && m_current->isolate == Dart_CurrentIsolate()); | |
99 return m_current->isolate; | |
100 } | |
101 | |
102 // Pop the currently active isolate and restore the previous one (if any). | |
103 void DartIsolateState::pop() | |
104 { | |
105 ASSERT(m_current && m_current->isolate == Dart_CurrentIsolate()); | |
106 DartIsolateLink* previous = m_current->previous; | |
107 if (previous) { | |
108 if (previous->isolate != m_current->isolate) { | |
109 Dart_ExitIsolate(); | |
110 Dart_EnterIsolate(previous->isolate); | |
111 } | |
112 } else { | |
113 Dart_ExitIsolate(); | |
114 } | |
115 popLink(); | |
116 } | |
117 | |
118 // Shutdown the given isolate. | |
119 void DartIsolateState::shutdown(Dart_Isolate isolate) | |
120 { | |
121 ASSERT(!m_current || m_current->isolate != isolate); | |
122 | |
123 push(isolate); | |
124 // FIXME: clear event listeners. | |
125 // FIXME: clear console messages. | |
126 DartDOMMap* domMap = DartUtilities::domMapForIsolate(isolate); | |
127 for (DartDOMMap::iterator it = domMap->begin(); it != domMap->end(); ++it) | |
128 DartDOMWrapper::derefDOMObject(it->second, it->first); | |
129 pop(); | |
130 | |
131 if (m_current) | |
132 Dart_ExitIsolate(); | |
133 Dart_EnterIsolate(isolate); | |
134 Dart_ShutdownIsolate(); | |
135 DartUtilities::unregisterIsolateContext(isolate); | |
136 if (m_current) | |
137 Dart_EnterIsolate(m_current->isolate); | |
138 } | |
139 | |
140 } | |
OLD | NEW |