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()); |
@@ -595,13 +650,14 @@ |
DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port, |
Dart_Port reply_port, |
Dart_Message dart_message) { |
- DARTSCOPE(Isolate::Current()); |
+ Isolate* isolate = Isolate::Current(); |
+ DARTSCOPE(isolate); |
siva
2011/11/24 00:52:31
The isolate variable is not used in this method is
turnidge
2011/11/29 01:01:31
Fixed.
|
const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); |
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 +671,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 +701,34 @@ |
} |
+DART_EXPORT bool Dart_HasLivePorts() { |
+ Isolate* isolate = Isolate::Current(); |
+ DARTSCOPE(isolate); |
+ const String& class_name = |
+ String::Handle(String::NewSymbol("ReceivePortImpl")); |
+ const String& function_name = |
+ String::Handle(String::NewSymbol("_getNumLivePorts")); |
+ const int kNumArguments = 0; |
+ 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); |
+ |
+ Dart_EnterScope(); |
siva
2011/11/24 00:52:31
Why is a Dart_EnterScope needed here? Normally we
turnidge
2011/11/29 01:01:31
Completely redid how this works.
|
+ Dart_Handle result; |
+ InvokeStatic(isolate, function, arguments, &result); |
+ const Integer& count = Api::UnwrapIntegerHandle(result); |
+ Dart_ExitScope(); |
+ |
+ return count.AsInt64Value() > 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 +759,57 @@ |
} |
+DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port) { |
+ 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(); |
+ 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) { |
+ 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)); |
siva
2011/11/24 00:52:31
The function resolution code seems to be identical
turnidge
2011/11/29 01:01:31
Added a TODO. Is that okay?
On 2011/11/24 00:52:
|
+ 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 +1685,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, |