Java Code Examples for net.sourceforge.htmlunit.corejs.javascript.Context#javaToJS()
The following examples show how to use
net.sourceforge.htmlunit.corejs.javascript.Context#javaToJS() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodWrapper.java From htmlunit with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object call(final Context context, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final Object javaResp; if (thisObj instanceof ScriptableWrapper) { final ScriptableWrapper wrapper = (ScriptableWrapper) thisObj; final Object wrappedObject = wrapper.getWrappedObject(); if (clazz_.isInstance(wrappedObject)) { // convert arguments final Object[] javaArgs = convertJSArgsToJavaArgs(context, scope, args); try { javaResp = method_.invoke(wrappedObject, javaArgs); } catch (final Exception e) { throw Context.reportRuntimeError("Exception calling wrapped function " + method_.getName() + ": " + e.getMessage()); } } else { throw buildInvalidCallException(thisObj); } } else { throw buildInvalidCallException(thisObj); } final Object jsResp = Context.javaToJS(javaResp, ScriptableObject.getTopLevelScope(scope)); return jsResp; }
Example 2
Source File: ScriptableWrapper.java From htmlunit with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * @see ScriptableObject#get(java.lang.String,net.sourceforge.htmlunit.corejs.javascript.Scriptable) */ @Override public Object get(final String name, final Scriptable start) { final Method propertyGetter = properties_.get(name); final Object response; if (propertyGetter != null) { response = invoke(propertyGetter); } else { final Object fromSuper = super.get(name, start); if (fromSuper != Scriptable.NOT_FOUND) { response = fromSuper; } else { final Object byName = invoke(getByNameFallback_, new Object[] {name}); if (byName != null) { response = byName; } else { response = Scriptable.NOT_FOUND; } } } return Context.javaToJS(response, ScriptableObject .getTopLevelScope(start)); }
Example 3
Source File: ScriptableWrapper.java From htmlunit with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * @see ScriptableObject#get(int, net.sourceforge.htmlunit.corejs.javascript.Scriptable) */ @Override public Object get(final int index, final Scriptable start) { if (getByIndexMethod_ != null) { final Object byIndex = invoke(getByIndexMethod_, new Object[] {Integer.valueOf(index)}); return Context.javaToJS(byIndex, ScriptableObject.getTopLevelScope(start)); } return super.get(index, start); }
Example 4
Source File: MethodWrapper.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object call(final Context context, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final Object javaResp; if (thisObj instanceof ScriptableWrapper) { final ScriptableWrapper wrapper = (ScriptableWrapper) thisObj; final Object wrappedObject = wrapper.getWrappedObject(); if (clazz_.isInstance(wrappedObject)) { // convert arguments final Object[] javaArgs = convertJSArgsToJavaArgs(context, scope, args); try { javaResp = method_.invoke(wrappedObject, javaArgs); } catch (final Exception e) { throw Context.reportRuntimeError("Exception calling wrapped function " + method_.getName() + ": " + e.getMessage()); } } else { throw buildInvalidCallException(thisObj); } } else { throw buildInvalidCallException(thisObj); } final Object jsResp = Context.javaToJS(javaResp, ScriptableObject.getTopLevelScope(scope)); return jsResp; }
Example 5
Source File: ScriptableWrapper.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * @see ScriptableObject#get(String,net.sourceforge.htmlunit.corejs.javascript.Scriptable) */ @Override public Object get(final String name, final Scriptable start) { final Method propertyGetter = properties_.get(name); final Object response; if (propertyGetter != null) { response = invoke(propertyGetter); } else { final Object fromSuper = super.get(name, start); if (fromSuper != Scriptable.NOT_FOUND) { response = fromSuper; } else { final Object byName = invoke(getByNameFallback_, new Object[] {name}); if (byName != null) { response = byName; } else { response = Scriptable.NOT_FOUND; } } } return Context.javaToJS(response, ScriptableObject .getTopLevelScope(start)); }
Example 6
Source File: ScriptableWrapper.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * @see ScriptableObject#get(int, net.sourceforge.htmlunit.corejs.javascript.Scriptable) */ @Override public Object get(final int index, final Scriptable start) { if (getByIndexMethod_ != null) { final Object byIndex = invoke(getByIndexMethod_, new Object[] {Integer.valueOf(index)}); return Context.javaToJS(byIndex, ScriptableObject.getTopLevelScope(start)); } return super.get(index, start); }