Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Bug 1128988 (part 2) #77

Open
wants to merge 63 commits into
base: pr77-base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
bc82016
runat-1128988: Merge increment() and decrement() into nudge()
joewalker Feb 20, 2015
5408bc6
runat-1128988: Use paramName consistently for parameter names
joewalker Feb 21, 2015
585f7b8
runat-1128988: Clarify some comments
joewalker Feb 21, 2015
d5be485
runat-1128988: Fix some missing Function.bind() calls
joewalker Feb 21, 2015
08be168
runat-1128988: Command specs that want to use fronts need to be objects
joewalker Feb 21, 2015
345fdda
runat-1128988: mockCommands added json converters that we added to basic
joewalker Feb 21, 2015
9895376
runat-1128988: Strengthen the tests we can make using mockCommands
joewalker Feb 21, 2015
37ceccb
runat-1128988: Support io.js
joewalker Mar 5, 2015
2847992
runat-1128988: Mock 'document' better
joewalker Mar 5, 2015
b5d2952
runat-1128988: Improve error handling
joewalker Mar 5, 2015
e289f80
runat-1128988: Mock 'document' better (Part 2)
joewalker Mar 5, 2015
06023e3
runat-1128988: Remove isNoDom checks
joewalker Mar 5, 2015
709687c
runat-1128988: Fix 'node' so it works properly remotely
joewalker Mar 5, 2015
30b612e
runat-1128988: Remove isNoDom
joewalker Mar 5, 2015
0e84444
runat-1128988: Consistently return a promise from loadModule()
joewalker Mar 6, 2015
33d8e7c
runat-1128988: Clarify comment
joewalker Mar 6, 2015
d374a91
runat-1128988: Replace document/globalObject with windowHolder
joewalker Mar 10, 2015
b04f95a
runat-1128988: Pass Errors through protocol.js correctly
joewalker Mar 12, 2015
d62af41
runat-1128988: Update the function to convert GCLI -> Mochitests
joewalker Mar 12, 2015
271e262
runat-1128988: Sync helpers.js with Firefox
joewalker Mar 12, 2015
5984685
runat-1128988: Fix misspelled attribute. Matters in an xhtml document
joewalker Mar 12, 2015
0deda2a
runat-1128988: Max line length = 80 chars. Wrap.
joewalker Mar 12, 2015
a44f58b
runat-1128988: Tests on 'node' type should access the NodeList properly
joewalker Mar 12, 2015
d49e5a3
runat-1128988: Refactor util.promiseEach
joewalker Mar 12, 2015
a96027c
runat-1128988: 2 places to make types more robust
joewalker Mar 12, 2015
3bf3d5e
runat-1128988: Remote fixes for note and delegate types
joewalker Mar 13, 2015
6c82474
runat-1128988: Stop caching the results of getBlank()
joewalker Mar 13, 2015
de35726
runat-1128988: Minor comment clarification
joewalker Mar 13, 2015
4dc4581
runat-1128988: Having functions called 'eval' seems dangerous
joewalker Mar 17, 2015
34370e7
runat-1128988: Remove 'with' from the template engine
joewalker Mar 17, 2015
f216e8a
runat-1128988: Remove onEnter/onLeave/onChange notification
joewalker Mar 17, 2015
5239d21
runat-1128988: Replace windowHolder with environment
joewalker Mar 17, 2015
8a31381
runat-1128988: Fix tests that we broke recently
joewalker Mar 17, 2015
2071763
runat-1128988: 2 minor fixes
joewalker Mar 17, 2015
291909e
runat-1128988: Pass on blankIsValid to delegate children
joewalker Mar 17, 2015
5d83bd3
runat-1128988: Use undefined for the value when !blankIsValid
joewalker Mar 17, 2015
75877de
runat-1128988: Be defensive about domSheet.ownerNode
joewalker Mar 17, 2015
6c0a31c
runat-1128988: Add event.once
joewalker Mar 19, 2015
6c11f94
runat-1128988: Don't stop loading modules if one fails
joewalker Mar 19, 2015
87cb176
runat-1128988: Simplify loading mockCommands in Firefox
joewalker Mar 19, 2015
879c05f
runat-1128988: Protocol.js events are lower-case-with-dashes
joewalker Mar 19, 2015
1a76df2
runat-1128988: Add event batching to commands-changed
joewalker Mar 19, 2015
def985f
runat-1128988: Simplify header injected into tests
joewalker Mar 19, 2015
2e53187
runat-1128988: Simplify header injected into tests (Fixed)
joewalker Mar 19, 2015
5eb2bff
runat-1128988: Log actual predictions when a test fails
joewalker Mar 19, 2015
28c80bf
runat-1128988: Use Promise.resolve for syncronous resolve.
joewalker Mar 19, 2015
04f795b
runat-1128988: Merge getSelectionData into getSeletionLookup
joewalker Mar 19, 2015
1053f7d
runat-1128988: Remote the javascript type correctly.
joewalker Mar 19, 2015
60a37ba
runat-1128988: setTimeout is undefined in the content process.
joewalker Mar 19, 2015
a037767
runat-1128988: Add mock command to help testing remote resources
joewalker Mar 19, 2015
b34b96f
runat-1128988: Remove values from tests that now run remotely
joewalker Mar 19, 2015
fa4ec3f
runat-1128988: Update test skips for remote testing
joewalker Mar 19, 2015
b388773
runat-1128988: Clone the typeSpec rather than try to clean up
joewalker Mar 19, 2015
40c8105
runat-1128988: Add system.destroy()
joewalker Mar 25, 2015
7bf1de9
runat-1128988: Extract removeItemsFromFront to a separate function
joewalker Mar 25, 2015
e1f2f75
runat-1128988: Introduce disconnectFront(system, front)
joewalker Mar 25, 2015
de3d7db
runat-1128988: Review fix: Simplify testNode
joewalker Mar 25, 2015
1860ace
runat-1128988: Sync with Templater.jsm
joewalker Mar 25, 2015
304318e
runat-1128988: Enable nested command execution
joewalker Mar 25, 2015
d46ff21
runat-1128988: Disallow using once with a callback
joewalker Mar 25, 2015
44fdb00
runat-1128988: Re-order functions
joewalker Apr 13, 2015
ee9b89f
runat-1128988: Format JSON output better
joewalker Apr 13, 2015
9330099
runat-1128988: Implement Task.spawn for the web
joewalker Apr 13, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/writing-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ number of built in types:

* string. This is a JavaScript string
* number. A JavaScript number
* boolean. A Javascript boolean
* boolean. A JavaScript boolean
* selection. This is an selection from a number of alternatives
* delegate. This type could change depending on other factors, but is well
defined when one of the conversion routines is called.
Expand Down Expand Up @@ -49,10 +49,10 @@ All types must inherit from Type and have the following methods:
*/
name: 'example',

In addition, defining the following functions can be helpful, although Type
In addition, defining the following function can be helpful, although Type
contains default implementations:
* increment(value)
* decrement(value)

* nudge(value, by)

Type, Conversion and Status are all declared by commands.js.

Expand Down
52 changes: 26 additions & 26 deletions lib/gcli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,12 @@ Object.defineProperty(Requisition.prototype, 'executionContext', {
enumerable: true
});

this._executionContext.updateExec = this._contextUpdateExec.bind(this);

if (legacy) {
this._executionContext.createView = view.createView;
this._executionContext.exec = this.exec.bind(this);
this._executionContext.update = this._contextUpdate.bind(this);
this._executionContext.updateExec = this._contextUpdateExec.bind(this);

Object.defineProperty(this._executionContext, 'document', {
get: function() { return requisition.document; },
Expand Down Expand Up @@ -659,7 +660,7 @@ Requisition.prototype.getParameterNames = function() {
* this is still an error status.
*/
Object.defineProperty(Requisition.prototype, 'status', {
get : function() {
get: function() {
var status = Status.VALID;
if (this._unassigned.length !== 0) {
var isAllIncomplete = true;
Expand Down Expand Up @@ -1446,26 +1447,9 @@ Requisition.prototype.complete = function(cursor, rank) {
/**
* Replace the current value with the lower value if such a concept exists.
*/
Requisition.prototype.decrement = function(assignment) {
var ctx = this.executionContext;
var val = assignment.param.type.decrement(assignment.value, ctx);
return Promise.resolve(val).then(function(replacement) {
if (replacement != null) {
var val = assignment.param.type.stringify(replacement, ctx);
return Promise.resolve(val).then(function(str) {
var arg = assignment.arg.beget({ text: str });
return this.setAssignment(assignment, arg);
}.bind(this));
}
}.bind(this));
};

/**
* Replace the current value with the higher value if such a concept exists.
*/
Requisition.prototype.increment = function(assignment) {
Requisition.prototype.nudge = function(assignment, by) {
var ctx = this.executionContext;
var val = assignment.param.type.increment(assignment.value, ctx);
var val = assignment.param.type.nudge(assignment.value, by, ctx);
return Promise.resolve(val).then(function(replacement) {
if (replacement != null) {
var val = assignment.param.type.stringify(replacement, ctx);
Expand Down Expand Up @@ -2102,10 +2086,14 @@ Requisition.prototype.exec = function(options) {
* unexpected change to the current command.
*/
Requisition.prototype._contextUpdateExec = function(typed, options) {
return this.updateExec(typed, options).then(function(reply) {
this.onExternalUpdate({ typed: typed });
var reqOpts = {
document: this.document,
environment: this.environment
};
var child = new Requisition(this.system, reqOpts);
return child.updateExec(typed, options).then(function(reply) {
return reply;
}.bind(this));
}.bind(child));
};

/**
Expand Down Expand Up @@ -2181,11 +2169,23 @@ Output.prototype.convert = function(type, conversionContext) {
};

Output.prototype.toJson = function() {
// Exceptions don't stringify, so we try a bit harder
var data = this.data;
if (this.error && JSON.stringify(this.data) === '{}') {
data = {
columnNumber: data.columnNumber,
fileName: data.fileName,
lineNumber: data.lineNumber,
message: data.message,
stack: data.stack
};
}

return {
typed: this.typed,
type: this.type,
data: this.data,
error: this.error
data: data,
isError: this.error
};
};

Expand Down
30 changes: 27 additions & 3 deletions lib/gcli/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ Command.prototype.toJson = function(customProps) {
return json;
};

/**
* Easy way to lookup parameters by full name
*/
Command.prototype.getParameterByName = function(name) {
var reply;
this.params.forEach(function(param) {
if (param.name === name) {
reply = param;
}
});
return reply;
};

/**
* Easy way to lookup parameters by short name
*/
Expand Down Expand Up @@ -264,16 +277,27 @@ function Parameter(types, paramSpec, command, groupName) {
': Missing defaultValue for optional parameter.');
}

this.defaultValue = (this.paramSpec.defaultValue !== undefined) ?
this.paramSpec.defaultValue :
this.type.getBlank().value;
if (this.paramSpec.defaultValue !== undefined) {
this.defaultValue = this.paramSpec.defaultValue;
}
else {
Object.defineProperty(this, 'defaultValue', {
get: function() {
return this.type.getBlank().value;
},
enumerable: true
});
}

// Resolve the documentation
this.manual = lookup(this.paramSpec.manual);
this.description = lookup(this.paramSpec.description, 'canonDescNone');

// Is the user required to enter data for this parameter? (i.e. has
// defaultValue been set to something other than undefined)
// TODO: When the defaultValue comes from type.getBlank().value (see above)
// then perhaps we should set using something like
// isDataRequired = (type.getBlank().status !== VALID)
this.isDataRequired = (this.defaultValue === undefined);

// Are we allowed to assign data to this parameter using positional
Expand Down
3 changes: 3 additions & 0 deletions lib/gcli/commands/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
var cli = require('../cli');
var mockCommands = require('../test/mockCommands');
var mockSettings = require('../test/mockSettings');
var mockDocument = require('../test/mockDocument');

exports.items = [
{
Expand Down Expand Up @@ -46,11 +47,13 @@ exports.items = [
on: function(requisition) {
mockCommands.setup(requisition);
mockSettings.setup(requisition.system);
mockDocument.setup(requisition);
},

off: function(requisition) {
mockCommands.shutdown(requisition);
mockSettings.shutdown(requisition.system);
mockDocument.shutdown(requisition);
}
}
];
22 changes: 20 additions & 2 deletions lib/gcli/commands/preflist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Promise = require('../util/promise').Promise;
/**
* Format a list of settings for display
*/
var prefsData = {
var prefsViewConverter = {
item: 'converter',
from: 'prefsData',
to: 'view',
Expand Down Expand Up @@ -97,6 +97,22 @@ var prefsData = {
}
};

/**
* Format a list of settings for display
*/
var prefsStringConverter = {
item: 'converter',
from: 'prefsData',
to: 'string',
exec: function(prefsData, conversionContext) {
var reply = '';
prefsData.settings.forEach(function(setting) {
reply += setting.name + ' -> ' + setting.value + '\n';
});
return reply;
}
};

/**
* 'pref list' command
*/
Expand Down Expand Up @@ -136,6 +152,8 @@ function PrefList(prefsData, conversionContext) {
this.search = prefsData.search;
this.settings = prefsData.settings;
this.conversionContext = conversionContext;

this.onLoad = this.onLoad.bind(this);
}

/**
Expand Down Expand Up @@ -194,4 +212,4 @@ PrefList.prototype.onSetClick = function(ev) {
this.conversionContext.update(typed);
};

exports.items = [ prefsData, prefList ];
exports.items = [ prefsViewConverter, prefsStringConverter, prefList ];
42 changes: 8 additions & 34 deletions lib/gcli/commands/server/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,17 @@ function buildFirefox(destDir) {
*/
function createCommonJsToJsTestFilter() {
var filter = function commonJsToJsTestFilter(data, location) {
var name = location.path.substring(1);
var name = location.path.replace(/\/test/, 'browser_gcli_').toLowerCase()
var header = '$1' +
'\n' +
'// <INJECTED SOURCE:START>\n' +
'\n' +
'\n\n' +
'// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT\n' +
'// DO NOT EDIT IT DIRECTLY\n' +
'\n' +
'var exports = {};\n' +
'// PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT\n' +
'\n' +
'var TEST_URI = "data:text/html;charset=utf-8,<p id=\'gcli-input\'>gcli-' + name + '</p>";\n' +
'const exports = {};\n' +
'\n' +
'function test() {\n' +
' return Task.spawn(*function() {\n' +
' let options = yield helpers.openTab(TEST_URI);\n' +
' yield helpers.openToolbar(options);\n' +
' options.requisition.system.addItems(mockCommands.items);\n' +
'\n' +
' yield helpers.runTests(options, exports);\n' +
'\n' +
' options.requisition.system.removeItems(mockCommands.items);\n' +
' yield helpers.closeToolbar(options);\n' +
' yield helpers.closeTab(options);\n' +
' }).then(finish, helpers.handleError);\n' +
'}\n' +
'\n' +
'// <INJECTED SOURCE:END>';
' helpers.runTestModule(exports, "' + name + '");\n' +
'}';
return data.toString()
// Inject the header above just after 'use strict'
.replace(/('use strict';)/, header)
Expand All @@ -167,23 +151,13 @@ function createCommonJsToJsTestFilter() {

function commonJsToJsMockFilter(data) {
var header = '$1' +
'\n' +
'// <INJECTED SOURCE:START>\n' +
'\n' +
'\n\n' +
'// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT\n' +
'// DO NOT EDIT IT DIRECTLY\n' +
'\n' +
'// <INJECTED SOURCE:END>\n';
'// PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT';

return data.toString()
// Inject the header above just after 'use strict'
.replace(/('use strict';)/, header)
// In mochitests everything is global
.replace(/var mockCommands = exports;/, 'var mockCommands = {};')
// Comment out test helpers that we define separately
.replace(/(var [A-z]* = require\(['"][A-z_\.\/]*\/assert['"]\);)/g, '// $1')
.replace(/(var [A-z]* = require\(['"][A-z_\.\/]*\/helpers['"]\);)/g, '// $1')
.replace(/(var [A-z]* = require\(['"][A-z_\.\/]*\/mockCommands['"]\);)/g, '// $1')
// Make the require statements absolute rather than relative.
// We're ignoring paths that start ../.. or ./ but this works for now
.replace(/\nvar ([A-z]*) = require\(['"]..\/([A-z_\/]*)['"]\)/g, '\nvar $1 = require(\'gcli/$2\')');
Expand Down
4 changes: 2 additions & 2 deletions lib/gcli/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ exports.items = [
}
else {
options = {
isNode: (typeof(process) !== 'undefined' && process.title === 'node'),
isNode: (typeof(process) !== 'undefined' &&
process.title.indexOf('node') != -1),
isFirefox: false,
isPhantomjs: false,
isNoDom: true,
requisition: new Requisition(context.system)
};
options.automator = createRequisitionAutomator(options.requisition);
Expand Down
Loading