2 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
8 var _keyword_argument_list
= [];
9 function _get_keyword_argument_setter (name
) {
10 return function (value
) { _keyword_argument_list
.push(name
); return value
; };
13 function _get_keyword_argument_getter (name
) {
14 return function () { _keyword_argument_list
.push(name
); return true; };
17 // This function must be called with all string arguments, all of
18 // which must begin with "$".
19 function define_keywords () {
20 for (var i
= 0, alen
= arguments
.length
; i
< alen
; ++i
) {
21 var name
= arguments
[i
];
22 this.__defineSetter__(name
, _get_keyword_argument_setter(name
));
23 this.__defineGetter__(name
, _get_keyword_argument_getter(name
));
27 var define_keyword
= define_keywords
;
29 function write_keywords (output
, input
, first_index
) {
30 if (first_index
== null) {
31 first_index
= input
.callee
.length
;
33 let max_index
= input
.length
;
34 let count
= max_index
- first_index
;
36 let offset
= _keyword_argument_list
.length
- 1;
37 for (let i
= max_index
- 1; i
>= first_index
; --i
) {
39 if (value
instanceof keyword_argument_forwarder
) {
44 let name
= _keyword_argument_list
[offset
--];
48 _keyword_argument_list
.length
-= count
;
52 function keyword_argument_forwarder (args
) {
53 if ("_processed_keywords" in args
) {
59 write_keywords(this, args
);
63 function keywords (args
) {
64 write_keywords(args
, arguments
);
65 write_keywords(args
, args
);
66 args
._processed_keywords
= true;
69 function forward_keywords (args
) {
70 return new keyword_argument_forwarder(args
);
73 function protect_keywords () {
74 return new keyword_argument_forwarder(arguments
);