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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 void* init_data = parent_isolate->init_callback_data(); | 174 void* init_data = parent_isolate->init_callback_data(); |
175 Isolate* child_isolate = reinterpret_cast<Isolate*>( | 175 Isolate* child_isolate = reinterpret_cast<Isolate*>( |
176 (callback)(state->script_url(), | 176 (callback)(state->script_url(), |
177 state->function_name(), | 177 state->function_name(), |
178 state->package_root(), | 178 state->package_root(), |
179 init_data, | 179 init_data, |
180 error)); | 180 error)); |
181 if (child_isolate == NULL) { | 181 if (child_isolate == NULL) { |
182 return false; | 182 return false; |
183 } | 183 } |
184 child_isolate->set_strict_compilation(state->checked_mode()); | |
Ivan Posva
2015/06/02 17:49:31
Please add:
// TODO(iposva): Evaluate whether it i
Lasse Reichstein Nielsen
2015/06/03 06:55:25
Done.
| |
184 if (!state->is_spawn_uri()) { | 185 if (!state->is_spawn_uri()) { |
185 // For isolates spawned using the spawnFunction semantics we set | 186 // For isolates spawned using the spawn semantics we set |
186 // the origin_id to the origin_id of the parent isolate. | 187 // the origin_id to the origin_id of the parent isolate. |
187 child_isolate->set_origin_id(parent_isolate->origin_id()); | 188 child_isolate->set_origin_id(parent_isolate->origin_id()); |
188 } | 189 } |
189 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); | 190 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); |
190 return true; | 191 return true; |
191 } | 192 } |
192 | 193 |
193 | 194 |
194 static void Spawn(Isolate* parent_isolate, IsolateSpawnState* state) { | 195 static void Spawn(Isolate* parent_isolate, IsolateSpawnState* state) { |
195 Thread::ExitIsolate(); | 196 Thread::ExitIsolate(); |
(...skipping 26 matching lines...) Expand all Loading... | |
222 Function& func = Function::Handle(); | 223 Function& func = Function::Handle(); |
223 func = Closure::function(closure); | 224 func = Closure::function(closure); |
224 if (func.IsImplicitClosureFunction() && func.is_static()) { | 225 if (func.IsImplicitClosureFunction() && func.is_static()) { |
225 #if defined(DEBUG) | 226 #if defined(DEBUG) |
226 Context& ctx = Context::Handle(); | 227 Context& ctx = Context::Handle(); |
227 ctx = Closure::context(closure); | 228 ctx = Closure::context(closure); |
228 ASSERT(ctx.num_variables() == 0); | 229 ASSERT(ctx.num_variables() == 0); |
229 #endif | 230 #endif |
230 // Get the parent function so that we get the right function name. | 231 // Get the parent function so that we get the right function name. |
231 func = func.parent_function(); | 232 func = func.parent_function(); |
233 bool checkedFlag = isolate->strict_compilation(); | |
232 Spawn(isolate, new IsolateSpawnState(port.Id(), | 234 Spawn(isolate, new IsolateSpawnState(port.Id(), |
233 func, | 235 func, |
234 message, | 236 message, |
235 paused.value())); | 237 paused.value(), |
238 checkedFlag)); | |
236 return Object::null(); | 239 return Object::null(); |
237 } | 240 } |
238 } | 241 } |
239 const String& msg = String::Handle(String::New( | 242 const String& msg = String::Handle(String::New( |
240 "Isolate.spawn expects to be passed a static or top-level function")); | 243 "Isolate.spawn expects to be passed a static or top-level function")); |
241 Exceptions::ThrowArgumentError(msg); | 244 Exceptions::ThrowArgumentError(msg); |
242 return Object::null(); | 245 return Object::null(); |
243 } | 246 } |
244 | 247 |
245 | 248 |
246 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 6) { | 249 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 7) { |
247 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 250 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
248 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1)); | 251 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1)); |
249 GET_NON_NULL_NATIVE_ARGUMENT(Instance, args, arguments->NativeArgAt(2)); | 252 GET_NON_NULL_NATIVE_ARGUMENT(Instance, args, arguments->NativeArgAt(2)); |
250 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(3)); | 253 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(3)); |
251 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(4)); | 254 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(4)); |
252 GET_NATIVE_ARGUMENT(String, package_root, arguments->NativeArgAt(5)); | 255 GET_NATIVE_ARGUMENT(Bool, checked, arguments->NativeArgAt(5)); |
256 GET_NATIVE_ARGUMENT(String, package_root, arguments->NativeArgAt(6)); | |
253 | 257 |
254 // Canonicalize the uri with respect to the current isolate. | 258 // Canonicalize the uri with respect to the current isolate. |
255 char* error = NULL; | 259 char* error = NULL; |
256 char* canonical_uri = NULL; | 260 char* canonical_uri = NULL; |
257 const Library& root_lib = | 261 const Library& root_lib = |
258 Library::Handle(isolate->object_store()->root_library()); | 262 Library::Handle(isolate->object_store()->root_library()); |
259 if (!CanonicalizeUri(isolate, root_lib, uri, | 263 if (!CanonicalizeUri(isolate, root_lib, uri, |
260 &canonical_uri, &error)) { | 264 &canonical_uri, &error)) { |
261 const String& msg = String::Handle(String::New(error)); | 265 const String& msg = String::Handle(String::New(error)); |
262 ThrowIsolateSpawnException(msg); | 266 ThrowIsolateSpawnException(msg); |
263 } | 267 } |
264 | 268 |
265 char* utf8_package_root = NULL; | 269 char* utf8_package_root = NULL; |
266 if (!package_root.IsNull()) { | 270 if (!package_root.IsNull()) { |
267 const intptr_t len = Utf8::Length(package_root); | 271 const intptr_t len = Utf8::Length(package_root); |
268 utf8_package_root = zone->Alloc<char>(len + 1); | 272 utf8_package_root = zone->Alloc<char>(len + 1); |
269 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); | 273 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); |
270 utf8_package_root[len] = '\0'; | 274 utf8_package_root[len] = '\0'; |
271 } | 275 } |
272 | 276 |
277 bool checkedFlag; | |
278 if (checked.IsNull()) { | |
279 checkedFlag = isolate->strict_compilation(); | |
280 } else { | |
281 checkedFlag = checked.value(); | |
282 } | |
283 | |
273 Spawn(isolate, new IsolateSpawnState(port.Id(), | 284 Spawn(isolate, new IsolateSpawnState(port.Id(), |
274 canonical_uri, | 285 canonical_uri, |
275 utf8_package_root, | 286 utf8_package_root, |
276 args, | 287 args, |
277 message, | 288 message, |
278 paused.value())); | 289 paused.value(), |
290 checkedFlag)); | |
279 return Object::null(); | 291 return Object::null(); |
280 } | 292 } |
281 | 293 |
282 | 294 |
283 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) { | 295 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) { |
284 const Array& result = Array::Handle(Array::New(3)); | 296 const Array& result = Array::Handle(Array::New(3)); |
285 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port()))); | 297 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port()))); |
286 result.SetAt(1, Capability::Handle( | 298 result.SetAt(1, Capability::Handle( |
287 Capability::New(isolate->pause_capability()))); | 299 Capability::New(isolate->pause_capability()))); |
288 result.SetAt(2, Capability::Handle( | 300 result.SetAt(2, Capability::Handle( |
(...skipping 13 matching lines...) Expand all Loading... | |
302 MessageWriter writer(&data, &allocator, false); | 314 MessageWriter writer(&data, &allocator, false); |
303 writer.WriteMessage(msg); | 315 writer.WriteMessage(msg); |
304 | 316 |
305 PortMap::PostMessage(new Message(port.Id(), | 317 PortMap::PostMessage(new Message(port.Id(), |
306 data, writer.BytesWritten(), | 318 data, writer.BytesWritten(), |
307 Message::kOOBPriority)); | 319 Message::kOOBPriority)); |
308 return Object::null(); | 320 return Object::null(); |
309 } | 321 } |
310 | 322 |
311 } // namespace dart | 323 } // namespace dart |
OLD | NEW |