Files
sdk/runtime/bin/eventhandler.cc
T
turnidge@google.com 8c64adf13e Deal with unhandled exceptions the same way in all Dart api functions.
--

Terminology change: invalid handles are now called error handles.

Unhandled exceptions used to be a kind of valid handle.  Now they are
a kind of error handle.

For the Dart_Invoke* functions, this means that the standard
error-checking blob drops from two tests to one test and is
harder to mess up.

Many other Dart api functions (Dart_ToString, for example) previously
dealt with unhandled exceptions by turning them into terse error
messages.  Now these functions preserve information about the
exceptions and generate better error messages.

Changed Dart_HandleMessage to return success/failure.  It seemed to fit.

--

Details:

Dart_IsValid becomes Dart_IsError (negated sense).

Dart_GetError now knows how to print a stack trace semi-nicely.

Dart_ExceptionOccurred -> Dart_IsUnhandledException.

Renamed ApiFailure class to ApiError to fit better.

ApiError now has a "data" pointer that points to either an error
message string or to an unhandled exception object.

Documentation changes aplenty.
Review URL: http://codereview.chromium.org//8501034

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1470 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-11 19:31:04 +00:00

69 lines
2.3 KiB
C++

// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "bin/dartutils.h"
#include "bin/eventhandler.h"
#include "include/dart_api.h"
static const intptr_t kNativeEventHandlerFieldIndex = 0;
/*
* Returns the reference of the EventHandler stored in the native field.
*/
static EventHandler* GetEventHandler(Dart_Handle handle) {
intptr_t value = 0;
Dart_Handle result = Dart_GetNativeInstanceField(
handle, kNativeEventHandlerFieldIndex, &value);
ASSERT(!Dart_IsError(result));
EventHandler* event_handler = reinterpret_cast<EventHandler*>(value);
ASSERT(event_handler != NULL);
return event_handler;
}
/*
* Sets the reference of the EventHandler in the native field.
*/
static void SetEventHandler(Dart_Handle handle, EventHandler* event_handler) {
Dart_SetNativeInstanceField(handle,
kNativeEventHandlerFieldIndex,
reinterpret_cast<intptr_t>(event_handler));
}
/*
* Starts the EventHandler thread and stores its reference in the dart
* EventHandler object. args[0] holds the reference to the dart EventHandler
* object.
*/
void FUNCTION_NAME(EventHandler_Start)(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_Handle handle = Dart_GetNativeArgument(args, 0);
EventHandler* event_handler = EventHandler::StartEventHandler();
SetEventHandler(handle, event_handler);
Dart_ExitScope();
}
/*
* Send data to the EventHandler thread to register for a given instance
* args[1] a ReceivePort args[2] with a notification event args[3]. args[0]
* holds the reference to the dart EventHandler object.
*/
void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_Handle handle = Dart_GetNativeArgument(args, 0);
EventHandler* event_handler = GetEventHandler(handle);
intptr_t id = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
handle = Dart_GetNativeArgument(args, 2);
Dart_Port dart_port =
DartUtils::GetIntegerInstanceField(handle, DartUtils::kIdFieldName);
intptr_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
event_handler->SendData(id, dart_port, data);
Dart_ExitScope();
}