Hi all,
I was facing an annoying issue about the hashcode *$N* property, stored
inside the java script object.
I'm using GWT 2.8.2 but no JSNI implementation, only JSInterop objects.
I'm writing an object (JsType native) in order to configure a chart for
Chart.js.
@JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
Every property is the ID of another object.
But unfortunately I got an error from Chart.js because it is scanning all
properties keys to get the objects but it does not recognize the value of
*$H*, being a number and not a object.
scales: {
$H: 135,
x: {id: "x", _charbaId: 2, type: "category", axis: "x", display: true, …},
y: {id: "y", _charbaId: 3, type: "linear", axis: "y", display: true, …}
}
It's clear that a hashcode must be stored therefore there is no way to remove
it.
Searching for a solution, I have found the *javaemul.internal.ObjectHashing*
class which is managing the H$ property, I guess:
public static native int getHashCode(Object o) /*-{
return o.$H || (o.$H = @ObjectHashing::getNextHashId()());
}-*/;
I think the definition of H$ property must be changed, in order to define the
property "not enumerable" (currently is writable, enumerable and configurable)
using *Object.defineProperty()*, as it is reported
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty.
The *Object.defineProperty()* method is not supported into Internet Explorer 8
therefore if going to manage the hascode in this way, GWT will drop the support
on IE8 as well.
In the J2CL implementation, it looks like already aligned with my proposal:
/**
* Utility functions for setting and retrieving system level hashcodes.
*/
class Hashing {
/**
* Gets a hash code on the passed-in object.
*
* @param {*} obj
* @return {number}
* @public
*/
static $getHashCode(obj) {
let o = /** @type {Object} */ (obj);
return o.$systemHashCode || (Object.defineProperties(o, {
$systemHashCode: {value: Hashing.$getNextHashId(), enumerable: false} }),
o.$systemHashCode);
}
Anyway, as workaround, I'm rewriting the hashcode property for this object,
maintaining the same value but setting the property as not enumerale and it
seems working.
--
You received this message because you are subscribed to the Google Groups "GWT
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-web-toolkit-contributors/96ff1644-0d01-44c2-a963-cff4e26dfb8co%40googlegroups.com.