this.classLoaderRef = new WeakReference<CompilingClassLoader>(cl);
}
public H getField(H jsContext, String name) {
LowLevelWebKit.pushJsContext(jsContext);
CompilingClassLoader classLoader = classLoaderRef.get();
if (classLoader == null) {
throw new RuntimeException("Invalid class loader.");
}
try {
int dispId = getDispId(name);
if (dispId < 0) {
return LowLevelWebKit.getJsUndefined(jsContext);
}
if (javaDispatch.isField(dispId)) {
Field field = javaDispatch.getField(dispId);
JsValueWebKit<H> jsValue = new JsValueWebKit<H>();
JsValueGlue.set(jsValue, classLoader, field.getType(), javaDispatch.getFieldValue(dispId));
H jsval = jsValue.getJsValue();
// Native code will eat an extra ref.
LowLevelWebKit.gcProtect(jsContext, jsval);
return jsval;
} else {
MethodAdaptor method = javaDispatch.getMethod(dispId);
AccessibleObject obj = method.getUnderlyingObject();
DispatchMethod<?> dispMethod = (DispatchMethod<?>) classLoader.getWrapperForObject(obj);
if (dispMethod == null) {
dispMethod = new MethodDispatch<H>(classLoader, method);
classLoader.putWrapperForObject(obj, dispMethod);
}
// Native code eats the same ref it gave us.
return LowLevelWebKit.wrapDispatchMethod(jsContext, method.toString(), dispMethod);
}
} finally {