@boristype/runtime 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/build/.executables.json +1 -0
- package/build/cache/index.js +14 -0
- package/build/cache.js +8 -0
- package/build/destructuring.js +22 -0
- package/build/filemap.js +15 -0
- package/build/init.js +24 -0
- package/build/package.json +11 -0
- package/build/polyfill/Array.js +550 -0
- package/build/polyfill/Math.js +37 -0
- package/build/polyfill/Object.js +24 -0
- package/build/polyfill/String.js +3 -0
- package/build/polyfill.js +18 -0
- package/build/prelude.js +1 -0
- package/build/require.js +220 -0
- package/build/semantic.js +185 -0
- package/build/spxml/bt-runtime.js +24 -0
- package/build/spxml/bt-runtime.xml +7 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 BorisType
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var storage = {};
|
|
2
|
+
function set(key, value) {
|
|
3
|
+
storage.SetProperty(key, value);
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
function get(key) {
|
|
7
|
+
return storage.GetOptProperty(key);
|
|
8
|
+
}
|
|
9
|
+
function has(key) {
|
|
10
|
+
return storage.HasProperty(key);
|
|
11
|
+
}
|
|
12
|
+
function init() {
|
|
13
|
+
storage = SafeObject();
|
|
14
|
+
}
|
package/build/cache.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"META:NAMESPACE:bt";
|
|
2
|
+
function object_rest(obj, exclude) {
|
|
3
|
+
var newObj;
|
|
4
|
+
var key;
|
|
5
|
+
newObj = {};
|
|
6
|
+
for (key in obj) {
|
|
7
|
+
if (exclude.indexOf(key) >= 0) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
newObj.SetProperty(key, obj.GetProperty(key));
|
|
11
|
+
}
|
|
12
|
+
return newObj;
|
|
13
|
+
}
|
|
14
|
+
function array_rest(arr, start) {
|
|
15
|
+
var newArr;
|
|
16
|
+
var i;
|
|
17
|
+
newArr = [];
|
|
18
|
+
for (i = start; i < arr.length; i++) {
|
|
19
|
+
newArr.push(arr[i]);
|
|
20
|
+
}
|
|
21
|
+
return newArr;
|
|
22
|
+
}
|
package/build/filemap.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"META:NAMESPACE:bt";
|
|
2
|
+
var fileMap = {};
|
|
3
|
+
function getFileUrl(fileKey) {
|
|
4
|
+
return fileMap.GetOptProperty(fileKey);
|
|
5
|
+
}
|
|
6
|
+
function loadFileMap(fileMapFileUrl) {
|
|
7
|
+
var fileMapContent;
|
|
8
|
+
var fileMapJson;
|
|
9
|
+
var fileKey;
|
|
10
|
+
fileMapContent = LoadUrlText(fileMapFileUrl);
|
|
11
|
+
fileMapJson = ParseJson(fileMapContent);
|
|
12
|
+
for (fileKey in fileMapJson) {
|
|
13
|
+
fileMap.SetProperty(fileKey, fileMapJson.GetProperty(fileKey));
|
|
14
|
+
}
|
|
15
|
+
}
|
package/build/init.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var LOG_CODE = "bt-runtime";
|
|
2
|
+
EnableLog(LOG_CODE, true);
|
|
3
|
+
try {
|
|
4
|
+
RegisterCodeLibrary("./polyfill.js");
|
|
5
|
+
RegisterCodeLibrary("./semantic.js");
|
|
6
|
+
RegisterCodeLibrary("./destructuring.js");
|
|
7
|
+
RegisterCodeLibrary("./require.js");
|
|
8
|
+
RegisterCodeLibrary("./cache.js");
|
|
9
|
+
bt.init_polyfill();
|
|
10
|
+
bt.init_require();
|
|
11
|
+
bt.init_cache();
|
|
12
|
+
LogEvent(LOG_CODE, "INFO: bt:runtime module registration success");
|
|
13
|
+
alert("[bt:runtime] INFO: bt:runtime module registration success");
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
LogEvent(LOG_CODE, "ERROR: bt:runtime module registration failed: " + err);
|
|
17
|
+
alert("[bt:runtime] ERROR: bt:runtime module registration failed: " + err);
|
|
18
|
+
}
|
|
19
|
+
function test() {
|
|
20
|
+
alert("hello world");
|
|
21
|
+
function govno() {
|
|
22
|
+
}
|
|
23
|
+
alert("test");
|
|
24
|
+
}
|
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
function at(array, index) {
|
|
2
|
+
var len;
|
|
3
|
+
var normalizedIndex;
|
|
4
|
+
var positiveIndex;
|
|
5
|
+
len = ArrayCount(array);
|
|
6
|
+
normalizedIndex = Int(index);
|
|
7
|
+
if (normalizedIndex < 0) {
|
|
8
|
+
positiveIndex = len + normalizedIndex;
|
|
9
|
+
return positiveIndex >= 0 ? array[positiveIndex] : undefined;
|
|
10
|
+
}
|
|
11
|
+
return normalizedIndex < len ? array[normalizedIndex] : undefined;
|
|
12
|
+
}
|
|
13
|
+
function copyWithin(array, target, start, end) {
|
|
14
|
+
var len;
|
|
15
|
+
var to;
|
|
16
|
+
var from;
|
|
17
|
+
var final;
|
|
18
|
+
var normalizedTarget;
|
|
19
|
+
var normalizedStart;
|
|
20
|
+
var normalizedEnd;
|
|
21
|
+
var count;
|
|
22
|
+
var i;
|
|
23
|
+
len = ArrayCount(array);
|
|
24
|
+
to = Int(target);
|
|
25
|
+
from = Int(start);
|
|
26
|
+
final = OptInt(end) ? Int(end) : len;
|
|
27
|
+
normalizedTarget = to < 0 ? Max(len + to, 0) : Min(to, len);
|
|
28
|
+
normalizedStart = from < 0 ? Max(len + from, 0) : Min(from, len);
|
|
29
|
+
normalizedEnd = final < 0 ? Max(len + final, 0) : Min(final, len);
|
|
30
|
+
count = Min(normalizedEnd - normalizedStart, len - normalizedTarget);
|
|
31
|
+
if (count > 0) {
|
|
32
|
+
if ((normalizedStart < normalizedTarget) && (normalizedTarget < (normalizedStart + count))) {
|
|
33
|
+
for (i = count - 1; i >= 0; i--) {
|
|
34
|
+
array[normalizedTarget + i] = array[normalizedStart + i];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (i = 0; i < count; i++) {
|
|
39
|
+
array[normalizedTarget + i] = array[normalizedStart + i];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return array;
|
|
44
|
+
}
|
|
45
|
+
function entries(array) {
|
|
46
|
+
var result;
|
|
47
|
+
var i;
|
|
48
|
+
result = [];
|
|
49
|
+
for (i = 0; i < ArrayCount(array); i++) {
|
|
50
|
+
result.push([i, array[i]]);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
function every(array, callback) {
|
|
55
|
+
var len;
|
|
56
|
+
var i;
|
|
57
|
+
var value;
|
|
58
|
+
var likeBoolResult;
|
|
59
|
+
len = ArrayCount(array);
|
|
60
|
+
for (i = 0; i < len; i++) {
|
|
61
|
+
value = array[i];
|
|
62
|
+
likeBoolResult = bt.callFunction(callback, [value, i, array]);
|
|
63
|
+
if ((((((likeBoolResult === false) || (likeBoolResult === 0)) || (likeBoolResult === -0)) || (likeBoolResult === "")) || (likeBoolResult === null)) || (likeBoolResult === undefined)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
function fill(array, value, start, end) {
|
|
70
|
+
var len;
|
|
71
|
+
var normalizedStart;
|
|
72
|
+
var normalizedEnd;
|
|
73
|
+
var from;
|
|
74
|
+
var to;
|
|
75
|
+
var i;
|
|
76
|
+
len = ArrayCount(array);
|
|
77
|
+
normalizedStart = start === undefined ? 0 : Int(start);
|
|
78
|
+
normalizedEnd = end === undefined ? len : Int(end);
|
|
79
|
+
from = normalizedStart < 0 ? Max(len + normalizedStart, 0) : Min(normalizedStart, len);
|
|
80
|
+
to = normalizedEnd < 0 ? Max(len + normalizedEnd, 0) : Min(normalizedEnd, len);
|
|
81
|
+
for (i = from; i < to; i++) {
|
|
82
|
+
array[i] = value;
|
|
83
|
+
}
|
|
84
|
+
return array;
|
|
85
|
+
}
|
|
86
|
+
function filter(array, callback) {
|
|
87
|
+
var result;
|
|
88
|
+
var len;
|
|
89
|
+
var i;
|
|
90
|
+
var value;
|
|
91
|
+
var likeBoolResult;
|
|
92
|
+
result = [];
|
|
93
|
+
len = ArrayCount(array);
|
|
94
|
+
for (i = 0; i < len; i++) {
|
|
95
|
+
value = array[i];
|
|
96
|
+
likeBoolResult = bt.callFunction(callback, [value, i, array]);
|
|
97
|
+
if (!((((((likeBoolResult === false) || (likeBoolResult === 0)) || (likeBoolResult === -0)) || (likeBoolResult === "")) || (likeBoolResult === null)) || (likeBoolResult === undefined))) {
|
|
98
|
+
result.push(value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
function find(array, callback) {
|
|
104
|
+
var len;
|
|
105
|
+
var i;
|
|
106
|
+
var value;
|
|
107
|
+
var likeBoolResult;
|
|
108
|
+
len = ArrayCount(array);
|
|
109
|
+
for (i = 0; i < len; i++) {
|
|
110
|
+
value = array[i];
|
|
111
|
+
likeBoolResult = bt.callFunction(callback, [value, i, array]);
|
|
112
|
+
if (!((((((likeBoolResult === false) || (likeBoolResult === 0)) || (likeBoolResult === -0)) || (likeBoolResult === "")) || (likeBoolResult === null)) || (likeBoolResult === undefined))) {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
function findIndex(array, callback) {
|
|
119
|
+
var len;
|
|
120
|
+
var i;
|
|
121
|
+
var value;
|
|
122
|
+
var likeBoolResult;
|
|
123
|
+
len = ArrayCount(array);
|
|
124
|
+
for (i = 0; i < len; i++) {
|
|
125
|
+
value = array[i];
|
|
126
|
+
likeBoolResult = bt.callFunction(callback, [value, i, array]);
|
|
127
|
+
if (!((((((likeBoolResult === false) || (likeBoolResult === 0)) || (likeBoolResult === -0)) || (likeBoolResult === "")) || (likeBoolResult === null)) || (likeBoolResult === undefined))) {
|
|
128
|
+
return i;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return -1;
|
|
132
|
+
}
|
|
133
|
+
function findLast(array, callback) {
|
|
134
|
+
var len;
|
|
135
|
+
var i;
|
|
136
|
+
var value;
|
|
137
|
+
var likeBoolResult;
|
|
138
|
+
len = ArrayCount(array);
|
|
139
|
+
for (i = len - 1; i >= 0; i--) {
|
|
140
|
+
value = array[i];
|
|
141
|
+
likeBoolResult = bt.callFunction(callback, [value, i, array]);
|
|
142
|
+
if (!((((((likeBoolResult === false) || (likeBoolResult === 0)) || (likeBoolResult === -0)) || (likeBoolResult === "")) || (likeBoolResult === null)) || (likeBoolResult === undefined))) {
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
function findLastIndex(array, callback) {
|
|
149
|
+
var len;
|
|
150
|
+
var i;
|
|
151
|
+
var value;
|
|
152
|
+
var likeBoolResult;
|
|
153
|
+
len = ArrayCount(array);
|
|
154
|
+
for (i = len - 1; i >= 0; i--) {
|
|
155
|
+
value = array[i];
|
|
156
|
+
likeBoolResult = bt.callFunction(callback, [value, i, array]);
|
|
157
|
+
if (!((((((likeBoolResult === false) || (likeBoolResult === 0)) || (likeBoolResult === -0)) || (likeBoolResult === "")) || (likeBoolResult === null)) || (likeBoolResult === undefined))) {
|
|
158
|
+
return i;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return -1;
|
|
162
|
+
}
|
|
163
|
+
function flat(array, depth) {
|
|
164
|
+
var result;
|
|
165
|
+
var i;
|
|
166
|
+
var value;
|
|
167
|
+
var flattened;
|
|
168
|
+
var __item0;
|
|
169
|
+
var item;
|
|
170
|
+
depth = depth === undefined ? 1 : Int(depth);
|
|
171
|
+
result = [];
|
|
172
|
+
for (i = 0; i < ArrayCount(array); i++) {
|
|
173
|
+
value = array[i];
|
|
174
|
+
if (IsArray(value) && (depth > 0)) {
|
|
175
|
+
flattened = flat(value, depth - 1);
|
|
176
|
+
for (__item0 in flattened) {
|
|
177
|
+
item = __item0;
|
|
178
|
+
result.push(item);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
result.push(value);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
function flatMap(array, callback) {
|
|
188
|
+
var result;
|
|
189
|
+
var len;
|
|
190
|
+
var i;
|
|
191
|
+
var value;
|
|
192
|
+
var mapped;
|
|
193
|
+
var __item1;
|
|
194
|
+
var item;
|
|
195
|
+
result = [];
|
|
196
|
+
len = ArrayCount(array);
|
|
197
|
+
for (i = 0; i < len; i++) {
|
|
198
|
+
value = array[i];
|
|
199
|
+
mapped = bt.callFunction(callback, [value, i, array]);
|
|
200
|
+
if (IsArray(mapped)) {
|
|
201
|
+
for (__item1 in mapped) {
|
|
202
|
+
item = __item1;
|
|
203
|
+
result.push(item);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
result.push(mapped);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
function forEach(array, callback) {
|
|
213
|
+
var len;
|
|
214
|
+
var i;
|
|
215
|
+
var value;
|
|
216
|
+
len = ArrayCount(array);
|
|
217
|
+
for (i = 0; i < len; i++) {
|
|
218
|
+
value = array[i];
|
|
219
|
+
bt.callFunction(callback, [value, i, array]);
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
function includes(array, searchElement, fromIndex) {
|
|
224
|
+
var from;
|
|
225
|
+
var len;
|
|
226
|
+
var startIndex;
|
|
227
|
+
var i;
|
|
228
|
+
from = fromIndex === undefined ? 0 : Int(fromIndex);
|
|
229
|
+
len = ArrayCount(array);
|
|
230
|
+
startIndex = from >= 0 ? from : Max(len + from, 0);
|
|
231
|
+
for (i = startIndex; i < len; i++) {
|
|
232
|
+
if (array[i] === searchElement) {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
function indexOf(array, searchElement, fromIndex) {
|
|
239
|
+
var from;
|
|
240
|
+
var len;
|
|
241
|
+
var startIndex;
|
|
242
|
+
var i;
|
|
243
|
+
from = fromIndex === undefined ? 0 : Int(fromIndex);
|
|
244
|
+
len = ArrayCount(array);
|
|
245
|
+
startIndex = from >= 0 ? from : Max(len + from, 0);
|
|
246
|
+
for (i = startIndex; i < len; i++) {
|
|
247
|
+
if (array[i] === searchElement) {
|
|
248
|
+
return i;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return -1;
|
|
252
|
+
}
|
|
253
|
+
function join(array, separator) {
|
|
254
|
+
var result;
|
|
255
|
+
var len;
|
|
256
|
+
var i;
|
|
257
|
+
separator = separator === undefined ? "," : separator;
|
|
258
|
+
result = "";
|
|
259
|
+
len = ArrayCount(array);
|
|
260
|
+
for (i = 0; i < len; i++) {
|
|
261
|
+
result += array[i];
|
|
262
|
+
if (i < (len - 1)) {
|
|
263
|
+
result += separator;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
function keys(array) {
|
|
269
|
+
var result;
|
|
270
|
+
var i;
|
|
271
|
+
result = [];
|
|
272
|
+
for (i = 0; i < ArrayCount(array); i++) {
|
|
273
|
+
result.push(i);
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
function lastIndexOf(array, searchElement, fromIndex) {
|
|
278
|
+
var len;
|
|
279
|
+
var from;
|
|
280
|
+
var startIndex;
|
|
281
|
+
var i;
|
|
282
|
+
len = ArrayCount(array);
|
|
283
|
+
from = fromIndex === undefined ? len - 1 : Int(fromIndex);
|
|
284
|
+
startIndex = from >= 0 ? Min(from, len - 1) : len + from;
|
|
285
|
+
for (i = startIndex; i >= 0; i--) {
|
|
286
|
+
if (array[i] === searchElement) {
|
|
287
|
+
return i;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return -1;
|
|
291
|
+
}
|
|
292
|
+
function map(array, callback) {
|
|
293
|
+
var result;
|
|
294
|
+
var len;
|
|
295
|
+
var i;
|
|
296
|
+
var value;
|
|
297
|
+
var mapped;
|
|
298
|
+
result = [];
|
|
299
|
+
len = ArrayCount(array);
|
|
300
|
+
for (i = 0; i < len; i++) {
|
|
301
|
+
value = array[i];
|
|
302
|
+
mapped = bt.callFunction(callback, [value, i, array]);
|
|
303
|
+
result.push(mapped);
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
function pop(array) {
|
|
308
|
+
var len;
|
|
309
|
+
var value;
|
|
310
|
+
len = ArrayCount(array);
|
|
311
|
+
if (len === 0) {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
value = array[len - 1];
|
|
315
|
+
array.splice(len - 1, 1);
|
|
316
|
+
return value;
|
|
317
|
+
}
|
|
318
|
+
function push(array, other) {
|
|
319
|
+
var __item2;
|
|
320
|
+
var item;
|
|
321
|
+
for (__item2 in other) {
|
|
322
|
+
item = __item2;
|
|
323
|
+
array.push(item);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function reduce(array, callback, initialValue) {
|
|
327
|
+
var len;
|
|
328
|
+
var accumulator;
|
|
329
|
+
var startIndex;
|
|
330
|
+
var i;
|
|
331
|
+
var value;
|
|
332
|
+
len = ArrayCount(array);
|
|
333
|
+
accumulator = undefined;
|
|
334
|
+
startIndex = undefined;
|
|
335
|
+
if (initialValue !== undefined) {
|
|
336
|
+
accumulator = initialValue;
|
|
337
|
+
startIndex = 0;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
if (len === 0) {
|
|
341
|
+
throw "Reduce of empty array with no initial value";
|
|
342
|
+
}
|
|
343
|
+
accumulator = array[0];
|
|
344
|
+
startIndex = 1;
|
|
345
|
+
}
|
|
346
|
+
for (i = startIndex; i < len; i++) {
|
|
347
|
+
value = array[i];
|
|
348
|
+
accumulator = bt.callFunction(callback, [accumulator, value, i, array]);
|
|
349
|
+
}
|
|
350
|
+
return accumulator;
|
|
351
|
+
}
|
|
352
|
+
function reduceRight(array, callback, initialValue) {
|
|
353
|
+
var len;
|
|
354
|
+
var accumulator;
|
|
355
|
+
var startIndex;
|
|
356
|
+
var i;
|
|
357
|
+
var value;
|
|
358
|
+
len = ArrayCount(array);
|
|
359
|
+
accumulator = undefined;
|
|
360
|
+
startIndex = undefined;
|
|
361
|
+
if (initialValue !== undefined) {
|
|
362
|
+
accumulator = initialValue;
|
|
363
|
+
startIndex = (len - 1);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
if (len === 0) {
|
|
367
|
+
throw "Reduce of empty array with no initial value";
|
|
368
|
+
}
|
|
369
|
+
accumulator = array[len - 1];
|
|
370
|
+
startIndex = (len - 2);
|
|
371
|
+
}
|
|
372
|
+
for (i = startIndex; i >= 0; i--) {
|
|
373
|
+
value = array[i];
|
|
374
|
+
accumulator = bt.callFunction(callback, [accumulator, value, i, array]);
|
|
375
|
+
}
|
|
376
|
+
return accumulator;
|
|
377
|
+
}
|
|
378
|
+
function reverse(array) {
|
|
379
|
+
var len;
|
|
380
|
+
var mid;
|
|
381
|
+
var i;
|
|
382
|
+
var oppositeIndex;
|
|
383
|
+
var temp;
|
|
384
|
+
len = ArrayCount(array);
|
|
385
|
+
mid = Int(len / 2);
|
|
386
|
+
for (i = 0; i < mid; i++) {
|
|
387
|
+
oppositeIndex = (len - i) - 1;
|
|
388
|
+
temp = array[i];
|
|
389
|
+
array[i] = array[oppositeIndex];
|
|
390
|
+
array[oppositeIndex] = temp;
|
|
391
|
+
}
|
|
392
|
+
return array;
|
|
393
|
+
}
|
|
394
|
+
function shift(array) {
|
|
395
|
+
var len;
|
|
396
|
+
var value;
|
|
397
|
+
len = ArrayCount(array);
|
|
398
|
+
if (len === 0) {
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
value = array[0];
|
|
402
|
+
array.splice(0, 1);
|
|
403
|
+
return value;
|
|
404
|
+
}
|
|
405
|
+
function slice(array, start, end) {
|
|
406
|
+
var len;
|
|
407
|
+
var normalizedStart;
|
|
408
|
+
var normalizedEnd;
|
|
409
|
+
var from;
|
|
410
|
+
var to;
|
|
411
|
+
var result;
|
|
412
|
+
var i;
|
|
413
|
+
len = ArrayCount(array);
|
|
414
|
+
normalizedStart = start === undefined ? 0 : Int(start);
|
|
415
|
+
normalizedEnd = end === undefined ? len : Int(end);
|
|
416
|
+
from = normalizedStart < 0 ? Max(len + normalizedStart, 0) : Min(normalizedStart, len);
|
|
417
|
+
to = normalizedEnd < 0 ? Max(len + normalizedEnd, 0) : Min(normalizedEnd, len);
|
|
418
|
+
result = [];
|
|
419
|
+
for (i = from; i < to; i++) {
|
|
420
|
+
result.push(array[i]);
|
|
421
|
+
}
|
|
422
|
+
return result;
|
|
423
|
+
}
|
|
424
|
+
function some(array, callback) {
|
|
425
|
+
var len;
|
|
426
|
+
var i;
|
|
427
|
+
var value;
|
|
428
|
+
var likeBoolResult;
|
|
429
|
+
len = ArrayCount(array);
|
|
430
|
+
for (i = 0; i < len; i++) {
|
|
431
|
+
value = array[i];
|
|
432
|
+
likeBoolResult = bt.callFunction(callback, [value, i, array]);
|
|
433
|
+
if (!((((((likeBoolResult === false) || (likeBoolResult === 0)) || (likeBoolResult === -0)) || (likeBoolResult === "")) || (likeBoolResult === null)) || (likeBoolResult === undefined))) {
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
function sort(array, compareFn) {
|
|
440
|
+
throw "Array.sort polyfill is not implemented yet";
|
|
441
|
+
}
|
|
442
|
+
function splice(array, start, deleteCount, items) {
|
|
443
|
+
var len;
|
|
444
|
+
var normalizedStart;
|
|
445
|
+
var normalizedDeleteCount;
|
|
446
|
+
var removed;
|
|
447
|
+
var i;
|
|
448
|
+
var newLength;
|
|
449
|
+
var delta;
|
|
450
|
+
deleteCount = deleteCount === undefined ? ArrayCount(array) - start : Int(deleteCount);
|
|
451
|
+
len = ArrayCount(array);
|
|
452
|
+
normalizedStart = start < 0 ? Max(len + start, 0) : Min(start, len);
|
|
453
|
+
normalizedDeleteCount = Min(deleteCount, len - normalizedStart);
|
|
454
|
+
removed = [];
|
|
455
|
+
for (i = 0; i < normalizedDeleteCount; i++) {
|
|
456
|
+
removed.push(array[normalizedStart + i]);
|
|
457
|
+
}
|
|
458
|
+
for (i = normalizedStart; i < (len - normalizedDeleteCount); i++) {
|
|
459
|
+
array[i] = array[i + normalizedDeleteCount];
|
|
460
|
+
}
|
|
461
|
+
for (i = (len - normalizedDeleteCount) - 1; i >= normalizedStart; i--) {
|
|
462
|
+
array[i + items.length] = array[i];
|
|
463
|
+
}
|
|
464
|
+
for (i = 0; i < items.length; i++) {
|
|
465
|
+
array[normalizedStart + i] = items[i];
|
|
466
|
+
}
|
|
467
|
+
newLength = (len - normalizedDeleteCount) + items.length;
|
|
468
|
+
delta = ArrayCount(array) - newLength;
|
|
469
|
+
array.splice(((len - normalizedDeleteCount) + items.length), delta);
|
|
470
|
+
return removed;
|
|
471
|
+
}
|
|
472
|
+
function toReversed(array) {
|
|
473
|
+
var len;
|
|
474
|
+
var result;
|
|
475
|
+
var i;
|
|
476
|
+
len = ArrayCount(array);
|
|
477
|
+
result = [];
|
|
478
|
+
for (i = 0; i < len; i++) {
|
|
479
|
+
result[i] = array[(len - i) - 1];
|
|
480
|
+
}
|
|
481
|
+
return result;
|
|
482
|
+
}
|
|
483
|
+
function toSorted(array, compareFn) {
|
|
484
|
+
throw "Array.toSorted polyfill is not implemented yet";
|
|
485
|
+
}
|
|
486
|
+
function toSpliced(array, start, deleteCount, items) {
|
|
487
|
+
var len;
|
|
488
|
+
var normalizedStart;
|
|
489
|
+
var normalizedDeleteCount;
|
|
490
|
+
var result;
|
|
491
|
+
var i;
|
|
492
|
+
var __item3;
|
|
493
|
+
var item;
|
|
494
|
+
deleteCount = deleteCount === undefined ? ArrayCount(array) - start : Int(deleteCount);
|
|
495
|
+
len = ArrayCount(array);
|
|
496
|
+
normalizedStart = start < 0 ? Max(len + start, 0) : Min(start, len);
|
|
497
|
+
normalizedDeleteCount = Min(deleteCount, len - normalizedStart);
|
|
498
|
+
result = [];
|
|
499
|
+
for (i = 0; i < normalizedStart; i++) {
|
|
500
|
+
result.push(array[i]);
|
|
501
|
+
}
|
|
502
|
+
for (__item3 in items) {
|
|
503
|
+
item = __item3;
|
|
504
|
+
result.push(item);
|
|
505
|
+
}
|
|
506
|
+
for (i = normalizedStart + normalizedDeleteCount; i < len; i++) {
|
|
507
|
+
result.push(array[i]);
|
|
508
|
+
}
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
function unshift(array, items) {
|
|
512
|
+
var len;
|
|
513
|
+
var i;
|
|
514
|
+
len = ArrayCount(array);
|
|
515
|
+
for (i = len - 1; i >= 0; i--) {
|
|
516
|
+
array[i + items.length] = array[i];
|
|
517
|
+
}
|
|
518
|
+
for (i = 0; i < items.length; i++) {
|
|
519
|
+
array[i] = items[i];
|
|
520
|
+
}
|
|
521
|
+
return len + ArrayCount(items);
|
|
522
|
+
}
|
|
523
|
+
function values(array) {
|
|
524
|
+
return ArraySelectAll(array);
|
|
525
|
+
}
|
|
526
|
+
function _with(array, index, value) {
|
|
527
|
+
var len;
|
|
528
|
+
var normalizedIndex;
|
|
529
|
+
var result;
|
|
530
|
+
var i;
|
|
531
|
+
var positiveIndex;
|
|
532
|
+
len = ArrayCount(array);
|
|
533
|
+
normalizedIndex = Int(index);
|
|
534
|
+
result = [];
|
|
535
|
+
for (i = 0; i < len; i++) {
|
|
536
|
+
result[i] = array[i];
|
|
537
|
+
}
|
|
538
|
+
if (normalizedIndex < 0) {
|
|
539
|
+
positiveIndex = len + normalizedIndex;
|
|
540
|
+
if (positiveIndex >= 0) {
|
|
541
|
+
result[positiveIndex] = value;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
if (normalizedIndex < len) {
|
|
546
|
+
result[normalizedIndex] = value;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function abs(num) {
|
|
2
|
+
if (num < 0) {
|
|
3
|
+
return -num;
|
|
4
|
+
}
|
|
5
|
+
else {
|
|
6
|
+
return num;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function ceil(num) {
|
|
10
|
+
var temp;
|
|
11
|
+
temp = undefined;
|
|
12
|
+
if (num < 0) {
|
|
13
|
+
temp = Math.round(-num);
|
|
14
|
+
return -(temp > -num ? temp - 1 : temp);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
temp = Math.round(num);
|
|
18
|
+
return temp < num ? temp + 1 : temp;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function floor(num) {
|
|
22
|
+
if (num < 0) {
|
|
23
|
+
return -(Math.round(-num) < -num ? Math.round(-num) + 1 : Math.round(-num));
|
|
24
|
+
}
|
|
25
|
+
return Math.round(num) > num ? Math.round(num) - 1 : Math.round(num);
|
|
26
|
+
}
|
|
27
|
+
function trunc(num) {
|
|
28
|
+
if (num < 0) {
|
|
29
|
+
return -(Math.round(-num) > -num ? Math.round(-num) - 1 : Math.round(-num));
|
|
30
|
+
}
|
|
31
|
+
return Math.round(num) > num ? Math.round(num) - 1 : Math.round(num);
|
|
32
|
+
}
|
|
33
|
+
function random() {
|
|
34
|
+
var value;
|
|
35
|
+
value = Random(0, 65535);
|
|
36
|
+
return value / 65535;
|
|
37
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function assign(target, source) {
|
|
2
|
+
throw "Not implemented";
|
|
3
|
+
}
|
|
4
|
+
function defineProperties(obj, properties) {
|
|
5
|
+
throw "Not implemented";
|
|
6
|
+
}
|
|
7
|
+
function defineProperty(obj, key, descriptor) {
|
|
8
|
+
throw "Not implemented";
|
|
9
|
+
}
|
|
10
|
+
function entries(obj) {
|
|
11
|
+
throw "Not implemented";
|
|
12
|
+
}
|
|
13
|
+
function fromEntries(entries) {
|
|
14
|
+
throw "Not implemented";
|
|
15
|
+
}
|
|
16
|
+
function groupBy(list, keyGetter) {
|
|
17
|
+
throw "Not implemented";
|
|
18
|
+
}
|
|
19
|
+
function keys(obj) {
|
|
20
|
+
throw "Not implemented";
|
|
21
|
+
}
|
|
22
|
+
function values(obj) {
|
|
23
|
+
throw "Not implemented";
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"META:NAMESPACE:bt";
|
|
2
|
+
var polyfill;
|
|
3
|
+
function init_polyfill() {
|
|
4
|
+
var ArrayPolyfill;
|
|
5
|
+
var ObjectPolyfill;
|
|
6
|
+
var StringPolyfill;
|
|
7
|
+
var MathPolyfill;
|
|
8
|
+
ArrayPolyfill = OpenCodeLibrary("./polyfill/Array.js");
|
|
9
|
+
ObjectPolyfill = OpenCodeLibrary("./polyfill/Object.js");
|
|
10
|
+
StringPolyfill = OpenCodeLibrary("./polyfill/String.js");
|
|
11
|
+
MathPolyfill = OpenCodeLibrary("./polyfill/Math.js");
|
|
12
|
+
polyfill = {
|
|
13
|
+
Array: ArrayPolyfill,
|
|
14
|
+
Math: MathPolyfill,
|
|
15
|
+
Object: ObjectPolyfill,
|
|
16
|
+
String: StringPolyfill
|
|
17
|
+
};
|
|
18
|
+
}
|
package/build/prelude.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/build/require.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"META:NAMESPACE:bt";
|
|
2
|
+
var moduleLock = {};
|
|
3
|
+
var urlCache = {};
|
|
4
|
+
var moduleCache = {};
|
|
5
|
+
function require(moduleName, dirname) {
|
|
6
|
+
var moduleUrl;
|
|
7
|
+
var cachedModule;
|
|
8
|
+
var module;
|
|
9
|
+
moduleUrl = findModuleSafe(moduleName, dirname);
|
|
10
|
+
cachedModule = GetOptObjectProperty(moduleCache, moduleUrl);
|
|
11
|
+
if (cachedModule !== undefined) {
|
|
12
|
+
return cachedModule.exports;
|
|
13
|
+
}
|
|
14
|
+
module = loadModuleSafe(moduleUrl);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
function findModuleSafe(moduleName, dirname) {
|
|
18
|
+
var moduleKey;
|
|
19
|
+
var moduleUrl;
|
|
20
|
+
moduleKey = dirname + moduleName;
|
|
21
|
+
moduleUrl = GetOptObjectProperty(urlCache, moduleKey);
|
|
22
|
+
if (moduleUrl !== undefined) {
|
|
23
|
+
return moduleUrl;
|
|
24
|
+
}
|
|
25
|
+
moduleUrl = findModule(moduleName, dirname);
|
|
26
|
+
if (moduleUrl === undefined) {
|
|
27
|
+
throw "Module not found";
|
|
28
|
+
}
|
|
29
|
+
SetObjectProperty(urlCache, moduleKey, moduleUrl);
|
|
30
|
+
return moduleUrl;
|
|
31
|
+
}
|
|
32
|
+
function findModule(module, dirname) {
|
|
33
|
+
var relativeFileUrl;
|
|
34
|
+
var relativeFilePath;
|
|
35
|
+
var indexFileUrl;
|
|
36
|
+
var indexFilePath;
|
|
37
|
+
var relativeJsFileUrl;
|
|
38
|
+
var relativeJsFilePath;
|
|
39
|
+
var currentDir;
|
|
40
|
+
var currentDirNodeModules;
|
|
41
|
+
var currentDirNodeModulesPath;
|
|
42
|
+
var moduleDirUrl;
|
|
43
|
+
var moduleDirPath;
|
|
44
|
+
var indexModuleFileUrl;
|
|
45
|
+
var indexModuleFilePath;
|
|
46
|
+
var modulePackageFileUrl;
|
|
47
|
+
var modulePackageData;
|
|
48
|
+
var modulePackageJson;
|
|
49
|
+
var moduleMainFile;
|
|
50
|
+
var mainFileUrl;
|
|
51
|
+
var mainFilePath;
|
|
52
|
+
var err;
|
|
53
|
+
var moduleDirJsUrl;
|
|
54
|
+
var moduleDirJsPath;
|
|
55
|
+
if (!StrBegins(dirname, "x-local://")) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
relativeFileUrl = UrlAppendPath(dirname, module);
|
|
59
|
+
relativeFilePath = UrlToFilePath(relativeFileUrl);
|
|
60
|
+
if (FileExists(relativeFilePath)) {
|
|
61
|
+
if (IsDirectory(relativeFilePath)) {
|
|
62
|
+
indexFileUrl = UrlAppendPath(relativeFileUrl, "index.js");
|
|
63
|
+
indexFilePath = UrlToFilePath(indexFileUrl);
|
|
64
|
+
if (FileExists(indexFilePath) && !IsDirectory(indexFilePath)) {
|
|
65
|
+
return indexFileUrl;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw "Module not found";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return relativeFileUrl;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
relativeJsFileUrl = relativeFileUrl + ".js";
|
|
76
|
+
relativeJsFilePath = UrlToFilePath(relativeJsFileUrl);
|
|
77
|
+
if (FileExists(relativeJsFilePath) && !IsDirectory(relativeJsFilePath)) {
|
|
78
|
+
return relativeJsFileUrl;
|
|
79
|
+
}
|
|
80
|
+
currentDir = dirname;
|
|
81
|
+
try {
|
|
82
|
+
while (currentDir !== "x-local://") {
|
|
83
|
+
currentDirNodeModules = UrlAppendPath(currentDir, "node_modules");
|
|
84
|
+
currentDirNodeModulesPath = UrlToFilePath(currentDirNodeModules);
|
|
85
|
+
if (FileExists(currentDirNodeModulesPath) && IsDirectory(currentDirNodeModulesPath)) {
|
|
86
|
+
moduleDirUrl = UrlAppendPath(currentDirNodeModules, module);
|
|
87
|
+
moduleDirPath = UrlToFilePath(moduleDirUrl);
|
|
88
|
+
if (FileExists(moduleDirPath)) {
|
|
89
|
+
if (IsDirectory(moduleDirPath)) {
|
|
90
|
+
indexModuleFileUrl = UrlAppendPath(moduleDirUrl, "index.js");
|
|
91
|
+
indexModuleFilePath = UrlToFilePath(indexModuleFileUrl);
|
|
92
|
+
if (FileExists(indexModuleFilePath) && !IsDirectory(indexModuleFilePath)) {
|
|
93
|
+
return indexModuleFileUrl;
|
|
94
|
+
}
|
|
95
|
+
modulePackageFileUrl = UrlAppendPath(moduleDirUrl, "package.json");
|
|
96
|
+
try {
|
|
97
|
+
modulePackageData = LoadUrlData(modulePackageFileUrl);
|
|
98
|
+
modulePackageJson = ParseJson(modulePackageData);
|
|
99
|
+
moduleMainFile = modulePackageJson.GetOptProperty("main");
|
|
100
|
+
mainFileUrl = UrlAppendPath(moduleDirUrl, moduleMainFile);
|
|
101
|
+
mainFilePath = UrlToFilePath(mainFileUrl);
|
|
102
|
+
if (((moduleMainFile !== undefined) && FileExists(mainFilePath)) && !IsDirectory(mainFilePath)) {
|
|
103
|
+
return mainFileUrl;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return moduleDirUrl;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
moduleDirJsUrl = moduleDirUrl + ".js";
|
|
116
|
+
moduleDirJsPath = UrlToFilePath(moduleDirJsUrl);
|
|
117
|
+
if (FileExists(moduleDirJsPath) && !IsDirectory(moduleDirJsPath)) {
|
|
118
|
+
return moduleDirJsUrl;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
currentDir = UrlParent(currentDir);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
function loadModuleSafe(moduleUrl) {
|
|
130
|
+
var cachedModule;
|
|
131
|
+
var module;
|
|
132
|
+
var err;
|
|
133
|
+
requireLock(moduleUrl);
|
|
134
|
+
try {
|
|
135
|
+
cachedModule = GetOptObjectProperty(moduleCache, moduleUrl);
|
|
136
|
+
if (cachedModule !== undefined) {
|
|
137
|
+
return cachedModule.exports;
|
|
138
|
+
}
|
|
139
|
+
module = loadModule(moduleUrl);
|
|
140
|
+
return module;
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
requireUnlock(moduleUrl);
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
requireUnlock(moduleUrl);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function loadModule(moduleUrl) {
|
|
151
|
+
var moduleLib;
|
|
152
|
+
var moduleContext;
|
|
153
|
+
moduleLib = OpenCodeLibrary(moduleUrl);
|
|
154
|
+
moduleContext = {
|
|
155
|
+
exports: {}
|
|
156
|
+
};
|
|
157
|
+
SetObjectProperty(moduleCache, moduleUrl, moduleContext);
|
|
158
|
+
moduleLib.__init(moduleLib, moduleContext);
|
|
159
|
+
return moduleContext;
|
|
160
|
+
}
|
|
161
|
+
function requireLock(key) {
|
|
162
|
+
var tid;
|
|
163
|
+
var marker;
|
|
164
|
+
var current;
|
|
165
|
+
var i;
|
|
166
|
+
tid = obtainUniqueThreadId();
|
|
167
|
+
marker = {
|
|
168
|
+
owner: tid
|
|
169
|
+
};
|
|
170
|
+
moduleLock.AddProperty(key, marker);
|
|
171
|
+
while (true) {
|
|
172
|
+
current = moduleLock.GetOptProperty(key);
|
|
173
|
+
if (current === marker) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
for (i = 0; i < 100; i++) {
|
|
177
|
+
}
|
|
178
|
+
Sleep(20);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function requireUnlock(key) {
|
|
182
|
+
var tid;
|
|
183
|
+
var current;
|
|
184
|
+
tid = obtainUniqueThreadId();
|
|
185
|
+
current = moduleLock.GetProperty(key);
|
|
186
|
+
if (current === undefined) {
|
|
187
|
+
throw "not locked";
|
|
188
|
+
}
|
|
189
|
+
if (current.owner !== tid) {
|
|
190
|
+
throw "not owner";
|
|
191
|
+
}
|
|
192
|
+
moduleLock.DeleteOptProperty(key);
|
|
193
|
+
}
|
|
194
|
+
function obtainUniqueThreadId() {
|
|
195
|
+
var tid;
|
|
196
|
+
var aux;
|
|
197
|
+
tid = undefined;
|
|
198
|
+
function generateId() {
|
|
199
|
+
return Random(100000, 999999) + "";
|
|
200
|
+
}
|
|
201
|
+
if (LdsIsServer) {
|
|
202
|
+
tid = (tid = ActiveThread.UniqueThreadId);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
aux = CurThreadAuxData;
|
|
206
|
+
if (aux.HasProperty("UniqueThreadId")) {
|
|
207
|
+
tid = aux.UniqueThreadId;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
tid = generateId();
|
|
211
|
+
aux.UniqueThreadId = tid;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return tid;
|
|
215
|
+
}
|
|
216
|
+
function init_require() {
|
|
217
|
+
moduleLock = SafeObject();
|
|
218
|
+
urlCache = SafeObject();
|
|
219
|
+
moduleCache = SafeObject();
|
|
220
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"META:NAMESPACE:bt";
|
|
2
|
+
function getProperty(object, propertyName) {
|
|
3
|
+
var dataType;
|
|
4
|
+
var objectTypeOfObject;
|
|
5
|
+
var returnValue;
|
|
6
|
+
var objectTypeOfReturnValue;
|
|
7
|
+
var newDesc;
|
|
8
|
+
var knownObjectMethods;
|
|
9
|
+
dataType = DataType(object);
|
|
10
|
+
if (dataType === "undefined") {
|
|
11
|
+
throw "TypeError: Cannot read properties of undefined (reading '" + propertyName + "')";
|
|
12
|
+
}
|
|
13
|
+
if (dataType === "null") {
|
|
14
|
+
throw "TypeError: Cannot read properties of null (reading '" + propertyName + "')";
|
|
15
|
+
}
|
|
16
|
+
if (dataType === "object") {
|
|
17
|
+
objectTypeOfObject = ObjectType(object);
|
|
18
|
+
if ((objectTypeOfObject === "JsArray") && (DataType(propertyName) === "integer")) {
|
|
19
|
+
if ((propertyName < 0) || (propertyName >= ArrayCount(object))) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return object[propertyName];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
returnValue = GetOptObjectProperty(object, propertyName);
|
|
27
|
+
objectTypeOfReturnValue = ObjectType(returnValue);
|
|
28
|
+
if (objectTypeOfReturnValue === "JsFuncObject") {
|
|
29
|
+
return returnValue;
|
|
30
|
+
}
|
|
31
|
+
if (((objectTypeOfReturnValue === "JsObject") && returnValue.HasProperty("@descriptor")) && (returnValue.GetProperty("@descriptor") === "function")) {
|
|
32
|
+
if (returnValue.HasProperty("obj") && (returnValue.GetProperty("obj") !== undefined)) {
|
|
33
|
+
return returnValue;
|
|
34
|
+
}
|
|
35
|
+
newDesc = {
|
|
36
|
+
"@descriptor": "function"
|
|
37
|
+
};
|
|
38
|
+
newDesc.SetProperty("obj", object);
|
|
39
|
+
newDesc.SetProperty("env", returnValue.env);
|
|
40
|
+
if (returnValue.HasProperty("callable")) {
|
|
41
|
+
newDesc.SetProperty("callable", returnValue.callable);
|
|
42
|
+
}
|
|
43
|
+
if (returnValue.HasProperty("lib")) {
|
|
44
|
+
newDesc.SetProperty("lib", returnValue.lib);
|
|
45
|
+
}
|
|
46
|
+
if (returnValue.HasProperty("ref")) {
|
|
47
|
+
newDesc.SetProperty("ref", returnValue.ref);
|
|
48
|
+
}
|
|
49
|
+
return newDesc;
|
|
50
|
+
}
|
|
51
|
+
if (returnValue === undefined) {
|
|
52
|
+
if (objectTypeOfObject === "JsObject") {
|
|
53
|
+
knownObjectMethods = ["HasProperty", "AddProperty", "GetOptProperty", "GetProperty", "SetProperty"];
|
|
54
|
+
if (ArrayOptFind(knownObjectMethods, "This === propertyName") !== undefined) {
|
|
55
|
+
return {
|
|
56
|
+
"@descriptor": "function",
|
|
57
|
+
obj: object,
|
|
58
|
+
env: undefined,
|
|
59
|
+
ref: propertyName
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (objectTypeOfObject === "JsArray") {
|
|
64
|
+
knownObjectMethods = ["push"];
|
|
65
|
+
if (ArrayOptFind(knownObjectMethods, "This === propertyName") !== undefined) {
|
|
66
|
+
return {
|
|
67
|
+
"@descriptor": "function",
|
|
68
|
+
obj: object,
|
|
69
|
+
env: undefined,
|
|
70
|
+
ref: propertyName
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (objectTypeOfObject === "DxTrans") {
|
|
75
|
+
knownObjectMethods = ["AddRespHeader", "CheckLdsAuth", "Execute", "GetSessionByID", "HandleNotFound", "PermanentRedirect", "Redirect", "SetRespStatus", "SetWrongAuth", "UpgradeToWebSocket"];
|
|
76
|
+
if (ArrayOptFind(knownObjectMethods, "This === propertyName") !== undefined) {
|
|
77
|
+
return {
|
|
78
|
+
"@descriptor": "function",
|
|
79
|
+
obj: object,
|
|
80
|
+
env: undefined,
|
|
81
|
+
ref: propertyName
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if ((objectTypeOfObject === "BmObject") || (objectTypeOfObject === "JsCodeLibrary")) {
|
|
86
|
+
return {
|
|
87
|
+
"@descriptor": "function",
|
|
88
|
+
obj: object,
|
|
89
|
+
env: undefined,
|
|
90
|
+
ref: propertyName
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return returnValue;
|
|
95
|
+
}
|
|
96
|
+
if (dataType === "string") {
|
|
97
|
+
if (propertyName === "length") {
|
|
98
|
+
return StrCharCount(object);
|
|
99
|
+
}
|
|
100
|
+
knownObjectMethods = ["Allocate", "charAt", "charCodeAt", "fromCharCode", "indexOf", "lastIndexOf", "slice", "split", "substr", "toLowerCase", "ToWinLineBreaks"];
|
|
101
|
+
if (ArrayOptFind(knownObjectMethods, "This === propertyName") !== undefined) {
|
|
102
|
+
return {
|
|
103
|
+
"@descriptor": "function",
|
|
104
|
+
obj: object,
|
|
105
|
+
env: undefined,
|
|
106
|
+
ref: propertyName
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw "TypeError: Cannot read properties of " + dataType + " (reading '" + propertyName + "')";
|
|
111
|
+
}
|
|
112
|
+
function setProperty(object, propertyName, value) {
|
|
113
|
+
var dataTypeOfObject;
|
|
114
|
+
dataTypeOfObject = DataType(object);
|
|
115
|
+
if (dataTypeOfObject === "undefined") {
|
|
116
|
+
throw "TypeError: Cannot set properties of undefined (setting '" + propertyName + "')";
|
|
117
|
+
}
|
|
118
|
+
if (dataTypeOfObject === "null") {
|
|
119
|
+
throw "TypeError: Cannot set properties of null (setting '" + propertyName + "')";
|
|
120
|
+
}
|
|
121
|
+
if (dataTypeOfObject === "object") {
|
|
122
|
+
SetObjectProperty(object, propertyName, value);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
throw "TypeError: Cannot set properties of " + dataTypeOfObject + " (setting '" + propertyName + "')";
|
|
126
|
+
}
|
|
127
|
+
function isFunction(object) {
|
|
128
|
+
var objectType;
|
|
129
|
+
objectType = ObjectType(object);
|
|
130
|
+
return (objectType === "JsFuncObject") || (((objectType === "JsObject") && object.HasProperty("@descriptor")) && (object.GetProperty("@descriptor") === "function"));
|
|
131
|
+
}
|
|
132
|
+
function callFunction(func, args) {
|
|
133
|
+
var funcObjectType;
|
|
134
|
+
var argsEval1;
|
|
135
|
+
var env2;
|
|
136
|
+
var obj2;
|
|
137
|
+
var callable2;
|
|
138
|
+
var env3;
|
|
139
|
+
var obj3;
|
|
140
|
+
var lib3;
|
|
141
|
+
var ref3;
|
|
142
|
+
var env4;
|
|
143
|
+
var obj4;
|
|
144
|
+
var ref4;
|
|
145
|
+
var argsEval4;
|
|
146
|
+
funcObjectType = ObjectType(func);
|
|
147
|
+
if (funcObjectType === "JsFuncObject") {
|
|
148
|
+
argsEval1 = collectArgsToEval("args", args.length);
|
|
149
|
+
return eval("func(" + argsEval1 + ")");
|
|
150
|
+
}
|
|
151
|
+
else if (((funcObjectType === "JsObject") && func.HasProperty("@descriptor")) && (func.GetProperty("@descriptor") === "function")) {
|
|
152
|
+
if (func.HasProperty("callable")) {
|
|
153
|
+
env2 = func.env;
|
|
154
|
+
obj2 = func.obj;
|
|
155
|
+
callable2 = func.callable;
|
|
156
|
+
return eval("callable2(env2, obj2, args)");
|
|
157
|
+
}
|
|
158
|
+
else if (func.HasProperty("lib")) {
|
|
159
|
+
env3 = func.env;
|
|
160
|
+
obj3 = func.obj;
|
|
161
|
+
lib3 = func.lib;
|
|
162
|
+
ref3 = func.ref;
|
|
163
|
+
return eval("lib3." + ref3 + "(env3, obj3, args)");
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
env4 = func.env;
|
|
167
|
+
obj4 = func.obj;
|
|
168
|
+
ref4 = func.ref;
|
|
169
|
+
argsEval4 = collectArgsToEval("args", args.length);
|
|
170
|
+
return eval("obj4." + ref4 + "(" + argsEval4 + ")");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
throw "TypeError: callable is not a function";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function collectArgsToEval(name, count) {
|
|
178
|
+
var args;
|
|
179
|
+
var i;
|
|
180
|
+
args = [];
|
|
181
|
+
for (i = 0; i < count; i++) {
|
|
182
|
+
args.push(((name + "[") + i) + "]");
|
|
183
|
+
}
|
|
184
|
+
return ArrayMerge(args, "This", ", ");
|
|
185
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function init() {
|
|
2
|
+
var LOG_CODE;
|
|
3
|
+
var err;
|
|
4
|
+
LOG_CODE = "bt-runtime";
|
|
5
|
+
EnableLog(LOG_CODE, true);
|
|
6
|
+
try {
|
|
7
|
+
alert("Component bt-runtime initializing...");
|
|
8
|
+
RegisterCodeLibrary("../polyfill.js");
|
|
9
|
+
RegisterCodeLibrary("../semantic.js");
|
|
10
|
+
RegisterCodeLibrary("../destructuring.js");
|
|
11
|
+
RegisterCodeLibrary("../require.js");
|
|
12
|
+
RegisterCodeLibrary("../cache.js");
|
|
13
|
+
bt.init_polyfill();
|
|
14
|
+
bt.init_require();
|
|
15
|
+
bt.init_cache();
|
|
16
|
+
alert("Component bt-runtime initialized");
|
|
17
|
+
LogEvent(LOG_CODE, "INFO: bt-runtime component registration success");
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
alert("ERROR: Component initializing: bt-runtime:\r\n" + err);
|
|
21
|
+
LogEvent(LOG_CODE, "ERROR: bt-runtime component registration failed: " + err);
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@boristype/runtime",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "BorisScript runtime polyfills for the BorisType compiler",
|
|
5
|
+
"files": [
|
|
6
|
+
"build",
|
|
7
|
+
"README.md"
|
|
8
|
+
],
|
|
9
|
+
"author": "punkhomov",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22.0.0"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/BorisType/BorisType.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/BorisType/BorisType/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/BorisType/BorisType#readme",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@boristype/types": "^1.0.0-alpha.3",
|
|
27
|
+
"@boristype/bt-cli": "^0.1.0-alpha.0",
|
|
28
|
+
"@boristype/ws-version": "^0.1.0-alpha.0"
|
|
29
|
+
},
|
|
30
|
+
"ws:package": "system",
|
|
31
|
+
"ws:name": "bt-runtime",
|
|
32
|
+
"ws:root": "./wt/bt/runtime",
|
|
33
|
+
"ws:apiext": {
|
|
34
|
+
"name": "bt:runtime",
|
|
35
|
+
"libs": [
|
|
36
|
+
"./init.xml"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "npx btc build --include-non-ts-files --compile-mode bare && node scripts/gen-package-file.js"
|
|
41
|
+
}
|
|
42
|
+
}
|