AFaust / alfresco-enhanced-script-environment

Eclipse Public License 1.0
12 stars 5 forks source link

Provide utility / enhancement to allow "===" comparison of JavaScript native objects with Java counterparts #5

Open AFaust opened 11 years ago

AFaust commented 11 years ago

Currently, a JavaScript native String cannot be compared using "===" with a Java String even if both have identical content and are - for all intents and purposes - identical from a scripting perspective. The same applies to other types of native JavaScript value types and their Java (java.lang) counterparts. It should be evaluated if Rhino allows us to provide an enhancement of the environment to allow transparent use of "===" for native JavaScript and equivalent Java objects.

AFaust commented 11 years ago

"===" / "!==" or better the "shallow (in)equality operator" is implemented at a static level in ScriptRuntime and can't be altered without recompiling Rhino. Only the the "==" / "!=" or regular "(in)equality operator" automatically performs a Java String-equality check if either the first left-hand-side expression resolves to a Java String or the right-hand-side expressions resolves to a Java String while the left-hand-side expression resolves to a Scriptable (NativeString is Scriptable).

Interestingly enough, the NativeString class does not seem to support "shallow (in)equality" correctly when two String literals from different source files are used as these do not evaluate to the same instance as required by the base ScriptableObject implementation for "equivalentValues()".

Furthermore, the Rhino interpretation of "===" / "!==" as "shallow (in)equality" operators does not correspond to the "strict equals" and "strict does-not-equals" operator specified in ECMA (http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.4 and http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.5)