-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjCafe.js
More file actions
executable file
·307 lines (260 loc) · 11.1 KB
/
jCafe.js
File metadata and controls
executable file
·307 lines (260 loc) · 11.1 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/**
* javascript:jCafe - Honeyblend (RC3) (v0.27)
*
* (C) Hypersoft-Systems: U.-S.-A. ~11-12-2017: NOW-TIME
* <hypersoft.systems@gmail.com>
*
* Author: Triston-Jerard: Taylor <pc.wiz.tt@gmail.com>
*
* Credit: TinyMCE: "Bolt"; LGPL
*
* Purpose: javascript, compatibility, S.-D.-K., code-forms, module-loader,
* components, templates, imports, prototypes, styling, DHTML,
* HTML5, WebComponents, WebScripting, interface, DOM.
*
* License:
*
* ~1: a workman is worthy of his/her hire.
* ~2: a license is a permission to do a wrong.
* ~3: zero-permission is given to do a wrong.
* ~4: a matter must be expressed to be resolved.
* ~5: the name of this contrivance is by the ownership of the rights-holder.
* ~6: the value of this contrivance is an original-work.
* ~7: transportation of this work, with this name, as this contrivance, -
* is with the lack of the modification of this source-model, by a -
* foreign-modification-copy-rights-holder.
* ~8: freedom for the listing, linking and selling as the derivative-works -
* is with the compliance of these terms.
* ~9: use of the name "jCafe" is with the claims of the compliance within -
* these terms.
* ~0 for the factual-wrong-doing within these terms by a source- -
* modification-holder is with this damage claim of these ownership rights.
**/
var jCafe = {/* Fresh Coffee Served Daily */};
/* for the boiling water.... */ (function(loader, paths, modules) {
var rt = Object.create(null);
// Only works in Chrome and FireFox, does not work in IE:
var setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
obj.__proto__ = proto;
return obj;
}
var getPrototypeOf = Object.getPrototypeOf || function(obj) {
return obj.__proto__;
}
// a not-too-cheap property writer
function defineProperty(o, p, n, v) {
// p = "hidden fixed component gateway": specification-list
if (arguments.length === 3)
return defineProperty(o, "default", (n = p), v);
var type; // gotchas
if ((type = typeof o) !== 'object' && type !== 'function') throw new TypeError(
"1st parameter type error: expected property host; got: "+type);
if (p && (type = typeof p) !== 'string') throw new TypeError(
"2nd parameter type error: expected string for property profile; got: "+type);
if ((type = typeof n) !== 'string') throw new TypeError(
"3rd parameter type error: expected string for property name; got: "+type);
var type, profile = profile = (p || "default").split(" "),
defn = {value: v, enumerable:true, writable: true, configurable: true};
profile.contains = function(q){return this.indexOf(q) !== -1;};
if (profile.contains("hidden")) defn.enumerable = false;
if (profile.contains("fixed")) defn.configurable = false;
if (profile.contains("component")) defn.writable = false;
if (profile.contains("constant")) defn.writable = defn.configurable = false; // same as: fixed component
if (profile.contains("system")) defn.enumerable = defn.writable = defn.configurable = false; // same as: fixed hidden component
if (profile.contains("utility")) defn.enumerable = defn.writable = false; // same as: hidden component
if (profile.contains("gateway")) {
var type = typeof v;
if (!v || type !== 'object') throw "4th parameter type error: expected type of (Object) with get and or set property values; got: "+type;
delete defn.value; delete defn.writable;
if (v.set) { type = typeof v.set;
if (type !== 'function') throw "4th parameter type error: expected type of (Object) parameter.set === function; got: "+type;
defn.set = v.set;
}
if (v.get) { type = typeof v.get;
if (type !== 'function') throw "4th parameter type error: expected type of (Object) parameter.get === function; got: "+type;
defn.get = v.get;
}
}
return Object.defineProperty(o, n, defn);
};
// short-cut for defineProperty
var defineComponent = function(o, n, v) {
return defineProperty(o, "component", n, v);
}
// short-cut for defineProperty
var defineGateway = function(o, n, v) { // our defineProperty used to handle these settings internally. it was a messy business.
return defineProperty(o, "gateway", n, v);
}
// short-cut for defineProperty
var defineConstant = function(o, n, v) {
return defineProperty(o, "constant", n, v);
}
// short-cut for defineProperty
var defineSystem = function(o, n, v) {
return defineProperty(o, "system", n, v);
}
// short-cut for defineProperty
var defineUtility = function(o, n, v) {
return defineProperty(o, "utility", n, v);
}
var listSplitter = ",";
var protectedJavascriptRootMethods = 'apply, call, bind, toString, valueOf, constructor, __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__'.split(listSplitter);
var protectedJavascriptRootProperties = '__proto__, prototype, constructor, name'.split(listSplitter);
var protectedJCafeRootMethods = 'defineSystem, defineConstant, defineUtility, defineComponent, protectedRootName, protectedUnitName, module, link'.split(listSplitter);
var protectedJCafeRootNames = 'rt, jcafe, jCafe'.split(listSplitter);
var protectedJCafeUnitNames = '__unit__, name'.split(listSplitter);
var protectedJavascriptUnitNames = '__proto__, __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__'.split(listSplitter);
var protectedRootNames = protectedJCafeRootNames.concat(
protectedJCafeRootMethods,
protectedJavascriptRootProperties,
protectedJavascriptRootMethods
);
var indexContains = function (dexer, query) {
return dexer.indexOf(query) !== -1;
}
function protectedRootName(name) {
return indexContains(protectedRootNames, name)
}
var protectedUnitNames = protectedJCafeUnitNames.concat(
protectedJavascriptUnitNames
);
function protectedUnitName(name) {
return indexContains(protectedUnitNames, name);
}
var guardRootName = function(n) {
if (protectedRootName(n)) throw "root name: "+n+"; is a protected root name";
}
var guardUnitName = function(p, n) {
guardRootName(p);
if (protectedUnitName(n))
throw "unit name: "+n+"; is a protected unit name";
};
var get = function (name) {
var actual = paths[name];
if (actual === undefined) {
var module = modules[name];
if (module !== undefined) return module;
throw 'unit [' + name + '] was undefined';
}
if (actual.compiled) return actual.module[actual.name];
else return compile(name);
};
var set = function (name, components, builder) {
if (typeof name !== 'string')
throw 'unit name must be a string';
else if (components === undefined)
throw 'no unit header for ' + name;
else if (builder === undefined)
throw 'no unit builder for ' + name;
var module = getUnitParent(name), unitName = getUnitName(name),
unit = { module: module, name: unitName, compiled: false,
components: components, builder: builder,
};
defineGateway(module, unitName, {get: function(){return get(name)} });
return paths[name] = module.__unit__[unitName] = unit;
};
// YES: WRITE TO jCafe
jCafe = function jCafe(n) {
// jCafe(n) will get(n) or set(parameters...); for the keyword: ((new)?jCafe.set:jCafe.get)(...)
if (this.constructor !== jCafe) return get(n);
else setPrototypeOf(this, set.apply(jCafe, arguments));
}
jCafe.prototype = {
constructor: jCafe
}
// link runtime with jCafe
defineComponent(jCafe, "rt", rt);
defineComponent(rt, "jCafe", jCafe);
// make our define systems a public interface
defineComponent(jCafe, "defineComponent", defineComponent); // read-only
defineComponent(jCafe, "defineGateway", defineGateway); // read-only: {get and/or set}
defineComponent(jCafe, "defineUtility", defineUtility); // hidden, read-only
defineComponent(jCafe, "defineSystem", defineSystem); // hidden, read-only, unconfigurable
defineComponent(jCafe, "defineConstant", defineConstant); // read-only, unconfigurable
defineComponent(jCafe, "getPrototypeOf", getPrototypeOf); // platform filler: Object.getPrototype
defineComponent(jCafe, "setPrototypeOf", setPrototypeOf); // platform filler: Object.setPrototype
// make rt like a module
var jCafeRuntimeModuleName = 'jcafe';
defineConstant(rt, "name", jCafeRuntimeModuleName);
defineComponent(jCafe, "protectedRootName", protectedRootName);
defineComponent(jCafe, "protectedUnitName", protectedUnitName);
var getUnitParent = function(n) {
return jCafe.module(getUnitParentName(n));
};
var unitSeparator = ".";
var getUnitParentName = function(n) {
if (! indexContains(n, unitSeparator)) return jCafeRuntimeModuleName; // no more data
var stack = n.split(unitSeparator);
stack.pop();
return stack.join(unitSeparator);
}
var getUnitRootName = function(n) { return n.split(unitSeparator)[0]; }
var getUnitName = function(n) {
var stack = n.split(unitSeparator);
var out = stack[stack.length - 1];
guardUnitName(getUnitRootName(n), out);
return out;
}
// module context
jCafe.module = function(n) {
if (n === jCafeRuntimeModuleName) // break-create-loop === return: rt
return rt;
var module = modules[n];
if (module !== undefined) return module;
var minor = getUnitName(n); // me name
(module = modules[n] // request === jCafe(n)/paths[n]
= getUnitParent(n)[minor] // write+/create getUnitParent.me = me
= Object.create(rt) // inherit runtime
);
defineConstant(module, "name", n);
defineSystem(module, "__unit__", Object.create(null))
if (! indexContains(n, unitSeparator)) jCafe[n] = module;
return module; // return request
}
// used internally, this one fires up the module & unit builder
var compile = function (name) {
var actual = paths[name];
if (actual === undefined) throw "unit identifier '"+ name + "' has no definition";
var components = actual.components;
var tool = actual.builder;
var module = getUnitParent(name);
var unit = build(module, tool, components);
if (unit === undefined)
throw "failed to initialize unit: '"+ name + "'; unit-builder returned undefined";
// override the first-run-getter, and update the value
defineProperty(module, actual.name, unit)
actual.compiled = true;
return unit;
};
var build = function (scope, callback, names) {
if (typeof scope === 'string') scope = modules[scope];
var len = names.length;
var units = new Array(len);
for (var i = 0; i < len; ++i)
units[i] = get(names[i]);
return callback.apply(scope, units);
};
// new jCafe(...) shortcut for pre-composed units
jCafe.link = function (name, ref) {
new jCafe(name, [], function () { return ref; });
};
jCafe.link("js.global", loader);
return /* PERCOLATOR */;
})/* load: jCafe Express */(this, Object.create(null), Object.create(null));
/* Grinding Coffee Beans... */(function initializeGlobalObjects() {
jCafe.link("js.lang.Number", Number);
jCafe.link("js.lang.Math", Math);
jCafe.link("js.lang.Object", Object);
jCafe.link("js.lang.Array", Array);
jCafe.link("js.lang.String", String);
jCafe.link("js.lang.Error", Error);
new jCafe("js.util.console",
[],
function () {
if (typeof console === "undefined")
console = { log: function () {throw "global reference: console was not known"} };
return console;
}
);
return /* BLEND: READY */;
})();