1
0
ソースを参照

amberc.js: rename check_configuration_ok() to check_configuration() which now returns a Promise

Manfred Kroehnert 11 年 前
コミット
fa8734f8e1
1 ファイル変更21 行追加14 行削除
  1. 21 14
      cli/support/amberc.js

+ 21 - 14
cli/support/amberc.js

@@ -195,26 +195,33 @@ AmberC.prototype.main = function(configuration, finished_callback) {
 		console.log = function() {};
 	}
 
-	if (this.check_configuration_ok(configuration)) {
-		this.defaults = configuration;
-		this.defaults.smalltalk = {}; // the evaluated compiler will be stored in this variable (see create_compiler)
-		this.collect_files(this.defaults.stFiles, this.defaults.jsFiles)
-	}
+	var self = this;
+	check_configuration(configuration).then(function(configuration) {
+		self.defaults = configuration;
+		self.defaults.smalltalk = {}; // the evaluated compiler will be stored in this variable (see create_compiler)
+		self.collect_files(self.defaults.stFiles, self.defaults.jsFiles)
+	}, function (error) {
+		console.log(error);
+	});
 };
 
 
 /**
- * Check if the passed in configuration object has sufficient/nonconflicting values
+ * Check if the passed in configuration object has sufficient/nonconflicting values.
+ * Calls reject with an Error object upon failure and resolve(configuration) upon success.
  */
-AmberC.prototype.check_configuration_ok = function(configuration) {
-	if (undefined === configuration) {
-		throw new Error('AmberC.check_configuration_ok(): missing configuration object');
-	}
+function check_configuration(configuration) {
+	return new Promise(function(resolve, reject) {
+		if (undefined === configuration) {
+			reject(Error('AmberC.check_configuration_ok(): missing configuration object'));
+		}
 
-	if (0 === configuration.jsFiles.length && 0 === configuration.stFiles.length) {
-		throw new Error('AmberC.check_configuration_ok(): no files to compile/link specified in configuration object');
-	}
-	return true;
+		if (0 === configuration.jsFiles.length && 0 === configuration.stFiles.length) {
+			reject(Error('AmberC.check_configuration_ok(): no files to compile/link specified in configuration object'));
+		}
+
+		resolve(configuration);
+	});
 };