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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // Start the new isolate if it is already marked as runnable. | 210 // Start the new isolate if it is already marked as runnable. |
211 Isolate* spawned_isolate = state->isolate(); | 211 Isolate* spawned_isolate = state->isolate(); |
212 MutexLocker ml(spawned_isolate->mutex()); | 212 MutexLocker ml(spawned_isolate->mutex()); |
213 spawned_isolate->set_spawn_state(state); | 213 spawned_isolate->set_spawn_state(state); |
214 if (spawned_isolate->is_runnable()) { | 214 if (spawned_isolate->is_runnable()) { |
215 spawned_isolate->Run(); | 215 spawned_isolate->Run(); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 | 219 |
220 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 4) { | 220 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 7) { |
221 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 221 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
222 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(1)); | 222 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(1)); |
223 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(2)); | 223 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(2)); |
224 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(3)); | 224 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(3)); |
| 225 GET_NATIVE_ARGUMENT(Bool, fatalErrors, arguments->NativeArgAt(4)); |
| 226 GET_NATIVE_ARGUMENT(SendPort, onExit, arguments->NativeArgAt(5)); |
| 227 GET_NATIVE_ARGUMENT(SendPort, onError, arguments->NativeArgAt(6)); |
| 228 |
225 if (closure.IsClosure()) { | 229 if (closure.IsClosure()) { |
226 Function& func = Function::Handle(); | 230 Function& func = Function::Handle(); |
227 func = Closure::function(closure); | 231 func = Closure::function(closure); |
228 if (func.IsImplicitClosureFunction() && func.is_static()) { | 232 if (func.IsImplicitClosureFunction() && func.is_static()) { |
229 #if defined(DEBUG) | 233 #if defined(DEBUG) |
230 Context& ctx = Context::Handle(); | 234 Context& ctx = Context::Handle(); |
231 ctx = Closure::context(closure); | 235 ctx = Closure::context(closure); |
232 ASSERT(ctx.num_variables() == 0); | 236 ASSERT(ctx.num_variables() == 0); |
233 #endif | 237 #endif |
234 // Get the parent function so that we get the right function name. | 238 // Get the parent function so that we get the right function name. |
235 func = func.parent_function(); | 239 func = func.parent_function(); |
| 240 |
| 241 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value(); |
| 242 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id(); |
| 243 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id(); |
| 244 |
236 Spawn(isolate, new IsolateSpawnState(port.Id(), | 245 Spawn(isolate, new IsolateSpawnState(port.Id(), |
237 func, | 246 func, |
238 message, | 247 message, |
239 paused.value())); | 248 paused.value(), |
| 249 fatal_errors, |
| 250 on_exit_port, |
| 251 on_error_port)); |
240 return Object::null(); | 252 return Object::null(); |
241 } | 253 } |
242 } | 254 } |
243 const String& msg = String::Handle(String::New( | 255 const String& msg = String::Handle(String::New( |
244 "Isolate.spawn expects to be passed a static or top-level function")); | 256 "Isolate.spawn expects to be passed a static or top-level function")); |
245 Exceptions::ThrowArgumentError(msg); | 257 Exceptions::ThrowArgumentError(msg); |
246 return Object::null(); | 258 return Object::null(); |
247 } | 259 } |
248 | 260 |
249 | 261 |
250 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 7) { | 262 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 10) { |
251 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 263 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
252 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1)); | 264 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1)); |
253 GET_NON_NULL_NATIVE_ARGUMENT(Instance, args, arguments->NativeArgAt(2)); | 265 GET_NON_NULL_NATIVE_ARGUMENT(Instance, args, arguments->NativeArgAt(2)); |
254 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(3)); | 266 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(3)); |
255 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(4)); | 267 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(4)); |
256 GET_NATIVE_ARGUMENT(Bool, checked, arguments->NativeArgAt(5)); | 268 GET_NATIVE_ARGUMENT(Bool, checked, arguments->NativeArgAt(5)); |
257 GET_NATIVE_ARGUMENT(String, package_root, arguments->NativeArgAt(6)); | 269 GET_NATIVE_ARGUMENT(String, package_root, arguments->NativeArgAt(6)); |
| 270 GET_NATIVE_ARGUMENT(Bool, fatalErrors, arguments->NativeArgAt(7)); |
| 271 GET_NATIVE_ARGUMENT(SendPort, onExit, arguments->NativeArgAt(8)); |
| 272 GET_NATIVE_ARGUMENT(SendPort, onError, arguments->NativeArgAt(9)); |
258 | 273 |
259 // Canonicalize the uri with respect to the current isolate. | 274 // Canonicalize the uri with respect to the current isolate. |
260 char* error = NULL; | 275 char* error = NULL; |
261 char* canonical_uri = NULL; | 276 char* canonical_uri = NULL; |
262 const Library& root_lib = | 277 const Library& root_lib = |
263 Library::Handle(isolate->object_store()->root_library()); | 278 Library::Handle(isolate->object_store()->root_library()); |
264 if (!CanonicalizeUri(isolate, root_lib, uri, | 279 if (!CanonicalizeUri(isolate, root_lib, uri, |
265 &canonical_uri, &error)) { | 280 &canonical_uri, &error)) { |
266 const String& msg = String::Handle(String::New(error)); | 281 const String& msg = String::Handle(String::New(error)); |
267 ThrowIsolateSpawnException(msg); | 282 ThrowIsolateSpawnException(msg); |
268 } | 283 } |
269 | 284 |
270 char* utf8_package_root = NULL; | 285 char* utf8_package_root = NULL; |
271 if (!package_root.IsNull()) { | 286 if (!package_root.IsNull()) { |
272 const intptr_t len = Utf8::Length(package_root); | 287 const intptr_t len = Utf8::Length(package_root); |
273 utf8_package_root = zone->Alloc<char>(len + 1); | 288 utf8_package_root = zone->Alloc<char>(len + 1); |
274 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); | 289 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); |
275 utf8_package_root[len] = '\0'; | 290 utf8_package_root[len] = '\0'; |
276 } | 291 } |
277 | 292 |
| 293 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value(); |
| 294 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id(); |
| 295 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id(); |
| 296 |
278 IsolateSpawnState* state = new IsolateSpawnState(port.Id(), | 297 IsolateSpawnState* state = new IsolateSpawnState(port.Id(), |
279 canonical_uri, | 298 canonical_uri, |
280 utf8_package_root, | 299 utf8_package_root, |
281 args, | 300 args, |
282 message, | 301 message, |
283 paused.value()); | 302 paused.value(), |
| 303 fatal_errors, |
| 304 on_exit_port, |
| 305 on_error_port); |
284 // If we were passed a value then override the default flags state for | 306 // If we were passed a value then override the default flags state for |
285 // checked mode. | 307 // checked mode. |
286 if (!checked.IsNull()) { | 308 if (!checked.IsNull()) { |
287 state->isolate_flags()->set_checked(checked.value()); | 309 state->isolate_flags()->set_checked(checked.value()); |
288 } | 310 } |
289 | 311 |
290 Spawn(isolate, state); | 312 Spawn(isolate, state); |
291 return Object::null(); | 313 return Object::null(); |
292 } | 314 } |
293 | 315 |
(...skipping 20 matching lines...) Expand all Loading... |
314 MessageWriter writer(&data, &allocator, false); | 336 MessageWriter writer(&data, &allocator, false); |
315 writer.WriteMessage(msg); | 337 writer.WriteMessage(msg); |
316 | 338 |
317 PortMap::PostMessage(new Message(port.Id(), | 339 PortMap::PostMessage(new Message(port.Id(), |
318 data, writer.BytesWritten(), | 340 data, writer.BytesWritten(), |
319 Message::kOOBPriority)); | 341 Message::kOOBPriority)); |
320 return Object::null(); | 342 return Object::null(); |
321 } | 343 } |
322 | 344 |
323 } // namespace dart | 345 } // namespace dart |
OLD | NEW |