new module to enable editing and deleting of bookmarks
[conkeror/arlinius.git] / modules / keywords.js
blobbf5fc8af3af29bc78858913dfd0e22a8ba846455
1 /**
2 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
5 * COPYING file.
6 **/
9 let _keyword_argument_list = [];
10 let _get_keyword_argument_setter = function _get_keyword_argument_setter (name) {
11 return function (value) { _keyword_argument_list.push(name); return value; };
14 let _get_keyword_argument_getter = function _get_keyword_argument_getter (name) {
15 return function () { _keyword_argument_list.push(name); return true; };
18 // This function must be called with all string arguments, all of
19 // which must begin with "$".
20 function define_keywords () {
21 for (var i = 0, alen = arguments.length; i < alen; ++i) {
22 var name = arguments[i];
23 this.__defineSetter__(name, _get_keyword_argument_setter(name));
24 this.__defineGetter__(name, _get_keyword_argument_getter(name));
28 var define_keyword = define_keywords;
30 function write_keywords (output, input, first_index) {
31 if (first_index == null)
32 first_index = input.callee.length;
33 let max_index = input.length;
34 let count = max_index - first_index;
35 if (count > 0) {
36 let offset = _keyword_argument_list.length - 1;
37 for (let i = max_index - 1; i >= first_index; --i) {
38 let value = input[i];
39 if (value instanceof keyword_argument_forwarder) {
40 for (let x in value)
41 output[x] = value[x];
42 --count;
43 } else {
44 let name = _keyword_argument_list[offset--];
45 output[name] = value;
48 _keyword_argument_list.length -= count;
52 let keyword_argument_forwarder = function keyword_argument_forwarder (args) {
53 if ("_processed_keywords" in args) {
54 for (let x in args) {
55 if (x[0] == "$")
56 this[x] = args[x];
58 } else
59 write_keywords(this, args);
62 function keywords (args) {
63 write_keywords(args, arguments);
64 write_keywords(args, args);
65 args._processed_keywords = true;
68 function forward_keywords (args) {
69 return new keyword_argument_forwarder(args);
72 function protect_keywords () {
73 return new keyword_argument_forwarder(arguments);
77 provide("keywords");