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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 if (state->isolate()->is_runnable()) { | 208 if (state->isolate()->is_runnable()) { |
209 state->isolate()->Run(); | 209 state->isolate()->Run(); |
210 } | 210 } |
211 | 211 |
212 return port.raw(); | 212 return port.raw(); |
213 } | 213 } |
214 | 214 |
215 | 215 |
216 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) { | 216 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) { |
217 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 217 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
218 bool throw_exception = false; | |
219 Function& func = Function::Handle(); | |
220 if (closure.IsClosure()) { | 218 if (closure.IsClosure()) { |
| 219 Function& func = Function::Handle(); |
221 func = Closure::function(closure); | 220 func = Closure::function(closure); |
222 const Class& cls = Class::Handle(func.Owner()); | 221 if (func.IsImplicitClosureFunction() && func.is_static()) { |
223 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { | 222 #if defined(DEBUG) |
224 throw_exception = true; | 223 Context& ctx = Context::Handle(); |
| 224 ctx = Closure::context(closure); |
| 225 ASSERT(ctx.num_variables() == 0); |
| 226 #endif |
| 227 return Spawn(arguments, new IsolateSpawnState(func)); |
225 } | 228 } |
226 } else { | |
227 throw_exception = true; | |
228 } | 229 } |
229 if (throw_exception) { | 230 const String& msg = String::Handle(String::New( |
230 const String& msg = String::Handle(String::New( | 231 "Isolate.spawn expects to be passed a static or top-level function")); |
231 "Isolate.spawn expects to be passed a top-level function")); | 232 Exceptions::ThrowArgumentError(msg); |
232 Exceptions::ThrowArgumentError(msg); | 233 return Object::null(); |
233 } | |
234 | |
235 #if defined(DEBUG) | |
236 Context& ctx = Context::Handle(); | |
237 ctx = Closure::context(closure); | |
238 ASSERT(ctx.num_variables() == 0); | |
239 #endif | |
240 | |
241 return Spawn(arguments, new IsolateSpawnState(func)); | |
242 } | 234 } |
243 | 235 |
244 | 236 |
245 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) { | 237 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) { |
246 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); | 238 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); |
247 | 239 |
248 // Canonicalize the uri with respect to the current isolate. | 240 // Canonicalize the uri with respect to the current isolate. |
249 char* error = NULL; | 241 char* error = NULL; |
250 char* canonical_uri = NULL; | 242 char* canonical_uri = NULL; |
251 const Library& root_lib = | 243 const Library& root_lib = |
(...skipping 16 matching lines...) Expand all Loading... |
268 | 260 |
269 // 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 |
270 // 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 |
271 // this by increasing the number of open control ports. | 263 // this by increasing the number of open control ports. |
272 isolate->message_handler()->increment_control_ports(); | 264 isolate->message_handler()->increment_control_ports(); |
273 | 265 |
274 return port.raw(); | 266 return port.raw(); |
275 } | 267 } |
276 | 268 |
277 } // namespace dart | 269 } // namespace dart |
OLD | NEW |