use of net.sourceforge.htmlunit.corejs.javascript.FunctionObject in project htmlunit by HtmlUnit.
the class JavaScriptEngine method configureFunctions.
private static void configureFunctions(final ClassConfiguration config, final ScriptableObject scriptable) {
final int attributes = ScriptableObject.EMPTY;
// the functions
final Map<String, Method> functionMap = config.getFunctionMap();
if (functionMap != null) {
for (final Entry<String, Method> functionInfo : functionMap.entrySet()) {
final String functionName = functionInfo.getKey();
final Method method = functionInfo.getValue();
final FunctionObject functionObject = new FunctionObject(functionName, method, scriptable);
scriptable.defineProperty(functionName, functionObject, attributes);
}
}
}
use of net.sourceforge.htmlunit.corejs.javascript.FunctionObject in project htmlunit by HtmlUnit.
the class JavaScriptEngine method configureStaticFunctions.
private static void configureStaticFunctions(final ClassConfiguration config, final ScriptableObject scriptable) {
final Map<String, Method> staticFunctionMap = config.getStaticFunctionMap();
if (staticFunctionMap != null) {
for (final Entry<String, Method> staticFunctionInfo : staticFunctionMap.entrySet()) {
final String functionName = staticFunctionInfo.getKey();
final Method method = staticFunctionInfo.getValue();
final FunctionObject staticFunctionObject = new FunctionObject(functionName, method, scriptable);
scriptable.defineProperty(functionName, staticFunctionObject, ScriptableObject.EMPTY);
}
}
}
use of net.sourceforge.htmlunit.corejs.javascript.FunctionObject in project htmlunit by HtmlUnit.
the class WindowOrWorkerGlobalScopeMixin method setTimeoutIntervalImpl.
private static int setTimeoutIntervalImpl(final Window window, final Object code, int timeout, final boolean isTimeout, final Object[] params) {
if (timeout < MIN_TIMER_DELAY) {
timeout = MIN_TIMER_DELAY;
}
final WebWindow webWindow = window.getWebWindow();
final Page page = (Page) window.getDomNodeOrNull();
Integer period = null;
if (!isTimeout) {
period = timeout;
}
if (code instanceof String) {
final String s = (String) code;
final String description = "window.set" + (isTimeout ? "Timeout" : "Interval") + "(" + s + ", " + timeout + ")";
final JavaScriptJob job = BackgroundJavaScriptFactory.theFactory().createJavaScriptJob(timeout, period, description, webWindow, s);
return webWindow.getJobManager().addJob(job, page);
}
if (code instanceof Function) {
final Function f = (Function) code;
final String functionName;
if (f instanceof FunctionObject) {
functionName = ((FunctionObject) f).getFunctionName();
} else {
// can this happen?
functionName = String.valueOf(f);
}
final String description = "window.set" + (isTimeout ? "Timeout" : "Interval") + "(" + functionName + ", " + timeout + ")";
final JavaScriptJob job = BackgroundJavaScriptFactory.theFactory().createJavaScriptJob(timeout, period, description, webWindow, f, params);
return webWindow.getJobManager().addJob(job, page);
}
throw Context.reportRuntimeError("Unknown type for function.");
}
use of net.sourceforge.htmlunit.corejs.javascript.FunctionObject in project htmlunit by HtmlUnit.
the class Reflect method setParentScope.
/**
* {@inheritDoc}
*/
@Override
public void setParentScope(final Scriptable scope) {
super.setParentScope(scope);
try {
final FunctionObject functionObject = new FunctionObject("has", getClass().getDeclaredMethod("has", Scriptable.class, String.class), scope);
defineProperty("has", functionObject, ScriptableObject.DONTENUM);
} catch (final Exception e) {
Context.throwAsScriptRuntimeEx(e);
}
}
use of net.sourceforge.htmlunit.corejs.javascript.FunctionObject in project htmlunit by HtmlUnit.
the class Intl method define.
private void define(final Class<? extends HtmlUnitScriptable> c, final BrowserVersion browserVersion) {
try {
final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(c, browserVersion);
final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, this, browserVersion);
final FunctionObject functionObject = new RecursiveFunctionObject(c.getSimpleName(), config.getJsConstructor(), this);
if (c == V8BreakIterator.class) {
prototype.setClassName("v8BreakIterator");
}
functionObject.addAsConstructor(this, prototype);
} catch (final Exception e) {
throw Context.throwAsScriptRuntimeEx(e);
}
}
Aggregations