Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart.h" | 8 #include "vm/dart.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 Isolate::SetCurrent(parent_isolate); | 159 Isolate::SetCurrent(parent_isolate); |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); | 162 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); |
| 163 | 163 |
| 164 Isolate::SetCurrent(parent_isolate); | 164 Isolate::SetCurrent(parent_isolate); |
| 165 return true; | 165 return true; |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 static RawObject* Spawn(NativeArguments* arguments, IsolateSpawnState* state) { | 169 static RawArray* Spawn(Isolate* isolate, |
|
siva
2014/07/01 21:42:56
This isolate parameter is not being used anywhere
Ivan Posva
2014/07/03 12:51:16
- Removed the unnecessary parameter, it was used i
| |
| 170 NativeArguments* arguments, | |
| 171 IsolateSpawnState* state) { | |
| 170 // Create a new isolate. | 172 // Create a new isolate. |
| 171 char* error = NULL; | 173 char* error = NULL; |
| 172 if (!CreateIsolate(state, &error)) { | 174 if (!CreateIsolate(state, &error)) { |
| 173 delete state; | 175 delete state; |
| 174 const String& msg = String::Handle(String::New(error)); | 176 const String& msg = String::Handle(String::New(error)); |
| 175 free(error); | 177 free(error); |
| 176 ThrowIsolateSpawnException(msg); | 178 ThrowIsolateSpawnException(msg); |
| 177 } | 179 } |
| 178 | 180 |
| 181 const Array& result = Array::Handle(Array::New(3)); | |
| 179 // Try to create a SendPort for the new isolate. | 182 // Try to create a SendPort for the new isolate. |
| 180 const SendPort& port = SendPort::Handle( | 183 const SendPort& port = SendPort::Handle( |
| 181 SendPort::New(state->isolate()->main_port())); | 184 SendPort::New(state->isolate()->main_port())); |
| 185 result.SetAt(0, port); | |
| 186 Capability& capability = Capability::Handle(); | |
| 187 capability = Capability::New(state->isolate()->pause_capability()); | |
| 188 result.SetAt(1, capability); // pauseCapability | |
| 189 capability = Capability::New(state->isolate()->terminate_capability()); | |
| 190 result.SetAt(2, capability); // terminateCapability | |
| 182 | 191 |
| 183 // Start the new isolate if it is already marked as runnable. | 192 // Start the new isolate if it is already marked as runnable. |
| 184 MutexLocker ml(state->isolate()->mutex()); | 193 MutexLocker ml(state->isolate()->mutex()); |
| 185 state->isolate()->set_spawn_state(state); | 194 state->isolate()->set_spawn_state(state); |
| 186 if (state->isolate()->is_runnable()) { | 195 if (state->isolate()->is_runnable()) { |
| 187 state->isolate()->Run(); | 196 state->isolate()->Run(); |
| 188 } | 197 } |
| 189 | 198 |
| 190 return port.raw(); | 199 return result.raw(); |
| 191 } | 200 } |
| 192 | 201 |
| 193 | 202 |
| 194 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) { | 203 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) { |
| 195 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 204 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
| 196 if (closure.IsClosure()) { | 205 if (closure.IsClosure()) { |
| 197 Function& func = Function::Handle(); | 206 Function& func = Function::Handle(); |
| 198 func = Closure::function(closure); | 207 func = Closure::function(closure); |
| 199 if (func.IsImplicitClosureFunction() && func.is_static()) { | 208 if (func.IsImplicitClosureFunction() && func.is_static()) { |
| 200 #if defined(DEBUG) | 209 #if defined(DEBUG) |
| 201 Context& ctx = Context::Handle(); | 210 Context& ctx = Context::Handle(); |
| 202 ctx = Closure::context(closure); | 211 ctx = Closure::context(closure); |
| 203 ASSERT(ctx.num_variables() == 0); | 212 ASSERT(ctx.num_variables() == 0); |
| 204 #endif | 213 #endif |
| 205 return Spawn(arguments, new IsolateSpawnState(func)); | 214 return Spawn(isolate, arguments, new IsolateSpawnState(func)); |
| 206 } | 215 } |
| 207 } | 216 } |
| 208 const String& msg = String::Handle(String::New( | 217 const String& msg = String::Handle(String::New( |
| 209 "Isolate.spawn expects to be passed a static or top-level function")); | 218 "Isolate.spawn expects to be passed a static or top-level function")); |
| 210 Exceptions::ThrowArgumentError(msg); | 219 Exceptions::ThrowArgumentError(msg); |
| 211 return Object::null(); | 220 return Object::null(); |
| 212 } | 221 } |
| 213 | 222 |
| 214 | 223 |
| 215 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) { | 224 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) { |
| 216 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); | 225 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); |
| 217 | 226 |
| 218 // Canonicalize the uri with respect to the current isolate. | 227 // Canonicalize the uri with respect to the current isolate. |
| 219 char* error = NULL; | 228 char* error = NULL; |
| 220 char* canonical_uri = NULL; | 229 char* canonical_uri = NULL; |
| 221 const Library& root_lib = | 230 const Library& root_lib = |
| 222 Library::Handle(arguments->isolate()->object_store()->root_library()); | 231 Library::Handle(arguments->isolate()->object_store()->root_library()); |
| 223 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, | 232 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, |
| 224 &canonical_uri, &error)) { | 233 &canonical_uri, &error)) { |
| 225 const String& msg = String::Handle(String::New(error)); | 234 const String& msg = String::Handle(String::New(error)); |
| 226 ThrowIsolateSpawnException(msg); | 235 ThrowIsolateSpawnException(msg); |
| 227 } | 236 } |
| 228 | 237 |
| 229 return Spawn(arguments, new IsolateSpawnState(canonical_uri)); | 238 return Spawn(isolate, arguments, new IsolateSpawnState(canonical_uri)); |
| 239 } | |
| 240 | |
| 241 | |
| 242 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) { | |
| 243 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | |
| 244 GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1)); | |
| 245 | |
| 246 // Make sure to route this request to the isolate library OOB mesage handler. | |
| 247 msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg))); | |
| 248 | |
| 249 uint8_t* data = NULL; | |
| 250 MessageWriter writer(&data, &allocator); | |
| 251 writer.WriteMessage(msg); | |
| 252 | |
| 253 PortMap::PostMessage(new Message(port.Id(), | |
| 254 data, writer.BytesWritten(), | |
| 255 Message::kOOBPriority)); | |
| 256 return Object::null(); | |
| 230 } | 257 } |
| 231 | 258 |
| 232 | 259 |
| 233 DEFINE_NATIVE_ENTRY(Isolate_mainPort, 0) { | 260 DEFINE_NATIVE_ENTRY(Isolate_mainPort, 0) { |
| 234 // The control port is being accessed as a regular port from Dart code. This | 261 // The control port is being accessed as a regular port from Dart code. This |
| 235 // is most likely due to the _startIsolate code in dart:isolate. Account for | 262 // is most likely due to the _startIsolate code in dart:isolate. Account for |
| 236 // this by increasing the number of open control ports. | 263 // this by increasing the number of open control ports. |
| 237 isolate->message_handler()->increment_control_ports(); | 264 isolate->message_handler()->increment_control_ports(); |
| 238 | 265 |
| 239 return ReceivePort::New(isolate->main_port()); | 266 return ReceivePort::New(isolate->main_port()); |
| 240 } | 267 } |
| 241 | 268 |
| 242 } // namespace dart | 269 } // namespace dart |
| OLD | NEW |