| 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 MutexLocker ml(state->isolate()->mutex()); | 208 MutexLocker ml(state->isolate()->mutex()); |
| 209 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); | 209 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); |
| 210 if (state->isolate()->is_runnable()) { | 210 if (state->isolate()->is_runnable()) { |
| 211 state->isolate()->Run(); | 211 state->isolate()->Run(); |
| 212 } | 212 } |
| 213 | 213 |
| 214 return port.raw(); | 214 return port.raw(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 1) { | 218 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) { |
| 219 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 219 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
| 220 bool throw_exception = false; | 220 bool throw_exception = false; |
| 221 Function& func = Function::Handle(); | 221 Function& func = Function::Handle(); |
| 222 if (closure.IsClosure()) { | 222 if (closure.IsClosure()) { |
| 223 func = Closure::function(closure); | 223 func = Closure::function(closure); |
| 224 const Class& cls = Class::Handle(func.Owner()); | 224 const Class& cls = Class::Handle(func.Owner()); |
| 225 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { | 225 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { |
| 226 throw_exception = true; | 226 throw_exception = true; |
| 227 } | 227 } |
| 228 } else { | 228 } else { |
| 229 throw_exception = true; | 229 throw_exception = true; |
| 230 } | 230 } |
| 231 if (throw_exception) { | 231 if (throw_exception) { |
| 232 const String& msg = String::Handle(String::New( | 232 const String& msg = String::Handle(String::New( |
| 233 "Isolate.spawn expects to be passed a top-level function")); | 233 "Isolate.spawn expects to be passed a top-level function")); |
| 234 Exceptions::ThrowArgumentError(msg); | 234 Exceptions::ThrowArgumentError(msg); |
| 235 } | 235 } |
| 236 | 236 |
| 237 #if defined(DEBUG) | 237 #if defined(DEBUG) |
| 238 Context& ctx = Context::Handle(); | 238 Context& ctx = Context::Handle(); |
| 239 ctx = Closure::context(closure); | 239 ctx = Closure::context(closure); |
| 240 ASSERT(ctx.num_variables() == 0); | 240 ASSERT(ctx.num_variables() == 0); |
| 241 #endif | 241 #endif |
| 242 | 242 |
| 243 return Spawn(arguments, new IsolateSpawnState(func)); | 243 return Spawn(arguments, new IsolateSpawnState(func)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 | 246 |
| 247 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) { | 247 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) { |
| 248 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); | 248 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); |
| 249 | 249 |
| 250 // Canonicalize the uri with respect to the current isolate. | 250 // Canonicalize the uri with respect to the current isolate. |
| 251 char* error = NULL; | 251 char* error = NULL; |
| 252 char* canonical_uri = NULL; | 252 char* canonical_uri = NULL; |
| 253 const Library& root_lib = | 253 const Library& root_lib = |
| 254 Library::Handle(arguments->isolate()->object_store()->root_library()); | 254 Library::Handle(arguments->isolate()->object_store()->root_library()); |
| 255 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, | 255 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, |
| 256 &canonical_uri, &error)) { | 256 &canonical_uri, &error)) { |
| 257 const String& msg = String::Handle(String::New(error)); | 257 const String& msg = String::Handle(String::New(error)); |
| 258 ThrowIsolateSpawnException(msg); | 258 ThrowIsolateSpawnException(msg); |
| 259 } | 259 } |
| 260 | 260 |
| 261 return Spawn(arguments, new IsolateSpawnState(canonical_uri)); | 261 return Spawn(arguments, new IsolateSpawnState(canonical_uri)); |
| 262 } | 262 } |
| 263 | 263 |
| 264 | 264 |
| 265 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { | 265 DEFINE_NATIVE_ENTRY(Isolate_mainPort, 0) { |
| 266 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); | 266 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); |
| 267 if (port.IsError()) { | 267 if (port.IsError()) { |
| 268 Exceptions::PropagateError(Error::Cast(port)); | 268 Exceptions::PropagateError(Error::Cast(port)); |
| 269 } | 269 } |
| 270 return port.raw(); | 270 return port.raw(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 } // namespace dart | 273 } // namespace dart |
| OLD | NEW |