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