Require a non-empty drag image to prevent crash
authorKevin Sawicki <kevinsawicki@gmail.com>
Thu, 26 Jan 2017 18:38:13 +0000 (10:38 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Thu, 26 Jan 2017 23:46:04 +0000 (15:46 -0800)
atom/browser/api/atom_api_web_contents.cc
spec/api-web-contents-spec.js

index 0d52112..a8f864c 100644 (file)
@@ -1327,9 +1327,17 @@ void WebContents::StartDrag(const mate::Dictionary& item,
 
   // Error checking.
   if (icon.IsEmpty()) {
+    args->ThrowError("Must specify 'icon' option");
+    return;
+  }
+
+#if defined(OS_MACOSX)
+  // NSWindow.dragImage requires a non-empty NSImage
+  if (icon->image().IsEmpty()) {
     args->ThrowError("Must specify non-empty 'icon' option");
     return;
   }
+#endif
 
   // Start dragging.
   if (!files.empty()) {
index 417b8d5..98aa116 100644 (file)
@@ -293,12 +293,14 @@ describe('webContents module', function () {
       }, /Must specify either 'file' or 'files' option/)
 
       assert.throws(() => {
-        w.webContents.startDrag({file: __filename, icon: __filename})
-      }, /Must specify non-empty 'icon' option/)
-
-      assert.throws(() => {
         w.webContents.startDrag({file: __filename})
-      }, /Must specify non-empty 'icon' option/)
+      }, /Must specify 'icon' option/)
+
+      if (process.platform === 'darwin') {
+        assert.throws(() => {
+          w.webContents.startDrag({file: __filename, icon: __filename})
+        }, /Must specify non-empty 'icon' option/)
+      }
     })
   })
 })