Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: Source/bindings/dart/scripts/templates/interface_h.template

Issue 469373002: Bindings generation emits (more) correct null checking (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/dartium
Patch Set: Adding in fixes to binding generation Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/dart/scripts/dart_types.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/dart/scripts/templates/interface_h.template
diff --git a/Source/bindings/dart/scripts/templates/interface_h.template b/Source/bindings/dart/scripts/templates/interface_h.template
index 353d0883faa9401b9b3ea4f4c69dcc670122f979..8d5f4a233a4c5dd4506e4fb569eb1c57dd665775 100644
--- a/Source/bindings/dart/scripts/templates/interface_h.template
+++ b/Source/bindings/dart/scripts/templates/interface_h.template
@@ -57,26 +57,42 @@ struct {{dart_class}} {
return static_cast<{{cpp_class}}*>(value);
}
+ // FIXME: This has redundant null checks, and much of this code should
+ // be moved to a common place to reduce code bloat.
+ // Convert to native, Dart_Null is an error
static NativeType* toNative(Dart_Handle handle, Dart_Handle& exception)
{
- DartDOMData* domData = DartDOMData::current();
- return DartDOMWrapper::unwrapDartWrapper<{{dart_class}}>(domData, handle, exception);
+ if (!Dart_IsNull(handle)) {
+ DartDOMData* domData = DartDOMData::current();
+ return DartDOMWrapper::unwrapDartWrapper<{{dart_class}}>(domData, handle, exception);
+ } else {
+ exception = Dart_NewStringFromCString("Null value is not a valid {{dart_class}}");
+ return 0;
+ }
}
+ // Convert nullable to native, Dart_Null maps to C++ null
static NativeType* toNativeWithNullCheck(Dart_Handle handle, Dart_Handle& exception)
{
- return Dart_IsNull(handle) ? 0 : toNative(handle, exception);
+ DartDOMData* domData = DartDOMData::current();
+ return DartDOMWrapper::unwrapDartWrapper<{{dart_class}}>(domData, handle, exception);
}
+ // Convert to native, Dart_Null is an error
static NativeType* toNative(Dart_NativeArguments args, int index, Dart_Handle& exception)
{
- return DartDOMWrapper::unwrapDartWrapper<{{dart_class}}>(args, index, exception);
+ NativeType* result = DartDOMWrapper::unwrapDartWrapper<{{dart_class}}>(args, index, exception);
+ if (result || exception) {
+ return result;
+ }
+ exception = Dart_NewStringFromCString("Null value is not a valid {{dart_class}}");
+ return 0;
}
+ // Convert nullable to native, Dart_Null maps to C++ null
static NativeType* toNativeWithNullCheck(Dart_NativeArguments args, int index, Dart_Handle& exception)
{
- // toNative accounts for Null objects also.
- return toNative(args, index, exception);
+ return DartDOMWrapper::unwrapDartWrapper<{{dart_class}}>(args, index, exception);
}
static Dart_Handle toDart(NativeType* value)
« no previous file with comments | « Source/bindings/dart/scripts/dart_types.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698