-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathinsert_safe_exceptions.js
More file actions
87 lines (62 loc) · 1.75 KB
/
insert_safe_exceptions.js
File metadata and controls
87 lines (62 loc) · 1.75 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
var fileName = WScript.Arguments(0),
tempFile = '.\\temp.cxx',
fso = new ActiveXObject('Scripting.FileSystemObject'),
stIn,
stOut,
prefix = "";
stOut = fso.OpenTextFile(fileName, 8);
stOut.WriteLine('');
stOut.Close();
stIn = fso.OpenTextFile(fileName, 1);
stOut = fso.CreateTextFile(tempFile, true);
while (true)
{
var line = stIn.ReadLine();
if (stIn.AtEndOfStream)
break;
stOut.WriteLine(line);
if (line.indexOf('#include "dfwc.h"') !== -1)
prefix = 'dfwc';
else
if (line.indexOf('#include "dfw.h"') !== -1)
prefix = 'dfw';
else
if (beginsWith(line, 'SWIGEXPORT'))
{
var lines = [], linesRelease = [], linesJResult = [];
while (true)
{
line = stIn.ReadLine();
if (stIn.AtEndOfStream || beginsWith(line, ' return jresult;') || beginsWith(line, '}'))
break;
if (line.indexOf('ReleaseStringUTFChars') !== -1)
linesRelease.push(line);
else
if (line.indexOf('jresult =') !== -1 && line.indexOf('NewStringUTF') !== -1)
linesJResult.push(line);
else
lines.push(line);
}
for (var i = 0; i < lines.length; i++)
stOut.WriteLine(lines[i]);
for (var i = 0; i < linesRelease.length; i++)
stOut.WriteLine(linesRelease[i]);
stOut.WriteLine(' if (' + prefix + '_getErrorFlag())');
stOut.WriteLine(' SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, ' + prefix + '_getErrorWhat());');
for (var i = 0; i < linesJResult.length; i++)
stOut.WriteLine(linesJResult[i]);
stOut.WriteLine(line);
}
}
stIn.Close();
stOut.Close();
fso.CopyFile(tempFile, fileName, true);
fso.DeleteFile(tempFile, true);
function beginsWith(str, prefix)
{
if (str.length < prefix.length)
return false;
if (str.substr(0, prefix.length) === prefix)
return true;
return false;
} // beginsWith