2 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
9 let _keyword_argument_list
= [];
10 let _get_keyword_argument_setter
= function _get_keyword_argument_setter(name
) {
11 return function (value
) { _keyword_argument_list
[_keyword_argument_list
.length
] = name
; return value
; }
14 let _get_keyword_argument_getter
= function _get_keyword_argument_getter(name
) {
15 return function () { _keyword_argument_list
[_keyword_argument_list
.length
] = name
; return true; }
18 // This function must be called with all string arguments, all of
19 // which must begin with "$".
20 function define_keywords()
22 for (var i
= 0; i
< arguments
.length
; ++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
) {
62 write_keywords(this, args
);
65 function keywords(args
) {
66 write_keywords(args
, arguments
);
67 write_keywords(args
, args
);
68 args
._processed_keywords
= true;
71 function forward_keywords(args
) {
72 return new keyword_argument_forwarder(args
);
75 function protect_keywords() {
76 return new keyword_argument_forwarder(arguments
);