Files
sdk/runtime/include
asiva@google.com d5fbbd593a Add a new API function to extract all the native arguments into an array
passed in by the caller.

This call can be used in DOM bindings patterns as follows:
Old code -

Dart_Handle exception = 0;
{
        WebGL* receiver = DartDOMWrapper::receiver< WebGL >(args);
        unsigned srcRGB = DartUtilities::dartToUnsigned(args, 1, exception);
        if (exception)
            goto fail;
        unsigned dstRGB = DartUtilities::dartToUnsigned(args, 2, exception);
        if (exception)
            goto fail;
        unsigned srcAlpha = DartUtilities::dartToUnsigned(args, 3, exception);
        if (exception)
            goto fail;
        unsigned dstAlpha = DartUtilities::dartToUnsigned(args, 4, exception);
        if (exception)
            goto fail;
        receiver->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
        return;
}
fail:
    Dart_ThrowException(exception);
    ASSERT_NOT_REACHED();


Proposed new code -

/**
 * One time initialization code for setting up argument descriptors
 */
const int kNumArgs = 5;
const int kNumNativeFields = 2;
static const uint8_t native_arg_descriptor[kNumArgs] = {
  DART_NATIVE_ARG_DESCRIPTOR(Dart_NativeArgument_kNativeFields, 0),
  DART_NATIVE_ARG_DESCRIPTOR(Dart_NativeArgument_kUint32, 1),
  DART_NATIVE_ARG_DESCRIPTOR(Dart_NativeArgument_kUint32, 2),
  DART_NATIVE_ARG_DESCRIPTOR(Dart_NativeArgument_kUint32, 3),
  DART_NATIVE_ARG_DESCRIPTOR(Dart_NativeArgument_kUint32, 4),
};
Dart_NativeArgument_Value native_args[kNumArgs];
intptr_t native_fields[kNumNativeFields];
native_args[0].as_native_fields.num_fields = kNumNativeFields;
native_args[0].as_native_fields.values = native_fields;

/**
 * Code executed for each invocation of the binding method
 */
Dart_Handle result = Dart_GetNativeArguments(args, kNumArgs, native_arg_descriptor, native_args);
if (Dart_IsError(result)) {
    Dart_ThrowException(result);
}
WebGL* receiver = DartDOMWrapper::receiver< WebGL >(native_args[0].as_native_fields.values);
unsigned srcRGB = native_args[1].as_uint32;
unsigned dstRGB = native_args[2].as_uint32;
unsigned srcAlpha = native_args[3].as_uint32;
unsigned dstAlpha = native_args[4].as_uint32;
receiver->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
return;

R=iposva@google.com, vsm@google.com

Review URL: https://codereview.chromium.org//282883002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@36464 260f80e4-7a28-3924-810f-c04153c831b5
2014-05-22 00:08:23 +00:00
..