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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 | 38 |
39 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 39 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
40 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 40 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
41 return reinterpret_cast<uint8_t*>(new_ptr); | 41 return reinterpret_cast<uint8_t*>(new_ptr); |
42 } | 42 } |
43 | 43 |
44 | 44 |
45 static void StoreError(Isolate* isolate, const Object& obj) { | 45 static void StoreError(Isolate* isolate, const Object& obj) { |
46 ASSERT(obj.IsError()); | 46 ASSERT(obj.IsError()); |
47 Error& error = Error::Handle(); | 47 isolate->object_store()->set_sticky_error(Error::Cast(obj)); |
48 error |= obj.raw(); | |
49 isolate->object_store()->set_sticky_error(error); | |
50 } | 48 } |
51 | 49 |
52 | 50 |
53 // TODO(turnidge): Move to DartLibraryCalls. | 51 // TODO(turnidge): Move to DartLibraryCalls. |
54 static RawObject* ReceivePortCreate(intptr_t port_id) { | 52 static RawObject* ReceivePortCreate(intptr_t port_id) { |
55 Isolate* isolate = Isolate::Current(); | 53 Isolate* isolate = Isolate::Current(); |
56 Function& func = | 54 Function& func = |
57 Function::Handle(isolate, | 55 Function::Handle(isolate, |
58 isolate->object_store()->receive_port_create_function()); | 56 isolate->object_store()->receive_port_create_function()); |
59 const int kNumArguments = 1; | 57 const int kNumArguments = 1; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 Api::NewHandle(isolate, library.raw()), | 182 Api::NewHandle(isolate, library.raw()), |
185 Api::NewHandle(isolate, uri.raw())); | 183 Api::NewHandle(isolate, uri.raw())); |
186 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); | 184 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
187 if (obj.IsError()) { | 185 if (obj.IsError()) { |
188 Error& error_obj = Error::Handle(); | 186 Error& error_obj = Error::Handle(); |
189 error_obj ^= obj.raw(); | 187 error_obj ^= obj.raw(); |
190 *error = zone->PrintToString("Unable to canonicalize uri '%s': %s", | 188 *error = zone->PrintToString("Unable to canonicalize uri '%s': %s", |
191 uri.ToCString(), error_obj.ToErrorCString()); | 189 uri.ToCString(), error_obj.ToErrorCString()); |
192 return false; | 190 return false; |
193 } else if (obj.IsString()) { | 191 } else if (obj.IsString()) { |
194 String& string_obj = String::Handle(); | 192 *canonical_uri = zone->MakeCopyOfString(String::Cast(obj).ToCString()); |
195 string_obj |= obj.raw(); | |
196 *canonical_uri = zone->MakeCopyOfString(string_obj.ToCString()); | |
197 return true; | 193 return true; |
198 } else { | 194 } else { |
199 *error = zone->PrintToString("Unable to canonicalize uri '%s': " | 195 *error = zone->PrintToString("Unable to canonicalize uri '%s': " |
200 "library tag handler returned wrong type", | 196 "library tag handler returned wrong type", |
201 uri.ToCString()); | 197 uri.ToCString()); |
202 return false; | 198 return false; |
203 } | 199 } |
204 } | 200 } |
205 | 201 |
206 | 202 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 Object& result = Object::Handle(); | 366 Object& result = Object::Handle(); |
371 result = state->ResolveFunction(); | 367 result = state->ResolveFunction(); |
372 delete state; | 368 delete state; |
373 state = NULL; | 369 state = NULL; |
374 if (result.IsError()) { | 370 if (result.IsError()) { |
375 StoreError(isolate, result); | 371 StoreError(isolate, result); |
376 return false; | 372 return false; |
377 } | 373 } |
378 ASSERT(result.IsFunction()); | 374 ASSERT(result.IsFunction()); |
379 Function& func = Function::Handle(isolate); | 375 Function& func = Function::Handle(isolate); |
380 func |= result.raw(); | 376 func ^= result.raw(); |
381 result = DartEntry::InvokeStatic(func, Object::empty_array()); | 377 result = DartEntry::InvokeStatic(func, Object::empty_array()); |
382 if (result.IsError()) { | 378 if (result.IsError()) { |
383 StoreError(isolate, result); | 379 StoreError(isolate, result); |
384 return false; | 380 return false; |
385 } | 381 } |
386 } | 382 } |
387 return true; | 383 return true; |
388 } | 384 } |
389 | 385 |
390 | 386 |
(...skipping 24 matching lines...) Expand all Loading... |
415 | 411 |
416 return port.raw(); | 412 return port.raw(); |
417 } | 413 } |
418 | 414 |
419 | 415 |
420 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 2) { | 416 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 2) { |
421 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 417 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
422 bool throw_exception = false; | 418 bool throw_exception = false; |
423 Function& func = Function::Handle(); | 419 Function& func = Function::Handle(); |
424 if (closure.IsClosure()) { | 420 if (closure.IsClosure()) { |
425 func |= Closure::function(closure); | 421 func = Closure::function(closure); |
426 const Class& cls = Class::Handle(func.Owner()); | 422 const Class& cls = Class::Handle(func.Owner()); |
427 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { | 423 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { |
428 throw_exception = true; | 424 throw_exception = true; |
429 } | 425 } |
430 } else { | 426 } else { |
431 throw_exception = true; | 427 throw_exception = true; |
432 } | 428 } |
433 if (throw_exception) { | 429 if (throw_exception) { |
434 const String& msg = String::Handle(String::New( | 430 const String& msg = String::Handle(String::New( |
435 "spawnFunction expects to be passed a closure to a top-level static " | 431 "spawnFunction expects to be passed a closure to a top-level static " |
436 "function")); | 432 "function")); |
437 ThrowIllegalArgException(msg); | 433 ThrowIllegalArgException(msg); |
438 } | 434 } |
439 | 435 |
440 GET_NATIVE_ARGUMENT(Instance, callback, arguments->NativeArgAt(1)); | 436 GET_NATIVE_ARGUMENT(Instance, callback, arguments->NativeArgAt(1)); |
441 Function& callback_func = Function::Handle(); | 437 Function& callback_func = Function::Handle(); |
442 if (callback.IsClosure()) { | 438 if (callback.IsClosure()) { |
443 callback_func |= Closure::function(callback); | 439 callback_func = Closure::function(callback); |
444 const Class& cls = Class::Handle(callback_func.Owner()); | 440 const Class& cls = Class::Handle(callback_func.Owner()); |
445 if (!callback_func.IsClosureFunction() || !callback_func.is_static() || | 441 if (!callback_func.IsClosureFunction() || !callback_func.is_static() || |
446 !cls.IsTopLevel()) { | 442 !cls.IsTopLevel()) { |
447 throw_exception = true; | 443 throw_exception = true; |
448 } | 444 } |
449 } else if (!callback.IsNull()) { | 445 } else if (!callback.IsNull()) { |
450 throw_exception = true; | 446 throw_exception = true; |
451 } | 447 } |
452 if (throw_exception) { | 448 if (throw_exception) { |
453 const String& msg = String::Handle(String::New( | 449 const String& msg = String::Handle(String::New( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 487 |
492 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { | 488 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { |
493 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); | 489 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); |
494 if (port.IsError()) { | 490 if (port.IsError()) { |
495 Exceptions::PropagateError(Error::Cast(port)); | 491 Exceptions::PropagateError(Error::Cast(port)); |
496 } | 492 } |
497 return port.raw(); | 493 return port.raw(); |
498 } | 494 } |
499 | 495 |
500 } // namespace dart | 496 } // namespace dart |
OLD | NEW |