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 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args); | 164 Exceptions::ThrowByType(Exceptions::kIsolateSpawn, args); |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 static bool CanonicalizeUri(Isolate* isolate, | 168 static bool CanonicalizeUri(Isolate* isolate, |
169 const Library& library, | 169 const Library& library, |
170 const String& uri, | 170 const String& uri, |
171 char** canonical_uri, | 171 char** canonical_uri, |
172 char** error) { | 172 char** error) { |
173 Zone* zone = isolate->current_zone(); | 173 Zone* zone = isolate->current_zone(); |
| 174 bool retval = false; |
174 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); | 175 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); |
175 if (handler == NULL) { | 176 if (handler != NULL) { |
| 177 Dart_EnterScope(); |
| 178 Dart_Handle result = handler(kCanonicalizeUrl, |
| 179 Api::NewHandle(isolate, library.raw()), |
| 180 Api::NewHandle(isolate, uri.raw())); |
| 181 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
| 182 if (obj.IsString()) { |
| 183 *canonical_uri = zone->MakeCopyOfString(String::Cast(obj).ToCString()); |
| 184 retval = true; |
| 185 } else if (obj.IsError()) { |
| 186 Error& error_obj = Error::Handle(); |
| 187 error_obj ^= obj.raw(); |
| 188 *error = zone->PrintToString("Unable to canonicalize uri '%s': %s", |
| 189 uri.ToCString(), error_obj.ToErrorCString()); |
| 190 } else { |
| 191 *error = zone->PrintToString("Unable to canonicalize uri '%s': " |
| 192 "library tag handler returned wrong type", |
| 193 uri.ToCString()); |
| 194 } |
| 195 Dart_ExitScope(); |
| 196 } else { |
176 *error = zone->PrintToString( | 197 *error = zone->PrintToString( |
177 "Unable to canonicalize uri '%s': no library tag handler found.", | 198 "Unable to canonicalize uri '%s': no library tag handler found.", |
178 uri.ToCString()); | 199 uri.ToCString()); |
179 return false; | |
180 } | 200 } |
181 Dart_Handle result = handler(kCanonicalizeUrl, | 201 return retval; |
182 Api::NewHandle(isolate, library.raw()), | |
183 Api::NewHandle(isolate, uri.raw())); | |
184 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); | |
185 if (obj.IsError()) { | |
186 Error& error_obj = Error::Handle(); | |
187 error_obj ^= obj.raw(); | |
188 *error = zone->PrintToString("Unable to canonicalize uri '%s': %s", | |
189 uri.ToCString(), error_obj.ToErrorCString()); | |
190 return false; | |
191 } else if (obj.IsString()) { | |
192 *canonical_uri = zone->MakeCopyOfString(String::Cast(obj).ToCString()); | |
193 return true; | |
194 } else { | |
195 *error = zone->PrintToString("Unable to canonicalize uri '%s': " | |
196 "library tag handler returned wrong type", | |
197 uri.ToCString()); | |
198 return false; | |
199 } | |
200 } | 202 } |
201 | 203 |
202 | 204 |
203 class SpawnState { | 205 class SpawnState { |
204 public: | 206 public: |
205 SpawnState(const Function& func, const Function& callback_func) | 207 SpawnState(const Function& func, const Function& callback_func) |
206 : isolate_(NULL), | 208 : isolate_(NULL), |
207 script_url_(NULL), | 209 script_url_(NULL), |
208 library_url_(NULL), | 210 library_url_(NULL), |
209 function_name_(NULL), | 211 function_name_(NULL), |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 488 |
487 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { | 489 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { |
488 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); | 490 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); |
489 if (port.IsError()) { | 491 if (port.IsError()) { |
490 Exceptions::PropagateError(Error::Cast(port)); | 492 Exceptions::PropagateError(Error::Cast(port)); |
491 } | 493 } |
492 return port.raw(); | 494 return port.raw(); |
493 } | 495 } |
494 | 496 |
495 } // namespace dart | 497 } // namespace dart |
OLD | NEW |