forked from rizinorg/jsdec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequire.js
51 lines (49 loc) · 1.43 KB
/
require.js
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
// SPDX-FileCopyrightText: 2017-2021 Giovanni Dante Grazioli <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause
var include = function(x) {
return ___internal_load(x);
};
var require = function(x) {
try {
if (arguments.callee.stack[x]) {
console.log("Circular dependency found.", x);
return null;
}
if (arguments.callee.loaded[x]) {
return arguments.callee.loaded[x];
}
arguments.callee.stack[x] = true;
var src = ___internal_require(x);
arguments.callee.loaded[x] = (src)();
arguments.callee.stack[x] = false;
return arguments.callee.loaded[x];
} catch (ee) {
console.log('Exception from ' + x);
console.log(ee.stack);
}
};
require.loaded = {};
require.stack = {};
/**
* https://github.com/svaarala/duktape/blob/master/doc/error-objects.rst
*
* this is required to be the first thing to be setup
* when there is an exception i want to have the whole
* stack to be printed.
*/
Duktape.errCreate = function(err) {
try {
if (typeof err === 'object') {
var exception = {
message: '' + err.message,
stack: '' + err.stack,
lineNumber: '' + err.lineNumber,
};
return exception;
}
} catch (e) {
console.log('Duktape.errCreate exception.');
console.log(e.stack);
}
return err;
};