[gjs] promise: Fix SpiderMonkey strict mode warnings



commit 8977798baac640c6da0de3fb7317c618f7605370
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Jan 23 15:51:11 2016 -0800

    promise: Fix SpiderMonkey strict mode warnings
    
    By default, our JS engine warns a bit overzealously about functions that
    don't always return a value; fix this by moving some return statements
    around. It also warns about 'use strict' used elsewhere than the very
    beginning of a function or file, so fix that as well.
    
    (You can turn off the extra warnings with GJS_DISABLE_EXTRA_WARNINGS, but
    we don't want the user to see extra warnings from the Promise code even
    if extra warnings are turned on. We can't disable the option from code,
    as it is set per context.)
    
    We annotate all modifications to the original Lie code with comments, so
    it's easy to tell what to modify if we ever wanted to pull in a new
    version.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=608450

 modules/_lie.js |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/modules/_lie.js b/modules/_lie.js
index 9cf528a..dbbe78f 100644
--- a/modules/_lie.js
+++ b/modules/_lie.js
@@ -1,5 +1,6 @@
 // jscs:disable validateIndentation
 (function () {
+'use strict';
 const GLib = imports.gi.GLib;
 
 var reqs = {
@@ -47,7 +48,7 @@ var process = {
 // BEGIN CODE FROM lie/lib/index.js
 // https://raw.githubusercontent.com/calvinmetcalf/lie/master/lib/index.js
 
-'use strict';
+// 'use strict';  // Moved for GJS
 var immediate = require('immediate');
 
 /* istanbul ignore next */
@@ -136,7 +137,8 @@ function unwrap(promise, func, value) {
     try {
       returnValue = func(value);
     } catch (e) {
-      return handlers.reject(promise, e);
+      handlers.reject(promise, e); // Changed for GJS
+      return; // Added for GJS
     }
     if (returnValue === promise) {
       handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));
@@ -195,6 +197,7 @@ function getThen(obj) {
       then.apply(obj, arguments);
     };
   }
+  return undefined; // added for GJS
 }
 
 function safelyResolveThenable(self, thenable) {
@@ -273,7 +276,7 @@ function all(iterable) {
   while (++i < len) {
     allResolver(iterable[i], i);
   }
-  return promise;
+  // return promise; // moved for GJS
   function allResolver(value, i) {
     self.resolve(value).then(resolveFromAll, function (error) {
       if (!called) {
@@ -289,6 +292,7 @@ function all(iterable) {
       }
     }
   }
+  return promise; // Added for GJS
 }
 
 Promise.race = race;
@@ -310,7 +314,7 @@ function race(iterable) {
   while (++i < len) {
     resolver(iterable[i]);
   }
-  return promise;
+  // return promise; // Moved for GJS
   function resolver(value) {
     self.resolve(value).then(function (response) {
       if (!called) {
@@ -324,6 +328,7 @@ function race(iterable) {
       }
     });
   }
+  return promise; // Added for GJS
 }
 
 // END CODE FROM lie/lib/index.js


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]