Browse Source

fix: reject the executeJavaScript promise when it fails to execute the script (#18714)

* fix: reject the executeJavaScript promise when it fails to execute the script

Closes #9102

* Update atom/renderer/api/atom_api_web_frame.cc

Co-Authored-By: Jeremy Apthorp <[email protected]>

* Update atom/renderer/api/atom_api_web_frame.cc

Co-Authored-By: Jeremy Apthorp <[email protected]>

* fix: missing semicolon
trop[bot] 5 years ago
parent
commit
33d860bcea
1 changed files with 14 additions and 3 deletions
  1. 14 3
      atom/renderer/api/atom_api_web_frame.cc

+ 14 - 3
atom/renderer/api/atom_api_web_frame.cc

@@ -99,9 +99,20 @@ class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
 
   void Completed(
       const blink::WebVector<v8::Local<v8::Value>>& result) override {
-    if (!result.empty() && !result[0].IsEmpty())
-      // Right now only single results per frame is supported.
-      promise_.Resolve(result[0]);
+    if (!result.empty()) {
+      if (!result[0].IsEmpty()) {
+        // Right now only single results per frame is supported.
+        promise_.Resolve(result[0]);
+      } else {
+        promise_.RejectWithErrorMessage(
+            "Script failed to execute, this normally means an error "
+            "was thrown. Check the renderer console for the error.");
+      }
+    } else {
+      promise_.RejectWithErrorMessage(
+          "WebFrame was removed before script could run. This normally means "
+          "the underlying frame was destroyed");
+    }
     delete this;
   }