-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathj2snotes.txt
More file actions
208 lines (190 loc) · 13.9 KB
/
j2snotes.txt
File metadata and controls
208 lines (190 loc) · 13.9 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
// Requires JSmolCore.js and (for now; probably) JSmol.js
// This version of j2slib requires jQuery and works in both Chrome and MSIE locally,
// though Chrome cannot read local data files, and MSIE cannot read local binary data files.
// Java programming notes by Bob Hanson:
//
// There are a few motifs to avoid when optimizing Java code to work smoothly
// with the J2S compiler:
//
// arrays:
//
// 1. an array with null elements cannot be typed and must be avoided.
// 2. instances of Java "instance of" involving arrays must be found and convered to calls to Clazz.isA...
// 3. new int[n][] must not be used. Use instead JU.AU.newInt2(n);
// 4. new int[] { 1, 2, 3 } has problems because it creates simply [ ] and not IntArray32
//
// numbers:
//
// 1. Remember that EVERY number in JavaScript is a double -- doesn't matter if it is in IntArray32 or not.
// 2. You cannot reliably use Java long, because doubles consume bits for the exponent which cannot be tested.
// 3. Bit 31 of an integer is unreliable, since (int) -1 is now , not just 0zFFFFFFFF, and
// FFFFFFFF + 1 = 100000000, not 0. In JavaScript, 0xFFFFFFFF is 4294967295, not -1.
// This means that writeInt(b) will fail if b is negative. What you need is instead
// writeInt((int)(b & 0xFFFFFFFFl) so that JavaScript knocks off the high bits explicitly.
//
// general:
//
// 1. j2sRequireImport xxxx is needed if xxxx is a method used in a static function
// 2. URL.getContent() is not supported. Use other means based on URL.toString()
// 3. It is critical for performance to avoid any significant amount of function overloading.
// In particular, methods such as xxx(int a, int b) and xxx(float a, int b) MUST be renamed,
// because JavaScript only has Number, and there is absolutely no way to tell these apart.
// It's probably bad Java programming, anyway.
// 4. Calls to super(...) can almost always be avoided. These trigger the SAEM
// (searchAndExecuteMethod) call, and it is very destructive to performance.
// Just find another way to do it.
// NOTES by Bob Hanson:
// J2S class changes:
// BH 12/21/2015 6:14:59 PM adding typeArray.buffer.slice to be compatible with Safari
// BH 12/20/2015 6:13:52 AM adding Int8Array; streamlining array checking
// BH 12/18/2015 5:02:52 PM adding .slice and also better array copy
// BH 7/24/2015 6:48:50 AM adding optional ?j2sdebug flag on page URL
// -- switches to using j2s/core/corexxx.js, not j2s/core/corexxx.z.js
// -- adds ";//# sourceURL="+file in eval(js)
// -- enables DebugJS.$(msg) call to debugger;
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
// see https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Debug_eval_sources
// BH 7/23/2015 6:45:55 PM added sourceURL in each js class eval(), allowing full
// breakpoint debugging and code checking in Firefox and Chrome
// BH 7/19/2015 6:18:17 PM added os.name, line.separator, etc. to System.getProperty()
// BH 7/19/2015 5:39:10 PM added java.lang.System = System
// BH 7/19/2015 10:33:10 AM fix for SAEM equating "null" with number or boolean
// BH 7/18/2015 6:08:05 PM for Jmol I was able to remove the $private/$fx business, but now
// I see that in general that cannot be done. Thinking about a strategy...
// BH 7/18/2015 4:43:38 PM better handling of TypeError and InternalError for e.getMessage() and e.getStackTrace()
// BH 7/17/2015 11:51:15 AM adds class.getResource(name) and class.getResourceAsStream(name)
// BH 7/16/2015 7:56:49 PM general instantiation using any constructor (in Java here):
// BH x = class.forName("my.class.name").newInstance()
// BH or
// BH x = class.forName("my.class.name").getConstructor(String.class,String.class).newInstance(new Object[] {"test", "now"})
// BH 7/15/2015 11:34:58 PM adding System.lineSeparator()
// BH 7/15/2015 7:32:41 AM adding class.getCanonicalName == getName
// BH 5/31/2015 5:38:14 PM NPEExceptionPredicate fix
// BH 4/25/2015 9:16:12 AM SAEM misrepresnting Number as Object in parameters and Integer as Number
// BH 4/24/2015 7:32:54 AM Object.hashCode() and System.getIdentityHashCode() fail. changed to: return this._$hashcode || (this._$hashcode = ++Clazz._hashCode)
// BH 4/23/2015 9:08:59 AM Clazz.instanceOf(a, b) needs to check for a == b.
// BH 4/23/2015 9:08:59 AM xx.getContentType() is nonfunctional. Array.newInstance now defines a wrapper for .getClass().getComponentType() that works
// BH 4/12/2015 11:48:03 AM added Clazz.getStackTrace(-n) -- reports actual parameter values for n levels
// BH 4/10/2015 8:23:05 AM adding Int32Array.prototype.clone and Float64.prototype.clone
// BH 4/5/2015 8:12:57 AM refactoring j2slib (this file) to make private functions really private using var
// BH 4/3/2015 6:14:34 AM adding anonymous local "ClazzLoader" (Clazz._Loader) --> "_Loader"
// BH 4/3/2015 6:14:34 AM adding Clazz._Loader._classPending, Clazz._Loader._classCount
// BH 4/3/2015 6:14:34 AM adding Clazz._Loader._checkLoad
// -- forces asynchronous class loading
// -- builds Clazz._Loader._classPending and Clazz._classCount
// -- allows reporting
// BH 3/24/2015 4:11:26 AM better file load failure message in _Loader.evaluate
// BH 2/28/2015 7:30:25 AM corrects newIntArray32() and newArray() for pre-defined arrays
// int[] a = new int[] {1,2,3,343};
// int[][] b = new int[][] {new int[]{4,5},new int[]{5,6}};
// BH 9/29/2014 11:34:19 PM removing support for getClass().isArray()
// BH 8/29/2014 9:15:57 AM total reworking of Java2Script in preparation for all-asynchronous loading
// (currently sync loading is only for
// LOAD command and load() function without ASYNC
// getInterface()
// see JSmol.js and Jmol._isAsync flag
// BH 5/11/2015 5:58:42 AM adding __signatures for debugging SAEM issues
// BH 3/29/2015 8:12:44 PM System.getProperty(x, "") does not return ""
// BH 8/23/2014 10:04:19 AM cleaning up a few general methods; Clazz.removeArrayItem
// BH 6/1/2014 10:58:46 AM fix for Clazz.isAP() not working
// BH 5/26/2014 5:19:29 PM removing superConstructor call in creating Enum constants
// BH 4/1/2014 7:55:54 PM removing all $fz references and instances where sub/super classes have same private function names
// BH 4/1/2014 4:47:30 PM all $_X removed; this is taken care of by Google Closure Compiler
// BH 4/1/2014 6:40:08 AM removing ClassLoader -- equals Clazz._Loader
// BH 4/1/2014 6:40:08 AM removing ClassLoaderProgressMonitor -- equals _LoaderProgressMonitor
// BH 4/1/2014 6:17:21 AM removing Class -- only used for "Class.forName" in Jmol, which ANT will now change to "Clazz._4Name"
// BH 3/7/2014 9:05:06 AM Array.prototype.toString should not be aliased. -- http://sourceforge.net/p/jmol/bugs/560/ with Google Visualization
// BH 1/30/2014 12:54:22 PM gave all field variables prefix underscore. This allows Google Closure Compiler to skip them.
// BH 12/3/2013 3:39:57 PM window["j2s.lib"].base implemented
// BH 12/1/2013 5:34:21 AM removed _LoaderProgressMonitor.initialize and all Clazz.event business; handled by Jmol.clearVars()
// BH 11/30/2013 12:43:58 PM adding Clazz.arrayIs() -- avoids Number.constructor.toString() infinite recursion
// BH 11/29/2013 6:33:51 AM adding Clazz._profiler -- reports use of SAEM
// BH 11/10/2013 9:02:20 AM fixing fading in MSIE
// BH 11/3/2013 7:21:39 AM additional wrapping functions for better compressibility
// BH 10/30/2013 8:10:58 AM added getClass().getResource() -- returning a relative string, not a URL
// BH 10/30/2013 6:43:00 AM removed second System def and added System.$props and default System.property "line.separator"
// BH 6/15/2013 8:02:07 AM corrections to Class.isAS to return true if first element is null
// BH 6/14/2013 4:41:09 PM corrections to Clazz.isAI and related methods to include check for null object
// BH 3/17/2013 11:54:28 AM adds stackTrace for ERROR
// BH 3/13/2013 6:58:26 PM adds Clazz.clone(me) for BS clone
// BH 3/12/2013 6:30:53 AM fixes Clazz.exceptionOf for ERROR condition trapping
// BH 3/2/2013 9:09:53 AM delete globals c$ and $fz
// BH 3/2/2013 9:10:45 AM optimizing defineMethod using "look no further" "@" parameter designation (see "\\@" below -- removed 3/23/13)
// BH 2/27/2013 optimizing Clazz.getParamsType for common cases () and (Number)
// BH 2/27/2013 optimizing SAEM delegation for hashCode and equals -- disallows overloading of equals(Object)
// BH 2/23/2013 found String.replaceAll does not work -- solution was to never call it.
// BH 2/9/2013 9:18:03 PM Int32Array/Float64Array fixed for MSIE9
// BH 1/25/2013 1:55:31 AM moved package.js from j2s/java to j2s/core
// BH 1/17/2013 4:37:17 PM String.compareTo() added
// BH 1/17/2013 4:52:22 PM Int32Array and Float64Array may not have .prototype.sort method
// BH 1/16/2013 6:20:34 PM Float64Array not available in Safari 5.1
// BH 1/14/2013 11:28:58 PM Going to all doubles in JavaScript (Float64Array, not Float32Array)
// so that (new float[] {13.48f})[0] == 13.48f, effectively
// BH 1/14/2013 12:53:41 AM Fix for Opera 10 not loading any files
// BH 1/13/2013 11:50:11 PM Fix for MSIE not loading (nonbinary) files locally
// BH 12/1/2012 9:52:26 AM Compiler note: Thread.start() cannot be executed within the constructor;
// BH 11/24/2012 11:08:39 AM removed unneeded sections
// BH 11/24/2012 10:23:22 AM all XHR uses sync loading (_Loader.setLoadingMode)
// BH 11/21/2012 7:30:06 PM if (base) map["@" + pkg] = base; critical for multiple applets
// BH 10/8/2012 3:27:41 PM if (clazzName.indexOf("Array") >= 0) return "Array"; in Clazz.getClassName for function
// BH removed Clazz.ie$plit = "\\2".split (/\\/).length == 1; unnecessary; using RegEx slows process significantly in all browsers
// BH 10/6/12 added Int32Array, Float32Array, newArrayBH, upgraded java.lang and java.io
// BH added Integer.bitCount in core.z.js
// BH changed alert to Clazz.alert in java.lang.Class.js *.ClassLoader.js, java.lang.thread.js
// BH removed toString from innerFunctionNames due to infinite recursion
// BH note: Logger.error(null, e) does not work -- get no constructor for (String) (TypeError)
// BH added j2s.lib.console
// BH allowed for alias="."
// BH removed alert def --> Clazz.alert
// BH added wrapper at line 2856
// BH newArray fix at line 2205
// BH System.getProperty fix at line 6693
// BH added Enum .value() method at line 2183
// BH added System.getSecurityManager() at end
// BH added String.contains() at end
// BH added System.gc() at end
// BH added Clazz.exceptionOf = updated
// BH added String.getBytes() at end
// JSmolJavaExt.js
// This library will be wrapped by an additional anonymous function using ANT in
// build_03_tojs.xml. This task will also modify variable names. References
// to Clazz._ will not be changed, but other Clazz.xxx will be changed to
// (local scope) Clazz_xxx, allowing them to be further compressed using
// Google Closure Compiler in that same ANT task.
// BH 6/10/2016 4:20:15 PM removed Clazz.dateToString
// BH 6/10/2016 5:53:20 AM aligned with SwingJS; combined with j2sJmol.js (same as j2sSwingjs)
// BH 3/9/2016 6:25:08 PM at least allow Error() by itself to work as before (inchi.js uses this)
// BH 12/21/2015 1:31:41 PM fixing String.instantialize for generic typed array
// BH 9/19/2015 11:05:45 PM Float.isInfinite(), Float.isNaN(), Double.isInfinite(), Double.isNaN() all not implemented
// BH 5/31/2015 5:53:04 PM Number.compareTo added
// BH 5/21/2015 5:46:30 PM Number("0xFFFFFFFF") is not -1
// BH 4/23/2015 9:08:59 AM xx.getComponentType() is nonfunctional. Array.newInstance now defines a wrapper for .getClass().getComponentType() that works
// BH 4/12/2015 1:37:44 PM adding Math.rint = Math.round
// BH 1/16/2015 10:09:38 AM Chrome failure jqGrig due to new String("x").toString() not being a simple string
// BH 8/14/2014 6:49:22 PM Character class efficiencies
// BH 7/24/2014 9:02:18 AM most browsers do not support String.codePointAt()
// BH 7/11/2014 4:17:22 PM fix for Boolean.valueOf("false") not being false
// BH 5/27/2014 6:29:59 AM ensure floats and doubles have decimal point in toString
// BH 4/1/2014 12:23:41 PM Encoding moved to Clazz._Encoding;
// BH 4/1/2014 7:51:46 AM removing java.lang.B00lean
// BH 3/7/2014 9:17:10 AM removing Array.toString; moving that code here from j2sJmol.js
// BH 1/30/2014 9:04:25 AM adding Throwable.getStackTrace() as a STRING
// BH 12/4/2013 9:20:44 PM fix for reassigning Date.prototype.toString()
// BH 12/3/2013 11:43:10 AM bizarre Safari bug in reassigning Boolean (OK, I admit, we shouldn't have done that...)
// BH 12/1/2013 6:50:16 AM evit Number.prototype.toString assignment removed!
// BH 11/30/2013 1:46:31 PM fixing Byte, Short, Long, Integer, Float, Double to reflect proper bounds and error conditions
// BH 11/29/2013 8:58:49 PM removing Boolean.toString(boolean)
// BH 11/4/2013 7:34:26 AM changing "var nativeClazz" to "var nativeClass" to avoid ANT replacement of "nativeClazz." to "nativeClazz_"
// BH 10/19/2013 1:29:27 PM fixed String.$replace()
// BH 10/18/2013 6:09:23 PM fixed (Double|Float).valueOf(NaN).valueOf(), which should return NaN, not throw an error
// BH 10/12/2013 11:18:44 AM fixed bug in Double(String) and Float(String) that was returning typeof "string"
// BH 10/10/2013 2:40:20 PM added Math.log10
// BH 7/23/2013 7:24:01 AM fixing Number.shortValue() and Number.byteValue() for negative values
// BH 6/16/2013 1:31:30 PM adding /| in String.replace -- thank you David Koes
// BH 3/13/2013 12:49:23 PM setting Boolean.valueOf() "@"
// BH 3/2/2013 10:46:45 PM removed Double.valueOf(String)
// BH 1/7/2013 7:40:06 AM added Clazz.dateToString
// BH 11/6/2012 8:26:33 PM added instanceof Int32Array in String.instantialize
// BH 10/13/2012 11:38:07 PM corrected Integer.parseInt to allow only +-0123456789; created Integer.parseIntRadix
// BH 11/1/2012 added Short
// BH 9/10/2012 6:27:21 AM added java.net.URL... classes