gboolean _gdart_marshaller_check_argument_in_array_parameters( GdartBridgeContext *self, Dart_Handle dart_list, gpointer arg_type, const TypeInfoKlass *arg_type_klass, gint fixed_length, Dart_Handle *dart_error_out, GError **error) { Dart_Handle temp_result, element; gintptr list_length, elem_i = 0; gpointer param_type; const TypeInfoKlass* param_type_klass; GError* inner_error = NULL; if (!arg_type_klass->get_param_type(arg_type, self, 0, ¶m_type, ¶m_type_klass, dart_error_out, error)) return FALSE; temp_result = Dart_ListLength(dart_list, &list_length); if (Dart_IsError(temp_result)) { *dart_error_out = temp_result; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); param_type_klass->free(param_type); return FALSE; } if (fixed_length != -1 && fixed_length != list_length) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: the array did not have a length, a fixed size or a null termination so I can't handle it", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: the array did not have a length, a fixed size or a null termination so I can't handle it", G_STRFUNC); param_type_klass->free(param_type); return FALSE; } for (; elem_i < list_length; elem_i++) { element = Dart_ListGetAt(dart_list, elem_i); if (Dart_IsError(element)) { *dart_error_out = element; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); param_type_klass->free(param_type); return FALSE; } if (!_gdart_marshaller_check_array_element(self, element, param_type, param_type_klass, dart_error_out, &inner_error)) { g_propagate_error(error, inner_error); param_type_klass->free(param_type); return FALSE; } } param_type_klass->free(param_type); return TRUE; }
/* LIbrary Initialise function */ DART_EXPORT Dart_Handle amqp_extension_Init(Dart_Handle parent_library) { if (Dart_IsError(parent_library)) { return parent_library; } Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); if (Dart_IsError(result_code)) return result_code; return Dart_Null(); }
/* Native entry point for the extension library. */ DART_EXPORT Dart_Handle test_extension_Init(Dart_Handle parent_library) { Dart_Handle result_code; if (Dart_IsError(parent_library)) { return parent_library; } result_code = Dart_SetNativeResolver(parent_library, ResolveName); if (Dart_IsError(result_code)) { return result_code; } return parent_library; }
gboolean _gdart_marshaller_check_argument_flags( GdartBridgeContext *self, Dart_Handle element, gpointer type, const EnumInfoKlass *type_klass, Dart_Handle *dart_error_out, GError **error) { Dart_Handle base_object_class, temp_result, inner_container, name_handle; bool is_proper_type; int64_t raw_result; base_object_class = gdart_bridge_context_get_base_enum_class(self, dart_error_out, error); if (base_object_class == NULL) { return false; } temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type); if (Dart_IsError(temp_result)) { *dart_error_out = temp_result; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); goto error; } if (!is_proper_type) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: received an unexpected base info type", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: received an unexpected base info type", G_STRFUNC); goto error; } name_handle = Dart_NewStringFromCString("index"); if (Dart_IsError(name_handle)) { *dart_error_out = name_handle; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } inner_container = Dart_GetField(element, name_handle); if (Dart_IsError(inner_container)) { *dart_error_out = inner_container; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } temp_result = Dart_IntegerToInt64(inner_container, &raw_result); if (Dart_IsError(temp_result)) { *dart_error_out = temp_result; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } return TRUE; error: return FALSE; }
gboolean _gdart_marshaller_check_argument_in_object( GdartBridgeContext *self, Dart_Handle dart_args, gint *dartarg_i, gpointer type, const ObjectInfoKlass *type_klass, Dart_Handle *dart_error_out, GError **error) { Dart_Handle element; element = Dart_ListGetAt(dart_args, (*dartarg_i)++); if (Dart_IsError(element)) { *dart_error_out = element; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); goto error; } return _gdart_marshaller_check_argument_object(self, element, type, type_klass, dart_error_out, error); error: return FALSE; }
Paint DartConverter<Paint>::FromDart(Dart_Handle dart_paint) { Paint result; result.is_null = true; if (Dart_IsNull(dart_paint)) return result; Dart_Handle value_handle = UIDartState::Current()->value_handle(); Dart_Handle data = Dart_GetField(dart_paint, value_handle); if (Dart_IsInteger(data)) { // This is a simple Paint object that just contains a color with // anti-aliasing enabled. The data is the color, represented as an // int in the same format as SkColor. result.sk_paint.setColor(DartConverter<SkColor>::FromDart(data)); result.sk_paint.setAntiAlias(true); result.is_null = false; return result; } DCHECK(Dart_IsList(data)); intptr_t length; Dart_ListLength(data, &length); CHECK_EQ(length, kNumberOfPaintFields); Dart_Handle values[kNumberOfPaintFields]; Dart_Handle range_result = Dart_ListGetRange(data, 0, kNumberOfPaintFields, values); if (Dart_IsError(range_result)) { return result; } SkPaint& paint = result.sk_paint; if (!Dart_IsNull(values[kStyle])) paint.setStyle(static_cast<SkPaint::Style>(DartConverter<int>::FromDart(values[kStyle]))); if (!Dart_IsNull(values[kStrokeWidth])) paint.setStrokeWidth(DartConverter<SkScalar>::FromDart(values[kStrokeWidth])); if (!Dart_IsNull(values[kStrokeCap])) paint.setStrokeCap(static_cast<SkPaint::Cap>(DartConverter<int>::FromDart(values[kStrokeCap]))); if (!Dart_IsNull(values[kIsAntiAlias])) paint.setAntiAlias(DartConverter<bool>::FromDart(values[kIsAntiAlias])); if (!Dart_IsNull(values[kColor])) paint.setColor(static_cast<SkColor>(DartConverter<int>::FromDart(values[kColor]))); if (!Dart_IsNull(values[kTransferMode])) paint.setXfermodeMode(static_cast<SkXfermode::Mode>(DartConverter<int>::FromDart(values[kTransferMode]))); if (!Dart_IsNull(values[kColorFilter])) paint.setColorFilter(DartConverter<ColorFilter*>::FromDart(values[kColorFilter])->filter()); if (!Dart_IsNull(values[kMaskFilter])) paint.setMaskFilter(DartConverter<MaskFilter*>::FromDart(values[kMaskFilter])->filter()); if (!Dart_IsNull(values[kFilterQuality])) paint.setFilterQuality(static_cast<SkFilterQuality>(DartConverter<int>::FromDart(values[kFilterQuality]))); if (!Dart_IsNull(values[kShader])) paint.setShader(DartConverter<Shader*>::FromDart(values[kShader])->shader()); result.is_null = false; return result; }
/* Native resolver for the extension library. */ Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { /* assert(Dart_IsString(name)); */ const char* c_name; Dart_Handle check_error; check_error = Dart_StringToCString(name, &c_name); if (Dart_IsError(check_error)) { Dart_PropagateError(check_error); } if ((strcmp("TestExtension_IfNull", c_name) == 0) && (argc == 2)) { return IfNull; } if ((strcmp("TestExtension_ThrowMeTheBall", c_name) == 0) && (argc == 1)) { return ThrowMeTheBall; } return NULL; }
Dart_Handle Isolate::New(const char* typeName, int argc, Dart_Handle* args) { // entering and leaving the scope here causes us to invalidate the instance handle! // Dart_EnterScope(); // Get type Dart_Handle type = Dart_GetType(library_, NewString(typeName), 0, NULL); if(Dart_IsError(type)) { LOG_E(Dart_GetError(type)); } // Invoke the unnamed constructor. Dart_Handle instance = Dart_New(type, Dart_Null(), argc, args); if (Dart_IsError(instance)) { // Dart_NewApiError LOG_E(Dart_GetError(instance) << " while instantiating '"<< type <<"'") } // Dart_ExitScope(); return instance; }
void VM::loadCinderDartLib() { string script = getCinderDartScript(); Dart_Handle source = toDart( script ); CIDART_CHECK( source ); Dart_Handle cinderDartLib = Dart_LoadLibrary( toDart( "cinder.dart" ), source, 0, 0 ); if( Dart_IsError( cinderDartLib ) ) { throw DartException( string( "failed to load cinder.dart, error message: " ) + Dart_GetError( cinderDartLib ) ); } CIDART_CHECK( Dart_SetNativeResolver( cinderDartLib, Script::resolveNameHandler, NULL ) ); // finalize any scripts loaded, needs to be done before the libs can be looked up and modified below CIDART_CHECK( Dart_FinalizeLoading( false ) ); // swap in custom _printClosure to enable print() in dart Dart_Handle internalLib = Dart_LookupLibrary( toDart( "dart:_internal" ) ); CIDART_CHECK( internalLib ); Dart_Handle print = Dart_GetField( cinderDartLib, toDart( "_printClosure" ) ); CIDART_CHECK( print ); CIDART_CHECK( Dart_SetField( internalLib, toDart( "_printClosure" ), print ) ); }
gboolean _gdart_marshaller_check_argument_in_struct_from_gtype( GdartBridgeContext *self, Dart_Handle dart_args, gint *dartarg_i, GType type, Dart_Handle *dart_error_out, GError **error) { Dart_Handle element; element = Dart_ListGetAt(dart_args, (*dartarg_i)++); if (Dart_IsError(element)) { *dart_error_out = element; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); goto error; } return _gdart_marshaller_check_argument_struct_from_gtype(self, element, type, dart_error_out, error); error: return FALSE; }
gboolean _gdart_marshaller_check_argument_in_array(GdartBridgeContext *self, Dart_Handle dart_args, gint *dartarg_i, gpointer arg_type, const TypeInfoKlass *arg_type_klass, gint garg_i, Dart_Handle *dart_error_out, GError **error) { Dart_Handle element; gint arg_to_suppress, fixed_length = 0; gboolean is_zero_terminated; if (!arg_type_klass->get_array_length(arg_type, self, &arg_to_suppress, dart_error_out, error)) return FALSE; if (!arg_type_klass->get_array_fixed_size(arg_type, self, &fixed_length, dart_error_out, error)) return FALSE; if (!arg_type_klass->is_zero_terminated(arg_type, self, &is_zero_terminated, dart_error_out, error)) return FALSE; if (arg_to_suppress == -1 && fixed_length == -1 && !is_zero_terminated) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: the array did not have a length, a fixed size or a null termination so I can't handle it", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: the array did not have a length, a fixed size or a null termination so I can't handle it", G_STRFUNC); return FALSE; } element = Dart_ListGetAt(dart_args, (*dartarg_i)++); if (Dart_IsError(element)) { *dart_error_out = element; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } if (!Dart_IsList(element) && !Dart_IsNull(element)) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: expected string or null", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: expected string or null", G_STRFUNC); return FALSE; } if (Dart_IsNull(element) && fixed_length == -1) return TRUE; return _gdart_marshaller_check_argument_in_array_parameters(self, element, arg_type, arg_type_klass, fixed_length, dart_error_out, error); }
gboolean _gdart_marshaller_check_argument_object( GdartBridgeContext *self, Dart_Handle element, gpointer type, const ObjectInfoKlass *type_klass, Dart_Handle *dart_error_out, GError **error) { Dart_Handle base_object_class, temp_result, inner_container, name_handle; bool is_proper_type; RawPointerContainer* raw_pointer; GdartBridgeContextWrappedObject* object_info; GObject* object; GType gtype; GIInfoType object_info_type; base_object_class = gdart_bridge_context_get_base_object_class(self, dart_error_out, error); if (base_object_class == NULL) { return false; } if (Dart_IsNull(element)) { return TRUE; } temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type); if (Dart_IsError(temp_result)) { *dart_error_out = temp_result; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); goto error; } if (!is_proper_type) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: received an unexpected base info type", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: received an unexpected base info type", G_STRFUNC); goto error; } name_handle = Dart_NewStringFromCString("_internal"); if (Dart_IsError(name_handle)) { *dart_error_out = name_handle; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } inner_container = Dart_GetField(element, name_handle); if (Dart_IsError(inner_container)) { *dart_error_out = inner_container; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } temp_result = Dart_GetNativeInstanceField(inner_container, 0, (intptr_t*) &raw_pointer); if (Dart_IsError(temp_result)) { *dart_error_out = temp_result; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } object_info = (GdartBridgeContextWrappedObject*) raw_pointer->raw_pointer; if (!object_info->object_info_klass.get_type(object_info->object_info, self, &object_info_type, dart_error_out, error)) return FALSE; if (object_info_type != GI_INFO_TYPE_OBJECT) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: expected an object but got a struct", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: expected an object but got a struct", G_STRFUNC); goto error; } object = (GObject*) object_info->object; if (!type_klass->get_gtype(type, self, >ype, dart_error_out, error)) return FALSE; if (!g_type_is_a(G_OBJECT_TYPE(object), gtype)) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: expected an object of one type but got another", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: expected an object of one type but got another", G_STRFUNC); goto error; } return TRUE; error: return FALSE; }
gboolean _gdart_marshaller_check_argument_struct_from_gtype( GdartBridgeContext *self, Dart_Handle element, GType type, Dart_Handle *dart_error_out, GError **error) { Dart_Handle base_object_class, temp_result, inner_container, name_handle; bool is_proper_type; RawPointerContainer* raw_pointer; GdartBridgeContextWrappedObject* object_info; base_object_class = gdart_bridge_context_get_base_object_class(self, dart_error_out, error); if (base_object_class == NULL) { return false; } if (Dart_IsNull(element)) { return TRUE; } temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type); if (Dart_IsError(temp_result)) { *dart_error_out = temp_result; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); goto error; } if (!is_proper_type) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: received an unexpected base info type", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: received an unexpected base info type", G_STRFUNC); goto error; } name_handle = Dart_NewStringFromCString("_internal"); if (Dart_IsError(name_handle)) { *dart_error_out = name_handle; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } inner_container = Dart_GetField(element, name_handle); if (Dart_IsError(inner_container)) { *dart_error_out = inner_container; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } temp_result = Dart_GetNativeInstanceField(inner_container, 0, (intptr_t*) &raw_pointer); if (Dart_IsError(temp_result)) { *dart_error_out = temp_result; g_set_error(error, GDART_ERROR, 1, "Error from Dart operation."); return FALSE; } object_info = (GdartBridgeContextWrappedObject*) raw_pointer->raw_pointer; /* TODO: This is super-unreliable because there is no way to trust the gtype * given. * if (object_info->type != type) { *dart_error_out = gdart_bridge_context_create_error_handle(self, "%s: got an argument of the wrong type. This might be due to a problem in the GIR file", G_STRFUNC); g_set_error(error, GDART_ERROR, 1, "%s: got an argument of the wrong type. This might be due to a problem in the GIR file", G_STRFUNC); goto error; } */ return TRUE; error: return FALSE; }
void throwIfError( Dart_Handle handle, const std::string &description ) { if( Dart_IsError( handle ) ) { throwException( description + ", description: " + Dart_GetError( handle ) ); } }