2 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
11 let _keyword_argument_list = [];
12 let _get_keyword_argument_setter = function _get_keyword_argument_setter (name) {
13 return function (value) { _keyword_argument_list.push(name); return value; };
16 let _get_keyword_argument_getter = function _get_keyword_argument_getter (name) {
17 return function () { _keyword_argument_list.push(name); return true; };
20 // This function must be called with all string arguments, all of
21 // which must begin with "$".
22 function define_keywords () {
23 for (var i = 0, alen = arguments.length; i < alen; ++i) {
24 var name = arguments[i];
25 this.__defineSetter__(name, _get_keyword_argument_setter(name));
26 this.__defineGetter__(name, _get_keyword_argument_getter(name));
30 var define_keyword = define_keywords;
32 function write_keywords (output, input, first_index) {
33 if (first_index == null)
34 first_index = input.callee.length;
35 let max_index = input.length;
36 let count = max_index - first_index;
38 let offset = _keyword_argument_list.length - 1;
39 for (let i = max_index - 1; i >= first_index; --i) {
41 if (value instanceof keyword_argument_forwarder) {
46 let name = _keyword_argument_list[offset--];
50 _keyword_argument_list.length -= count;
54 let keyword_argument_forwarder = function keyword_argument_forwarder (args) {
55 if ("_processed_keywords" in args) {
61 write_keywords(this, args);
64 function keywords (args) {
65 write_keywords(args, arguments);
66 write_keywords(args, args);
67 args._processed_keywords = true;
70 function forward_keywords (args) {
71 return new keyword_argument_forwarder(args);
74 function protect_keywords () {
75 return new keyword_argument_forwarder(arguments);