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" |
11 #include "vm/exceptions.h" | 11 #include "vm/exceptions.h" |
12 #include "vm/lockers.h" | 12 #include "vm/lockers.h" |
13 #include "vm/longjump.h" | 13 #include "vm/longjump.h" |
14 #include "vm/message_handler.h" | 14 #include "vm/message_handler.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
17 #include "vm/port.h" | 17 #include "vm/port.h" |
18 #include "vm/resolver.h" | 18 #include "vm/resolver.h" |
19 #include "vm/snapshot.h" | 19 #include "vm/snapshot.h" |
20 #include "vm/symbols.h" | 20 #include "vm/symbols.h" |
| 21 #include "vm/unicode.h" |
21 | 22 |
22 namespace dart { | 23 namespace dart { |
23 | 24 |
24 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 25 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
25 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 26 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
26 return reinterpret_cast<uint8_t*>(new_ptr); | 27 return reinterpret_cast<uint8_t*>(new_ptr); |
27 } | 28 } |
28 | 29 |
29 | 30 |
30 DEFINE_NATIVE_ENTRY(CapabilityImpl_factory, 1) { | 31 DEFINE_NATIVE_ENTRY(CapabilityImpl_factory, 1) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if (callback == NULL) { | 147 if (callback == NULL) { |
147 *error = strdup("Null callback specified for isolate creation\n"); | 148 *error = strdup("Null callback specified for isolate creation\n"); |
148 Isolate::SetCurrent(parent_isolate); | 149 Isolate::SetCurrent(parent_isolate); |
149 return false; | 150 return false; |
150 } | 151 } |
151 | 152 |
152 void* init_data = parent_isolate->init_callback_data(); | 153 void* init_data = parent_isolate->init_callback_data(); |
153 Isolate* child_isolate = reinterpret_cast<Isolate*>( | 154 Isolate* child_isolate = reinterpret_cast<Isolate*>( |
154 (callback)(state->script_url(), | 155 (callback)(state->script_url(), |
155 state->function_name(), | 156 state->function_name(), |
| 157 state->package_root(), |
156 init_data, | 158 init_data, |
157 error)); | 159 error)); |
158 if (child_isolate == NULL) { | 160 if (child_isolate == NULL) { |
159 Isolate::SetCurrent(parent_isolate); | 161 Isolate::SetCurrent(parent_isolate); |
160 return false; | 162 return false; |
161 } | 163 } |
162 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); | 164 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); |
163 | 165 |
164 Isolate::SetCurrent(parent_isolate); | 166 Isolate::SetCurrent(parent_isolate); |
165 return true; | 167 return true; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 return Spawn(isolate, new IsolateSpawnState(port.Id(), func, message)); | 211 return Spawn(isolate, new IsolateSpawnState(port.Id(), func, message)); |
210 } | 212 } |
211 } | 213 } |
212 const String& msg = String::Handle(String::New( | 214 const String& msg = String::Handle(String::New( |
213 "Isolate.spawn expects to be passed a static or top-level function")); | 215 "Isolate.spawn expects to be passed a static or top-level function")); |
214 Exceptions::ThrowArgumentError(msg); | 216 Exceptions::ThrowArgumentError(msg); |
215 return Object::null(); | 217 return Object::null(); |
216 } | 218 } |
217 | 219 |
218 | 220 |
219 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 4) { | 221 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 5) { |
220 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 222 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
221 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1)); | 223 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1)); |
222 GET_NON_NULL_NATIVE_ARGUMENT(Instance, args, arguments->NativeArgAt(2)); | 224 GET_NON_NULL_NATIVE_ARGUMENT(Instance, args, arguments->NativeArgAt(2)); |
223 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(3)); | 225 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(3)); |
| 226 GET_NATIVE_ARGUMENT(String, package_root, arguments->NativeArgAt(4)); |
224 | 227 |
225 // Canonicalize the uri with respect to the current isolate. | 228 // Canonicalize the uri with respect to the current isolate. |
226 char* error = NULL; | 229 char* error = NULL; |
227 char* canonical_uri = NULL; | 230 char* canonical_uri = NULL; |
228 const Library& root_lib = | 231 const Library& root_lib = |
229 Library::Handle(arguments->isolate()->object_store()->root_library()); | 232 Library::Handle(arguments->isolate()->object_store()->root_library()); |
230 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, | 233 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, |
231 &canonical_uri, &error)) { | 234 &canonical_uri, &error)) { |
232 const String& msg = String::Handle(String::New(error)); | 235 const String& msg = String::Handle(String::New(error)); |
233 ThrowIsolateSpawnException(msg); | 236 ThrowIsolateSpawnException(msg); |
234 } | 237 } |
235 | 238 |
236 return Spawn(isolate, new IsolateSpawnState(port.Id(), canonical_uri, | 239 char* utf8_package_root = NULL; |
237 args, message)); | 240 if (!package_root.IsNull()) { |
| 241 const intptr_t len = Utf8::Length(package_root); |
| 242 Zone* zone = isolate->current_zone(); |
| 243 utf8_package_root = zone->Alloc<char>(len + 1); |
| 244 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); |
| 245 utf8_package_root[len] = '\0'; |
| 246 } |
| 247 |
| 248 return Spawn(isolate, new IsolateSpawnState( |
| 249 port.Id(), canonical_uri, utf8_package_root, args, message)); |
238 } | 250 } |
239 | 251 |
240 | 252 |
241 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) { | 253 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) { |
242 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); | 254 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); |
243 GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1)); | 255 GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1)); |
244 | 256 |
245 // Make sure to route this request to the isolate library OOB mesage handler. | 257 // Make sure to route this request to the isolate library OOB mesage handler. |
246 msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg))); | 258 msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg))); |
247 | 259 |
248 uint8_t* data = NULL; | 260 uint8_t* data = NULL; |
249 MessageWriter writer(&data, &allocator); | 261 MessageWriter writer(&data, &allocator); |
250 writer.WriteMessage(msg); | 262 writer.WriteMessage(msg); |
251 | 263 |
252 PortMap::PostMessage(new Message(port.Id(), | 264 PortMap::PostMessage(new Message(port.Id(), |
253 data, writer.BytesWritten(), | 265 data, writer.BytesWritten(), |
254 Message::kOOBPriority)); | 266 Message::kOOBPriority)); |
255 return Object::null(); | 267 return Object::null(); |
256 } | 268 } |
257 | 269 |
258 } // namespace dart | 270 } // namespace dart |
OLD | NEW |