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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 static bool CreateIsolate(Isolate* parent_isolate, | 165 static bool CreateIsolate(Isolate* parent_isolate, |
166 IsolateSpawnState* state, | 166 IsolateSpawnState* state, |
167 char** error) { | 167 char** error) { |
168 Dart_IsolateCreateCallback callback = Isolate::CreateCallback(); | 168 Dart_IsolateCreateCallback callback = Isolate::CreateCallback(); |
169 if (callback == NULL) { | 169 if (callback == NULL) { |
170 *error = strdup("Null callback specified for isolate creation\n"); | 170 *error = strdup("Null callback specified for isolate creation\n"); |
171 return false; | 171 return false; |
172 } | 172 } |
173 | 173 |
| 174 Dart_IsolateFlags api_flags; |
| 175 state->isolate_flags()->CopyTo(&api_flags); |
| 176 |
174 void* init_data = parent_isolate->init_callback_data(); | 177 void* init_data = parent_isolate->init_callback_data(); |
175 Isolate* child_isolate = reinterpret_cast<Isolate*>( | 178 Isolate* child_isolate = reinterpret_cast<Isolate*>( |
176 (callback)(state->script_url(), | 179 (callback)(state->script_url(), |
177 state->function_name(), | 180 state->function_name(), |
178 state->package_root(), | 181 state->package_root(), |
| 182 &api_flags, |
179 init_data, | 183 init_data, |
180 error)); | 184 error)); |
181 if (child_isolate == NULL) { | 185 if (child_isolate == NULL) { |
182 return false; | 186 return false; |
183 } | 187 } |
184 // TODO(iposva): Evaluate whether it's ok to override the embedder's setup. | |
185 // Currently the strict_compilation flag is ignored if it's false and | |
186 // checked-mode was enabled using a command-line flag. The command-line flag | |
187 // overrides the user code's request. | |
188 child_isolate->set_strict_compilation(state->checked_mode()); | |
189 if (!state->is_spawn_uri()) { | 188 if (!state->is_spawn_uri()) { |
190 // For isolates spawned using the spawn semantics we set | 189 // For isolates spawned using the spawn semantics we set |
191 // the origin_id to the origin_id of the parent isolate. | 190 // the origin_id to the origin_id of the parent isolate. |
192 child_isolate->set_origin_id(parent_isolate->origin_id()); | 191 child_isolate->set_origin_id(parent_isolate->origin_id()); |
193 } | 192 } |
194 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); | 193 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); |
195 return true; | 194 return true; |
196 } | 195 } |
197 | 196 |
198 | 197 |
(...skipping 28 matching lines...) Expand all Loading... |
227 Function& func = Function::Handle(); | 226 Function& func = Function::Handle(); |
228 func = Closure::function(closure); | 227 func = Closure::function(closure); |
229 if (func.IsImplicitClosureFunction() && func.is_static()) { | 228 if (func.IsImplicitClosureFunction() && func.is_static()) { |
230 #if defined(DEBUG) | 229 #if defined(DEBUG) |
231 Context& ctx = Context::Handle(); | 230 Context& ctx = Context::Handle(); |
232 ctx = Closure::context(closure); | 231 ctx = Closure::context(closure); |
233 ASSERT(ctx.num_variables() == 0); | 232 ASSERT(ctx.num_variables() == 0); |
234 #endif | 233 #endif |
235 // Get the parent function so that we get the right function name. | 234 // Get the parent function so that we get the right function name. |
236 func = func.parent_function(); | 235 func = func.parent_function(); |
237 bool checkedFlag = isolate->strict_compilation(); | |
238 Spawn(isolate, new IsolateSpawnState(port.Id(), | 236 Spawn(isolate, new IsolateSpawnState(port.Id(), |
239 func, | 237 func, |
240 message, | 238 message, |
241 paused.value(), | 239 paused.value())); |
242 checkedFlag)); | |
243 return Object::null(); | 240 return Object::null(); |
244 } | 241 } |
245 } | 242 } |
246 const String& msg = String::Handle(String::New( | 243 const String& msg = String::Handle(String::New( |
247 "Isolate.spawn expects to be passed a static or top-level function")); | 244 "Isolate.spawn expects to be passed a static or top-level function")); |
248 Exceptions::ThrowArgumentError(msg); | 245 Exceptions::ThrowArgumentError(msg); |
249 return Object::null(); | 246 return Object::null(); |
250 } | 247 } |
251 | 248 |
252 | 249 |
(...skipping 18 matching lines...) Expand all Loading... |
271 } | 268 } |
272 | 269 |
273 char* utf8_package_root = NULL; | 270 char* utf8_package_root = NULL; |
274 if (!package_root.IsNull()) { | 271 if (!package_root.IsNull()) { |
275 const intptr_t len = Utf8::Length(package_root); | 272 const intptr_t len = Utf8::Length(package_root); |
276 utf8_package_root = zone->Alloc<char>(len + 1); | 273 utf8_package_root = zone->Alloc<char>(len + 1); |
277 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); | 274 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); |
278 utf8_package_root[len] = '\0'; | 275 utf8_package_root[len] = '\0'; |
279 } | 276 } |
280 | 277 |
281 bool checkedFlag; | 278 IsolateSpawnState* state = new IsolateSpawnState(port.Id(), |
282 if (checked.IsNull()) { | 279 canonical_uri, |
283 checkedFlag = isolate->strict_compilation(); | 280 utf8_package_root, |
284 } else { | 281 args, |
285 checkedFlag = checked.value(); | 282 message, |
| 283 paused.value()); |
| 284 // If we were passed a value then override the default flags state for |
| 285 // checked mode. |
| 286 if (!checked.IsNull()) { |
| 287 state->isolate_flags()->set_checked(checked.value()); |
286 } | 288 } |
287 | 289 |
288 Spawn(isolate, new IsolateSpawnState(port.Id(), | 290 Spawn(isolate, state); |
289 canonical_uri, | |
290 utf8_package_root, | |
291 args, | |
292 message, | |
293 paused.value(), | |
294 checkedFlag)); | |
295 return Object::null(); | 291 return Object::null(); |
296 } | 292 } |
297 | 293 |
298 | 294 |
299 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) { | 295 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) { |
300 const Array& result = Array::Handle(Array::New(3)); | 296 const Array& result = Array::Handle(Array::New(3)); |
301 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port()))); | 297 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port()))); |
302 result.SetAt(1, Capability::Handle( | 298 result.SetAt(1, Capability::Handle( |
303 Capability::New(isolate->pause_capability()))); | 299 Capability::New(isolate->pause_capability()))); |
304 result.SetAt(2, Capability::Handle( | 300 result.SetAt(2, Capability::Handle( |
(...skipping 13 matching lines...) Expand all Loading... |
318 MessageWriter writer(&data, &allocator, false); | 314 MessageWriter writer(&data, &allocator, false); |
319 writer.WriteMessage(msg); | 315 writer.WriteMessage(msg); |
320 | 316 |
321 PortMap::PostMessage(new Message(port.Id(), | 317 PortMap::PostMessage(new Message(port.Id(), |
322 data, writer.BytesWritten(), | 318 data, writer.BytesWritten(), |
323 Message::kOOBPriority)); | 319 Message::kOOBPriority)); |
324 return Object::null(); | 320 return Object::null(); |
325 } | 321 } |
326 | 322 |
327 } // namespace dart | 323 } // namespace dart |
OLD | NEW |