File: keywords.js

package info (click to toggle)
conkeror 1.0.3%2Bgit170123-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,988 kB
  • sloc: ansic: 280; sh: 255; xml: 173; makefile: 69
file content (77 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
 *
 * Use, modification, and distribution are subject to the terms specified in the
 * COPYING file.
 **/

var _keyword_argument_list = [];
function _get_keyword_argument_setter (name) {
    return function (value) { _keyword_argument_list.push(name); return value; };
}

function _get_keyword_argument_getter (name) {
    return function () { _keyword_argument_list.push(name); return true; };
}

// This function must be called with all string arguments, all of
// which must begin with "$".
function define_keywords () {
    for (var i = 0, alen = arguments.length; i < alen; ++i) {
        var name = arguments[i];
        this.__defineSetter__(name, _get_keyword_argument_setter(name));
        this.__defineGetter__(name, _get_keyword_argument_getter(name));
    }
}

var define_keyword = define_keywords;

function write_keywords (output, input, first_index) {
    if (first_index == null) {
        first_index = input.callee.length;
    }
    let max_index = input.length;
    let count = max_index - first_index;
    if (count > 0) {
        let offset = _keyword_argument_list.length - 1;
        for (let i = max_index - 1; i >= first_index; --i) {
            let value = input[i];
            if (value instanceof keyword_argument_forwarder) {
                for (let x in value)
                    output[x] = value[x];
                --count;
            } else {
                let name = _keyword_argument_list[offset--];
                output[name] = value;
            }
        }
        _keyword_argument_list.length -= count;
    }
}

function keyword_argument_forwarder (args) {
    if ("_processed_keywords" in args) {
        for (let x in args) {
            if (x[0] == "$")
                this[x] = args[x];
        }
    } else {
        write_keywords(this, args);
    }
}

function keywords (args) {
    write_keywords(args, arguments);
    write_keywords(args, args);
    args._processed_keywords = true;
}

function forward_keywords (args) {
    return new keyword_argument_forwarder(args);
}

function protect_keywords () {
    return new keyword_argument_forwarder(arguments);
}

provide("keywords");