Chromium Code Reviews| Index: runtime/vm/dart_api_impl.cc |
| =================================================================== |
| --- runtime/vm/dart_api_impl.cc (revision 1762) |
| +++ runtime/vm/dart_api_impl.cc (working copy) |
| @@ -85,6 +85,61 @@ |
| } |
| +// NOTE: Need to pass 'result' as a parameter here in order to avoid |
| +// warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| +// which shows up because of the use of setjmp. |
| +static void InvokeStatic(Isolate* isolate, |
| + const Function& function, |
| + GrowableArray<const Object*>& args, |
| + Dart_Handle* result) { |
| + ASSERT(isolate != NULL); |
| + LongJump* base = isolate->long_jump_base(); |
| + LongJump jump; |
| + isolate->set_long_jump_base(&jump); |
| + if (setjmp(*jump.Set()) == 0) { |
| + const Array& kNoArgumentNames = Array::Handle(); |
| + const Instance& retval = Instance::Handle( |
| + DartEntry::InvokeStatic(function, args, kNoArgumentNames)); |
| + if (retval.IsUnhandledException()) { |
| + *result = Api::ErrorFromException(retval); |
| + } else { |
| + *result = Api::NewLocalHandle(retval); |
| + } |
| + } else { |
| + SetupErrorResult(result); |
| + } |
| + isolate->set_long_jump_base(base); |
| +} |
| + |
| + |
| +// NOTE: Need to pass 'result' as a parameter here in order to avoid |
| +// warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| +// which shows up because of the use of setjmp. |
| +static void InvokeDynamic(Isolate* isolate, |
| + const Instance& receiver, |
| + const Function& function, |
| + GrowableArray<const Object*>& args, |
| + Dart_Handle* result) { |
| + ASSERT(isolate != NULL); |
| + LongJump* base = isolate->long_jump_base(); |
| + LongJump jump; |
| + isolate->set_long_jump_base(&jump); |
| + if (setjmp(*jump.Set()) == 0) { |
| + const Array& kNoArgumentNames = Array::Handle(); |
| + const Instance& retval = Instance::Handle( |
| + DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); |
| + if (retval.IsUnhandledException()) { |
| + *result = Api::ErrorFromException(retval); |
| + } else { |
| + *result = Api::NewLocalHandle(retval); |
| + } |
| + } else { |
| + SetupErrorResult(result); |
| + } |
| + isolate->set_long_jump_base(base); |
| +} |
| + |
| + |
| Dart_Handle Api::NewLocalHandle(const Object& object) { |
| Isolate* isolate = Isolate::Current(); |
| ASSERT(isolate != NULL); |
| @@ -359,7 +414,7 @@ |
| } |
| -// TODO(turnidge): This clonse Api::Error. I need to use va_copy to |
| +// TODO(turnidge): This clones Api::Error. I need to use va_copy to |
| // fix this but not sure if it available on all of our builds. |
| DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| DARTSCOPE(Isolate::Current()); |
| @@ -601,7 +656,7 @@ |
| const String& class_name = |
| String::Handle(String::NewSymbol("ReceivePortImpl")); |
| const String& function_name = |
| - String::Handle(String::NewSymbol("handleMessage_")); |
| + String::Handle(String::NewSymbol("_handleMessage")); |
| const int kNumArguments = 3; |
| const Array& kNoArgumentNames = Array::Handle(); |
| const Function& function = Function::Handle( |
| @@ -615,6 +670,7 @@ |
| arguments.Add(&Integer::Handle(Integer::New(dest_port))); |
| arguments.Add(&Integer::Handle(Integer::New(reply_port))); |
| arguments.Add(&msg); |
| + // TODO(turnidge): This call should be wrapped in a longjmp |
| const Object& result = Object::Handle( |
| DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| if (result.IsUnhandledException()) { |
| @@ -644,6 +700,13 @@ |
| } |
| +DART_EXPORT bool Dart_HasLivePorts() { |
| + Isolate* isolate = Isolate::Current(); |
| + ASSERT(isolate); |
| + return isolate->live_ports() > 0; |
| +} |
| + |
| + |
| static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| return reinterpret_cast<uint8_t*>(new_ptr); |
| @@ -674,6 +737,59 @@ |
| } |
| +DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port) { |
|
siva
2011/11/29 19:50:27
I am still not clear why this should not be
Dart_G
|
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); |
| + const String& function_name = String::Handle(String::NewSymbol("_create")); |
| + const int kNumArguments = 1; |
| + const Array& kNoArgumentNames = Array::Handle(); |
| + // TODO(turnidge): Consider adding a helper function to make |
| + // function resolution by class name and function name more concise. |
| + const Function& function = Function::Handle( |
| + Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
| + class_name, |
| + function_name, |
| + kNumArguments, |
| + kNoArgumentNames, |
| + Resolver::kIsQualified)); |
| + GrowableArray<const Object*> arguments(kNumArguments); |
| + arguments.Add(&Integer::Handle(Integer::New(port))); |
| + Dart_Handle result; |
| + InvokeStatic(isolate, function, arguments, &result); |
| + return result; |
| +} |
| + |
| + |
| +DART_EXPORT Dart_Handle Dart_NewReceivePort(Dart_Port port) { |
|
siva
2011/11/29 19:50:27
Ditto comment about why not Dart_GetReceivePort(po
|
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + const String& class_name = |
| + String::Handle(String::NewSymbol("ReceivePortImpl")); |
| + const String& function_name = String::Handle(String::NewSymbol("_create")); |
| + const int kNumArguments = 1; |
| + const Array& kNoArgumentNames = Array::Handle(); |
| + const Function& function = Function::Handle( |
| + Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
| + class_name, |
| + function_name, |
| + kNumArguments, |
| + kNoArgumentNames, |
| + Resolver::kIsQualified)); |
| + GrowableArray<const Object*> arguments(kNumArguments); |
| + arguments.Add(&Integer::Handle(Integer::New(port))); |
| + Dart_Handle result; |
| + InvokeStatic(isolate, function, arguments, &result); |
| + return result; |
| +} |
| + |
| + |
| +DART_EXPORT Dart_Port Dart_GetMainPort() { |
| + Isolate* isolate = Isolate::Current(); |
| + ASSERT(isolate); |
| + return isolate->main_port(); |
| +} |
| + |
| // --- Scopes ---- |
| @@ -1549,61 +1665,6 @@ |
| // --- Methods and Fields --- |
| -// NOTE: Need to pass 'result' as a parameter here in order to avoid |
| -// warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| -// which shows up because of the use of setjmp. |
| -static void InvokeStatic(Isolate* isolate, |
| - const Function& function, |
| - GrowableArray<const Object*>& args, |
| - Dart_Handle* result) { |
| - ASSERT(isolate != NULL); |
| - LongJump* base = isolate->long_jump_base(); |
| - LongJump jump; |
| - isolate->set_long_jump_base(&jump); |
| - if (setjmp(*jump.Set()) == 0) { |
| - const Array& kNoArgumentNames = Array::Handle(); |
| - const Instance& retval = Instance::Handle( |
| - DartEntry::InvokeStatic(function, args, kNoArgumentNames)); |
| - if (retval.IsUnhandledException()) { |
| - *result = Api::ErrorFromException(retval); |
| - } else { |
| - *result = Api::NewLocalHandle(retval); |
| - } |
| - } else { |
| - SetupErrorResult(result); |
| - } |
| - isolate->set_long_jump_base(base); |
| -} |
| - |
| - |
| -// NOTE: Need to pass 'result' as a parameter here in order to avoid |
| -// warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| -// which shows up because of the use of setjmp. |
| -static void InvokeDynamic(Isolate* isolate, |
| - const Instance& receiver, |
| - const Function& function, |
| - GrowableArray<const Object*>& args, |
| - Dart_Handle* result) { |
| - ASSERT(isolate != NULL); |
| - LongJump* base = isolate->long_jump_base(); |
| - LongJump jump; |
| - isolate->set_long_jump_base(&jump); |
| - if (setjmp(*jump.Set()) == 0) { |
| - const Array& kNoArgumentNames = Array::Handle(); |
| - const Instance& retval = Instance::Handle( |
| - DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); |
| - if (retval.IsUnhandledException()) { |
| - *result = Api::ErrorFromException(retval); |
| - } else { |
| - *result = Api::NewLocalHandle(retval); |
| - } |
| - } else { |
| - SetupErrorResult(result); |
| - } |
| - isolate->set_long_jump_base(base); |
| -} |
| - |
| - |
| DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, |
| Dart_Handle class_name_in, |
| Dart_Handle function_name_in, |