How to use next method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

General.js

Source: General.js Github

copy
1'use strict';
2
3var General = require('./GeneralService');
4
5module.exports.addmultisigaddress = function addmultisigaddress (req, res, next) {
6  General.addmultisigaddress(req.swagger.params, res, next);
7};
8
9module.exports.dumpprivkey = function dumpprivkey (req, res, next) {
10  General.dumpprivkey(req.swagger.params, res, next);
11};
12
13module.exports.dumpwallet = function dumpwallet (req, res, next) {
14  General.dumpwallet(req.swagger.params, res, next);
15};
16
17module.exports.encryptwallet = function encryptwallet (req, res, next) {
18  General.encryptwallet(req.swagger.params, res, next);
19};
20
21module.exports.generate = function generate (req, res, next) {
22  General.generate(req.swagger.params, res, next);
23};
24
25module.exports.generatepublickey = function generatepublickey (req, res, next) {
26  General.generatepublickey(req.swagger.params, res, next);
27};
28
29module.exports.getaccount = function getaccount (req, res, next) {
30  General.getaccount(req.swagger.params, res, next);
31};
32
33module.exports.getaccountaddress = function getaccountaddress (req, res, next) {
34  General.getaccountaddress(req.swagger.params, res, next);
35};
36
37module.exports.getaddressesbyaccount = function getaddressesbyaccount (req, res, next) {
38  General.getaddressesbyaccount(req.swagger.params, res, next);
39};
40
41module.exports.getbalance = function getbalance (req, res, next) {
42  General.getbalance(req.swagger.params, res, next);
43};
44
45module.exports.getblock = function getblock (req, res, next) {
46  General.getblock(req.swagger.params, res, next);
47};
48
49module.exports.getblockchaininfo = function getblockchaininfo (req, res, next) {
50  General.getblockchaininfo(req.swagger.params, res, next);
51};
52
53module.exports.getblockcount = function getblockcount (req, res, next) {
54  General.getblockcount(req.swagger.params, res, next);
55};
56
57module.exports.getinfo = function getinfo (req, res, next) {
58  General.getinfo(req.swagger.params, res, next);
59};
60
61module.exports.getmempoolinfo = function getmempoolinfo (req, res, next) {
62  General.getmempoolinfo(req.swagger.params, res, next);
63}
64
65module.exports.getdifficulty = function getdifficulty (req, res, next) {
66  General.getdifficulty(req.swagger.params, res, next);
67}
68
69module.exports.getmininginfo = function getmininginfo (req, res, next) {
70  General.getmininginfo(req.swagger.params, res, next);
71};
72
73module.exports.getnetworkinfo = function getnetworkinfo (req, res, next) {
74  General.getnetworkinfo(req.swagger.params, res, next);
75};
76
77module.exports.getnewaddress = function getnewaddress (req, res, next) {
78  General.getnewaddress(req.swagger.params, res, next);
79};
80
81module.exports.getpeerinfo = function getpeerinfo (req, res, next) {
82  General.getpeerinfo(req.swagger.params, res, next);
83};
84
85module.exports.getreceivedbyaccount = function getreceivedbyaccount (req, res, next) {
86  General.getreceivedbyaccount(req.swagger.params, res, next);
87};
88
89module.exports.getreceivedbyaddress = function getreceivedbyaddress (req, res, next) {
90  General.getreceivedbyaddress(req.swagger.params, res, next);
91};
92
93module.exports.gettransaction = function gettransaction (req, res, next) {
94  General.gettransaction(req.swagger.params, res, next);
95};
96
97module.exports.getunconfirmedbalance = function getunconfirmedbalance (req, res, next) {
98  General.getunconfirmedbalance(req.swagger.params, res, next);
99};
100
101module.exports.getwalletinfo = function getwalletinfo (req, res, next) {
102  General.getwalletinfo(req.swagger.params, res, next);
103};
104
105module.exports.importaddress = function importaddress (req, res, next) {
106  General.importaddress(req.swagger.params, res, next);
107};
108
109module.exports.importprivkey = function importprivkey (req, res, next) {
110  General.importprivkey(req.swagger.params, res, next);
111};
112
113module.exports.importpubkey = function importpubkey (req, res, next) {
114  General.importpubkey(req.swagger.params, res, next);
115};
116
117module.exports.importwallet = function importwallet (req, res, next) {
118  General.importwallet(req.swagger.params, res, next);
119};
120
121module.exports.listaccounts = function listaccounts (req, res, next) {
122  General.listaccounts(req.swagger.params, res, next);
123};
124
125module.exports.listaddressgroupings = function listaddressgroupings (req, res, next) {
126  General.listaddressgroupings(req.swagger.params, res, next);
127};
128
129module.exports.listreceivedbyaccount = function listreceivedbyaccount (req, res, next) {
130  General.listreceivedbyaccount(req.swagger.params, res, next);
131};
132
133module.exports.listreceivedbyaddress = function listreceivedbyaddress (req, res, next) {
134  General.listreceivedbyaddress(req.swagger.params, res, next);
135};
136
137module.exports.listsinceblock = function listsinceblock (req, res, next) {
138  General.listsinceblock(req.swagger.params, res, next);
139};
140
141module.exports.listtransactions = function listtransactions (req, res, next) {
142  General.listtransactions(req.swagger.params, res, next);
143};
144
145module.exports.listunspent = function listunspent (req, res, next) {
146  General.listunspent(req.swagger.params, res, next);
147};
148
149module.exports.move = function move (req, res, next) {
150  General.move(req.swagger.params, res, next);
151};
152module.exports.sendfrom = function sendfrom (req, res, next) {
153  General.sendfrom(req.swagger.params, res, next);
154};
155
156module.exports.sendmany = function sendmany (req, res, next) {
157  General.sendmany(req.swagger.params, res, next);
158};
159
160module.exports.sendtoaddress = function sendtoaddress (req, res, next) {
161  General.sendtoaddress(req.swagger.params, res, next);
162};
163
164module.exports.signmessage = function signmessage (req, res, next) {
165  General.signmessage(req.swagger.params, res, next);
166};
167
168module.exports.syscoindecoderawtransaction = function syscoindecoderawtransaction (req, res, next) {
169  General.syscoindecoderawtransaction(req.swagger.params, res, next);
170};
171
172module.exports.validateaddress = function validateaddress (req, res, next) {
173  General.validateaddress(req.swagger.params, res, next);
174};
175
176module.exports.verifymessage = function verifymessage (req, res, next) {
177  General.verifymessage(req.swagger.params, res, next);
178};
179
180module.exports.walletlock = function walletlock (req, res, next) {
181  General.walletlock(req.swagger.params, res, next);
182};
183
184module.exports.walletpassphrase = function walletpassphrase (req, res, next) {
185  General.walletpassphrase(req.swagger.params, res, next);
186};
187
188module.exports.walletpassphrasechange = function walletpassphrasechange (req, res, next) {
189  General.walletpassphrasechange(req.swagger.params, res, next);
190};
191
192module.exports.syscoinlistreceivedbyaddress = function syscoinlistreceivedbyaddress (req, res, next) {
193  General.syscoinlistreceivedbyaddress(req.swagger.params, res, next);
194};
195
196module.exports.getaddressbalance = function getaddressbalance (req, res, next) {
197  console.log(req.swagger.params);
198  General.getaddressbalance(req.swagger.params, res, next);
199};
200
201module.exports.getaddressdeltas = function getaddressdeltas (req, res, next) {
202  General.getaddressdeltas(req.swagger.params, res, next);
203};
204
205module.exports.getaddressmempool = function getaddressmempool (req, res, next) {
206  General.getaddressmempool(req.swagger.params, res, next);
207};
208
209module.exports.syscoinsendrawtransaction = function getaddressmempool (req, res, next) {
210  General.syscoinsendrawtransaction(req.swagger.params, res, next);
211};
212
213module.exports.getgenerate = function getgenerate (req, res, next) {
214  General.getgenerate(req.swagger.params, res, next);
215};
216
217module.exports.setgenerate = function setgenerate (req, res, next) {
218  General.setgenerate(req.swagger.params, res, next);
219};
220
221module.exports.setnetworkactive = function setnetworkactive (req, res, next) {
222  General.setnetworkactive(req.swagger.params, res, next);
223};
224
225module.exports.mnsync = function mnsync (req, res, next) {
226  General.mnsync(req.swagger.params, res, next);
227};
228
229module.exports.dumphdinfo = function dumphdinfo (req, res, next) {
230  General.dumphdinfo(req.swagger.params, res, next);
231};
232
233module.exports.debug = function debug (req, res, next) {
234  General.debug(req.swagger.params, res, next);
235};
236
237module.exports.instantsendtoaddress = function debug (req, res, next) {
238  General.instantsendtoaddress(req.swagger.params, res, next);
239};
240module.exports.getaddresstxids = function getaddresstxids (req, res, next) {
241  General.getaddresstxids(req.swagger.params, res, next);
242};
243
244module.exports.getblockhashes = function getblockhashes (req, res, next) {
245  General.getblockhashes(req.swagger.params, res, next);
246};
247
248module.exports.getblockhash = function getblockhash (req, res, next) {
249  General.getblockhash(req.swagger.params, res, next);
250}
251
252module.exports.getblockheaders = function getblockheaders (req, res, next) {
253  General.getblockheaders(req.swagger.params, res, next);
254};
255
256module.exports.getchaintips = function getchaintips (req, res, next) {
257  General.getchaintips(req.swagger.params, res, next);
258};
259
260module.exports.getspentinfo = function getspentinfo (req, res, next) {
261  General.getspentinfo(req.swagger.params, res, next);
262};
263
264module.exports.getgovernanceinfo = function getgovernanceinfo (req, res, next) {
265  General.getgovernanceinfo(req.swagger.params, res, next);
266};
267
268module.exports.getpoolinfo = function getpoolinfo (req, res, next) {
269  General.getpoolinfo(req.swagger.params, res, next);
270};
271
272module.exports.getsuperblockbudget = function getsuperblockbudget (req, res, next) {
273  General.getsuperblockbudget(req.swagger.params, res, next);
274};
275
276module.exports.gobject = function gobject (req, res, next) {
277  General.gobject(req.swagger.params, res, next);
278};
279
280module.exports.masternode = function masternode (req, res, next) {
281  General.masternode(req.swagger.params, res, next);
282};
283
284module.exports.masternodebroadcast = function masternodebroadcast (req, res, next) {
285  General.masternodebroadcast(req.swagger.params, res, next);
286};
287
288module.exports.masternodelist = function masternodelist (req, res, next) {
289  General.masternodelist(req.swagger.params, res, next);
290};
291
292module.exports.fundrawtransaction = function masternodelist (req, res, next) {
293  General.fundrawtransaction(req.swagger.params, res, next);
294};
295
296module.exports.getblocktemplate = function masternodelist (req, res, next) {
297  General.getblocktemplate(req.swagger.params, res, next);
298};
299
300module.exports.signrawtransaction = function masternodelist (req, res, next) {
301  General.signrawtransaction(req.swagger.params, res, next);
302};
303
304module.exports.lockunspent = function masternodelist (req, res, next) {
305  General.lockunspent(req.swagger.params, res, next);
306};
307
308module.exports.getaddressutxos = function getaddressutxos (req, res, next) {
309  General.getaddressutxos(req.swagger.params, res, next);
310};
311
312module.exports.setaccount = function setaccount (req, res, next) {
313  General.setaccount(req.swagger.params, res, next);
314};
315
316module.exports.resendwallettransactions = function resendwallettransactions (req, res, next) {
317  General.resendwallettransactions(req.swagger.params, res, next);
318};
Full Screen

delete.js

Source: delete.js Github

copy
1'use strict';
2
3var async = require('async');
4var _ = require('lodash');
5
6var db = require('../database');
7var topics = require('../topics');
8var user = require('../user');
9var groups = require('../groups');
10var notifications = require('../notifications');
11var plugins = require('../plugins');
12
13module.exports = function (Posts) {
14	Posts.delete = function (pid, uid, callback) {
15		var postData;
16		async.waterfall([
17			function (next) {
18				plugins.fireHook('filter:post.delete', { pid: pid, uid: uid }, next);
19			},
20			function (data, next) {
21				Posts.setPostFields(pid, { deleted: 1, deleterUid: uid }, next);
22			},
23			function (next) {
24				Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'timestamp'], next);
25			},
26			function (_post, next) {
27				postData = _post;
28				topics.getTopicFields(_post.tid, ['tid', 'cid', 'pinned'], next);
29			},
30			function (topicData, next) {
31				postData.cid = topicData.cid;
32				async.parallel([
33					function (next) {
34						updateTopicTimestamp(topicData, next);
35					},
36					function (next) {
37						db.sortedSetRemove('cid:' + topicData.cid + ':pids', pid, next);
38					},
39					function (next) {
40						topics.updateTeaser(postData.tid, next);
41					},
42				], next);
43			},
44			function (results, next) {
45				plugins.fireHook('action:post.delete', { post: _.clone(postData), uid: uid });
46				next(null, postData);
47			},
48		], callback);
49	};
50
51	Posts.restore = function (pid, uid, callback) {
52		var postData;
53		async.waterfall([
54			function (next) {
55				plugins.fireHook('filter:post.restore', { pid: pid, uid: uid }, next);
56			},
57			function (data, next) {
58				Posts.setPostFields(pid, { deleted: 0, deleterUid: 0 }, next);
59			},
60			function (next) {
61				Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp'], next);
62			},
63			function (_post, next) {
64				postData = _post;
65				topics.getTopicFields(_post.tid, ['tid', 'cid', 'pinned'], next);
66			},
67			function (topicData, next) {
68				postData.cid = topicData.cid;
69				async.parallel([
70					function (next) {
71						updateTopicTimestamp(topicData, next);
72					},
73					function (next) {
74						db.sortedSetAdd('cid:' + topicData.cid + ':pids', postData.timestamp, pid, next);
75					},
76					function (next) {
77						topics.updateTeaser(postData.tid, next);
78					},
79				], next);
80			},
81			function (results, next) {
82				plugins.fireHook('action:post.restore', { post: _.clone(postData), uid: uid });
83				next(null, postData);
84			},
85		], callback);
86	};
87
88	function updateTopicTimestamp(topicData, callback) {
89		var timestamp;
90		async.waterfall([
91			function (next) {
92				topics.getLatestUndeletedPid(topicData.tid, next);
93			},
94			function (pid, next) {
95				if (!parseInt(pid, 10)) {
96					return callback();
97				}
98				Posts.getPostField(pid, 'timestamp', next);
99			},
100			function (_timestamp, next) {
101				timestamp = _timestamp;
102				if (!parseInt(timestamp, 10)) {
103					return callback();
104				}
105				topics.updateTimestamp(topicData.tid, timestamp, next);
106			},
107			function (next) {
108				if (parseInt(topicData.pinned, 10) !== 1) {
109					db.sortedSetAdd('cid:' + topicData.cid + ':tids', timestamp, topicData.tid, next);
110				} else {
111					next();
112				}
113			},
114		], callback);
115	}
116
117	Posts.purge = function (pid, uid, callback) {
118		async.waterfall([
119			function (next) {
120				Posts.exists(pid, next);
121			},
122			function (exists, next) {
123				if (!exists) {
124					return callback();
125				}
126				plugins.fireHook('filter:post.purge', { pid: pid, uid: uid }, next);
127			},
128			function (data, next) {
129				async.parallel([
130					function (next) {
131						deletePostFromTopicUserNotification(pid, next);
132					},
133					function (next) {
134						deletePostFromCategoryRecentPosts(pid, next);
135					},
136					function (next) {
137						deletePostFromUsersBookmarks(pid, next);
138					},
139					function (next) {
140						deletePostFromUsersVotes(pid, next);
141					},
142					function (next) {
143						deletePostFromReplies(pid, next);
144					},
145					function (next) {
146						deletePostFromGroups(pid, next);
147					},
148					function (next) {
149						db.sortedSetsRemove(['posts:pid', 'posts:votes', 'posts:flagged'], pid, next);
150					},
151				], function (err) {
152					next(err);
153				});
154			},
155			function (next) {
156				Posts.getPostData(pid, next);
157			},
158			function (postData, next) {
159				plugins.fireHook('action:post.purge', { post: postData, uid: uid });
160				db.delete('post:' + pid, next);
161			},
162		], callback);
163	};
164
165	function deletePostFromTopicUserNotification(pid, callback) {
166		var postData;
167		async.waterfall([
168			function (next) {
169				Posts.getPostFields(pid, ['tid', 'uid'], next);
170			},
171			function (_postData, next) {
172				postData = _postData;
173				db.sortedSetsRemove([
174					'tid:' + postData.tid + ':posts',
175					'tid:' + postData.tid + ':posts:votes',
176					'uid:' + postData.uid + ':posts',
177				], pid, next);
178			},
179			function (next) {
180				topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], next);
181			},
182			function (topicData, next) {
183				async.parallel([
184					function (next) {
185						db.decrObjectField('global', 'postCount', next);
186					},
187					function (next) {
188						db.decrObjectField('category:' + topicData.cid, 'post_count', next);
189					},
190					function (next) {
191						topics.decreasePostCount(postData.tid, next);
192					},
193					function (next) {
194						topics.updateTeaser(postData.tid, next);
195					},
196					function (next) {
197						updateTopicTimestamp(topicData, next);
198					},
199					function (next) {
200						db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
201					},
202					function (next) {
203						db.sortedSetIncrBy('tid:' + postData.tid + ':posters', -1, postData.uid, next);
204					},
205					function (next) {
206						user.incrementUserPostCountBy(postData.uid, -1, next);
207					},
208					function (next) {
209						notifications.rescind('new_post:tid:' + postData.tid + ':pid:' + pid + ':uid:' + postData.uid, next);
210					},
211				], next);
212			},
213		], function (err) {
214			callback(err);
215		});
216	}
217
218	function deletePostFromCategoryRecentPosts(pid, callback) {
219		async.waterfall([
220			function (next) {
221				db.getSortedSetRange('categories:cid', 0, -1, next);
222			},
223			function (cids, next) {
224				var sets = cids.map(function (cid) {
225					return 'cid:' + cid + ':pids';
226				});
227
228				db.sortedSetsRemove(sets, pid, next);
229			},
230		], callback);
231	}
232
233	function deletePostFromUsersBookmarks(pid, callback) {
234		async.waterfall([
235			function (next) {
236				db.getSetMembers('pid:' + pid + ':users_bookmarked', next);
237			},
238			function (uids, next) {
239				var sets = uids.map(function (uid) {
240					return 'uid:' + uid + ':bookmarks';
241				});
242
243				db.sortedSetsRemove(sets, pid, next);
244			},
245			function (next) {
246				db.delete('pid:' + pid + ':users_bookmarked', next);
247			},
248		], callback);
249	}
250
251	function deletePostFromUsersVotes(pid, callback) {
252		async.waterfall([
253			function (next) {
254				async.parallel({
255					upvoters: function (next) {
256						db.getSetMembers('pid:' + pid + ':upvote', next);
257					},
258					downvoters: function (next) {
259						db.getSetMembers('pid:' + pid + ':downvote', next);
260					},
261				}, next);
262			},
263			function (results, next) {
264				var upvoterSets = results.upvoters.map(function (uid) {
265					return 'uid:' + uid + ':upvote';
266				});
267
268				var downvoterSets = results.downvoters.map(function (uid) {
269					return 'uid:' + uid + ':downvote';
270				});
271
272				async.parallel([
273					function (next) {
274						db.sortedSetsRemove(upvoterSets, pid, next);
275					},
276					function (next) {
277						db.sortedSetsRemove(downvoterSets, pid, next);
278					},
279					function (next) {
280						db.deleteAll(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], next);
281					},
282				], next);
283			},
284		], callback);
285	}
286
287	function deletePostFromReplies(pid, callback) {
288		async.waterfall([
289			function (next) {
290				Posts.getPostField(pid, 'toPid', next);
291			},
292			function (toPid, next) {
293				if (!parseInt(toPid, 10)) {
294					return callback(null);
295				}
296				async.parallel([
297					async.apply(db.sortedSetRemove, 'pid:' + toPid + ':replies', pid),
298					async.apply(db.decrObjectField, 'post:' + toPid, 'replies'),
299				], next);
300			},
301		], callback);
302	}
303
304	function deletePostFromGroups(pid, callback) {
305		async.waterfall([
306			function (next) {
307				Posts.getPostField(pid, 'uid', next);
308			},
309			function (uid, next) {
310				if (!parseInt(uid, 10)) {
311					return callback();
312				}
313				groups.getUserGroupMembership('groups:visible:createtime', [uid], next);
314			},
315			function (groupNames, next) {
316				groupNames = groupNames[0];
317				var keys = groupNames.map(function (groupName) {
318					return 'group:' + groupName + ':member:pids';
319				});
320
321				db.sortedSetsRemove(keys, pid, next);
322			},
323		], callback);
324	}
325};
326
Full Screen

bootstrap.js

Source: bootstrap.js Github

copy
1function Word(vocab, name, source, func) {
2  this.vocab = vocab;
3  this.name = name;
4  this.source = source;
5  this.func = func;
6}
7
8Word.prototype.execute = function(next) {
9  this.func(next);
10}
11
12Word.prototype.toString = function() {
13  var html = [];
14  html.push("<a href='/responder/browser/browse?vocab=")
15  html.push(this.vocab);
16  html.push("&amp;word=")
17  html.push(this.name);
18  html.push("'>")
19  html.push(this.name);
20  html.push("</a>");
21  return html.join("");
22}
23
24function Hashtable() {
25  this.table = { }
26}
27
28Hashtable.prototype.fromAlist = function(alist) {
29  var obj = { }
30  for(var i=0;i<alist.length;++i) {  
31    var item = alist[i];
32    obj[item[0]] = item[1];
33  }
34  this.table = obj;
35  return this;
36}
37
38Hashtable.prototype.toAlist = function() {
39  var table = this.table;
40  var alist = [ ];
41  for(k in table) {
42    var v = table[k];
43    alist.push([k,v]);
44  }
45  return alist;
46}
47
48Hashtable.prototype.get = function(key) {
49  var table = this.table;
50  if(table.hasOwnProperty(key)) {
51    return table[key];
52  }
53  return false;
54}
55
56Hashtable.prototype.set = function(key, value) {
57  this.table[key] = value;
58}
59
60Hashtable.prototype.toString = function() {
61  var table = this.table;
62  var result = [];
63  result.push("H{")
64  for(k in table) {
65    var v = table[k];
66    result.push(" { ");
67    result.push(k);
68    result.push(" ");
69    result.push(v);
70    result.push(" }");
71  }
72  result.push("}");
73  return result.join("");    
74}
75
76function Continuation() {
77  this.data_stack = [ ];
78  this.retain_stack = [ ];
79  this.name_stack = [ ];
80  this.next = false;
81  this.nesting = 0;
82}
83
84Continuation.prototype.clone = function() {
85  var c = new Continuation();
86  c.data_stack = this.data_stack.slice(0);
87  c.retain_stack = this.retain_stack.slice(0);
88  c.name_stack = this.name_stack.slice(0);
89  c.nesting = this.nesting;
90  c.next = this.next;
91  return c;
92}
93
94function Factor() {
95  this.vocabs = { scratchpad: { }, io: { } };
96  this.in_vocab = "scratchpad";
97  this.using_vocabs = [ "scratchpad", "kernel","math","sequences","parser","alien","browser-dom", "words", "io", "hashtables" ];
98  this.cont = new Continuation();
99}
100
101var factor = new Factor();
102
103Factor.prototype.call_next = function(next) {
104  if(next) {
105    if(this.cont.nesting++ > 150) {
106      this.cont.nesting = 0;
107      setTimeout(next, 0);
108   }
109    else {
110      next();
111    }
112  }
113}
114
115Factor.prototype.push_data = function(v, next) {
116  factor.cont.data_stack.push(v);
117  factor.call_next(next);
118}
119
120Factor.prototype.use = function(v, next) {
121  factor.cont.data_stack.push(v);
122  factor.get_word("kernel", "use+").execute(next);
123}
124
125Factor.prototype.using = function(v, next) {
126  factor.cont.data_stack.push(v);
127  factor.get_word("kernel", "using").execute(next);
128}
129
130var fjsc_repl = false;
131
132Factor.prototype.set_in = function(v, next) {
133  factor.cont.data_stack.push(v);
134  factor.get_word("kernel", "set-in").execute(next);
135  if (fjsc_repl) {
136    fjsc_repl.ps = '( ' + v + ' )';
137  }
138}
139
140Factor.prototype.get_word = function(vocab,name) {
141  return factor.vocabs[vocab][name];
142}
143
144Factor.prototype.find_word = function(name) {
145  for(var v = 0; v<factor.using_vocabs.length; ++v) {
146    var w = factor.vocabs[factor.using_vocabs[v]][name];
147    if(w)
148      return w;
149  }
150  return false;
151}
152
153Factor.prototype.add_word = function(vocab,name, source, func) {
154  var v = factor.vocabs[vocab];
155  if(!v) {
156    v = { };
157    factor.vocabs[vocab] = v;
158  }
159  v[name] = new Word(vocab,name,source,func);
160}
161
162Factor.prototype.remove_word = function(vocab,name) {
163  var v = factor.vocabs[vocab];
164  if(!v) {
165    v = { };
166    factor.vocabs[vocab] = v;
167  }
168  delete v[name];
169}
170    
171Factor.prototype.define_word = function(name, source, func, next) {
172  factor.vocabs[factor.in_vocab][name] = new Word(factor.in_vocab, name, source, function(next) {
173    var old = factor.cont.next;
174    factor.cont.next = function() {
175      factor.cont.next = old;
176      factor.call_next(next);
177    }
178    func();
179  });
180  factor.call_next(next);
181}
182
183Factor.prototype.make_quotation = function(source, func) {
184  return new Word("quotations", "quotation", source, function(next) {
185    var old = factor.cont.next;
186    factor.cont.next = function() {
187      factor.cont.next = old;
188      factor.call_next(next);
189    }
190    func();
191  });
192}
193
194Factor.prototype.server_eval = function(text, handler, next) {
195   var self = this;
196   $.post("compile", { code: text }, function(result) {
197     factor.run_eval = function(func) {
198       factor.cont.next = function() { handler(text,result); } 
199       try {
200         func(factor);
201       } catch(ex) {
202         alert("Error Parsing Javascript: " + ex); 
203         handler(text, result);
204       }
205       if(next) 
206         factor.call_next(next);
207     }
208     try {
209       eval("factor.run_eval" + result);
210     } catch(e) {
211       factor.run_eval(function() { alert("Error Parsing Javascript: " + e); });
212     }
213   });
214}
215
216/* kernel-internals vocabulary */
217factor.add_word("kernel-internals", ">n", "primitive", function(next) {
218  var data_stack = factor.cont.data_stack;
219  var name_stack = factor.cont.name_stack;
220  name_stack.push(data_stack.pop());
221  factor.call_next(next);
222});
223
224factor.add_word("kernel-internals", "n>", "primitive", function(next) {
225  var data_stack = factor.cont.data_stack;
226  var name_stack = factor.cont.name_stack;
227  data_stack.push(name_stack.pop());
228  factor.call_next(next);
229});
230
231/* Kernel Vocabulary */
232factor.add_word("kernel","dup", "primitive", function(next) {
233  var stack = factor.cont.data_stack;
234  stack[stack.length] = stack[stack.length-1];
235  factor.call_next(next);
236});
237
238factor.add_word("kernel", "drop", "primitive", function(next) {
239  factor.cont.data_stack.pop();
240  factor.call_next(next);
241});
242
243factor.add_word("kernel", "nip", "primitive", function(next) {
244  var stack = factor.cont.data_stack;
245  stack[stack.length-2] = stack[stack.length-1];
246  stack.pop();
247  factor.call_next(next);
248});
249
250factor.add_word("kernel", "over", "primitive", function(next) {
251  var stack = factor.cont.data_stack;
252  stack[stack.length] = stack[stack.length-2];
253  factor.call_next(next);
254});
255
256factor.add_word("kernel", "pick", "primitive", function(next) {
257  var stack = factor.cont.data_stack;
258  stack[stack.length] = stack[stack.length-3];
259  factor.call_next(next);
260});
261
262factor.add_word("kernel", "swap", "primitive", function(next) {
263  var stack = factor.cont.data_stack;
264  var temp = stack[stack.length-2];
265  stack[stack.length-2] = stack[stack.length-1];
266  stack[stack.length-1] = temp;
267  factor.call_next(next);
268});
269
270factor.add_word("kernel", ">r", "primitive", function(next) {
271  var data_stack = factor.cont.data_stack;
272  var retain_stack = factor.cont.retain_stack;
273  retain_stack.push(data_stack.pop());
274  factor.call_next(next);
275});
276
277factor.add_word("kernel", "r>", "primitive", function(next) {
278  var data_stack = factor.cont.data_stack;
279  var retain_stack = factor.cont.retain_stack;
280  data_stack.push(retain_stack.pop());
281  factor.call_next(next);
282});
283
284factor.add_word("kernel", "call", "primitive", function(next) {
285  var quot = factor.cont.data_stack.pop();
286  quot.execute(next);
287});
288
289factor.add_word("kernel", "execute", "primitive", function(next) {
290  var quot = factor.cont.data_stack.pop();
291  quot.execute(next);
292});
293
294factor.add_word("kernel", "clear", "primitive", function(next) {
295  factor.cont.data_stack = [];
296  factor.cont.retain_stack = [];
297  factor.call_next(next);
298});
299
300factor.add_word("kernel", "if", "primitive", function(next) {  
301  var stack = factor.cont.data_stack;
302  var else_quot = stack.pop();
303  var then_quot = stack.pop();
304  var condition = stack.pop();
305  if(condition) {
306    then_quot.execute(next);
307  } else {
308    else_quot.execute(next);
309  }
310});
311
312factor.add_word("kernel", "f", "primitive", function(next) {  
313  factor.cont.data_stack.push(false);
314  factor.call_next(next);
315});
316
317factor.add_word("kernel", "t", "primitive", function(next) {  
318  factor.cont.data_stack.push(true);
319  factor.call_next(next);
320});
321
322factor.add_word("kernel", "=", "primitive", function(next) {   
323  var stack = factor.cont.data_stack;
324  stack.push(stack.pop()==stack.pop());
325  factor.call_next(next);
326});
327
328factor.add_word("kernel", "bootstrap", "primitive", function(next) {  
329  factor.cont.data_stack.push("/responder/fjsc-resources/bootstrap.factor");
330  factor.get_word("parser", "run-file").execute(next);
331});
332
333factor.add_word("kernel", "callcc0", "primitive", function(next) {  
334  var data_stack = factor.cont.data_stack;
335  var quot = data_stack.pop();
336  var new_cont = factor.cont.clone();  
337  var old_next = factor.cont.next;
338  factor.cont.next = function() {
339      factor.cont.next = old_next;
340      factor.call_next(next);
341  }
342  new_cont.data_stack.push(factor.cont);
343  factor.cont = new_cont;
344  quot.execute(next);  
345});
346
347factor.add_word("kernel", "callcc1", "primitive", function(next) {  
348  factor.get_word("kernel", "callcc0").execute(next);
349});
350
351factor.add_word("kernel", "continue", "primitive", function(next) {  
352  var data_stack = factor.cont.data_stack;
353  var cont = data_stack.pop(); 
354  factor.cont = cont.clone();
355  factor.call_next(cont.next);
356});
357
358factor.add_word("kernel", "continue-with", "primitive", function(next) {  
359  var data_stack = factor.cont.data_stack;
360  var cont = data_stack.pop(); 
361  var data = data_stack.pop(); 
362  factor.cont = cont.clone();
363  factor.cont.data_stack.push(data);
364  factor.call_next(cont.next);
365});
366
367factor.add_word("kernel", "set-in", "primitive", function(next) {   
368  var stack = factor.cont.data_stack;
369  var vocab = stack.pop();
370  var v = factor.vocabs[vocab];
371  if(!v) {
372    v = { };
373    factor.vocabs[vocab] = v;
374  }
375  factor.in_vocab = vocab;
376  factor.call_next(next);  
377});
378
379factor.add_word("kernel", "current-vocab", "primitive", function(next) {   
380  var stack = factor.cont.data_stack;
381  stack.push(factor.in_vocab);
382  factor.call_next(next);  
383});
384
385factor.add_word("kernel", "use+", "primitive", function(next) {   
386  var stack = factor.cont.data_stack;
387  var vocab = stack.pop();
388  var v = factor.vocabs[vocab];
389  if(!v) {
390    v = { };
391    factor.vocabs[vocab] = v;
392  }
393  factor.using_vocabs.push(vocab);
394  factor.call_next(next);  
395});
396
397factor.add_word("kernel", "using", "primitive", function(next) {   
398  var stack = factor.cont.data_stack;
399  var vocabs = stack.pop();
400
401  for(var i=0;i<vocabs.length;++i) {  
402    var v = factor.vocabs[vocabs[i]];
403    if(!v) {
404      v = { };
405      factor.vocabs[vocabs[i]] = v;
406    }
407    factor.using_vocabs.push(vocabs[i]);
408  }
409  factor.call_next(next);  
410});
411
412factor.add_word("kernel", "current-using", "primitive", function(next) {   
413  var stack = factor.cont.data_stack;
414  stack.push(factor.using_vocabs);
415  factor.call_next(next);  
416});
417
418factor.add_word("kernel", "forget", "primitive", function(next) {   
419  var stack = factor.cont.data_stack;
420  var word = stack.pop();
421  factor.remove_word(word.vocab, word.name);
422  factor.call_next(next);  
423});
424
425factor.add_word("kernel", ">function", "primitive", function(next) {   
426  var stack = factor.cont.data_stack;
427  var word = stack.pop();
428  stack.push(function() { word.func(function() { }) });
429  factor.call_next(next);  
430});
431
432factor.add_word("kernel", "curry", "primitive", function(next) {   
433  var stack = factor.cont.data_stack;
434  var quot = stack.pop();
435  var value = stack.pop();
436  
437  stack.push(factor.make_quotation("quotation", function(next) {
438    factor.cont.data_stack.push(value);   
439    quot.execute(factor.cont.next);
440  }));
441  factor.call_next(next);
442});
443
444/* Math vocabulary */
445factor.add_word("math", "*", "primitive", function(next) {
446  var stack = factor.cont.data_stack;
447  stack.push(stack.pop() * stack.pop());
448  factor.call_next(next);
449});
450
451factor.add_word("math", "+", "primitive", function(next) {
452  var stack = factor.cont.data_stack;
453  stack.push(stack.pop() + stack.pop());
454  factor.call_next(next);
455});
456
457factor.add_word("math", "-", "primitive", function(next) {
458  var stack = factor.cont.data_stack;
459  var v1 = stack.pop();
460  var v2 = stack.pop();
461  stack.push(v2 - v1);
462  factor.call_next(next);
463});
464
465factor.add_word("math", "/", "primitive", function(next) {
466  var stack = factor.cont.data_stack;
467  var v1 = stack.pop();
468  var v2 = stack.pop();
469  stack.push(v2 / v1);
470  factor.call_next(next);
471});
472
473factor.add_word("parser", "run-file", "primitive", function(next) {  
474  var stack = factor.cont.data_stack;
475  var url = stack.pop();
476  $.get(url, function(result) {
477    factor.server_eval(result, function() { }, next);
478  });
479});
480
481
482factor.add_word("alien", "alien-invoke", "primitive", function(next) {  
483  var stack = factor.cont.data_stack;
484  var arg_types = stack.pop();
485  var method_name = stack.pop();
486  var library_name = stack.pop();
487  var return_values = stack.pop();
488  var obj = stack.pop();
489  var args = [ ];
490  for(var i = 0; i < arg_types.length; ++i) {
491    args[i] = stack.pop();
492  }
493  var func = obj[method_name];
494  if(method_name=="alert") {
495    func = function(a) { alert(a); }
496  }
497  var v = func.apply(obj, args.reverse());
498  if(return_values.length > 0)
499    stack.push(v);
500  factor.call_next(next);
501});
502
503factor.add_word("alien", "alien-property", "primitive", function(next) {  
504  var stack = factor.cont.data_stack;
505  var obj = stack.pop();
506  var property_name = stack.pop();
507  var v = obj[property_name];
508  stack.push(v);
509  factor.call_next(next);
510});
511
512factor.add_word("alien", "set-alien-property", "primitive", function(next) {  
513  var stack = factor.cont.data_stack;
514  var obj = stack.pop();
515  var property_name = stack.pop();
516  var data = stack.pop();
517  obj[property_name] = v;
518  factor.call_next(next);
519});
520
521factor.add_word("alien", "uneval", "primitive", function(next) {
522  var stack = factor.cont.data_stack;
523  stack.push(uneval(stack.pop()));
524  factor.call_next(next);
525});
526
527factor.add_word("words", "vocabs", "primitive", function(next) {   
528  var stack = factor.cont.data_stack;
529  var result = [];
530  for(v in factor.vocabs) {
531    result.push(v);
532  }
533  stack.push(result);
534  factor.call_next(next);
535});
536
537factor.add_word("words", "words", "primitive", function(next) {   
538  var stack = factor.cont.data_stack;
539  var vocab = factor.vocabs[stack.pop()];
540  var result = [];
541  for(w in vocab) {
542    result.push(vocab[w]);
543  }
544  stack.push(result);
545  factor.call_next(next);
546});
547
548factor.add_word("words", "all-words", "primitive", function(next) {   
549  var stack = factor.cont.data_stack;
550  var result = [];
551  for(v in factor.vocabs) {
552    for(w in factor.vocabs[v]) {
553      result.push(factor.vocabs[v][w]);
554    }
555  }
556  stack.push(result);
557  factor.call_next(next);
558});
559
560/* Sequences vocabulary */
561factor.add_word("sequences", "nth", "primitive", function(next) {   
562  var stack = factor.cont.data_stack;
563  var seq = stack.pop();
564  var index = stack.pop();
565  stack.push(seq[index]);
566  factor.call_next(next);
567});
568
569factor.add_word("sequences", "first", "primitive", function(next) {   
570  var stack = factor.cont.data_stack;
571  var seq = stack.pop();
572  stack.push(seq[0]);
573  factor.call_next(next);
574});
575
576factor.add_word("sequences", "second", "primitive", function(next) {   
577  var stack = factor.cont.data_stack;
578  var seq = stack.pop();
579  stack.push(seq[1]);
580  factor.call_next(next);
581});
582
583factor.add_word("sequences", "third", "primitive", function(next) {   
584  var stack = factor.cont.data_stack;
585  var seq = stack.pop();
586  stack.push(seq[2]);
587  factor.call_next(next);
588});
589
590factor.add_word("sequences", "fourth", "primitive", function(next) {   
591  var stack = factor.cont.data_stack;
592  var seq = stack.pop();
593  stack.push(seq[0]);
594  factor.call_next(next);
595});
596
597factor.add_word("sequences", "first2", "primitive", function(next) {   
598  var stack = factor.cont.data_stack;
599  var seq = stack.pop();
600  stack.push(seq[0],seq[1]);
601  factor.call_next(next);
602});
603
604factor.add_word("sequences", "first3", "primitive", function(next) {   
605  var stack = factor.cont.data_stack;
606  var seq = stack.pop();
607  stack.push(seq[0],seq[1],seq[2]);
608  factor.call_next(next);
609});
610
611factor.add_word("sequences", "first4", "primitive", function(next) {   
612  var stack = factor.cont.data_stack;
613  var seq = stack.pop();
614  stack.push(seq[0],seq[1],seq[2],seq[3]);
615  factor.call_next(next);
616});
617
618factor.add_word("sequences", "each", "primitive", function(next) {   
619  var stack = factor.cont.data_stack;
620  var quot = stack.pop();
621  var seq = stack.pop();
622  for(var i=0;i<seq.length;++i) {  
623    stack.push(seq[i]);
624    quot.execute();
625  }
626  factor.call_next(next);
627});
628
629factor.add_word("sequences", "map", "primitive", function(next) {   
630  var stack = factor.cont.data_stack;
631  var quot = stack.pop();
632  var seq = stack.pop();
633  var result = [ ];
634  for(var i=0;i<seq.length;++i) {  
635    stack.push(seq[i]);
636    quot.execute();
637    result[i]=stack.pop();
638  }
639  stack.push(result);
640  factor.call_next(next);
641});
642
643factor.add_word("sequences", "reduce", "primitive", function(next) {   
644  var stack = factor.cont.data_stack;
645  var quot = stack.pop();
646  var prev = stack.pop();
647  var seq = stack.pop();
648  for(var i=0;i<seq.length;++i) {  
649    stack.push(prev);
650    stack.push(seq[i]);
651    quot.execute();
652    prev=stack.pop();Al
653  }
654  stack.push(prev);
655  factor.call_next(next);
656});
657
658/* hashtables vocabulary */
659factor.add_word("hashtables", "alist>hash", "primitive", function(next) {   
660  var stack = factor.cont.data_stack;
661  var alist = stack.pop();
662  stack.push(new Hashtable().fromAlist(alist));
663  factor.call_next(next);
664});
665
666factor.add_word("hashtables", "hash>alist", "primitive", function(next) {   
667  var stack = factor.cont.data_stack;
668  var hashtable = stack.pop();
669  stack.push(hashtable.toAlist());
670  factor.call_next(next);
671});
672
673factor.add_word("hashtables", "hash", "primitive", function(next) {   
674  var stack = factor.cont.data_stack;
675  var hashtable = stack.pop();
676  var key = stack.pop();
677  stack.push(hashtable.get(key));
678  factor.call_next(next);
679});
680
681factor.add_word("hashtables", "set-hash", "primitive", function(next) {   
682  var stack = factor.cont.data_stack;
683  var hashtable = stack.pop();
684  var key = stack.pop();
685  var value = stack.pop();
686  hashtable.set(key, value);
687  factor.call_next(next);
688});
689
690factor.add_word("sequences", "hash-each", "primitive", function(next) {   
691  var stack = factor.cont.data_stack;
692  var quot = stack.pop();
693  var hashtable = stack.pop().table;
694  for(k in hashtable) {  
695    var v = hashtable[k]; 
696    stack.push(k, v);
697    quot.execute();
698  }
699  factor.call_next(next);
700});
701
702factor.add_word("sequences", "hash-map", "primitive", function(next) {   
703  var stack = factor.cont.data_stack;
704  var quot = stack.pop();
705  var hashtable = stack.pop().table;
706  var result = [ ];
707  for(k in hashtable) {  
708    var v = hashtable[k];
709    stack.push(k,v);
710    quot.execute();
711    result.push(stack.pop());
712  }
713  stack.push(result);
714  factor.call_next(next);
715});
716
717/* browser-dom vocab */
718factor.add_word("browser-dom", "window", "primitive", function(next) {  
719  factor.cont.data_stack.push(window);
720  factor.call_next(next);
721});
722
723factor.add_word("browser-dom", "document", "primitive", function(next) {  
724  factor.cont.data_stack.push(document);
725  factor.call_next(next);
726});
727
728factor.add_word("browser-dom", "load-script", "primitive", function(next) {  
729  var stack = factor.cont.data_stack;
730  $("head/script#jsonrequest").remove();
731  var script = document.createElement("script");
732  script.id = "jsonrequest";    
733  script.type = "text/javascript";
734  script.src = stack.pop();
735  $("head").append(script);
736  factor.call_next(next); 
737});
738
739var handle_json = false;
740factor.add_word("browser-dom", "json-request", "primitive", function(next) {  
741  var stack = factor.cont.data_stack;
742  handle_json = function(data) { 
743    factor.cont.data_stack.push(data);
744    factor.call_next(next);
745  }
746  factor.get_word("browser-dom", "load-script").execute();
747});
748
749
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)